# ducmanhchu/food-selling architecture

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

- Interactive diagram: https://gitdiagram.com/ducmanhchu/food-selling
- Repository: https://github.com/ducmanhchu/food-selling

## Overview

##### Project type and purpose
- TLU Food is a full-stack web application combining an online food ordering system (“Web” Django app) with a culinary blog (“Blog” Django app).
- The frontend is a React single-page application (SPA) that consumes a Django REST API secured with JWT.
- The README confirms features: product browsing, shopping cart, order placement, user auth, blog CRUD, comments, and an admin dashboard.

##### File structure
- Top-level “backend” directory is a Django project (TLUfood/) with two apps:
- Blog/ – blog models, serializers, views, templates, migrations.
- Web/ – ordering models (products, orders, cart, payments), serializers, views, migrations.
- backend/manage.py, requirements.txt, import.py, data.json indicate setup, data import, migrations.
- Top-level “frontend” directory is a Vite-powered React project with:
- src/api – Axios wrappers for dishes, orders, users, posts.
- src/components – reusable UI pieces (CartContext, Dish, Post, Review, etc.).
- src/pages – route components (Home, DishDetail, Checkout, Blog, Posting, etc.).
- index.html, vite.config.js, package.json for build and dev configuration.

##### README for additional insights
- Confirms tech stack: React.js + Bootstrap + React Router + Axios; Django + DRF + JWT + SQLite.
- Mentions modular architecture, responsive design, admin dashboard.

a. Main components
- Client (Browser/Mobile) – React SPA
- Frontend Layer – React components, pages, routing, state management (CartContext)
- API Layer – Axios HTTP client
- Backend Layer – Django REST Framework project comprising:
– Authentication (JWT issuance/validation)
– Blog app (CRUD endpoints for posts & comments)
– Web app (endpoints for products, cart, orders, payments, user profiles)
– Admin site (Django admin UI for managing models)
- Database – SQLite (or configurable RDBMS)
- Static assets hosting (served by Django in production or via CDN)

b. Relationships and interactions
1. User interacts with React SPA in browser → UI triggers React Router navigation & component rendering.
2. SPA uses Axios (src/api/*) to call REST endpoints on Django server (authenticated with JWT in headers).
3. Django Middleware verifies JWT, dispatches to DRF viewsets/serializers in Blog or Web apps.
4. Views perform CRUD on Django ORM models, persist data to SQLite.
5. Responses (JSON) flow back to SPA; state updates (cart, posts, orders).
6. Admin users connect to /admin (Django admin) to manage models directly.

c. Architectural patterns/design principles
- Layered architecture: Presentation (React), Application/API (Django REST), Data (SQLite).
- Separation of concerns: Two Django apps isolate blog vs. ordering logic.
- RESTful API design with serializers and viewsets.
- JWT-based stateless authentication.
- React component hierarchy and Context for global state (CartContext).

d. Relevant technologies/frameworks
- React.js, React Router, Axios, Vite (frontend build)
- Django, Django REST Framework, Django admin (backend)
- JWT Authentication (DRF Simple JWT or custom)
- SQLite (default) – could be PostgreSQL in production
- Bootstrap (CSS framework for responsive UI)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend
    Browser["Browser/Mobile"]:::frontend
    Browser -->|"renders"| ReactSPA

    subgraph "Frontend Layer" 
        direction TB
        ReactSPA["React SPA"]:::frontend
        ReactSPA --> Router["App.jsx"]:::frontend
        ReactSPA --> Entry["main.jsx"]:::frontend
        ReactSPA --> Components["Components"]:::frontend
        ReactSPA --> Pages["Pages"]:::frontend
        ReactSPA --> APIClients["Axios API Clients"]:::frontend
    end

    %% Axios to Backend
    APIClients -->|"HTTP/JSON (JWT)"| DjangoAPI

    %% Backend
    subgraph "Backend Layer"
        direction TB
        DjangoAPI["Django REST API"]:::backend
        DjangoAPI --> Auth["JWT Auth Middleware"]:::backend

        subgraph "Blog App"
            direction TB
            BlogModels["models.py"]:::backend
            BlogSerializers["serializers.py"]:::backend
            BlogViews["views.py"]:::backend
            BlogURLs["urls.py"]:::backend
            BlogAdmin["admin.py"]:::backend
        end

        subgraph "Web App"
            direction TB
            WebModels["models.py"]:::backend
            WebSerializers["serializers.py"]:::backend
            WebViews["views.py"]:::backend
            WebURLs["urls.py"]:::backend
            WebAdmin["admin.py"]:::backend
        end

        DjangoAPI --> BlogURLs
        DjangoAPI --> WebURLs
        DjangoAPI --> AdminSite["Admin Dashboard"]:::backend
    end

    %% Database
    DjangoAPI -->|"ORM"| Database["SQLite Database"]:::db

    %% Click Events Frontend
    click ReactSPA "https://github.com/ducmanhchu/food-selling/tree/main/frontend/src/"
    click Router "https://github.com/ducmanhchu/food-selling/blob/main/frontend/src/App.jsx"
    click Entry "https://github.com/ducmanhchu/food-selling/blob/main/frontend/src/main.jsx"
    click Components "https://github.com/ducmanhchu/food-selling/tree/main/frontend/src/components/"
    click Pages "https://github.com/ducmanhchu/food-selling/tree/main/frontend/src/pages/"
    click APIClients "https://github.com/ducmanhchu/food-selling/tree/main/frontend/src/api/"

    %% Click Events Backend
    click Auth "https://github.com/ducmanhchu/food-selling/blob/main/backend/TLUfood/settings.py"
    click BlogModels "https://github.com/ducmanhchu/food-selling/blob/main/backend/Blog/models.py"
    click BlogSerializers "https://github.com/ducmanhchu/food-selling/blob/main/backend/Blog/serializers.py"
    click BlogViews "https://github.com/ducmanhchu/food-selling/blob/main/backend/Blog/views.py"
    click BlogURLs "https://github.com/ducmanhchu/food-selling/blob/main/backend/Blog/urls.py"
    click BlogAdmin "https://github.com/ducmanhchu/food-selling/blob/main/backend/Blog/admin.py"
    click WebModels "https://github.com/ducmanhchu/food-selling/blob/main/backend/Web/models.py"
    click WebSerializers "https://github.com/ducmanhchu/food-selling/blob/main/backend/Web/serializers.py"
    click WebViews "https://github.com/ducmanhchu/food-selling/blob/main/backend/Web/views.py"
    click WebURLs "https://github.com/ducmanhchu/food-selling/blob/main/backend/Web/urls.py"
    click WebAdmin "https://github.com/ducmanhchu/food-selling/blob/main/backend/Web/admin.py"
    click AdminSite "https://github.com/ducmanhchu/food-selling/blob/main/backend/TLUfood/urls.py"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#004085,stroke-width:1px
    classDef backend fill:#D5F5E3,stroke:#1E8449,stroke-width:1px
    classDef db fill:#FADBD8,stroke:#C0392B,stroke-width:1px
```
