How caodinhbao/foodiego works
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: app.js App · db.js DB · ci.yml CI · docker-compose.yml Compose
Components 20
Infra
Local orchestration, CI, and runtime support
Backend
Node.js API and data access
- Server · HTTP process entry for the Node backend
backend/src/server.js - App · Wires middleware and route registration
backend/src/app.js - AuthN/Z · JWT authentication and role authorization
backend/src/middlewares/authenticate.js - DB · MySQL connection and persistence layer
backend/src/config/db.js - Auth · Register, login, and profile flows
backend/src/modules/auth/auth.router.js - Users · Admin user management and role changes
backend/src/modules/users/users.router.js - Restaurants · Restaurant lifecycle and ownership
backend/src/modules/restaurants/restaurants.router.js - Menu Items · Restaurant-linked menu CRUD
backend/src/modules/menu-items/menu-items.router.js - Orders · Order creation and status transitions
backend/src/modules/orders/orders.router.js - Admin · Admin-facing API surface
backend/src/modules/admin/admin.router.js - Flash Sales · Promotional ordering features
backend/src/modules/flash-sales/flash-sales.router.js - Loyalty · Rewards and retention features
backend/src/modules/loyalty/loyalty.router.js - Notifications · Notification delivery hooks
backend/src/modules/notifications/notifications.router.js - Migrations · Versioned MySQL schema changes and seed data
backend/migrations/001_init_mysql.sql
Delivery
Python fee-calculation service
- Fee API · Delivery-fee calculation endpoint
delivery-service/main.py
Frontend
Static browser client
- Client API · Thin JS layer for backend calls
frontend/js/api.js - Pages · Role- and task-oriented HTML views
frontend/index.html
Docs
Process and planning artifacts
- Project Plan · Planning and process documentation
docs/project-plan.md
Connections 27
- 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