# caodinhbao/foodiego architecture

> Architecture diagram of the GitHub repository caodinhbao/foodiego, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/caodinhbao/foodiego
- Repository: https://github.com/caodinhbao/foodiego

## Overview

1. **Repository shape**
   - This is a small monorepo for a food-ordering platform.
   - The runtime pieces are split into: a Node.js/Express backend, a Python FastAPI delivery-fee service, a static frontend, and MySQL as the shared data store.
   - Docker Compose is the main orchestration boundary for local execution.

2. **Primary system of record: MySQL**
   - The backend persists domain data in MySQL using versioned SQL migrations under `backend/migrations`.
   - The schema covers the core food-ordering entities: users, restaurants, menu items, orders, order items, and reviews.
   - `seed.sql` and setup scripts indicate the repo supports repeatable database bootstrap for development/testing.

3. **Backend architecture: modular Express API**
   - The Node backend is organized by domain modules under `backend/src/modules`.
   - Each module owns its own router, and some modules also include a service layer for business logic.
   - Core domains are: `auth`, `users`, `restaurants`, `menu-items`, `orders`, plus smaller domains like `admin`, `flash-sales`, `loyalty`, and `notifications`.

4. **Request handling flow in the backend**
   - HTTP traffic enters `backend/src/server.js`, then `app.js` wires the Express app, middleware, and route registration.
   - Route handlers sit in module routers, while shared cross-cutting concerns are in `backend/src/middlewares`.
   - The typical flow is: request → auth/role middleware → module router → service/database access → response.

5. **Authentication and authorization boundary**
   - Auth is JWT-based, with role enforcement for Customer, Restaurant Owner, and Admin.
   - `authenticate.js` likely validates the token and attaches the user context.
   - `authorize.js` enforces role-based access, which is central to the API surface because many endpoints are role-restricted.

6. **Backend domain responsibilities**
   - `auth` handles register/login/profile.
   - `users` is admin-oriented user management, including role changes.
   - `restaurants` manages restaurant lifecycle and ownership.
   - `menu-items` manages menu CRUD tied to restaurants.
   - `orders` manages order creation, retrieval, and status transitions.

7. **Order lifecycle as a key business flow**
   - Orders move through a fixed status pipeline: accepted → preparing → delivering → completed, with cancellation supported.
   - The backend owns order state transitions and exposes them through status update endpoints.
   - This is the most important stateful workflow in the system and likely drives both customer views and owner operations.

8. **External service boundary: FastAPI delivery-fee calculator**
   - Delivery fee calculation is intentionally split into a separate Python service in `delivery-service/`.
   - It exposes a single calculation endpoint and is independent of the Node backend runtime.
   - This creates a clear service boundary: the backend owns commerce state, while the Python service owns pricing logic for delivery.

9. **Frontend boundary**
   - The `frontend/` directory is a static HTML/CSS/JS client, not a separate SPA framework.
   - `frontend/js/api.js` suggests a thin client that calls the backend API directly.
   - The pages are role- and task-oriented: login, orders, profile, restaurant views, and an admin page.

10. **Testing strategy**
   - The backend is covered by Jest/Supertest unit and integration tests.
   - There are module-level tests plus end-to-end style integration tests under `backend/src/tests/integration`.
   - This implies the backend API contract and DB-backed flows are the main tested surface.

11. **Infrastructure and local deployment**
   - `docker-compose.yml` coordinates backend, delivery service, and MySQL for local development.
   - Each service also has its own Dockerfile, which suggests containerized builds are first-class.
   - The repo includes a Windows helper script for backend startup, but Docker Compose is the primary environment abstraction.

12. **CI/CD and quality gates**
   - GitHub Actions runs CI from `.github/workflows/ci.yml`.
   - Quality tooling includes ESLint, Jest coverage, and SonarQube-oriented measurement goals documented in `docs/`.
   - The repo is organized around delivery metrics as well as functionality, so code quality and lead time are part of the project architecture.

13. **Docs and process artifacts**
   - The `docs/` folder contains backlog, metrics, sprint/process documents, and the project plan.
   - These are not runtime components, but they indicate the repo is also used as a process/measurement case study, not just an application codebase.

14. **Overall architectural picture**
   - The backend is the central orchestration layer: it authenticates users, enforces roles, manages restaurant/order state, and persists to MySQL.
   - The delivery-fee service is the only explicit external computation service.
   - The frontend is a thin consumer of backend APIs, while CI, migrations, and test suites support repeatable delivery and validation.

Main entry points: [`backend/src/app.js`](https://github.com/caodinhbao/foodiego/blob/main/backend/src/app.js) (App), [`backend/src/config/db.js`](https://github.com/caodinhbao/foodiego/blob/main/backend/src/config/db.js) (DB), [`.github/workflows/ci.yml`](https://github.com/caodinhbao/foodiego/blob/main/.github/workflows/ci.yml) (CI), [`docker-compose.yml`](https://github.com/caodinhbao/foodiego/blob/main/docker-compose.yml) (Compose)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_infra["Infra"]
  node_docker_compose["Compose<br/>orchestration<br/>[docker-compose.yml]"]
  node_ci_workflow["CI<br/>pipeline<br/>[ci.yml]"]
end

subgraph group_backend["Backend"]
  node_backend_server["Server<br/>entrypoint<br/>[server.js]"]
  node_backend_app["App<br/>[app.js]"]
  node_backend_authn{{"AuthN/Z<br/>middleware<br/>[authenticate.js]"}}
  node_backend_db[("DB<br/>mysql access<br/>[db.js]")]
  node_backend_auth["Auth<br/>[auth.router.js]"]
  node_backend_users["Users<br/>[users.router.js]"]
  node_backend_restaurants["Restaurants"]
  node_backend_menu["Menu Items"]
  node_backend_orders["Orders<br/>[orders.router.js]"]
  node_backend_admin["Admin<br/>[admin.router.js]"]
  node_backend_flash["Flash Sales"]
  node_backend_loyalty["Loyalty<br/>[loyalty.router.js]"]
  node_backend_notifications["Notifications"]
  node_backend_migrations["Migrations<br/>schema<br/>[001_init_mysql.sql]"]
end

subgraph group_delivery["Delivery"]
  node_delivery_main["Fee API<br/>fastapi service<br/>[main.py]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_api["Client API<br/>browser client<br/>[api.js]"]
  node_frontend_pages["Pages<br/>static ui<br/>[index.html]"]
end

subgraph group_docs["Docs"]
  node_docs_plan["Project Plan<br/>docs<br/>[project-plan.md]"]
end

node_docker_compose -->|"runs"| node_backend_server
node_docker_compose -->|"runs"| node_delivery_main
node_docker_compose -->|"provisions"| node_backend_db
node_backend_server -->|"boots"| node_backend_app
node_backend_app -->|"uses"| node_backend_authn
node_backend_app -->|"routes"| node_backend_auth
node_backend_app -->|"routes"| node_backend_users
node_backend_app -->|"routes"| node_backend_restaurants
node_backend_app -->|"routes"| node_backend_menu
node_backend_app -->|"routes"| node_backend_orders
node_backend_app -->|"routes"| node_backend_admin
node_backend_app -->|"routes"| node_backend_flash
node_backend_app -->|"routes"| node_backend_loyalty
node_backend_app -->|"routes"| node_backend_notifications
node_backend_auth -->|"reads/writes"| node_backend_db
node_backend_users -->|"reads/writes"| node_backend_db
node_backend_restaurants -->|"reads/writes"| node_backend_db
node_backend_menu -->|"reads/writes"| node_backend_db
node_backend_orders -->|"reads/writes"| node_backend_db
node_backend_orders -->|"calls"| node_delivery_main
node_frontend_api -->|"calls"| node_backend_app
node_frontend_pages -->|"uses"| node_frontend_api
node_ci_workflow -->|"verifies"| node_backend_server
node_ci_workflow -->|"verifies"| node_delivery_main
node_ci_workflow -->|"verifies"| node_frontend_pages
node_backend_migrations -->|"defines"| node_backend_db
node_docs_plan -.->|"describes"| node_ci_workflow

click node_docker_compose "https://github.com/caodinhbao/foodiego/blob/main/docker-compose.yml"
click node_ci_workflow "https://github.com/caodinhbao/foodiego/blob/main/.github/workflows/ci.yml"
click node_backend_server "https://github.com/caodinhbao/foodiego/blob/main/backend/src/server.js"
click node_backend_app "https://github.com/caodinhbao/foodiego/blob/main/backend/src/app.js"
click node_backend_authn "https://github.com/caodinhbao/foodiego/blob/main/backend/src/middlewares/authenticate.js"
click node_backend_db "https://github.com/caodinhbao/foodiego/blob/main/backend/src/config/db.js"
click node_backend_auth "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/auth/auth.router.js"
click node_backend_users "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/users/users.router.js"
click node_backend_restaurants "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/restaurants/restaurants.router.js"
click node_backend_menu "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/menu-items/menu-items.router.js"
click node_backend_orders "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/orders/orders.router.js"
click node_backend_admin "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/admin/admin.router.js"
click node_backend_flash "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/flash-sales/flash-sales.router.js"
click node_backend_loyalty "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/loyalty/loyalty.router.js"
click node_backend_notifications "https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/notifications/notifications.router.js"
click node_backend_migrations "https://github.com/caodinhbao/foodiego/blob/main/backend/migrations/001_init_mysql.sql"
click node_delivery_main "https://github.com/caodinhbao/foodiego/blob/main/delivery-service/main.py"
click node_frontend_api "https://github.com/caodinhbao/foodiego/blob/main/frontend/js/api.js"
click node_frontend_pages "https://github.com/caodinhbao/foodiego/blob/main/frontend/index.html"
click node_docs_plan "https://github.com/caodinhbao/foodiego/blob/main/docs/project-plan.md"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_docker_compose,node_ci_workflow toneBlue
class node_backend_server,node_backend_app,node_backend_authn,node_backend_db,node_backend_auth,node_backend_users,node_backend_restaurants,node_backend_menu,node_backend_orders,node_backend_admin,node_backend_flash,node_backend_loyalty,node_backend_notifications,node_backend_migrations toneAmber
class node_delivery_main toneMint
class node_frontend_api,node_frontend_pages toneRose
class node_docs_plan toneIndigo
```

## Components

### Infra

Local orchestration, CI, and runtime support

- [Compose](https://github.com/caodinhbao/foodiego/blob/main/docker-compose.yml): orchestration · Local multi-service runtime boundary · `docker-compose.yml`
- [CI](https://github.com/caodinhbao/foodiego/blob/main/.github/workflows/ci.yml): pipeline · GitHub Actions validation workflow · `.github/workflows/ci.yml`

### Backend

Node.js API and data access

- [Server](https://github.com/caodinhbao/foodiego/blob/main/backend/src/server.js): entrypoint · HTTP process entry for the Node backend · `backend/src/server.js`
- [App](https://github.com/caodinhbao/foodiego/blob/main/backend/src/app.js): express app · Wires middleware and route registration · `backend/src/app.js`
- [AuthN/Z](https://github.com/caodinhbao/foodiego/blob/main/backend/src/middlewares/authenticate.js): middleware · JWT authentication and role authorization · `backend/src/middlewares/authenticate.js`
- [DB](https://github.com/caodinhbao/foodiego/blob/main/backend/src/config/db.js): mysql access · MySQL connection and persistence layer · `backend/src/config/db.js`
- [Auth](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/auth/auth.router.js): module · Register, login, and profile flows · `backend/src/modules/auth/auth.router.js`
- [Users](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/users/users.router.js): module · Admin user management and role changes · `backend/src/modules/users/users.router.js`
- [Restaurants](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/restaurants/restaurants.router.js): module · Restaurant lifecycle and ownership · `backend/src/modules/restaurants/restaurants.router.js`
- [Menu Items](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/menu-items/menu-items.router.js): module · Restaurant-linked menu CRUD · `backend/src/modules/menu-items/menu-items.router.js`
- [Orders](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/orders/orders.router.js): module · Order creation and status transitions · `backend/src/modules/orders/orders.router.js`
- [Admin](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/admin/admin.router.js): module · Admin-facing API surface · `backend/src/modules/admin/admin.router.js`
- [Flash Sales](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/flash-sales/flash-sales.router.js): module · Promotional ordering features · `backend/src/modules/flash-sales/flash-sales.router.js`
- [Loyalty](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/loyalty/loyalty.router.js): module · Rewards and retention features · `backend/src/modules/loyalty/loyalty.router.js`
- [Notifications](https://github.com/caodinhbao/foodiego/blob/main/backend/src/modules/notifications/notifications.router.js): module · Notification delivery hooks · `backend/src/modules/notifications/notifications.router.js`
- [Migrations](https://github.com/caodinhbao/foodiego/blob/main/backend/migrations/001_init_mysql.sql): schema · Versioned MySQL schema changes and seed data · `backend/migrations/001_init_mysql.sql`

### Delivery

Python fee-calculation service

- [Fee API](https://github.com/caodinhbao/foodiego/blob/main/delivery-service/main.py): fastapi service · Delivery-fee calculation endpoint · `delivery-service/main.py`

### Frontend

Static browser client

- [Client API](https://github.com/caodinhbao/foodiego/blob/main/frontend/js/api.js): browser client · Thin JS layer for backend calls · `frontend/js/api.js`
- [Pages](https://github.com/caodinhbao/foodiego/blob/main/frontend/index.html): static ui · Role- and task-oriented HTML views · `frontend/index.html`

### Docs

Process and planning artifacts

- [Project Plan](https://github.com/caodinhbao/foodiego/blob/main/docs/project-plan.md): docs · Planning and process documentation · `docs/project-plan.md`

## Connections

- Compose → Server: runs · Starts the Node backend container
- Compose → Fee API: runs · Starts the delivery-fee service container
- Compose → DB: provisions · Connects services to MySQL
- Server → App: boots · Server hands off to Express app setup
- App → AuthN/Z: uses · Applies request authentication and role checks
- App → Auth: routes · Registers auth module endpoints
- App → Users: routes · Registers user management endpoints
- App → Restaurants: routes · Registers restaurant endpoints
- App → Menu Items: routes · Registers menu-item endpoints
- App → Orders: routes · Registers order endpoints
- App → Admin: routes · Registers admin endpoints
- App → Flash Sales: routes · Registers flash-sale endpoints
- App → Loyalty: routes · Registers loyalty endpoints
- App → Notifications: routes · Registers notification endpoints
- Auth → DB: reads/writes · Persists accounts and sessions
- Users → DB: reads/writes · Manages users and roles
- Restaurants → DB: reads/writes · Stores restaurant records
- Menu Items → DB: reads/writes · Stores menu catalog data
- Orders → DB: reads/writes · Stores orders and status changes
- Orders → Fee API: calls · Requests delivery-fee calculations
- Client API → App: calls · Browser client consumes backend API
- Pages → Client API: uses · Pages invoke the shared API helper
- CI → Server: verifies · Runs backend tests and checks
- CI → Fee API: verifies · Runs service tests and checks
- CI → Pages: verifies · Validates client assets
- Migrations → DB: defines · Creates and seeds the schema
- Project Plan → CI: describes · Documents process and quality goals
