How mois666/sig-delivery works
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: src/index.ts Server entry · routes/index.ts API routes · DriverHome.tsx Pages · validate.ts Validation middleware
Components 26
Backend API
Node.js/Express server, domain modules, and persistence/runtime services.
- Server entry · Starts the API server and Socket.IO runtime.
delivery-back-node/src/index.ts - API routes · Central router that delegates to feature modules.
delivery-back-node/src/routes/index.ts - Auth middleware · Protects authenticated backend endpoints.
delivery-back-node/src/middlewares/auth.ts - Validation middleware · Runs request validation before controllers.
delivery-back-node/src/middlewares/validate.ts - Auth module · Login and session/token flows.
delivery-back-node/src/modules/auth/index.ts - User module · User management endpoints and rules.
delivery-back-node/src/modules/user/index.ts - City module · City administration features.
delivery-back-node/src/modules/city/index.ts - Zone module · Geographic zones and matching logic.
delivery-back-node/src/modules/zone/index.ts - Order module · Delivery order workflows and status changes.
delivery-back-node/src/modules/order/index.ts - Compliance module · Rule enforcement with explicit service and repository layers.
delivery-back-node/src/modules/compliance/index.ts - Geo service · Geospatial calculations and zone-related helpers.
delivery-back-node/src/modules/zone/services/geo.service.ts - Compliance service · Business logic for compliance checks.
delivery-back-node/src/modules/compliance/services/compliance.service.ts - Compliance repo · Repository layer for compliance persistence.
delivery-back-node/src/modules/compliance/repositories/compliance.repository.ts - Prisma client · Shared Prisma instance used across modules.
delivery-back-node/src/lib/prisma.ts - DB schema · Typed data model and migrations source of truth.
delivery-back-node/prisma/schema.prisma - Seed data · Initial data population for development.
delivery-back-node/prisma/seed.ts - MySQL · Primary relational persistence store.
delivery-back-node/docker-compose.yml - Redis · 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 · Top-level React entry and provider composition.
delivery-frontend/src/main.tsx - Providers · Wraps app-wide contexts and cross-cutting providers.
delivery-frontend/src/providers/Providers.tsx - Main layout · Authenticated app frame with navigation chrome.
delivery-frontend/src/layouts/MainLayout.tsx - Pages · User, driver, and admin screens.
delivery-frontend/src/pages/DriverHome.tsx - API client · Frontend boundary for backend requests.
delivery-frontend/src/api/appDB.ts - Socket client · Socket.IO connection and event wiring.
delivery-frontend/src/lib/socket.ts - Stores · Domain state for auth, users, cities, orders, zones, ranking, wallet, and socket.
delivery-frontend/src/stores/authStore.ts - Maps · Map picking and geospatial interactions for zones and cities.
delivery-frontend/src/components/maps/LeafletMapSelector.tsx
Connections 37
- 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.