How tigranbs/nestjs-cookie-jwt-example works
Project type and purpose
• This is a Node.js/TypeScript server-side application built on the NestJS framework.
• It serves as a starter backend API with built-in modules for authentication (JWT), controllers, and services.
File structure
• Top-level config files:
• nest-cli.json (Nest CLI configuration)
• tsconfig.json / tsconfig.build.json (TypeScript compiler settings)
• package.json / package-lock.json (dependencies and scripts)
• .eslintrc.js, .prettierrc (linting and formatting)
• src/ (application source)
• main.ts – bootstraps the Nest application
• app.module.ts – root module that aggregates sub-modules and providers
• app.controller.ts & app.service.ts – example controller and business-logic provider
• auth/
– auth.module.ts – encapsulates authentication concerns
– auth.controller.ts – authentication endpoints (e.g., login)
– jwt.strategy.ts – Passport strategy for JWT validation
– guards.ts – route guards for protecting endpoints
• test/
• e2e-spec.ts – end-to-end tests
• jest-e2e.json – test framework configuration
Extract insights from the README
• Confirms it’s a NestJS TypeScript starter repo.
a. Main components
1. Client (e.g., REST client, Postman, frontend UI)
2. NestJS HTTP Server
– Controllers layer (app.controller, auth.controller)
– Services/providers layer (app.service, AuthService, JWT strategy)
– Guards (authorization logic)
3. (Optional) Persistence layer – e.g., TypeORM/Mongoose module you’d add
5. CI/CD pipeline (CircleCI badge indicates integration potential)
b. Relationships & data flow
• Client → HTTP request → Controller
• Controller → calls Service (business logic)
• Service ↔ (optional) Database adapter/repository
• AuthController / Guards ↔ JWT Strategy → validate token against secret or user store
• Service returns data → Controller → HTTP response → Client
c. Architectural patterns & principles
• Modular design: each domain (Auth, App) in its own Nest module
• Dependency injection: modules declare providers that NestDI injects
• Layered architecture: Controllers (API layer) → Services (business layer) → Persistence (data layer)
• Guard/Strategy pattern for pluggable authentication
d. Key technologies/frameworks
• NestJS core: Modules, Controllers, Providers
• Passport.js JWT strategy (jwt.strategy.ts)
• TypeScript for static types
• Jest for unit and e2e testing
• Optional: ORM (TypeORM/Mongoose) if added later