How rajappan47/incident-management-portal-backend works
Purpose and entry point
This is a Node.js backend for incident management: authentication, users/admin operations, incident lifecycle, categories, comments, activity auditing, dashboards, and health checks. Application startup is index.js; HTTP surface is organized under routes/.
HTTP and request boundary
Route modules expose domain APIs and hand requests to controllers:
• Incident workflows: routes/incidentRoutes.js, controllers/incidentController.js
• Identity/access: routes/authRoutes.js, controllers/authController.js, routes/userRoutes.js
• Operational views: routes/dashboardRoutes.js, controllers/dashboardController.js, routes/healthRoutes.js
Cross-cutting request enforcement is implemented before controller handling: authentication and roles in middlewares/authMiddleware.js and middlewares/roleMiddleware.js; validation in middlewares/validationMiddleware.js; rate limiting, logging, uploads, and error conversion in middlewares/rateLimiter.js, middlewares/uploadMiddleware.js, and middlewares/errorHandler.js.
Domain service layer
Controllers delegate business operations to services, separating HTTP concerns from domain logic. The primary workflow service is services/incidentService.js, supported by services/commentService.js, services/categoryService.js, and services/activityService.js. Identity and administration are handled by services/authService.js, services/userService.js, and services/adminService.js. Dashboard aggregation and outbound notification responsibilities sit in services/dashboardService.js and services/notificationService.js.
Persistence and core entities
The data model is document/model-oriented, with database setup centralized in config/db.js. Core persisted entities are incidents, users, categories, comments, attachments, priorities, and audit records:
models/Incident.js, models/User.js, models/Category.js, models/Comment.js, models/Attachment.js, models/Priority.js, and models/ActivityLog.js.
The principal data flow is request → middleware → route/controller → service → model/database, with service results returned through controllers and failures routed to centralized error handling.
Incident lifecycle, SLA, and auditing
Incident handling is the architectural center: creation and updates pass through incident validation (validators/incidentValidator.js), are processed by controllers/incidentController.js and services/incidentService.js, and persist through models/Incident.js. SLA calculation is isolated in utils/calculateSLA.js. Activity changes are recorded through utils/activityLogger.js and services/activityService.js into models/ActivityLog.js; comments and attachments extend the incident record via their own models/services.
Background and external-facing operations
jobs/escalationJob.js is the asynchronous control path for escalation/SLA-related processing, independent of synchronous API requests. Notifications are abstracted by services/notificationService.js, creating a boundary for external delivery providers. File uploads cross a filesystem boundary through middlewares/uploadMiddleware.js into uploads/. API documentation configuration is present at config/swagger.js.
Runtime and operational boundaries
The runtime is a JavaScript/Node.js service (index.js, package.json). Database connectivity is encapsulated by config/db.js; callers should not spread database initialization into controllers or routes. Operational observability is split between request logging (middlewares/morganMiddleware.js), application logging (utils/logger.js), activity auditing, and a dedicated health endpoint (routes/healthRoutes.js).
Main entry points: incidentRoutes.js API routes · incidentService.js Incident service · Incident.js Core models · authMiddleware.js Request middleware
Components 19
Runtime
- Node application · Application startup and composition root.
index.js
HTTP boundary
- API routes · Incident, identity, dashboard, and health endpoints.
routes/incidentRoutes.js - Request middleware · Auth, roles, validation, rate limits, uploads, logging, and errors.
middlewares/authMiddleware.js - Incident validation
validators/incidentValidator.js - Incident controller
controllers/incidentController.js - Identity controllers · Authentication and user administration HTTP handling.
controllers/authController.js - Operational controllers · Dashboard and health HTTP handling.
controllers/dashboardController.js
Domain services
- Incident service · Owns incident lifecycle processing.
services/incidentService.js - Incident support services · Comments, categories, and activity operations.
services/commentService.js - Identity services · Authentication, users, and administration.
services/authService.js - Dashboard service
services/dashboardService.js - Notification service · Abstracts outbound notification providers.
services/notificationService.js - SLA calculation
utils/calculateSLA.js - Activity logger
utils/activityLogger.js
Persistence & operations
- Database connection · Centralized database connectivity.
config/db.js - Core models · Incidents, users, categories, comments, attachments, priorities, and audit records.
models/Incident.js - Upload storage
- Escalation job · Asynchronous SLA and escalation processing.
jobs/escalationJob.js - Application logger
utils/logger.js
Connections 25
- Node application → Database connection: initializes
- Node application → API routes: mounts
- Node application → Request middleware: installs
- Request middleware → API routes: enforces before
- Request middleware → Upload storage: stores uploads
- Request middleware → Application logger: request logging
- API routes → Incident validation: validates incidents
- API routes → Incident controller: dispatches
- API routes → Identity controllers: dispatches
- API routes → Operational controllers: dispatches
- Incident controller → Incident service: delegates
- Identity controllers → Identity services: delegates
- Operational controllers → Dashboard service: delegates
- Incident service → SLA calculation: calculates SLA
- Incident service → Incident support services: uses comments and audit
- Incident service → Core models: persists incidents
- Incident support services → Activity logger: records changes
- Activity logger → Core models: writes audit records
- Incident support services → Core models: persists related entities
- Identity services → Core models: persists users
- Dashboard service → Core models: aggregates
- Notification service → Incident service: supports lifecycle alerts
- Escalation job → Incident service: processes escalation
- Escalation job → Notification service: sends escalation alerts
- Core models → Database connection: uses