How jcsb83/base-nestjs-backend works
This repository is a NestJS HTTP API foundation rather than a domain-specific application: requests reach health and metrics endpoints, while bootstrap supplies validated configuration, global validation, Swagger, logging, and shutdown handling. The major runtime branches are health/readiness, Prometheus metrics, and shared request logging with selectable Log4js or Loki backends. The README documents these capabilities; unsampled implementation details are represented at their exact enclosing directories, and edges are limited to relationships shown in excerpts, the source index, or README.
Main entry points: main.ts API bootstrap · app.module.ts Root modules · shared.module.ts Logger selection · metrics.module.ts Metrics wiring
Components 24
Application bootstrap
- API bootstrap
src/main.ts - Root modules
src/app.module.ts - Swagger UI
src/main.ts - Request validation
src/main.ts
Health and metrics
- Health endpoints
src/modules/health/health.controller.ts - Health checks
src/modules/health/health.module.ts - Metrics endpoint
src/modules/metrics/metrics.controller.ts - HTTP metrics capture
src/modules/metrics/metrics.middleware.ts - Prometheus registry
src/modules/metrics/metrics.service.ts - Metrics wiring
src/modules/metrics/metrics.module.ts
Request logging
- Request log interceptor
src/modules/shared/interceptors/log-request.interceptor.ts - Logger selection
src/modules/shared/shared.module.ts - Log4js backend
src/modules/shared/services/log4jsLogger.service.ts - Loki backend
src/modules/shared/services/lokiLogger.service.ts - HTTP error mapping
src/modules/shared/controllers/common.controller.ts - Response DTO
src/modules/shared/dto/response.dto.ts - Use-case errors
src/modules/shared/errors/usecase.error.ts - Error levels
src/modules/shared/errors/errorLevel.enum.ts - Repository errors
src/modules/shared/errors/repository.error.ts - Shared utilities
src/modules/shared/utils/utils.ts
Configuration
- Environment settings
src/app.config.module.ts - Validated app config
src/app.config.ts
Other components
- HTTP clients
- Loki service
Connections 30
- HTTP clients → API bootstrap: sends HTTP
README.md - API bootstrap → Root modules: creates app
src/main.ts - API bootstrap → Validated app config: reads config
src/main.ts - API bootstrap → Swagger UI: configures docs
src/main.ts - API bootstrap → Request validation: installs pipe
src/main.ts - API bootstrap → Request log interceptor: installs interceptor
src/main.ts - Root modules → Environment settings: loads module
src/app.module.ts - Root modules → Health checks: loads module
src/app.module.ts - Root modules → Metrics wiring: loads module
src/app.module.ts - Root modules → Logger selection: loads module
src/app.module.ts - Environment settings → Validated app config: provides config
src/app.config.module.ts - Health checks → Health endpoints: registers routes
src/modules/health/health.module.ts - Health endpoints → Validated app config: checks log mode
src/modules/health/health.controller.ts - Health endpoints → Loki service: pings readiness
README.md - HTTP clients → Health endpoints: checks health
README.md - Metrics wiring → Metrics endpoint: registers routes
src/modules/metrics/metrics.module.ts - Metrics wiring → HTTP metrics capture: registers middleware
src/modules/metrics/metrics.module.ts - Metrics wiring → Prometheus registry: provides service
src/modules/metrics/metrics.module.ts - Metrics endpoint → Prometheus registry: reads metrics
src/modules/metrics/metrics.controller.ts - HTTP metrics capture → Prometheus registry: records requests
src/modules/metrics/metrics.middleware.ts - HTTP clients → Metrics endpoint: scrapes metrics
README.md - Logger selection → Validated app config: selects by mode
src/modules/shared/shared.module.ts - Logger selection → Log4js backend: creates logger
src/modules/shared/shared.module.ts - Logger selection → Loki backend: creates logger
src/modules/shared/shared.module.ts - Request log interceptor → Shared utilities: generates log ID
src/modules/shared/interceptors/log-request.interceptor.ts - Request log interceptor → Logger selection: emits request logs
src/modules/shared/shared.module.ts - Loki backend → Loki service: pushes logs
README.md - HTTP error mapping → Response DTO: builds response
src/modules/shared/controllers/common.controller.ts - HTTP error mapping → Use-case errors: maps errors
src/modules/shared/controllers/common.controller.ts - Use-case errors → Error levels: reads level
src/modules/shared/errors/usecase.error.ts