# staciax/django-book-store architecture

> Architecture diagram of the GitHub repository staciax/django-book-store, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/staciax/django-book-store
- Repository: https://github.com/staciax/django-book-store

## Overview

##### Project type and purpose
- This is a full‑stack Django web application serving an academic e‑commerce platform for novels, anime, and comic books.
- It uses:
- Django for the backend (MVC pattern with apps “store” and “user”)
- A Next.js‑style file‑based router under `store/routes` for server‑side rendered pages
- Tailwind CSS and vanilla JS for frontend styling and interactive widgets
- PostgreSQL as the relational database
- A Docker Compose setup for containerized deployment

##### File structure
- Top‐level: Docker config (`Dockerfile`, `docker-compose.yaml`, `.env.example`, `entrypoint.sh`), Makefile, Python/Node configuration.
- `app/`: Django project configuration (settings, ASGI/WSGI, URLs).
- `store/`: Main shop app containing:
- `models/`, `migrations/` (data layer)
- `views/`, `routes/` (presentation and routing layer)
- `templates/`, `static/` (static assets and HTML templates)
- `forms/`, `admin/`, `context_processors/` (auxiliary modules)
- `core/routers.py` implements the custom “page.py” render logic
- `user/`: Authentication models and admin
- Node tooling: `package.json`, Tailwind config, ESLint, Prettier

##### README insights
- Describes features: membership, search, cart, payment, order history
- Emphasizes environment variables for Django, payment (PromptPay), and Postgres
- Explains file‑based routing like Next.js under `store/routes`

##### Main components
a. Client
- Browser requests HTML pages, CSS, JS assets
- Interacts (via forms, AJAX) with backend APIs for cart, login, checkout
b. Reverse Proxy / Web Server (optional)
- Nginx or Gunicorn/ Daphne container in front of Django
- Serves static assets, routes dynamic requests to Django ASGI/WSGI
c. Django Backend
- `app/` project: global settings, URL dispatcher
- `store/` app:
- Models (products, users, orders, payments, etc.)
- Views & routers (`views/` + `routes/`), template rendering
- Admin interface (`admin/`)
- `user/` app: user model and authentication
d. Database
- PostgreSQL container managed via Docker Compose
e. Static‑build Tooling
- Node container for Tailwind CSS (`npm run dev`), ESLint, Prettier
f. External Services
- PromptPay payment API

##### Relationships and interactions
- Client → Web Server
- GET/POST requests for pages, form submits, API calls
- Web Server ↔ Django ASGI/WSGI
- Django handles routing (`app/urls.py` + `store/routes`) and view logic
- Django → PostgreSQL
- ORM queries/transactions for products, users, orders
- Django → PromptPay API
- Payment initiation and callback handling
- Node/Tailwind process → Static assets
- Generates CSS and JS which are served by Web Server

##### Architectural patterns and principles
- MVC:
- Models in `store/models` and `user/models`
- Views/Controllers in `store/views` and `store/routes`
- Templates in `store/templates`
- File‑based routing inspired by Next.js under `store/routes`
- Modular Django apps (separation of store vs. user)
- Containerization and environment‑driven configuration

##### Important details to capture
- Django’s custom router layer (`store/core/routers.py`) for auto‑detecting templates
- The split between template‑based pages (`.html`) and their corresponding `page.py` handlers
- The administrative interface (`/admin/`) backed by `store/admin/*.py`
- Environment variables driving secrets, DB connections, and payment credentials
- The Docker Compose relationship between Django, Postgres, and Node/Tailwind

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Client Browser"]:::frontend
    Browser -->|HTTP GET/POST| WebServer

    %% Web Server / Reverse Proxy
    subgraph "Web Server Container"
        direction TB
        WebServer["Nginx / Gunicorn / Daphne"]:::backend
        WebServer -->|Static Files| StaticAssets
        WebServer -->|Dynamic Requests| ASGIApp
    end
    click Dockerfile "https://github.com/staciax/django-book-store/tree/master/Dockerfile"
    click dockerCompose "https://github.com/staciax/django-book-store/blob/master/docker-compose.yaml"
    click entrypoint "https://github.com/staciax/django-book-store/blob/master/entrypoint.sh"

    %% Static Assets Node
    StaticAssets["Static Assets (CSS/JS/HTML)"]:::frontend

    %% Django Application
    subgraph "Django Application Container"
        direction TB
        ASGIApp["app/asgi.py"]:::backend
        WSGIApp["app/wsgi.py"]:::backend
        Settings["app/settings.py"]:::backend
        URLs["app/urls.py"]:::backend

        ASGIApp -->|Routes| URLs
        ASGIApp -->|Config| Settings

        subgraph "Store App"
            direction TB
            Routers["store/core/routers.py"]:::backend
            ModelsGroup["Models"]:::backend
            ViewsGroup["Views & Controllers"]:::backend
            RoutesGroup["File-based Routes"]:::backend
            TemplatesGroup["Templates"]:::frontend
            StaticGroup["Static (store/static/)"]:::frontend
            AdminGroup["Admin Interface"]:::backend
            FormsGroup["Forms"]:::backend
            ContextGroup["Context Processors"]:::backend

            ModelsGroup --> Routers
            RoutesGroup --> Routers
            ViewsGroup --> Routers
            TemplatesGroup --> RoutesGroup
            StaticGroup --> StaticAssets
        end

        subgraph "User App"
            direction TB
            UserModels["user/models.py"]:::backend
            UserAdmin["user/admin.py"]:::backend
            UserMigrations["user/migrations/0001_initial.py"]:::backend
        end

        ASGIApp -->|Includes app/urls.py| URLs
        URLs -->|store/* and user/*| Routers
        URLs -->|admin/| AdminGroup
    end
    click asgi "https://github.com/staciax/django-book-store/blob/master/app/asgi.py"
    click wsgi "https://github.com/staciax/django-book-store/blob/master/app/wsgi.py"
    click settings "https://github.com/staciax/django-book-store/blob/master/app/settings.py"
    click urls "https://github.com/staciax/django-book-store/blob/master/app/urls.py"

    click routers "https://github.com/staciax/django-book-store/blob/master/store/core/routers.py"

    click prodModel "https://github.com/staciax/django-book-store/blob/master/store/models/products.py"
    click cartModel "https://github.com/staciax/django-book-store/blob/master/store/models/carts.py"
    click orderModel "https://github.com/staciax/django-book-store/blob/master/store/models/orders.py"
    click paymentModel "https://github.com/staciax/django-book-store/blob/master/store/models/payments.py"

    click viewCarts "https://github.com/staciax/django-book-store/blob/master/store/views/carts.py"
    click viewOrders "https://github.com/staciax/django-book-store/blob/master/store/views/orders.py"
    click viewPayments "https://github.com/staciax/django-book-store/blob/master/store/views/payments.py"

    click routeCheckout "https://github.com/staciax/django-book-store/blob/master/store/routes/store/cart/checkout/page.py"
    click templates "https://github.com/staciax/django-book-store/tree/master/store/templates/"
    click cssFile "https://github.com/staciax/django-book-store/blob/master/store/static/store/css/style.css"
    click jsCart "https://github.com/staciax/django-book-store/blob/master/store/static/store/js/cart.js"
    click jsSearch "https://github.com/staciax/django-book-store/blob/master/store/static/store/js/search-box.js"

    click adminProd "https://github.com/staciax/django-book-store/blob/master/store/admin/products.py"
    click adminOrders "https://github.com/staciax/django-book-store/blob/master/store/admin/orders.py"
    click adminPayments "https://github.com/staciax/django-book-store/blob/master/store/admin/payments.py"

    click formOrders "https://github.com/staciax/django-book-store/blob/master/store/forms/orders.py"
    click contextAccount "https://github.com/staciax/django-book-store/blob/master/store/context_processors/account.py"

    click userModels "https://github.com/staciax/django-book-store/blob/master/user/models.py"
    click userAdmin "https://github.com/staciax/django-book-store/blob/master/user/admin.py"
    click userMigrations "https://github.com/staciax/django-book-store/blob/master/user/migrations/0001_initial.py"

    %% Node/Tailwind Container
    subgraph "Static Build Tooling (Node Container)"
        direction TB
        PackageJSON["package.json"]:::frontend
        TailwindConfig["tailwind.config.mjs"]:::frontend
        PostCSSConfig["postcss.config.mjs"]:::frontend
        ESLintConfig["eslint.config.mjs"]:::frontend
        PrettierConfig["prettier.config.mjs"]:::frontend
    end
    click pkg "https://github.com/staciax/django-book-store/blob/master/package.json"
    click tailwind "https://github.com/staciax/django-book-store/blob/master/tailwind.config.mjs"
    click postcss "https://github.com/staciax/django-book-store/blob/master/postcss.config.mjs"
    click eslint "https://github.com/staciax/django-book-store/blob/master/eslint.config.mjs"
    click prettier "https://github.com/staciax/django-book-store/blob/master/prettier.config.mjs"

    PackageJSON --> TailwindConfig
    PackageJSON --> PostCSSConfig
    PackageJSON --> ESLintConfig
    PackageJSON --> PrettierConfig
    TailwindConfig -->|Generates CSS| StaticAssets
    PostCSSConfig -->|Build Process| StaticAssets

    %% Database
    Postgres[(PostgreSQL Database)]:::db
    ASGIApp -->|ORM Queries| Postgres
    WSGIApp -->|ORM Queries| Postgres

    click envExample "https://github.com/staciax/django-book-store/blob/master/.env.example"
    click dockerCompose "https://github.com/staciax/django-book-store/blob/master/docker-compose.yaml"

    %% External Service
    PromptPay["PromptPay API"]:::external
    ASGIApp -->|API Calls| PromptPay

    %% Legend Styles
    classDef frontend fill:#e0ffe0,stroke:#0a0,stroke-width:1px;
    classDef backend fill:#e0f0ff,stroke:#00f,stroke-width:1px;
    classDef db fill:#ffe0b3,stroke:#f90,stroke-width:1px;
    classDef external fill:#ffe0e0,stroke:#f00,stroke-width:1px;
```
