# epireve/grocerygo architecture

> Architecture diagram of the GitHub repository epireve/grocerygo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/epireve/grocerygo
- Repository: https://github.com/epireve/grocerygo

## Overview

##### Project type and purpose
- GroceryGo is a monolithic Django web application (MVT pattern) for online grocery shopping, with separate apps for user accounts, products, cart, orders, and shared “core” logic.
- It also includes an enhanced Admin Dashboard exposing custom API endpoints (e.g. sales trends, low-stock alerts) and a static frontend built with Tailwind CSS and Shadcn/ui, plus Chart.js visualizations.

##### Main components
A. Presentation Layer
- Web Browser / Client
- Static Assets Server (Tailwind CSS, JS bundles, images)
- Templates (HTML + Shadcn/ui)
B. Application Layer (Django services)
- Django Core (URL routing, middleware)
- Accounts app (authentication, profiles, password reset)
- Products app (product & category models, management)
- Cart app (cart management, coupon logic)
- Orders app (order placement, status history)
- Admin Dashboard (custom BI APIs + Chart.js data endpoints)
C. Data Layer
- SQLite database (all models consolidated; migrations managed per app)

##### Relationships and data flow
- Browser → HTTP requests → Django URL router
- Router → appropriate app view → ORM queries → SQLite → view logic
- View → renders Template + Context → Browser
- Browser (Admin UI) → AJAX to Admin API endpoints → JSON (sales trend, order status, low-stock)
- Static assets served directly (or via `collectstatic`) to Browser
- Scripts (run-dev, import, tests) interact directly with management commands and database

##### Architectural patterns and design principles
- Layered architecture (Presentation / Application / Data)
- Monolithic Django MVT with clearly separated apps per domain
- Custom API layer within Django admin for real-time BI
- Theme management and data visualization decoupled via CSS variables and Chart.js
- Migration-aware testing infrastructure (custom test runner, schema fixes)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Web Browser / Client"]:::presentation
        StaticAssets["Static Assets Server"]:::presentation
        Templates["Templates (HTML + Shadcn/ui)"]:::presentation
    end

    %% Backend Layer
    subgraph "Django Backend" 
        direction TB
        Core["Core (routing, middleware)"]:::backend
        Accounts["Accounts App"]:::backend
        Products["Products App"]:::backend
        Cart["Cart App"]:::backend
        Orders["Orders App"]:::backend
        AdminAPI["Admin Dashboard & API"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["SQLite Database"]:::data
        Media["Media Storage"]:::data
    end

    %% Connections
    Browser -->|"HTTP GET/POST"| Core
    Core -->|"dispatch to app view"| Accounts
    Core -->|"dispatch to app view"| Products
    Core -->|"dispatch to app view"| Cart
    Core -->|"dispatch to app view"| Orders
    Core -->|"dispatch to Admin API"| AdminAPI
    Accounts -->|"ORM read/write"| DB
    Products -->|"ORM read/write"| DB
    Cart -->|"ORM read/write"| DB
    Orders -->|"ORM read/write"| DB
    AdminAPI -->|"ORM read/write"| DB
    Core -->|"renders HTML/JSON response"| Browser
    Browser -->|"AJAX → /admin/api/* → JSON"| AdminAPI
    Browser -->|"GET CSS/JS/images"| StaticAssets
    StaticAssets -->|"serves assets"| Browser
    Core -->|"loads Templates"| Templates
    Core -->|"uses Templates"| Browser
    Products --> Media
    Cart --> Media
    Orders --> Media

    %% Click Events
    click StaticAssets "https://github.com/epireve/grocerygo/tree/main/grocery_go/static_src/"
    click Templates "https://github.com/epireve/grocerygo/tree/main/grocery_go/templates/"
    click Core "https://github.com/epireve/grocerygo/blob/main/grocerygo/urls.py"
    click Accounts "https://github.com/epireve/grocerygo/tree/main/accounts/"
    click Products "https://github.com/epireve/grocerygo/tree/main/products/"
    click Cart "https://github.com/epireve/grocerygo/tree/main/cart/"
    click Orders "https://github.com/epireve/grocerygo/tree/main/orders/"
    click AdminAPI "https://github.com/epireve/grocerygo/blob/main/grocerygo/admin.py"
    click DB "https://github.com/epireve/grocerygo/blob/main/db.sqlite3"
    click Media "https://github.com/epireve/grocerygo/tree/main/media/"

    %% Styles
    classDef presentation fill:#cfe2f3,stroke:#333,stroke-width:1px
    classDef backend fill:#d9ead3,stroke:#333,stroke-width:1px
    classDef data fill:#fce5cd,stroke:#333,stroke-width:1px
```
