Why a vanilla JavaScript board
The module builds the frontend as one plain HTML file with CSS and JavaScript, no framework and no build step. That choice keeps the AI-assisted workflow visible: the markup, the styles, the fetch calls, the render logic and the event handlers are all in one place you can read. It also gives the assistant fewer places to invent structure you did not ask for.
Key ideaBuild the board in layers. Static layout first, then styling, then fetch/render logic, then UI states, then drag-and-drop.
What the board must do
Seven requirements. The exact status strings matter: the UI may show friendly labels, but it sends the API’s own values.
| Requirement | What it means |
|---|---|
| Three status columns | Render columns for the exact API statuses: ToDo, InProgress, and Done. The UI may display them as To Do, In Progress, and Done. |
| Priority sorting | Within each column, sort cards High -> Medium -> Low. If priorities tie, keep a predictable secondary order such as lower id first. |
| Backend data | Load tasks with GET /tasks from the FastAPI backend, typically running at localhost:8000 during the demo. |
| UI states | Show loading while fetching, empty placeholders for columns without cards, the normal ready board when data exists, and an error state when the fetch fails. |
| Drag-and-drop | After the static board works, use browser-native drag-and-drop to move cards between columns. No external drag library is required for the module. |
| Server persistence | On drop, send PATCH /tasks/{id} with the new status. The backend decides whether the move is valid. |
| Rejected moves | If the server returns 422 or the network fails, refresh or revert the UI and show the user an error message. |
The build sequence
Each step adds one layer and is checked before the next. Asking chat for a plan before asking for code (step 4) is the same habit as prompt P2.
- Create frontend/index.html and open it with a local static server such as Live Server.
- Write the static board skeleton: page header, three columns, and one sample card.
- Use inline suggestions for repeated HTML and CSS patterns, but inspect each suggestion before keeping it.
- Ask chat for a small fetch/render plan before asking for implementation.
- Add fetchTasks() and renderBoard() so real tasks from GET /tasks appear in the correct columns.
- Add loading, empty, ready, and error states before adding drag-and-drop complexity.
- Use DevTools to check failed requests, status codes, and response bodies.
- Add drag-and-drop only after the board renders correctly from real backend data.
- B1Static layoutHeader, three columns, sample card
- StylingInline suggestions, inspected
- B2Fetch / renderGET /tasks into the right columns
- B3UI statesLoading, empty, ready, error
- B5Drag-and-dropPATCH, revert on rejection
Labels are the matching prompts in the Module 3 library. B4 (CORS) is used only if the browser cannot fetch.
Constants from the demo
The notes print four constants the demo board uses. Keeping them in one place means the base URL, the exact statuses, their display labels and the sort order are defined once, and a refactor has one obvious thing not to change.
Code from the notesAPI_BASE = "http://localhost:8000" STATUSES = ["ToDo", "InProgress", "Done"] STATUS_LABELS = { ToDo: "To Do", InProgress: "In Progress", Done: "Done" } PRIORITY_ORDER = { High: 0, Medium: 1, Low: 2 }
When the browser blocks the request: CORS
During the demo the frontend and backend run on different local origins: the page might be served from localhost:5500 while FastAPI runs on localhost:8000. If the browser console says a request was blocked by CORS policy, the fix is in the backend: allow the local frontend origin in the FastAPI app. The notes say the recording treats this as a practical troubleshooting step, not optional trivia. Typical origins to consider are http://localhost:5500, http://127.0.0.1:5500 and whatever dev-server origin your setup uses. Add only what your local setup needs and keep the change visible in app/main.py. Before you change anything, gather the evidence prompt B4 asks for: the page URL, the backend URL, the exact console error and what the Network tab shows, so you can tell CORS apart from a wrong URL or a stopped server.
Read with careThe port numbers are examples from the demo, not requirements. Your static server may use a different origin; allow that one, and do not reach for a wildcard to make the error go away.
Drag-and-drop that respects the server
Drag-and-drop uses the browser’s native API: each card carries its task id, each column is a drop target, and a drop sends PATCH /tasks/{id} with the new status. The backend decides whether the move is valid. Prompt B5 spells out the behavior the notes require: move the card locally first so the UI feels responsive, keep the move on success, and on a 422 or a network failure revert the card, re-render and show the message. A drop into the card’s own column sends nothing.
- Valid move: PATCH succeeds, and the card stays in its new column.
- Rejected move: the server returns 422, the card reverts or the board refreshes, and the server’s message is shown.
- Network failure: revert and show a clear fallback message.
- Same-column drop: no PATCH at all.
Key ideaA drag that only moves a card on screen is decoration. The feature is the PATCH, and the honest revert when the server says no.
Verify the board
Each behavior has a piece of evidence you can actually point to. Note the last row: a same-column drop that fires a PATCH is noisy at best, and against Module 2’s rule set, which rejects same-status moves, it would come back as an error.
| Behavior to verify | Evidence to use |
|---|---|
| Three columns render | Browser view shows To Do, In Progress, and Done columns with correct counts or clear empty states. |
| Priority sort works | Create or seed High, Medium, and Low tasks and confirm the visual order inside each column. |
| Loading state appears | Reload while the request is pending or use DevTools throttling to see the loading behavior. |
| Empty state appears | A column with no tasks still has a clear placeholder and remains visually understandable. |
| Error state appears | Stop the backend and reload. The UI should show a clear error instead of a blank board. |
| Valid drag persists | Drag a card to a valid next status. DevTools shows PATCH /tasks/{id} and the server returns success. |
| Rejected drag is handled | Try an invalid transition such as moving a Done task back to ToDo if the backend rejects it. The card should revert or refresh, and the UI should show the server message. |
| Same-column drag is not noisy | Dropping a card back into its original column should not send unnecessary PATCH requests. |
Read with careThe point about same-status moves is this guide’s inference from the Module 2 notes, not something the Module 3 notes state. Fetch also does not reject on a 404 or 422 by itself, as the Fetch reading stresses, so your code must check the response status to reach the rejected-move path at all.
Key takeaways
- Send the API’s exact status values; show friendly labels only in the UI.
- Add one layer at a time, and add drag-and-drop last.
- Diagnose CORS from the console and Network tab, then allow only the origins you need.
- A drop is a PATCH: keep it on success, revert and explain on rejection, send nothing for the same column.
- Every board behavior has a check you can show, from throttled loading to a stopped backend.