How luigi-menor/backend-revida works
This repository is a NestJS backend API organized into feature modules, with Prisma as the persistence layer and JWT-based authentication for protected access. There is no frontend in this repo; the architecture is server-side only.
1. Application composition
- src/main.ts is the runtime entrypoint.
- src/app.module.ts composes the app by wiring together the feature modules: auth, families, audit, and database.
- The structure is classic NestJS: controllers expose HTTP routes, services hold business logic, and modules define dependency boundaries.
2. HTTP/API boundary
- src/auth/auth.controller.ts and src/families/families.controller.ts define the public API surface.
- Controllers are thin adapters that pass request data into the corresponding services.
- DTOs under src/auth/dto and src/families/dto define request shapes for login/register and family create/update operations.
3. Authentication subsystem
- src/auth/auth.module.ts, auth.service.ts, auth.controller.ts, and jwt.strategy.ts form the authentication boundary.
- The auth flow supports register and login, and likely issues JWTs after credential validation.
- jwt.strategy.ts indicates Passport/JWT is used to authenticate subsequent requests and guard protected endpoints.
4. Domain subsystem: families
- src/families is the main business module in the repo.
- It exposes CRUD-style operations for “families” via families.controller.ts and families.service.ts.
- create-family.dto.ts and update-family.dto.ts show a standard command/input model for family records.
5. Persistence layer
- src/database/database.service.ts and database.module.ts provide the persistence abstraction.
- prisma/schema.prisma and prisma.config.ts show Prisma is the ORM/schema tool used to access the database.
- The database module is the boundary between application services and the underlying datastore; services should not talk directly to the database engine.
6. Data flow through the system
- Typical request path is: HTTP controller → feature service → database service/Prisma → datastore.
- For auth, the flow is: register/login request → auth service → user persistence → JWT response.
- For families, the flow is: families controller → families service → Prisma-backed persistence.
7. Cross-cutting audit capability
- src/audit/audit.module.ts and audit.service.ts define a separate auditing subsystem.
- This is likely used to record important domain or security events independently of the main business logic.
- Architecturally, it acts as a cross-cutting service that other modules can inject rather than embedding logging/audit logic inside controllers.
8. Error handling boundary
- src/common/filters/prisma-exception.filter.ts is a shared exception translation layer.
- Its purpose is to convert Prisma/database errors into framework-level HTTP responses, preventing raw persistence errors from leaking to API consumers.
- This is an important boundary between infrastructure failures and API semantics.
9. Module-level separation
- auth, families, audit, and database are intentionally separated into feature modules instead of one monolith service.
- That makes the dependency graph clearer: auth and families depend on persistence; audit can be consumed by multiple features; common utilities are shared without being feature-specific.
10. Testing footprint
- There are unit tests for auth.service and families.service, plus an e2e test harness under test/.
- This suggests the main behavioral seams are the service layer and the full HTTP pipeline.
- The architecture is therefore centered on service-level domain logic with end-to-end verification at the API boundary.
11. Tooling and project shape
- The repo uses standard NestJS tooling (nest-cli.json, TypeScript configs, ESLint, Prettier).
- Prisma configuration and schema files indicate database schema management is part of the repo, not an external concern.
- The project is designed as a deployable Node.js service with a conventional NestJS module graph.
Overall, the diagram should show a NestJS HTTP application at the top, feature controllers feeding feature services in the middle, Prisma-backed persistence at the bottom, and shared cross-cutting concerns around the edges: JWT authentication strategy, Prisma error translation, and auditing.
Main entry points: database.service.ts Database service · app.module.ts App module · auth.service.ts Auth service · families.service.ts Families service
Components 19
Runtime
NestJS application bootstrap and composition
- Bootstrap · Application startup and Nest runtime bootstrap
src/main.ts - App module · Wires the application feature modules together
src/app.module.ts
Auth
JWT-based authentication boundary
- Auth module · Authentication feature boundary
src/auth/auth.module.ts - Auth API · Login and register HTTP endpoints
src/auth/auth.controller.ts - Auth service · Credential validation and JWT issuance
src/auth/auth.service.ts - JWT strategy · Passport JWT request authentication
src/auth/jwt.strategy.ts
Families
Core domain module for family records
- Families module · Families feature boundary
src/families/families.module.ts - Families API · CRUD HTTP endpoints for families
src/families/families.controller.ts - Families service · Business logic for family records
src/families/families.service.ts
Audit
Cross-cutting audit subsystem
- Audit module · Audit subsystem boundary
src/audit/audit.module.ts - Audit service · Records notable domain or security events
src/audit/audit.service.ts
Persistence
Database and Prisma integration
- Database module · Prisma-backed persistence boundary
src/database/database.module.ts - Database service · Application access to persisted data
src/database/database.service.ts
Shared
Cross-cutting application concerns
- Prisma filter · Translates Prisma errors to HTTP responses
src/common/filters/prisma-exception.filter.ts
Prisma
Prisma schema and configuration
- Prisma schema · Database schema definition for Prisma
prisma/schema.prisma - Prisma config · Prisma CLI and tooling configuration
prisma.config.ts
Tests
Representative service and e2e coverage
- Auth tests · Service-level authentication coverage
src/auth/auth.service.spec.ts - Families tests · Service-level families coverage
src/families/families.service.spec.ts - E2E tests · End-to-end HTTP pipeline coverage
test/app.e2e-spec.ts
Connections 29
- Bootstrap → App module: boots · Bootstrap initializes the Nest application module
- App module → Auth module: imports · Application composition includes authentication
- App module → Families module: imports · Application composition includes families
- App module → Audit module: imports · Application composition includes audit
- App module → Database module: imports · Application composition includes persistence
- Auth module → Auth API: exposes · Module registers the auth HTTP adapter
- Auth module → Auth service: provides · Module provides authentication logic
- Auth module → JWT strategy: uses · Module wires Passport JWT authentication
- Auth API → Auth service: calls · Controller delegates login and register operations
- Auth service → Database service: persists · Authentication logic relies on persisted user data
- Auth service → Audit service: emits · Authentication events can be audited
- JWT strategy → Database service: reads · JWT validation depends on persisted identity state
- Families module → Families API: exposes · Module registers the families HTTP adapter
- Families module → Families service: provides · Module provides families business logic
- Families API → Families service: calls · Controller delegates CRUD operations
- Families service → Database service: persists · Families logic reads and writes via persistence
- Families service → Audit service: emits · Family changes can be audited
- Audit module → Audit service: provides · Module exposes the audit subsystem
- Database module → Database service: provides · Module exposes the persistence service
- Database service → Prisma schema: maps to · Persistence layer is backed by Prisma schema
- Database service → Prisma config: configured by · Prisma tooling is configured for the database layer
- Prisma filter → Database service: translates errors · Shared filter converts persistence failures to API responses
- Auth API → Prisma filter: uses · Auth endpoints benefit from database error translation
- Families API → Prisma filter: uses · Families endpoints benefit from database error translation
- Auth tests → Auth service: covers · Unit tests target auth service behavior
- Families tests → Families service: covers · Unit tests target families service behavior
- E2E tests → Bootstrap: exercises · End-to-end tests run through the full application bootstrap
- E2E tests → Auth API: exercises · E2E tests cover HTTP auth flows
- E2E tests → Families API: exercises · E2E tests cover HTTP families flows