Skip to Content
Documentation

Documentation

Disclaimer

The documentation in this directory was written with the assistance of GitHub Copilot (powered by Claude Sonnet 4.6).

Every document has been manually reviewed and verified against the actual implementation to ensure accuracy and correctness. If you find any discrepancies, please open an issue or submit a pull request.

Standards & References

This project follows established industry standards and methodologies. The sections below document the specific specs, RFCs, and practices this codebase is built against.

Twelve-Factor App

This project aligns with the Twelve-Factor App  methodology — a set of best practices for building modern, scalable, maintainable server-side applications.

FactorHow it applies
CodebaseSingle repo, one codebase tracked in Git, multiple deploys via env
DependenciesAll dependencies declared in package.json, enforced with PNPM lockfile
ConfigAll configuration via environment variables, validated at startup via AppEnvDto
Backing ServicesMongoDB, Redis, AWS S3/SES, Firebase — treated as attached resources via env config
Build, Release, RunBuild (pnpm build) is strictly separated from runtime
ProcessesStateless app processes — session and cache state stored in Redis, not in-memory
Port BindingApp self-contained via NestJS HTTP server, port exposed via APP_PORT env
ConcurrencyHorizontal scaling supported — stateless processes, shared Redis for sessions
DisposabilityFast startup, graceful shutdown — no sticky sessions or local state
Dev/Prod ParitySame stack (Docker Compose) for local dev and production
LogsLogs as event streams via Pino to stdout — no log file management in app
Admin ProcessesOne-off tasks via dedicated migration and seed scripts (pnpm migration:seed)

Security Standards

ConcernStandard
JWT Access TokenES256 — ECDSA + SHA-256 (RFC 7518 , RFC 7519 )
JWT Refresh TokenES512 — ECDSA + SHA-512 (RFC 7518 , RFC 7519 )
Two-Factor AuthTOTP — SHA-1, 6 digits, 30s period (RFC 6238 )
Password Hashingbcrypt — 8 salt rounds
Encryption at RestAES-256-CBC (2FA secrets), AES-CBC + PKCS7 (general data)
HTTP Security HeadersHelmet  v8 — CSP, Strict-Transport-Security, X-Frame-Options, etc.
CORSConfigurable allowlist with wildcard subdomain support, preflight max-age 24h
Rate Limiting10 requests / 500ms window — global guard via @nestjs/throttler 
AuthorizationCASL  — fine-grained ability-based access control (subject + action)
API Key AuthMachine-to-machine via x-api-key header
Sensitive DataAuto-redacted in logs (password, token, apiKey) via Pino serializers
Threat CoverageOWASP Top 10  — input validation, injection prevention, auth hardening

Table of Contents

Getting Started

Start here to get the project running and understand its foundations.

  1. Installation — Set up the development environment step by step
  2. Environment — Configure all environment variables via .env
  3. Configuration — Understand the Config Module and per-concern config files
  4. Project Structure — Learn the modular architecture and repository design pattern

Core

Essential systems that power every feature in the project.

  1. Database — Prisma + MongoDB replica set, transactions, and the Database Module
  2. Authentication — JWT (ES256/ES512), session lifecycle, API key auth
  3. AuthorizationUserProtected, RoleProtected, PolicyAbilityProtected, TermPolicyAcceptanceProtected
  4. Device — Device fingerprinting, DeviceOwnership, max 1 session per device
  5. Response — Standardized response decorators, pagination response, file download
  6. Request ValidationValidationPipe, class-validator, body/query/path validation
  7. Handling Error — Exception filters, standardized HTTP error responses, i18n errors
  8. Message — i18n with nestjs-i18n, nested JSON message files in src/languages/
  9. Cache — Redis caching with shared RedisCacheModule, TTL strategy
  10. Queue — BullMQ background jobs, QueueProcessorBase, retry/backoff
  11. Logger — Pino logging, file rotation, sensitive data redaction, Sentry integration
  12. Security and Middleware — HTTP middleware layer, headers, rate limiting

Advanced

Additional features and integrations for production-grade deployments.

  1. Pagination — Offset-based, cursor-based pagination, advanced filtering
  2. Notification — Multi-channel notifications (email, push, inApp, silent) via BullMQ
  3. Two Factor — TOTP 2FA with authenticator apps and backup codes
  4. Feature Flag — Dynamic feature management, gradual rollouts, A/B testing
  5. Activity Log — Recording successful user activities with @ActivityLog
  6. Term Policy — Legal agreements, versioning, and user consent enforcement
  7. File Upload — Single/multiple file uploads, CSV processing, upload decorators
  8. Presign — AWS S3 presigned URLs for secure time-limited object access
  9. Third Party Integration — AWS S3/SES, Firebase, Sentry, no-op mode
  10. Doc — Swagger/OpenAPI decorators via the Doc Module
  11. Analytics — Planned analytics design using MongoDB aggregation pipelines
Last updated on