# mois666/sig-delivery architecture

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

- Interactive diagram: https://gitdiagram.com/mois666/sig-delivery
- Repository: https://github.com/mois666/sig-delivery

## Overview

1. **Repository shape**
   - This is a two-part delivery platform: a **Node.js backend** in `delivery-back-node/` and a **React SPA frontend** in `delivery-frontend/`.
   - The backend is the system of record and real-time event source; the frontend is a client that consumes HTTP APIs and Socket.IO events.

2. **Backend runtime and infrastructure**
   - The backend runs on **Node.js/Express** with **Prisma ORM** against **MySQL**.
   - **Redis** is also part of the local stack and is managed alongside MySQL via `docker-compose.yml`; it likely supports real-time/session/cache use cases.
   - `prisma/schema.prisma`, migrations, and `seed.ts` define and initialize the data model.

3. **Backend request pipeline**
   - `src/index.ts` is the application entrypoint.
   - Requests flow through shared middleware in `src/middlewares/`:
     - `auth.ts` for protected endpoints
     - `validate.ts` for request validation
   - Routing is centralized in `src/routes/index.ts` and then delegated into module-specific routers.

4. **Backend modular domain boundaries**
   - The API is split into feature modules under `src/modules/`, each with its own route/controller/validation layer.
   - Main domains visible in the tree:
     - `auth` for login/session/token flows
     - `user` for user management
     - `city` for city administration
     - `zone` for geographic zones
     - `order` for delivery orders
     - `compliance` for rule/constraint enforcement
   - This structure suggests a controller-first API organized by business capability rather than by technical layer.

5. **Backend business logic and persistence**
   - Most modules expose controllers and validations; some also have a deeper service/repository split.
   - `compliance` uses a **repository + service** pattern, indicating more explicit domain logic and persistence access.
   - `zone` includes `geo.service.ts`, which implies geospatial calculations or zone matching are part of the backend business rules.

6. **Backend data access**
   - `src/lib/prisma.ts` provides a shared Prisma client instance.
   - Prisma migrations and seed data are first-class, so the backend’s persistence boundary is strongly typed and schema-driven.
   - The local database bootstrap in the README indicates a development flow of `docker-compose up`, `prisma db push`, `prisma generate`, then seeding.

7. **Real-time backend channel**
   - The README states the backend exposes **Socket.IO** on the same server as the API.
   - This makes the backend both an HTTP API and a real-time event broadcaster, likely for order status updates, driver activity, or notifications.
   - Redis being present in the stack supports this kind of event-driven architecture, even if the exact pub/sub wiring is not visible from the tree.

8. **Frontend application shell**
   - The frontend is a **Vite + React + TypeScript** app.
   - Global composition lives in `src/main.tsx`, `src/providers/Providers.tsx`, and layout components under `src/layouts/`.
   - `AuthProvider`, `MainLayout`, `Navbar`, `Sidebar`, and `MobileMenu` define the app shell and authenticated navigation structure.

9. **Frontend state and server interaction**
   - The app keeps domain state in dedicated stores under `src/stores/`:
     - `authStore`
     - `userStore`
     - `cityStore`
     - `orderStore`
     - `rankingStore`
     - `walletStore`
     - `zoneStore`
     - `socketStore`
   - This suggests a client-side state layer that coordinates both API data and live socket state.

10. **Frontend API boundary**
   - HTTP integration is isolated in `src/api/`, notably `appDB.ts` and `zones.ts`.
   - The frontend appears to call the backend through a small API abstraction rather than inline fetches across pages.
   - Socket connectivity is separated into `src/lib/socket.ts` and `src/lib/echo.ts`, reinforcing the split between REST-like reads and realtime updates.

11. **Frontend feature areas**
   - User-facing pages include login, profile, ranking, wallet, driver home, and active delivery.
   - Admin functionality is separated under `src/pages/admin/` with dedicated screens for dashboard, orders, users, cities, and zones.
   - This indicates role-based UI surfaces rather than a single generic dashboard.

12. **Maps and geolocation**
   - Zone and city workflows rely heavily on mapping and location selection.
   - `src/components/maps/LeafletMapSelector.tsx`, `MapPicker.tsx`, and `src/lib/geoUtils.ts` show that geospatial interaction is a core client concern.
   - The README also mentions external map/geocoding keys, so the frontend likely integrates with **Leaflet**, **Google Maps**, and a geocoding service.

13. **Shared UI and interaction patterns**
   - Reusable UI is packaged into cards, timelines, status components, and modal dialogs.
   - `ThemeProvider`, `use-toast`, and `use-mobile` indicate cross-cutting concerns for theming, feedback, and responsive behavior.
   - `public/sounds/order.mp3` suggests the UI also provides audible feedback for order events.

14. **End-to-end data flow**
   - Typical flow: user action in the React UI → API request through `src/api/` → backend route/controller/validation → Prisma/MySQL persistence → optional Socket.IO broadcast → frontend store/socket update.
   - The architecture is therefore a classic **client/API/database** model with a real-time side channel for live delivery state.

15. **What to show in an architecture diagram**
   - Draw two main boxes: **Backend API + realtime server** and **Frontend SPA**.
   - Under the backend, show modules for auth, users, cities, zones, orders, and compliance, all feeding into Prisma/MySQL.
   - Show Redis and Socket.IO as supporting runtime services.
   - On the frontend, show pages layered over layouts, stores, API clients, and map/geolocation integrations.

Main entry points: [`delivery-back-node/src/index.ts`](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/index.ts) (Server entry), [`delivery-back-node/src/routes/index.ts`](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/routes/index.ts) (API routes), [`delivery-frontend/src/pages/DriverHome.tsx`](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/pages/DriverHome.tsx) (Pages), [`delivery-back-node/src/middlewares/validate.ts`](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/middlewares/validate.ts) (Validation middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API"]
  node_backend_entry(("Server entry<br/>Express bootstrap<br/>[index.ts]"))
  node_backend_routes["API routes<br/>Route composition<br/>[index.ts]"]
  node_backend_auth_mw["Auth middleware<br/>HTTP middleware<br/>[auth.ts]"]
  node_backend_validate_mw["Validation middleware<br/>HTTP middleware<br/>[validate.ts]"]
  node_backend_auth_mod["Auth module<br/>API module<br/>[index.ts]"]
  node_backend_user_mod["User module<br/>API module<br/>[index.ts]"]
  node_backend_city_mod["City module<br/>API module<br/>[index.ts]"]
  node_backend_zone_mod["Zone module<br/>API module<br/>[index.ts]"]
  node_backend_order_mod["Order module<br/>API module<br/>[index.ts]"]
  node_backend_compliance_mod["Compliance module<br/>Domain module<br/>[index.ts]"]
  node_backend_geo_service["Geo service<br/>Zone service<br/>[geo.service.ts]"]
  node_backend_compliance_service["Compliance service<br/>Domain service"]
  node_backend_compliance_repo["Compliance repo<br/>Data access"]
  node_backend_prisma[("Prisma client<br/>ORM client<br/>[prisma.ts]")]
  node_backend_schema["DB schema<br/>Prisma schema<br/>[schema.prisma]"]
  node_backend_seed["Seed data<br/>Bootstrap script<br/>[seed.ts]"]
  node_backend_mysql[("MySQL<br/>Database<br/>[docker-compose.yml]")]
  node_backend_redis[("Redis<br/>Cache/bus<br/>[docker-compose.yml]")]
end

subgraph group_frontend["Frontend SPA"]
  node_frontend_shell(("App shell<br/>React bootstrap<br/>[main.tsx]"))
  node_frontend_providers["Providers<br/>Context setup<br/>[Providers.tsx]"]
  node_frontend_layout["Main layout<br/>UI shell<br/>[MainLayout.tsx]"]
  node_frontend_pages["Pages<br/>Route views<br/>[DriverHome.tsx]"]
  node_frontend_api["API client<br/>HTTP client<br/>[appDB.ts]"]
  node_frontend_socket["Socket client<br/>Realtime client<br/>[socket.ts]"]
  node_frontend_stores["Stores<br/>Client state<br/>[authStore.ts]"]
  node_frontend_maps["Maps<br/>Geolocation UI"]
end

node_backend_entry -->|"mounts"| node_backend_routes
node_backend_entry -->|"serves"| node_backend_auth_mod
node_backend_entry -->|"serves"| node_backend_user_mod
node_backend_entry -->|"serves"| node_backend_city_mod
node_backend_entry -->|"serves"| node_backend_zone_mod
node_backend_entry -->|"serves"| node_backend_order_mod
node_backend_entry -->|"serves"| node_backend_compliance_mod
node_backend_routes -->|"delegates"| node_backend_auth_mod
node_backend_routes -->|"delegates"| node_backend_user_mod
node_backend_routes -->|"delegates"| node_backend_city_mod
node_backend_routes -->|"delegates"| node_backend_zone_mod
node_backend_routes -->|"delegates"| node_backend_order_mod
node_backend_routes -->|"delegates"| node_backend_compliance_mod
node_backend_auth_mod -->|"protects"| node_backend_auth_mw
node_backend_auth_mod -->|"validates"| node_backend_validate_mw
node_backend_user_mod -->|"validates"| node_backend_validate_mw
node_backend_city_mod -->|"validates"| node_backend_validate_mw
node_backend_zone_mod -->|"validates"| node_backend_validate_mw
node_backend_order_mod -->|"validates"| node_backend_validate_mw
node_backend_compliance_mod -->|"uses"| node_backend_compliance_service
node_backend_compliance_service -->|"reads/writes"| node_backend_compliance_repo
node_backend_zone_mod -->|"uses"| node_backend_geo_service
node_backend_compliance_repo -->|"queries"| node_backend_prisma
node_backend_prisma -->|"based on"| node_backend_schema
node_backend_schema -->|"persists to"| node_backend_mysql
node_backend_seed -->|"seeds"| node_backend_mysql
node_backend_entry -.->|"supports"| node_backend_redis
node_frontend_shell -->|"wraps"| node_frontend_providers
node_frontend_shell -->|"renders"| node_frontend_layout
node_frontend_layout -->|"hosts"| node_frontend_pages
node_frontend_pages -->|"fetches"| node_frontend_api
node_frontend_pages -->|"subscribes"| node_frontend_socket
node_frontend_pages -->|"updates"| node_frontend_stores
node_frontend_stores -->|"syncs"| node_frontend_api
node_frontend_stores -->|"listens"| node_frontend_socket
node_frontend_pages -->|"uses"| node_frontend_maps
node_frontend_maps -->|"writes"| node_frontend_api

click node_backend_entry "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/index.ts"
click node_backend_routes "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/routes/index.ts"
click node_backend_auth_mw "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/middlewares/auth.ts"
click node_backend_validate_mw "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/middlewares/validate.ts"
click node_backend_auth_mod "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/auth/index.ts"
click node_backend_user_mod "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/user/index.ts"
click node_backend_city_mod "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/city/index.ts"
click node_backend_zone_mod "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/zone/index.ts"
click node_backend_order_mod "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/order/index.ts"
click node_backend_compliance_mod "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/compliance/index.ts"
click node_backend_geo_service "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/zone/services/geo.service.ts"
click node_backend_compliance_service "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/compliance/services/compliance.service.ts"
click node_backend_compliance_repo "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/compliance/repositories/compliance.repository.ts"
click node_backend_prisma "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/lib/prisma.ts"
click node_backend_schema "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/prisma/schema.prisma"
click node_backend_seed "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/prisma/seed.ts"
click node_backend_mysql "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/docker-compose.yml"
click node_backend_redis "https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/docker-compose.yml"
click node_frontend_shell "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/main.tsx"
click node_frontend_providers "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/providers/Providers.tsx"
click node_frontend_layout "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/layouts/MainLayout.tsx"
click node_frontend_pages "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/pages/DriverHome.tsx"
click node_frontend_api "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/api/appDB.ts"
click node_frontend_socket "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/lib/socket.ts"
click node_frontend_stores "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/stores/authStore.ts"
click node_frontend_maps "https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/components/maps/LeafletMapSelector.tsx"

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_backend_entry,node_backend_routes,node_backend_auth_mw,node_backend_validate_mw,node_backend_auth_mod,node_backend_user_mod,node_backend_city_mod,node_backend_zone_mod,node_backend_order_mod,node_backend_compliance_mod,node_backend_geo_service,node_backend_compliance_service,node_backend_compliance_repo,node_backend_prisma,node_backend_schema,node_backend_seed,node_backend_mysql,node_backend_redis toneBlue
class node_frontend_shell,node_frontend_providers,node_frontend_layout,node_frontend_pages,node_frontend_api,node_frontend_socket,node_frontend_stores,node_frontend_maps toneAmber
```

## Components

### Backend API

Node.js/Express server, domain modules, and persistence/runtime services.

- [Server entry](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/index.ts): Express bootstrap · Starts the API server and Socket.IO runtime. · `delivery-back-node/src/index.ts`
- [API routes](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/routes/index.ts): Route composition · Central router that delegates to feature modules. · `delivery-back-node/src/routes/index.ts`
- [Auth middleware](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/middlewares/auth.ts): HTTP middleware · Protects authenticated backend endpoints. · `delivery-back-node/src/middlewares/auth.ts`
- [Validation middleware](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/middlewares/validate.ts): HTTP middleware · Runs request validation before controllers. · `delivery-back-node/src/middlewares/validate.ts`
- [Auth module](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/auth/index.ts): API module · Login and session/token flows. · `delivery-back-node/src/modules/auth/index.ts`
- [User module](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/user/index.ts): API module · User management endpoints and rules. · `delivery-back-node/src/modules/user/index.ts`
- [City module](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/city/index.ts): API module · City administration features. · `delivery-back-node/src/modules/city/index.ts`
- [Zone module](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/zone/index.ts): API module · Geographic zones and matching logic. · `delivery-back-node/src/modules/zone/index.ts`
- [Order module](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/order/index.ts): API module · Delivery order workflows and status changes. · `delivery-back-node/src/modules/order/index.ts`
- [Compliance module](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/compliance/index.ts): Domain module · Rule enforcement with explicit service and repository layers. · `delivery-back-node/src/modules/compliance/index.ts`
- [Geo service](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/zone/services/geo.service.ts): Zone service · Geospatial calculations and zone-related helpers. · `delivery-back-node/src/modules/zone/services/geo.service.ts`
- [Compliance service](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/compliance/services/compliance.service.ts): Domain service · Business logic for compliance checks. · `delivery-back-node/src/modules/compliance/services/compliance.service.ts`
- [Compliance repo](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/modules/compliance/repositories/compliance.repository.ts): Data access · Repository layer for compliance persistence. · `delivery-back-node/src/modules/compliance/repositories/compliance.repository.ts`
- [Prisma client](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/src/lib/prisma.ts): ORM client · Shared Prisma instance used across modules. · `delivery-back-node/src/lib/prisma.ts`
- [DB schema](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/prisma/schema.prisma): Prisma schema · Typed data model and migrations source of truth. · `delivery-back-node/prisma/schema.prisma`
- [Seed data](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/prisma/seed.ts): Bootstrap script · Initial data population for development. · `delivery-back-node/prisma/seed.ts`
- [MySQL](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/docker-compose.yml): Database · Primary relational persistence store. · `delivery-back-node/docker-compose.yml`
- [Redis](https://github.com/mois666/sig-delivery/blob/main/delivery-back-node/docker-compose.yml): Cache/bus · Supporting runtime service for cache/session/realtime needs. · `delivery-back-node/docker-compose.yml`

### Frontend SPA

React/Vite client, UI shell, state, and API/realtime integrations.

- [App shell](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/main.tsx): React bootstrap · Top-level React entry and provider composition. · `delivery-frontend/src/main.tsx`
- [Providers](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/providers/Providers.tsx): Context setup · Wraps app-wide contexts and cross-cutting providers. · `delivery-frontend/src/providers/Providers.tsx`
- [Main layout](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/layouts/MainLayout.tsx): UI shell · Authenticated app frame with navigation chrome. · `delivery-frontend/src/layouts/MainLayout.tsx`
- [Pages](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/pages/DriverHome.tsx): Route views · User, driver, and admin screens. · `delivery-frontend/src/pages/DriverHome.tsx`
- [API client](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/api/appDB.ts): HTTP client · Frontend boundary for backend requests. · `delivery-frontend/src/api/appDB.ts`
- [Socket client](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/lib/socket.ts): Realtime client · Socket.IO connection and event wiring. · `delivery-frontend/src/lib/socket.ts`
- [Stores](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/stores/authStore.ts): Client state · Domain state for auth, users, cities, orders, zones, ranking, wallet, and socket. · `delivery-frontend/src/stores/authStore.ts`
- [Maps](https://github.com/mois666/sig-delivery/blob/main/delivery-frontend/src/components/maps/LeafletMapSelector.tsx): Geolocation UI · Map picking and geospatial interactions for zones and cities. · `delivery-frontend/src/components/maps/LeafletMapSelector.tsx`

## Connections

- Server entry → API routes: mounts · Server starts by wiring the router tree.
- Server entry → Auth module: serves · Exposes auth endpoints.
- Server entry → User module: serves · Exposes user endpoints.
- Server entry → City module: serves · Exposes city endpoints.
- Server entry → Zone module: serves · Exposes zone endpoints.
- Server entry → Order module: serves · Exposes order endpoints.
- Server entry → Compliance module: serves · Exposes compliance endpoints.
- API routes → Auth module: delegates · Routes into the auth module.
- API routes → User module: delegates · Routes into the user module.
- API routes → City module: delegates · Routes into the city module.
- API routes → Zone module: delegates · Routes into the zone module.
- API routes → Order module: delegates · Routes into the order module.
- API routes → Compliance module: delegates · Routes into the compliance module.
- Auth module → Auth middleware: protects · Uses auth guard for secured endpoints.
- Auth module → Validation middleware: validates · Validates request payloads.
- User module → Validation middleware: validates · Validates user requests.
- City module → Validation middleware: validates · Validates city requests.
- Zone module → Validation middleware: validates · Validates zone requests.
- Order module → Validation middleware: validates · Validates order requests.
- Compliance module → Compliance service: uses · Domain logic lives in the service layer.
- Compliance service → Compliance repo: reads/writes · Service persists through the repository.
- Zone module → Geo service: uses · Geospatial calculations support zone logic.
- Compliance repo → Prisma client: queries · Repository accesses the database through Prisma.
- Prisma client → DB schema: based on · Client is generated from the Prisma schema.
- DB schema → MySQL: persists to · Schema maps to MySQL tables.
- Seed data → MySQL: seeds · Bootstrap data populates the database.
- Server entry → Redis: supports · Redis supports the runtime stack.
- App shell → Providers: wraps · App bootstrap composes providers.
- App shell → Main layout: renders · Main UI shell is mounted by the app.
- Main layout → Pages: hosts · Layout frames the routed pages.
- Pages → API client: fetches · Pages use the HTTP API boundary.
- Pages → Socket client: subscribes · Pages consume realtime events.
- Pages → Stores: updates · Pages read and write domain state.
- Stores → API client: syncs · Stores are hydrated from API calls.
- Stores → Socket client: listens · Stores react to socket events.
- Pages → Maps: uses · Zone and city screens use mapping tools.
- Maps → API client: writes · Map interactions back form data and requests.
