Skip to content

Module 04 / Lesson 01

Follow a vertical slice from form to saved row

Module 04 · Real-World ContextStep 01 of 04

Never trust a green checkmark or a loading spinner until you have verified the database write and security boundaries.

You click "Publish Update". A green toast notification pops up saying "Published successfully!" But when you open a private browser window, nothing has changed. The AI had simply written a fake timer (setTimeout) that showed a toast without actually persisting data to the database. Or worse: anyone on the internet could edit your company’s incidents because row-level security was missing.

Narrated lesson · 1:22
Read the narration transcript

Follow the Publish button past the toast

An operator posts an update in the status app, sees Published, and closes the form. From the operator's screen the feature looks fine.

A visitor reloads and still sees the older text. Before rewriting the page, trace what the button sent, what the server returned, and whether anything was saved.

Build one complete publish path

The form owns the text the operator is typing. It sends that input to the existing publish action and shows a pending state while the request is open.

The server checks the message and whether this operator can publish to the incident. The code that checks permissions remains part of the feature even when the interface hides the control.

The data helper writes the update and returns the result. Now the interface can say it was saved, or keep the draft and say the save failed.

Compare the trace before and after

The first diff went through a dispatcher and several generic wrappers. The reviewer had to follow every hop to find the result.

The revised diff shows where the publish result comes from. I can still explain who authorizes it, who stores it, and what the visitor reads.

Verify persistence and public visibility

Publish a sample update and reload the incident. Open the public page in a separate session. The expected text should be visible once.

Make one local write fail. The form should retain the draft. Include both results in the pull request so someone else can repeat the check.

The everyday problem

An operator clicks Publish in the status app, sees a green toast, and walks away. Another person refreshes the public incident page and sees nothing new. Now you need to answer a basic question. Did the interface submit the update, did the server accept it, or did the database ever save it? A dozen new helper files can make that question harder than it needs to be.

Walk through the change with the people who use it. The operator needs an honest reply and should keep the draft if something fails. A visitor should see the published update after the save. Treat those as one narrow piece of work. You can add more ways to publish after that piece is easy to follow.

Why the agent got it wrong

Given a broad instruction to make the code scalable, an agent can invent a new event bus, command classes, a data store, and repository wrappers. Each might look reasonable as a pattern. The cost here is that a reviewer has to follow every hop to figure out whether the update was saved exactly once and what happened when it failed.

The key distinction is between a logical boundary and a file boundary. Browser submission, validation, authorization, persistence, and public presentation are different responsibilities. They may live across several files that already exist. A fixed three-file limit can push useful checks into the wrong place. Count the decisions you have to explain, and keep all of the ones the feature needs.

The tool and technique

Build a vertical slice. That means one observable behavior through the interface, server, and data together. In the status app the slice is “publish one update on an existing incident.” Preserve the project’s server auth and data helpers. The server action checks the incoming data, gets the current operator’s authority from the project’s trusted session, and asks the data layer to insert the update.

Ask the agent to trace the present call chain before editing. Have it name each input, the place that checks it, and the success or failure the caller receives. Set a stop point if the existing data contract is unclear. That conversation tends to reveal both unnecessary new layers and missing validation.

Follow a vertical slice from the form to a stored row

Trace one operator action through the form, trusted server handler, and database. A vertical slice means implementing one complete behavior through the layers. Keeping those connections visible makes it easier to review a small agent patch.

src/components/incident-form.tsx → submit the form
src/app/incidents/actions.ts → validate text and check permission
Existing Supabase server client → store the authorized update

On refresh: the same approved update appears in the incident history.

Walk through the trace with the diff open. Find the write and the place that reads it back. An existing shared abstraction earns its place when it makes the trace clearer or protects an invariant.

On screen in the status app

Look at the two workflow sketches below. The broad proposal hides an update behind a generic dispatch chain. The narrow version gives the form a publish action with a meaningful contract. If the action communicates a failure, the form keeps what the operator typed. If it succeeds, the UI can show the published result. The public view still obtains its data from the appropriate published source.

Walk the flow once using a seeded incident titled Event Delivery delay. Enter a short update and click Publish. In the local app, confirm the action returns a saved identifier, reload the incident page, and read the update. Then open the public page in a separate visitor session. Compare the text with the published text in the operator view.

src/app/incidents/[id]/publish-action.ts

Before

Form → generic dispatcher → command handler → event wrapper → repository wrapper → save

After

Form → existing publish action → typed data helper

Action contract:
- Resolve the operator from the server session.
- Validate the incident and message.
- Enforce organization membership and publish permission.
- Return the saved update ID or a recoverable error.
- Refresh the public view only after a successful save.

What to watch for

A direct call to the existing data helper can be easier to review. It still has to respect the project’s persistence, authorization, and caching boundaries. A shared helper can make sense when several paths must apply the same rule. Ask what behavior the next layer guarantees. If the answer is just a renaming of the current function, you probably don’t need the layer yet.

Local examples use seeded accounts and sample data. The architecture must still handle missing input, lost permission, repeat submits, and failed writes. A simple diagram can show these forks. It’s much easier to review a narrow slice when you can explain the failure path in one sentence.

How you know it worked

Open the browser network panel and run the publish path. Follow the form’s action to the stored result and reload the public page. Check that the update persists and appears once. In a controlled fixture, make the action reject the save and confirm the form keeps the text and shows a useful message.

Include the changed files and both outcomes in the pull request. If the result fails after reload, follow the evidence backward and check persistence and public reads separately. In the next lesson you’ll keep the required data change in a versioned migration.

References