A RESTful Task Management API built for the FlyRank AI Backend Internship, featuring full CRUD operations, layered architecture, input validation, and interactive Swagger documentation.
README orijinal dilinde gösteriliyor.
FlyRank Internship · Backend Track · Week 3 · Assignment A2 — Connecting your CRUD to the database. A CRUD task API that started in-memory (A1) and now stores its data in a real SQLite database, so it survives a server restart.
tasks.db
— no server process to install, configure, or keep running.tasks.db is created automatically, in the project root, the first time
the app runs (src/db.js opens it with better-sqlite3, which creates
the file if it doesn't exist). It's listed in .gitignore — the repo
ships the code that creates the database, not the database itself, so
every clone starts fresh with the same 3 seeded tasks.
npm install
npm start
That's it — one command. On first run it creates tasks.db, creates the
tasks table, and seeds 3 example tasks. GET /tasks will show exactly
those 3 tasks, and restarting the server (or deleting tasks.db and
starting again) doesn't duplicate them.
The server listens on http://localhost:3000 (override with PORT=...).
| Method | Path | Description |
|---|---|---|
| GET | /tasks |
List all tasks |
| GET | /tasks/:id |
Get one task (404 if unknown) |
| POST | /tasks |
Create a task (400 if title missing) |
| PUT | /tasks/:id |
Update a task (404/400 as above) |
| DELETE | /tasks/:id |
Delete a task (204 on success) |
Identical behavior to the A1 in-memory version — same request/response
shapes, same status codes (200/201/204/400/404), same JSON error
shape ({ "error": "..." }). Only the storage underneath changed.
GET /tasks, plus GET /stats)GET /tasks?search=milk — WHERE title LIKE ?GET /tasks?done=true — WHERE done = ?GET /tasks?sort=title — ORDER BY titleGET /stats — { "total": 3, "done": 1, "pending": 2 } via SELECT COUNT(*)/SUM(done)An index on tasks.title (CREATE INDEX IF NOT EXISTS idx_tasks_title ON tasks (title))
backs the search and sort extras — an index lets SQLite look title values
up directly instead of scanning every row.
Via the API: create a task, stop the server (Ctrl+C), start it again
(npm start), then GET /tasks — the task is still there.
Via DB Browser for SQLite: open tasks.db in DB Browser for SQLite,
browse the tasks table's rows directly — the same rows the API serves.
Manual step for whoever owns this repo: open
tasks.dbin DB Browser for SQLite and take a screenshot of thetaskstable for this README. That's a visual, hands-on step the assignment specifically asks a human to do — drop the image atdocs/db-browser-screenshot.pngand addhere.
Full write-up and every query's output: docs/stage4-sql-by-hand.md.
One example query and what it returned:
SELECT * FROM tasks WHERE done = 1;
-- 3|Write CRUD API|1
That query returned only task #3, the single seeded task with done = 1.
Running it (via the sqlite3 CLI, and equally via DB Browser's "Execute
SQL" tab) and then calling GET /tasks from the running API — with no
restart — showed the exact same data both ways. There's no "syncing"
between the API and the database viewer; they're both just reading
tasks.db.
scripts/test-api.sh runs the same curl checks against this SQLite
version that would have been run against the A1 in-memory version — same
requests, same expected status codes:
npm start & # in one terminal
bash scripts/test-api.sh # in another
All 9 checks pass. That's the proof that storage really is "just an implementation detail": nothing about what the client sends or receives changed, only where the data lives underneath did. If the tests still pass unchanged, the API's contract never moved — the whole promise of separating an API from its storage layer.
Full write-up, both prompts, both AI-generated versions, and the raw
diffs: docs/stage6-ai-rematch/.
Three concrete things the AI's first attempt got wrong that mine didn't:
GET /tasks/:id glued req.params.id straight into the SQL string
instead of using a ? placeholder — despite being told to
parameterize everything. curl /tasks/abc crashes it with a 500
and a leaked stack trace; my version returns a clean 404.done as SQLite's raw 0/1 instead of a JSON boolean,
a silent contract change from the in-memory version's behavior.It also did one thing better, unprompted: it turned on
journal_mode = WAL, a genuinely good default for concurrent access that
I hadn't set myself. Full details, plus the rematch after tightening the
prompt, are in ai-vs-me.md.
One honest commit per stage — A1 baseline, Stage 0 through Stage 6,
plus an Extras commit for the stretch goals:
git log --oneline
tasks.db), not in memorytasks table created automatically if missing200/201/204/400/404) with JSON error messagesscripts/test-api.sh, 9/9 passing)This repo is initialized and committed locally with one commit per stage. Pushing it to a public GitHub repo is a step I've left for the repo owner to do explicitly (it requires their own GitHub account/auth):
gh repo create task-manager-api --public --source=. --remote=origin
git push -u origin main