Task Manager API
Grow a task through layered structure, list controls, category references, an index check, validation with rate limits, and structured logs.
YOUR BUILD CHECKLIST
- Keep routes, controller, service, and data access as separate .
- Paginate, filter, and sort GET /tasks.
- Reference categories by id instead of embedding the whole category list on every task.
- Expose an explain route that shows COLLSCAN before an index and IXSCAN after.
- Validate titles and return 429 when the window is full.
- Replace ad hoc console text with log lines that include level and msg.
STAGE BRIEF
1. Layered structure
Uses Structuring a real backend
Keep listTasks and sendTasks separate from the route registration even while they share one file.
Open the related lessonYOUR APP
Work in one file. When you move to the next stage, this code stays. Each Run still fires one request (or one stdout capture) against a fresh database when MongoDB is involved.
GET /tasks
Project mode: your code carries into the next stage. Each Run is still one request.
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Solution walkthrough
Each stage has a finished file for that point in the project. Open it when you are stuck. Loading a starter or a solution is your choice; the editor does not overwrite your work unless you ask.
1. Layered structure
Uses Structuring a real backend
Keep listTasks and sendTasks separate from the route registration even while they share one file.
2. List controls
Uses Headers, status codes, and pagination
Support limit, offset, done, topic, and sort=title on GET /tasks.
3. Categories by reference
Uses Embedding vs referencing
Store categoryId on each task and resolve the category name from a categories collection.
4. Index before and after
Uses Indexes and query performance
GET /tasks/explain?topic=indexes reports COLLSCAN. With index=1 it should report IXSCAN.
5. Validation and rate limit
Uses Never trust client input, Rate limiting and abuse basics
Reject blank titles with 400. When the in-memory bucket is already full, return 429 before insert.
6. Structured logging
Uses Structured logging
Log JSON objects with level and msg on validation failure and on create.
Make it your own
The original works. These are your next experiments.
- Optional: add a cursor-based page instead of offset.
- Optional: log a requestId you generate per request.