Backend Overview
The backend is an Express.js REST API located at apps/backend/. It is compiled by Babel and run by Node.js.
Package Details
| Field | Value |
|---|---|
| Package | @my-app/backend |
| Entry | src/app.js |
| Build out | dist/app.js |
| Dev server | nodemon + @babel/node |
| Port | 3500 (production) / 3000 (default) |
Directory Structure
apps/backend/src/
├── app.js ← Express app entry point
├── config/
│ └── app.config.js ← JWT, port, DB config
├── controllers/ ← HTTP handlers + business logic
│ ├── *.controller.js
│ ├── *.business.js
│ └── admin/
│ ├── device.controller.js / device.business.js
│ ├── user.controller.js / user.business.js
│ └── unit.controller.js / unit.business.js
├── middleware/
│ └── auth.middleware.js ← JWT + session validation guards
├── models/ ← Mongoose schemas + models
├── routes/ ← Express routers
│ ├── *.router.js
│ ├── device/
│ │ └── deviceSensorData.router.js
│ └── admin/
│ ├── device.router.js
│ └── user.router.js
├── services/
│ └── aws/
│ └── email.service.js ← SES email (verification, alerts)
├── helpers/
│ ├── response.helper.js
│ ├── date.helper.js
│ ├── query.helper.js
│ └── paginaton.helper.js
├── database/
│ ├── index.js ← factory + singleton
│ └── mongodb/ ← MongoDBDatabase + DB operation classes
└── interfaces/
└── database.interface.js ← abstract DB contractApp Entry (app.js)
The main Express application:
- CORS — whitelists
localhost,127.0.0.1,*.intecoglogistech.com,*.amplifyapp.com;credentials: true - Middleware stack —
cookieParser→express.json→express.urlencoded→bodyParser - MongoDB —
mongoose.connect(process.env.MONGODB_URI) - Routes — mounts all routers under
/api/v1/
Mounted Routes
| Mount Path | Router |
|---|---|
/api/v1/user | routes/user.router.js |
/api/v1/auth | routes/auth.router.js |
/api/v1/unit | routes/unit.router.js |
/api/v1/report | routes/report.router.js |
/api/v1/recipient | routes/recipient.router.js |
/api/v1/device | routes/device.router.js |
/api/v1/devices/sensor-data | routes/device/deviceSensorData.router.js |
/api/v1/admin/devices | routes/admin/device.router.js |
/api/v1/admin/users | routes/admin/user.router.js |
Key Dependencies
| Package | Purpose |
|---|---|
express | HTTP server framework |
mongoose | MongoDB ODM |
jsonwebtoken | JWT signing + verification |
bcryptjs | Password hashing |
@aws-sdk/client-ses | AWS SES v3 for email sending |
aws-sdk | AWS SDK v2 (S3, Lambda) |
helmet | Security headers |
cors | CORS policy enforcement |
cookie-parser | Parse userAccessToken cookie |
pdfkit | PDF report generation (streaming) |
puppeteer | Headless browser for PDF generation |
winston | Structured logging |
moment-timezone | Date formatting for reports |
http-status-codes | Named HTTP status constants |
Babel Path Aliases
The babel.config.js configures module-resolver aliases:
| Alias | Resolves to |
|---|---|
@ | ./src |
@ctrl | ./src/controllers |
@helpers | ./src/helpers |
@db | ./src/database |
@tests | ./src/__tests__ |
Config (src/config/app.config.js)
js
{
port: process.env.PORT || 3000,
jwt: {
token_secret: process.env.JWT_SECRET || 'secret',
token_life: 36000 * 24 * 30 // 30 days (in seconds)
},
viewsPath: 'views',
publicPath: 'public'
}WARNING
Always override JWT_SECRET with a strong secret in production via environment variable. The fallback 'secret' is unsafe.
