Exercises — Capstone Project
One fresh project, zero copy-paste from tasks-api, every concept from all nine lessons exercised at least once. If you can ship this, you've genuinely internalized the stack.
Domain: a minimal Trello-style API — Users, Boards, Cards.
Functional Spec
Entities (MongoDB)
- User: email (unique, lowercased), username (unique), password (hashed), roles
['user']default, refreshTokensstring[](hashed), timestamps. - Board: title, description?, ownerId (ref User), memberIds (ObjectId[]), timestamps.
- Card: boardId (ref Board), title, description?, status
'todo' | 'doing' | 'done'(default todo), position (int ≥ 0), assigneeId?, timestamps.
Endpoints
Auth (@Public() where obvious): register, login (accessToken in body, refreshToken HttpOnly cookie with all five options), refresh (rotation + reuse detection + nuke-on-replay), logout, logout-all, GET /auth/me (no password/refreshTokens leaked).
Boards: CRUD. Rules: any authenticated user creates; only owner or member reads; only owner updates; only owner or admin deletes; POST /boards/:id/members (owner only) adds a member by userId.
Cards: nested under boards (/boards/:boardId/cards). CRUD + PATCH .../cards/:id/move ({ status, position }). Only board members touch cards. Validation: title ≤100, description ≤500, status enum, position @IsInt() @Min(0) with query/body coercion handled.
Ops: GET /health — public, unwrapped (your @SkipTransform mechanism), excluded from request logging.
Cross-cutting requirements (the actual test)
| Layer | Must include |
|---|---|
| Pipes | Global ValidationPipe (all 3 options), nested DTO validation somewhere (e.g., card checklist: ChecklistItemDto[]), PartialType for updates |
| Filters | AllExceptionsFilter via APP_FILTER, standard envelope with success:false + errorCode + requestId, custom BoardNotFoundException/CardNotFoundException, E11000 → 409 |
| Interceptors | Transform (success envelope + requestId), Logging, Timeout(5s), and the board list endpoint returns pagination meta |
| Guards | AuthGuard (real JWT), RolesGuard, @Public(), @Roles('admin'), @CurrentUser(); board-membership check — justify guard vs service placement in a comment |
| Middleware | helmet, CORS (credentials, single origin), cookie-parser, RequestLogger (request-ID + finish-event + level-by-status, health excluded), rate limiter on auth routes only (5/min — brute-force protection) |
| Swagger | Plugin enabled, bearer + cookie schemes, tags, @ApiOperation everywhere, composed ApiAuthResponses() etc., wrapped-response docs on at least two endpoints, disabled in production |
| Config | .env + global ConfigModule; no secret ever hardcoded |
Prerequisite mechanisms — where each was taught
A few requirements above were introduced outside the main theory. If any feel unfamiliar, revisit them before starting — they're not new inventions:
@SkipTransform(unwrapped/health) — Module 04, "Opting a route out" + stretch goal F1.requestIdin every envelope — Module 06, "Thread the request ID into every response" + exercise C4.errorCodeon errors — Module 03, "Machine-readable error codes" + exercise C1.- Pagination
meta— Module 04, "The other way to extend the envelope" + challenge C1 (route-scoped interceptor reshaping{ items, total, page, limit }). E11000→ 409 — Module 07, the users service's duplicate-key catch.
The capstone still expects you to build them from memory — this is just the map back to where each one lives.
Testing gate (definition of done)
- Unit: BoardsService ownership/membership logic, AuthService (enumeration-safe login, Nth-call token payloads, reuse detection), AuthGuard, TransformInterceptor. All external deps mocked.
- E2E (MongoMemoryServer + real AppModule): full auth journey incl. rotation replay → 403; board membership matrix (owner/member/stranger/admin × read/update/delete); card move flow; validation failure envelope; rate-limit 429 on the 6th login attempt.
npm testandnpm run test:e2eboth green; coverage ≥80% onsrc/commonand services.
Suggested Build Order (mirrors the lessons)
- Scaffold + in-memory Boards CRUD (Module 01 skills) — get routes breathing first.
- DTO validation (02). 3. Filter + envelope (03). 4. Interceptors (04). 5. Guards/decorators with the simulated token (05). 6. Middleware layer (06). 7. Swap in Mongo + real JWT auth (07). 8. Swagger (08). 9. Tests (09).
Feel how each layer slots in without rewriting controllers/services — that's the thesis of the whole course.
Trace Exam (do this on paper, closed book)
For each request, list every layer that executes in order, where it stops, and the exact response envelope: 1. POST /auth/login, 6th attempt within a minute, correct credentials. 2. PATCH /boards/:id by a member who isn't the owner, valid token. 3. POST /boards/:boardId/cards with { "title": "", "position": -1, "extra": true }, valid member token. 4. POST /auth/refresh replaying an already-rotated cookie. 5. GET /health — which layers touch it at all? 6. DELETE /boards/:id by an admin who is neither owner nor member.
Then verify each against the live app. Any mismatch between prediction and reality = the concept to restudy.
Final Self-Assessment
- I built every layer from memory, referencing docs — not the lesson files
- My controllers never exceeded ~5 lines of logic
- I can defend every architectural placement decision (middleware vs guard vs interceptor vs pipe vs filter)
- The rotation-replay E2E test exists and passes
- Predictions in the Trace Exam matched reality 6/6
