Guide 02 / 021 min read
Architecture, Authentication, and Security
Detailed architecture of NestJS modules, JWT authentication guards, and database isolation.
Modular NestJS Architecture#
The codebase leverages the NestJS dependency injection container to maintain decoupled, testable components:
- Controllers: Handle HTTP routing, status code mapping, and header parsing.
- Services: Encapsulate core business rules, transactional logic, and external system coordination.
- Modules: Group related controllers, services, and database repositories into cohesive functional boundaries.
Authentication Pipeline#
Security is enforced through NestJS guards and passport strategies:
- JWT Strategy: Requests bearing a Bearer token in the
Authorizationheader are validated against the signing secret. - Auth Guard: Endpoints decorated with auth guards reject unauthenticated or expired tokens with standard
401 Unauthorizedresponses. - User Context: Successfully verified claims are attached to the request object for use by downstream services.
Database Integration & Data Integrity#
The application connects to PostgreSQL to persist core relational data:
- Schemas enforce referential integrity with cascading updates and foreign key constraints.
- Sensitive credentials such as user passwords are encrypted using one-way cryptographic hashing before storage.