How nazim1971/node-vms works
1. Overall shape: a modular NestJS backend monolith
- This repository is a single NestJS application organized as feature modules, not separate services.
- Each domain area has its own *.module.ts, *.controller.ts, and *.service.ts, with shared cross-cutting concerns under src/common.
- The app exposes HTTP APIs, a WebSocket gateway, and background jobs from the same codebase.
2. Runtime and infrastructure dependencies
- Primary state is in PostgreSQL via Prisma.
- Redis is used for JWT blacklisting, caching, and job/real-time support.
- BullMQ powers scheduled background jobs.
- Socket.IO provides real-time GPS/event broadcasting.
- Logging uses Winston, and the service is configured for standard NestJS production hardening.
3. Bootstrap and request pipeline
- src/main.ts bootstraps the Nest app.
- Requests flow through global concerns before reaching controllers: validation, exception filtering, logging, response shaping, sensitive-field stripping, and auditing.
- The repository strongly suggests a consistent API envelope for successful and error responses, which is important for diagramming the edge of the system.
4. Multi-tenancy is a core architectural boundary
- Every business operation is tenant-scoped; tenant isolation is a first-class rule, not just a data convention.
- Guards such as tenant.guard.ts, plus auth/role/feature guards, enforce access before a controller reaches its service.
- The SUPER_ADMIN role is explicitly exempt from most tenant/feature restrictions, which is an important exception path in the architecture.
5. Identity, authorization, and approval workflow
- The auth module handles login, refresh tokens, tenant registration, and initial super-admin seeding.
- JWT access/refresh tokens and bcrypt are the core identity mechanisms.
- New admin tenants go through an approval flow: pending registration, review in admin-applications, then activation or rejection by SUPER_ADMIN.
- Authorization is layered: authentication, tenant scoping, role checks, and feature access checks.
6. Feature-flag boundary for modules
- feature-access is a platform-level control plane for enabling/disabling tenant modules.
- Feature guards gate entire subsystems such as vehicles, workshop, maintenance, tracking, bookings, fuel, accounting, and reports.
- This means some domain modules are optional per tenant; in a diagram, this should be shown as a policy layer between the API and those feature modules.
7. Core operational domains
- The main business modules are vehicles, drivers, branches, users, tenants, contracts, bookings, trips, assignments, and scheduling.
- These modules model fleet operations and resource allocation.
- contracts and bookings appear to connect the commercial side to vehicle availability, while assignments, scheduling, and trips manage operational execution.
8. Maintenance, workshop, and document lifecycle
- maintenance, documents, workshop, and fuel form the vehicle health and servicing side of the system.
- workshop includes jobs, parts/labor breakdown, and cost tracking.
- documents and maintenance are tied to expiry/overdue alerting, which links this domain to the alert subsystem.
9. Accounting and reporting layer
- expenses, income, and accounting provide financial tracking and reporting inputs.
- reports and accounting generate aggregate views such as profit/loss, mileage, fuel, and usage reports.
- These modules are downstream consumers of operational data from bookings, trips, fuel, and maintenance.
10. Tracking and real-time telemetry
- tracking handles GPS location ingestion from drivers/vehicles.
- The readme indicates a Redis-backed cache plus WebSocket broadcast path, so this is a hybrid flow: write location data, update cache, then push updates to connected clients.
- gateways/app.gateway.ts is the real-time edge of the system and should be drawn as parallel to HTTP controllers, not inside them.
11. Background jobs and alerting
- jobs and alerts form the asynchronous subsystem.
- Scheduled jobs scan for document expiry, contract expiry, maintenance due, and offline vehicles.
- Alerts are likely persisted and then queried via API, while the job runners are the producers.
- This subsystem depends on PostgreSQL for state and Redis/BullMQ for scheduling/execution.
12. Audit and observability
- audit records immutable state-changing activity through an interceptor, not by manual logging in each service.
- logging.interceptor.ts and the Winston logger provide request-level observability.
- sensitive-fields.interceptor.ts removes credentials from output, which is important for showing the response path in diagrams.
13. Shared infrastructure and utilities
- src/database wraps Prisma access; this is the main persistence boundary for all feature modules.
- src/shared and src/common hold reusable guards, decorators, pipes, helpers, filters, Redis integration, and logger config.
- These shared pieces are what keep the feature modules thin and consistent.
14. Data model and migration history
- The repository includes a full Prisma migration history plus SQL backups and migration dumps.
- That suggests the schema is central to the design and likely stable enough to treat as a formal contract.
- docker-compose.yml and the Supabase-oriented environment variables indicate the system is intended to run against managed PostgreSQL and Redis in production-like environments.
15. How to draw the architecture
- Draw the app as a single NestJS backend with three primary entry points: HTTP controllers, WebSocket gateway, and BullMQ jobs.
- Place auth/tenant/role/feature guards in front of all business modules.
- Show Prisma/PostgreSQL as the authoritative data store, Redis as the support layer for blacklisting/cache/jobs, and WebSocket as the live telemetry channel.
- Group the domain modules into functional clusters: fleet operations, maintenance/workshop, finance/reporting, admin/control-plane, and async alerts/jobs.
Main entry points: app.module.ts App module · feature-access.module.ts Feature access · database.module.ts Prisma DB · bookings.module.ts Bookings
Components 32
Entry & pipeline
NestJS bootstrap and global request/response pipeline
- Bootstrap · Application startup and module wiring
src/main.ts - App module · Top-level composition of all feature modules
src/app.module.ts - API pipeline · Validation, exceptions, logging, response shaping, and sensitive-field stripping
src/common/interceptors/response.interceptor.ts
Platform services
Shared infrastructure and cross-cutting controls
- Access control · Auth, tenant, role, and feature guards with public/current-user decorators
src/common/guards/tenant.guard.ts - Feature access · Tenant feature gating for optional modules and SUPER_ADMIN exceptions
src/feature-access/feature-access.module.ts - Auth · Login, refresh tokens, tenant registration, and super-admin seeding
src/auth/auth.module.ts - Tenants · Tenant lifecycle and tenant-scoped configuration
src/tenants/tenants.module.ts - Users · User accounts, resets, and profile-linked identity data
src/users/users.module.ts - Admin applications · Pending tenant onboarding, review, approval, or rejection
src/admin-applications/admin-applications.module.ts - Prisma DB · Repository-wide persistence boundary over PostgreSQL
src/database/database.module.ts - Redis · JWT blacklisting, caching, and job/real-time support
src/common/redis/redis.module.ts - Audit · Immutable change capture through an interceptor-backed flow
src/audit/audit.module.ts
Fleet ops
Core operational domain modules
- Vehicles · Vehicle registry and lifecycle records
src/vehicles/vehicles.module.ts - Drivers · Driver records and assignment-ready personnel
src/drivers/drivers.module.ts - Branches · Branch-level operational locations
src/branches/branches.module.ts - Contracts · Vehicle contracts and availability-linked commercial terms
src/contracts/contracts.module.ts - Bookings · Booking flow connecting demand to vehicles and drivers
src/bookings/bookings.module.ts - Assignments · Vehicle-driver allocation and operational assignment records
src/assignments/assignments.module.ts - Scheduling · Availability checks and operational planning
src/scheduling/scheduling.module.ts - Trips · Trip lifecycle and execution tracking
src/trips/trips.module.ts
Service domains
Maintenance, workshop, and document lifecycle
- Documents · Vehicle and operational document records and expiry tracking
src/documents/documents.module.ts - Maintenance · Maintenance logs and overdue/expiry-related workflows
src/maintenance/maintenance.module.ts - Workshop · Jobs, parts/labor, and repair cost tracking
src/workshop/workshop.module.ts - Fuel · Fuel logs supporting vehicle health and reporting
src/fuel/fuel.module.ts
Finance & reports
Financial tracking and aggregation
- Expenses · Expense capture for financial reporting
src/expenses/expenses.module.ts - Income · Revenue capture and financial inputs
src/income/income.module.ts - Accounting · Profit/loss and finance summaries over operational data
src/accounting/accounting.module.ts - Reports · Aggregate operational reporting across fleet and finance data
src/reports/reports.module.ts
Async & realtime
Jobs, alerts, and live telemetry
- Tracking · GPS location ingestion and cache-backed live tracking
src/tracking/tracking.module.ts - Socket gateway · Socket.IO broadcast channel for live vehicle and event updates
src/gateways/app.gateway.ts - Jobs · Scheduled background scans and queue-driven execution
src/jobs/jobs.module.ts - Alerts · Persisted alerts produced by jobs and domain events
src/alerts/alerts.module.ts
Connections 48
- Bootstrap → App module: boots · Bootstrap starts the Nest application
- App module → API pipeline: wraps · Global pipeline applies to incoming requests
- App module → Access control: enforces · All protected handlers pass through layered guards
- App module → Prisma DB: uses · Feature modules share the Prisma/PostgreSQL boundary
- App module → Redis: uses · Shared Redis support for cache, auth, and jobs
- App module → Audit: observes · State-changing operations feed audit capture
- App module → Auth: exposes · Authentication entrypoint
- App module → Tenants: exposes · Tenant administration entrypoint
- App module → Users: exposes · User administration entrypoint
- App module → Admin applications: exposes · Tenant approval workflow entrypoint
- App module → Feature access: polices · Feature control plane gates optional subsystems
- App module → Vehicles: exposes · Fleet operations API
- App module → Drivers: exposes · Fleet personnel API
- App module → Branches: exposes · Organizational location API
- App module → Contracts: exposes · Commercial contracts API
- App module → Bookings: exposes · Booking and allocation API
- App module → Assignments: exposes · Assignment API
- App module → Scheduling: exposes · Availability and planning API
- App module → Trips: exposes · Trip execution API
- App module → Documents: exposes · Compliance documents API
- App module → Maintenance: exposes · Maintenance API
- App module → Workshop: exposes · Workshop repair API
- App module → Fuel: exposes · Fuel logging API
- App module → Expenses: exposes · Expense API
- App module → Income: exposes · Income API
- App module → Accounting: exposes · Accounting API
- App module → Reports: exposes · Reporting API
- App module → Tracking: exposes · GPS ingestion API
- App module → Socket gateway: streams · Realtime Socket.IO edge runs alongside HTTP
- App module → Jobs: runs · Background job subsystem
- App module → Alerts: exposes · Alert query and persistence API
- Auth → Prisma DB: reads/writes · Credentials, tokens, and tenant registration state
- Auth → Redis: blacklists · Refresh/JWT support via Redis
- Admin applications → Auth: feeds · Approved tenant onboarding leads into auth/activation
- Feature access → Vehicles: gates · Feature policy controls access to vehicle subsystem
- Feature access → Bookings: gates · Feature policy controls access to booking subsystem
- Feature access → Maintenance: gates · Feature policy controls access to maintenance subsystem
- Feature access → Tracking: gates · Feature policy controls access to tracking subsystem
- Feature access → Accounting: gates · Feature policy controls access to accounting subsystem
- Feature access → Reports: gates · Feature policy controls access to reporting subsystem
- Vehicles → Prisma DB: persists · Vehicle data is stored through Prisma
- Drivers → Prisma DB: persists · Driver data is stored through Prisma
- Branches → Prisma DB: persists · Branch data is stored through Prisma
- Contracts → Vehicles: allocates · Contracts constrain vehicle availability
- Contracts → Prisma DB: persists · Contract state is stored through Prisma
- Bookings → Assignments: creates · Bookings produce allocation records
- Bookings → Vehicles: selects · Booking flow selects available vehicles
- Bookings → Drivers: selects · Booking flow selects available drivers