How devangelcrow/inventory_backend works
1. This repository is a NestJS 11 backend for electronic invoicing, built in TypeScript with Prisma ORM against PostgreSQL 16. It is organized as a modular monolith, with a single HTTP application plus a separate worker entrypoint for background jobs.
2. The core architectural style is Hexagonal Architecture with DDD and CQRS. Each business module is split into domain, application, and infrastructure layers, and application writes are modeled as Commands while reads are modeled as Queries, dispatched through Nest’s CommandBus and QueryBus.
3. The main runtime entrypoints are src/main.ts for the REST API and src/worker.ts for BullMQ processing. The worker is separate from HTTP and is meant for queue consumers such as email processing or other async tasks.
4. Persistence is centered on Prisma and PostgreSQL. Domain repository interfaces live in each module’s domain layer, while Prisma-backed implementations sit in infrastructure. Database changes are managed through Prisma migrations and seeded through a set of seeders under prisma/seeds.
5. auth is the session and identity lifecycle module. It covers register/login/logout, access and refresh token handling, email verification, password reset flows, session revocation, and profile updates. It also depends on email delivery, JWT token services, refresh-token persistence, and throttling/lockout rules.
6. identity-access-management manages system users and their authentication-facing identity records. It exposes user CRUD and lookup flows used by auth, and acts as a bridge between user records and other identity concepts such as username, email, password state, and reset flows.
7. profile owns person-centric data: person, address, document, and document type. This module is notable because profile updates fan out into multiple sub-entities and are wrapped in a shared transaction boundary, so a single request can update person/address/document consistently.
8. catalogs provides reference data used across the rest of the system: countries, genders, marital status, geographic divisions, category status, and global status. It is heavily value-object driven and serves as a shared lookup source for profile, IAM, and other modules.
9. security is the authorization subsystem. It defines roles, permissions, routes, category permissions, and user-role relationships, plus the “menu” projection used by clients. It also exposes guards and custom decorators that enforce route-level permissions and user-specific access checks.
10. storage abstracts file persistence behind a backend registry. It can store files locally or in S3-compatible storage, selected by configuration. Upload flows validate file type and metadata, then persist file records and file content/path details separately from application data.
11. audit records sensitive actions as structured audit logs. It is designed as a cross-cutting module: the application can mark operations as auditable, and the infrastructure layer can intercept or record those events without coupling business handlers directly to logging concerns.
12. shared contains the platform-level foundation used by every module: common pagination DTOs, domain/application exceptions, base repository abstractions, transaction helpers, cache/Redis wiring, Prisma wiring, HTTP filters/interceptors/middleware, health checks, and utility mappers. This is the main boundary where reusable infrastructure lives instead of inside business modules.
13. HTTP flow is layered: controller → validation DTOs/guards/interceptors → CQRS command/query → handler → service/use case → repository implementation → Prisma/PostgreSQL. For some flows, especially profile updates and file uploads, the request also passes through transaction and multipart/file-handling infrastructure before reaching the handler.
14. The supporting infrastructure matters to the diagram: Redis is used for cache/queues, BullMQ for async processing, JWT and Passport strategies for auth, Swagger/Scalar for docs, and Docker Compose for local orchestration of the app, PostgreSQL, Redis, and SonarQube. Health and metrics endpoints are also present under shared/infrastructure/health.
15. Overall, the system is not a generic CRUD app: it is a domain-heavy backend with distinct bounded contexts for identity, profile, catalogs, security, storage, and audit, all coordinated through NestJS module boundaries and Prisma-backed persistence.
Main entry points: app.module.ts App module · auth.module.ts Auth · prisma.module.ts Prisma · security.module.ts Security
Components 20
Runtime
HTTP API and worker entrypoints
- App module · Main HTTP composition root that wires feature modules and shared infrastructure
src/app.module.ts - HTTP main · Bootstraps the Nest HTTP application
src/main.ts - Worker module · Composition root for background job processing
src/worker.module.ts - Worker main · Bootstraps BullMQ consumers and async processing
src/worker.ts
Business modules
Bounded contexts and their main flows
- Auth · Register, login, refresh, logout, verification, reset, and session revocation flows
src/modules/auth/auth.module.ts - Identity IAM · System users and authentication-facing identity records
src/modules/identity-access-management/identity-access-management.module.ts - Profile · Person, address, document, and document type management
src/modules/profile/profile.module.ts - Catalogs · Shared lookup and value-object driven reference data
src/modules/catalogs/catalogs.module.ts - Security · Roles, permissions, routes, menus, and user-role access checks
src/modules/security/security.module.ts - Storage · File upload and backend selection across local and S3-compatible storage
src/modules/storage/storage.module.ts - Audit · Structured audit logging for sensitive actions
src/modules/audit/audit.module.ts
Shared foundation
Cross-cutting application and infrastructure primitives
- Shared core · Common domain, application, HTTP, cache, queue, and utility foundations
src/shared - HTTP stack · Controllers, DTOs, guards, filters, and CQRS dispatch
src/shared/infrastructure/http/filters/http-exception.filter.ts - Transactions · Transactional helpers and request-scoped transaction coordination
src/shared/infrastructure/decorators/transactional.decorator.ts
Platform
Persistence, queues, cache, and external runtime dependencies
- Prisma · Prisma service and relational persistence boundary
src/shared/infrastructure/persistence/prisma/prisma.module.ts - PostgreSQL · Primary relational datastore
- Redis/BullMQ · Cache, throttling, and background job transport
src/shared/infrastructure/queues/queues.module.ts - Email/JWT · Email delivery and token strategy services used by auth
src/modules/auth/infrastructure/services/jwt-token-hasher.service.ts - Migrations · Prisma migration history for database changes
prisma/migrations/20260609191024/migration.sql - Seeders · Prisma seed set for reference and initial data
prisma/seeds/main.seeder.ts
Connections 31
- HTTP main → App module: boots · HTTP bootstrap loads the main Nest application graph
- Worker main → Worker module: boots · Worker bootstrap loads queue consumers
- App module → Shared core: imports · Application composition depends on shared foundations
- App module → Auth: loads · HTTP app includes the auth bounded context
- App module → Identity IAM: loads · HTTP app includes identity management
- App module → Profile: loads · HTTP app includes profile management
- App module → Catalogs: loads · HTTP app includes reference data APIs
- App module → Security: loads · HTTP app includes authorization APIs
- App module → Storage: loads · HTTP app includes storage APIs
- App module → Audit: loads · HTTP app includes audit APIs
- Worker module → Storage: consumes · Worker can process async storage-related jobs
- Worker module → Auth: consumes · Worker handles queued auth email jobs
- Auth → Identity IAM: queries · Auth relies on user identity lookup and lifecycle operations
- Auth → Profile: reads profile · Auth updates and authenticates against profile data
- Auth → Security: checks access · Auth interacts with role and permission context
- Auth → Email/JWT: uses · Auth depends on email delivery and JWT services
- Profile → Catalogs: uses lookups · Profile validates person data against catalog values
- Profile → Transactions: wraps writes · Profile updates are coordinated in a shared transaction boundary
- Security → Catalogs: uses status · Security reuses global status and related catalog data
- Security → Redis/BullMQ: caches · Authorization checks can use cache-backed access data
- Storage → Redis/BullMQ: queues · Upload and file processing can use background queues
- Storage → Prisma: persists · Storage metadata and file records are stored through Prisma
- Audit → Prisma: persists · Audit logs are written via Prisma-backed repository implementations
- Shared core → Prisma: provides · Shared persistence wiring includes Prisma integration
- Prisma → PostgreSQL: connects to · Prisma talks to PostgreSQL as the primary database
- Prisma → Migrations: managed by · Schema changes are applied through migrations
- Prisma → Seeders: initialized by · Initial and reference data are loaded from seeders
- Auth → HTTP stack: served by · Auth flows are exposed through the HTTP stack
- Catalogs → HTTP stack: served by · Catalog CRUD and reads are exposed through HTTP
- Security → HTTP stack: served by · Authorization endpoints and guards sit in the HTTP layer
- Storage → HTTP stack: served by · File upload and storage endpoints are exposed through HTTP