How holgadom/nest-pokedex works
Project Type and Purpose
• This is a modular monolith backend service written in NestJS, exposing a REST API for “Pokemon” resources, alongside a simple seed‐data endpoint. It also serves static assets from the public directory. It uses MongoDB for persistence and relies on an external Pokemon API during seeding.
File Structure Highlights
• Top level: Docker orchestrator (docker-compose.yaml), environment template (.env.example), Nest CLI config, lint & formatting rules, public/ (static frontend).
• src/ modular breakdown:
• common/ – shared adapters (Axios HTTP client), DTOs, pipes (MongoID parser), interfaces
• config/ – environment config & Joi validation
• pokemon/ – controller, service, DTOs, entity schema
• seed/ – controller, service, interfaces for external API response
• app.module.ts & main.ts – NestJS bootstrap
• Tests under test/, TypeScript build configs.
Key Architectural Patterns
• NestJS Modules for logical boundaries
• Layered design: Controller → Service → Adapter/Repository → Database
• Dependency injection for adapters & config
• Adapter pattern for HTTP (Axios) calls to external services
• Configuration module validated by Joi
• Docker Compose manages the NestJS app and MongoDB instance
a. External Clients & Static UI
• Browser / API consumer
• public/index.html & CSS (optional static UI)
b. API Gateway (NestJS HTTP Server)
• Main NestJS instance (port 3000)
• Request routing by controllers (PokemonController, SeedController)
c. Business Logic Layer
• PokemonService: CRUD operations against MongoDB
• SeedService: fetches from external Pokemon API via AxiosAdapter, transforms & writes to DB
d. Shared/Common Layer
• AxiosAdapter: implements HttpAdapter interface
• Pipes (e.g., ParseMongoIdPipe)
• DTOs & validation
e. Data Storage
• MongoDB container (as defined in docker-compose.yaml)
• Collections: pokemon
f. External Dependencies
• Public Pokemon REST API (seed source)
Relationships & Data Flow
• Client → HTTP request → NestJS Controller → Service → (DB via Mongoose/TypeORM)
• Seed flow: Controller → SeedService → AxiosAdapter → External API → data mapping → MongoDB
• Environment config injected at startup via ConfigModule → used by adapters & DB connector