Thesis
Browsing worked. Reviewing did not.
The feature was stubbed at both ends, so finishing it meant touching every tier.
The Book Review Platform lets readers browse a catalog of books, open a book's details and leave a review. In the version I started from, the first two worked. The API route for posting a review returned 501 Not Implemented, and the React form displayed a note telling the developer to implement it.
Definition of done was fixed up front: a reader can submit a review for any book and see it immediately; the API returns the correct status for success, a missing book and an empty review; and the server starts reliably on Windows, macOS and Linux.
| Component | Initial state | What I delivered |
|---|---|---|
| POST route | Returned 501 "not implemented" | Full implementation: ObjectId lookup, atomic append, 201 and 404 responses |
| React handler | Showed placeholder text instead of posting | Request with error handling, immutable state update, input reset, status messages |
| start script | Crashed on Windows before the server could run | Cross-platform script that also fails fast if seeding fails |
System
Three tiers, each talking only to its neighbor
The frontend never touches the database; the API owns all database access.

| Method | Route | Purpose | Responses |
|---|---|---|---|
| GET | /books | List all books. Reviews are excluded with a projection to keep the list light | 200 |
| GET | /books/:id | One book with its full reviews array | 200 · 404 |
| POST | /books/:id/reviews | Append a review to a book — the route implemented here | 201 · 400 · 404 |
Data model
Each book is one document with its reviews embedded as an array. That shape is what makes the feature cheap: one query reads a book with all its reviews, and one atomic update adds a review. The seed script inserts four classics only when the collection is empty, so restarts never create duplicates.
Route
Find the right book, append once, report honestly
Three decisions, each of which fails silently if taken the obvious way.
Why the atomic append matters more than it looks
The intuitive implementation reads the book, pushes onto the array in application code, and writes the document back. That is also how reviews get lost: two submissions arriving close together each read the same array, and the second write silently discards the first.
The response contract
An empty review is rejected with 400 before any database work happens. A zero match count means no book carries that ID, so the route returns 404. Otherwise it returns 201 — the status that means a resource was created, rather than a generic success.
Client
Update the screen without asking the server again
The immutability detail is what makes the review appear instantly.
The component tracks three pieces of state: the book and its reviews, the text being typed, and the status message shown under the form. The submit handler blocks the browser's default form submission, rejects empty input before making any network call, and posts the review to the endpoint for the selected book.
Once the server confirms, it appends the review to state, clears the input and shows a success message. Any failure is caught and reported to the user rather than breaking the page.
Why the state update is immutable
The update creates a new object and a new array rather than modifying the existing one. React detects the change by reference, so pushing onto the existing array in place would leave the screen stale even though the data had changed — a bug that looks like a failed request when nothing failed at all.
It also saves a round trip: there is no refetch of the whole book after a successful post, because the client already knows exactly what changed.

Incident
The feature could not be tested until the server would start
A cross-platform bug hiding in a single character.
Symptom. Running the start script in the backend crashed immediately with an error saying Node could not find a module named seed.js; — semicolon included. With no API running, the frontend loaded and showed an empty book list, which looks like a data problem and is not.
Root cause. The script was node seed.js; nodemon index.js. On macOS and Linux, npm runs scripts through a POSIX shell, where the semicolon separates two commands. On Windows, npm uses the command interpreter, which does not, so Node received seed.js; as the filename.
Fix. Replacing the separator with &&, which works in every shell. That also buys a safety property worth more than the portability: the server now starts only if seeding succeeded, so the API never runs against a database that failed to initialize.


Proof
Every response path exercised
Not only the happy one — the two failure paths are where honest APIs are made.
| Scenario | Expected | Result |
|---|---|---|
| Syntax check on the route file | No errors | Pass |
| Valid review against a real book | 201 | Pass review stored in the book's array |
| Review against an unknown ID | 404 | Pass |
| Submission with no review content | 400 | Pass existing validation intact |
| End-to-end through the browser | Review appears, message shown | Pass |
The third and fourth scenarios are the ones that justify the effort. A 404 that quietly returns 201 is exactly the kind of defect that surfaces months later as "some reviews just don't save," and confirming the pre-existing validation still held after my changes is how you avoid fixing one path while breaking another.

Status
What works, and what I would improve next
The first item is a real gap, not a polish task.
| Capability | State | Note |
|---|---|---|
| Review endpoint | Shipped | Atomic append, correct status for success and missing book |
| Client submission and instant render | Shipped | Immutable state update, no refetch, errors surfaced to the user |
| Cross-platform startup | Shipped | Also fails fast if seeding fails |
| Malformed ID handling | Open | A malformed ID throws, so the user gets a 500. Validate the ID or wrap the logic and return a helpful 400 |
| Connection reuse | Open | Each request opens and closes its own client. Connect once at startup and share the pooled client; close in a finally block to prevent leaks on errors |
| Richer review records | Open | Store reviews as objects with text, rating, author and timestamp, and return the created review from the 201 |
| Configuration | Open | Move the database URL and API base URL into environment variables instead of hard-coding localhost |
| Automated tests | Open | API tests for the 201, 400 and 404 paths and a form test, run in CI |