How mwanago/nestjs-typescript works
Purpose and Runtime
This is a TypeScript/NestJS backend starter expanded into a multi-domain API platform: users/authentication, content, catalog, payments, messaging, files, and operations. It runs on Node.js; bootstrap and application composition are in src/main.ts and src/app.module.ts. src/repl.ts provides a separate interactive Nest application entry point.
Application Composition and Transport Boundaries
src/app.module.ts is the dependency-composition root, wiring feature modules around shared database, logging, search, PubSub, and health capabilities. Most domain APIs use REST controllers, while posts also expose GraphQL through src/posts/posts.resolver.ts and the generated schema src/schema.gql. Real-time chat is a gateway boundary in src/chat/chat.gateway.ts; subscribers define a protobuf contract at src/subscribers/subscribers.proto, indicating a service/RPC integration boundary.
Persistence and Operational Cross-Cutting Layer
Database-backed entities are distributed by domain, with infrastructure rooted in src/database/database.module.ts and database logging in src/database/databaseLogger.ts. Core persisted aggregates include users (src/users/user.entity.ts), posts (src/posts/post.entity.ts), and Stripe webhook events (src/stripeWebhook/StripeEvent.entity.ts). Cross-cutting request processing includes logging middleware (src/utils/logs.middleware.ts), raw-body handling for signed webhook verification (src/utils/rawBody.middleware.ts), and null-value response normalization (src/utils/excludeNull.interceptor.ts).
Identity, Authorization, and Account Verification
Authentication is centered on src/authentication/authentication.service.ts and exposed through src/authentication/authentication.controller.ts. It supports local credentials plus JWT access, refresh, and two-factor strategies/guards, with authorization boundaries implemented in src/authentication/jwt-authentication.guard.ts and src/authentication/jwt-refresh.guard.ts. Account lifecycle extends to email verification (src/emailConfirmation/emailConfirmation.service.ts), Google authentication (src/googleAuthentication/googleAuthentication.service.ts), and SMS/two-factor verification (src/sms/sms.service.ts).
Content, Query, and Caching Flow
Posts are the richest content domain: REST and GraphQL requests enter src/posts/posts.controller.ts or src/posts/posts.resolver.ts, then flow through src/posts/posts.service.ts to persistence. Search is separated into src/posts/postsSearch.service.ts, with Elasticsearch explicitly represented by src/health/elasticsearchHealthIndicator.ts. HTTP cache behavior is scoped to posts in src/posts/httpCache.interceptor.ts. Comments use CQRS-style command/query dispatch, with write and read handlers at src/comments/commands/handlers/create-comment.handler.ts and src/comments/queries/handlers/getComments.handler.ts.
Commerce and External Payment Processing
Product catalog management is divided between product categories and products: src/productCategories/productCategories.service.ts and src/products/products.service.ts. Payment operations are mediated by src/stripe/stripe.service.ts; charge and saved-card HTTP endpoints are in src/charge/charge.controller.ts and src/credit-cards/creditCards.controller.ts. Stripe callbacks enter the dedicated webhook controller/service boundary (src/stripeWebhook/stripeWebhook.controller.ts, src/stripeWebhook/stripeWebhook.service.ts), which requires raw request bodies and records webhook events.
Communications, Files, and Background-Facing Services
Email delivery and scheduling are distinct capabilities in src/email/email.service.ts and src/emailScheduling/emailScheduling.service.ts; SMS is handled separately. File metadata/storage is modeled through src/files/files.service.ts, while local upload handling is isolated in src/localFiles/localFiles.service.ts. Image optimization is exposed as a dedicated processing boundary in src/optimize/image.processor.ts. docker-compose.yml is the repository’s infrastructure orchestration entry point; Elasticsearch is materially implied by the search and health components.
Main entry points: app.module.ts Application composition · stripeWebhook.controller.ts Stripe webhooks · database.module.ts Database layer · authentication.service.ts Authentication API
Components 22
Runtime
- Nest bootstrap
src/main.ts - Application composition · Wires domain modules and shared capabilities.
src/app.module.ts - Interactive REPL
src/repl.ts - Database layer · Provides database-backed domain persistence.
src/database/database.module.ts - Request processing · Logging, raw-body handling, and null normalization.
src/utils/rawBody.middleware.ts
Identity
- Authentication API · Local, JWT, refresh, and two-factor authentication.
src/authentication/authentication.service.ts - JWT guards
src/authentication/jwt-authentication.guard.ts - Account verification · Email, Google, and SMS/two-factor verification.
src/emailConfirmation/emailConfirmation.service.ts - Users
src/users/user.entity.ts
Content
- Posts REST & GraphQL · Exposes REST and GraphQL post operations.
src/posts/posts.controller.ts - Posts service
src/posts/posts.service.ts - Posts
src/posts/post.entity.ts - Post search
src/posts/postsSearch.service.ts - Elasticsearch · Used by post search and health checks.
src/health/elasticsearchHealthIndicator.ts - Comments CQRS · Separates comment writes from reads.
src/comments/commands/handlers/create-comment.handler.ts
Commerce
- Catalog services
src/products/products.service.ts - Stripe payments · Mediates charges and saved-card operations.
src/stripe/stripe.service.ts - Stripe webhooks · Verifies signed callbacks and records events.
src/stripeWebhook/stripeWebhook.controller.ts - Webhook events
src/stripeWebhook/StripeEvent.entity.ts
Communications & Files
- Email & scheduling
src/email/email.service.ts - Files & image processing · File metadata, local uploads, and image optimization.
src/files/files.service.ts - Chat & subscriber RPC · Chat gateway and protobuf subscriber contract.
src/chat/chat.gateway.ts
Connections 24
- Nest bootstrap → Application composition: boots
- Interactive REPL → Application composition: creates app
- Application composition → Database layer: configures
- Application composition → Request processing: applies
- Application composition → Authentication API: mounts
- Application composition → Posts REST & GraphQL: mounts
- Application composition → Catalog services: mounts
- Application composition → Stripe payments: mounts
- Application composition → Chat & subscriber RPC: mounts
- Request processing → Stripe webhooks: raw body for
- Authentication API → JWT guards: issues tokens for
- Authentication API → Users: authenticates
- Account verification → Users: verifies accounts
- Posts REST & GraphQL → Posts service: invokes
- Posts service → Posts: persists
- Posts service → Post search: indexes/searches
- Post search → Elasticsearch: queries
- Comments CQRS → Database layer: reads and writes
- Catalog services → Database layer: persists
- Stripe payments → Stripe webhooks: receives callbacks
- Stripe webhooks → Webhook events: records
- Stripe webhooks → Stripe payments: processes events
- Email & scheduling → Account verification: delivers verification
- Files & image processing → Database layer: stores metadata