NestJS Zero to Hero 01 — Mental Model, Setup và API đầu tiên
Hiểu NestJS giải quyết bài toán gì, dựng TaskFlow API bằng NestJS 11 và TypeScript strict, rồi lần theo một request từ bootstrap tới controller.
Filter/Tag
21 entries
Hiểu NestJS giải quyết bài toán gì, dựng TaskFlow API bằng NestJS 11 và TypeScript strict, rồi lần theo một request từ bootstrap tới controller.
Thiết kế controller mỏng, route REST có chủ đích, status/header/query/param đúng ngữ nghĩa và xây Tasks API in-memory có thể kiểm thử bằng curl.
Làm chủ provider token, custom provider, useClass/useValue/useFactory/useExisting, scope và cách thiết kế dependency có thể thay thế, kiểm thử.
Dùng module như public API của capability, kiểm soát provider visibility, tránh global/circular dependency và tạo dynamic module cấu hình rõ ràng.
Lần theo middleware, guard, interceptor, pipe, controller và exception filter; đặt auth, validation, logging và error mapping đúng tầng.
Validate environment lúc startup, chia config theo namespace, bảo vệ secret, chuẩn hóa structured logging và biến main.ts thành bootstrap có thể kiểm thử.
Thiết kế API contract có runtime validation, response serialization, pagination, versioning, stable error và OpenAPI để client có thể tích hợp an toàn.
Kết nối PostgreSQL bằng Prisma 7 driver adapter, quản lý schema/migration/client lifecycle và implement repository mà không để ORM rò vào domain.
Đưa business rule ra khỏi Nest/Prisma, thiết kế domain model và application use case, map adapter ở composition root, giữ modular monolith dễ test.
Thiết kế transaction boundary, optimistic concurrency, idempotency key và retry an toàn để TaskFlow đúng khi nhiều request chạy đồng thời.
Xây password login an toàn, access JWT có issuer/audience, global Passport guard, refresh session rotation/reuse detection và logout/revoke có state.
Thiết kế permission/policy/resource authorization, tenant isolation, chống IDOR và cấu hình Helmet, CORS, CSRF, rate limit, audit log đúng threat model.
Xây testing pyramid cho domain/use case/module/Prisma/HTTP, dùng Nest TestingModule, Supertest và Testcontainers, giữ test deterministic và cô lập.
Đo p95/p99, event loop, query và memory; thử Fastify đúng cách, thiết kế cache tenant-aware/invalidation và bảo vệ hệ thống khỏi overload.
Đưa tác vụ chậm sang BullMQ/Redis, thiết kế retry/backoff/dead letter, xử lý job idempotent và nối PostgreSQL transaction với queue qua outbox.
Chọn SSE hay WebSocket, xác thực connection, authorize room theo tenant, xử lý reconnect/replay/backpressure và broadcast qua nhiều Nest replica.
Thêm GraphQL adapter lên cùng use case, thiết kế schema/pagination/error/auth, giải N+1 bằng DataLoader và giới hạn depth/complexity/operation.
Tách Notification service có lý do, dùng RabbitMQ event at-least-once và gRPC nội bộ có deadline, version contract, idempotency, tracing và ownership dữ liệu.
Instrument traces/metrics/logs bằng OpenTelemetry, thiết kế low-cardinality RED metrics, liveness/readiness và shutdown drain HTTP/DB/queue an toàn.
Đóng gói NestJS thành image tối thiểu, chạy migration/release an toàn, dựng CI/CD quality gates, rollout/rollback và hoàn thiện TaskFlow portfolio capstone.
Thiết kế NestJS 11 như một runtime kiến trúc: module boundary, DI scope, request lifecycle, validation, policy guard, interceptor, error contract, Prisma 7, testing và graceful shutdown.