Backend Overview
Public Summary
The backend is an Express service organized by modules and built with layered architecture: route/controller, service, repository, model.
Internal Details
Startup Lifecycle
- Load environment and initialize Express.
- Connect MongoDB.
- Seed required baseline data.
- Start scheduled jobs (scraper and analytics).
- Start HTTP server.
Middleware Stack (Order Matters)
- Helmet security headers.
- Credential handling and CORS.
- Body parsers and cookie parser.
- Visitor tracking.
- Route mounting.
- Centralized error handler.
Module Boundaries
Main modules include auth, chain, product, market, image, scraper, search, feature-flag, public-holiday, report, and analytics.
Source Anchors
| Path | Relevance |
|---|---|
apps/server/src/server.js | Startup lifecycle |
apps/server/src/app.js | Middleware stack and route mounting |
apps/server/src/container.js | DI composition root |
apps/server/src/modules/ | All module directories |
Risks and Trade-offs
- Container wiring is explicit and readable, but growth in module count increases maintenance cost in one central file.
- Cron jobs in the same process improve simplicity but reduce isolation from API workload.