Skip to content

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

FieldValue
Package@my-app/backend
Entrysrc/app.js
Build outdist/app.js
Dev servernodemon + @babel/node
Port3500 (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 contract

App Entry (app.js)

The main Express application:

  1. CORS — whitelists localhost, 127.0.0.1, *.intecoglogistech.com, *.amplifyapp.com; credentials: true
  2. Middleware stackcookieParserexpress.jsonexpress.urlencodedbodyParser
  3. MongoDBmongoose.connect(process.env.MONGODB_URI)
  4. Routes — mounts all routers under /api/v1/

Mounted Routes

Mount PathRouter
/api/v1/userroutes/user.router.js
/api/v1/authroutes/auth.router.js
/api/v1/unitroutes/unit.router.js
/api/v1/reportroutes/report.router.js
/api/v1/recipientroutes/recipient.router.js
/api/v1/deviceroutes/device.router.js
/api/v1/devices/sensor-dataroutes/device/deviceSensorData.router.js
/api/v1/admin/devicesroutes/admin/device.router.js
/api/v1/admin/usersroutes/admin/user.router.js

Key Dependencies

PackagePurpose
expressHTTP server framework
mongooseMongoDB ODM
jsonwebtokenJWT signing + verification
bcryptjsPassword hashing
@aws-sdk/client-sesAWS SES v3 for email sending
aws-sdkAWS SDK v2 (S3, Lambda)
helmetSecurity headers
corsCORS policy enforcement
cookie-parserParse userAccessToken cookie
pdfkitPDF report generation (streaming)
puppeteerHeadless browser for PDF generation
winstonStructured logging
moment-timezoneDate formatting for reports
http-status-codesNamed HTTP status constants

Babel Path Aliases

The babel.config.js configures module-resolver aliases:

AliasResolves 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.

Intecog Logistech IoT Monitoring Platform