Contents Lesson 1 of 19

10 min read · professional

Three tools, one product — what composition costs

By the end of this lesson you will have a State section in PLAN.md that places every piece of state your watchlist, screener and backtester keep as panel-local, shared or persisted, with a reason beside each, and a Rebuild section for the cockpit under the four headings — committed before a line of dashboard code exists.

You have three working things: a watchlist, a screener, a backtester. This course puts them on one surface, where three tools sharing a page stop being three tools.

Before you start. This course reads the watchlist from Build Your First Tool, the screener from Build a Screener and the backtester from Backtest Strategies, all in one repository. Starting here without the last two? Branch from the end of Backtest Strategies:

git remote add upstream https://github.com/EodHistoricalData/academy-dashboard-starter.git
git fetch upstream
git switch -c my-cockpit upstream/ref/backtest-strategies/u4
npm install

If you cloned the starter rather than forking it, origin already is the starter: skip the first line and write origin where these lessons write upstream. Every "Compare with ours" in this course names a branch on that remote, such as upstream/ref/build-a-dashboard/u1.

What breaks the moment they share a screen

Each tool was built assuming it owned everything: its own fetch, its own storage key, its own idea of what "selected" means. Put them side by side and four assumptions collide.

Two panels want the same quote. The watchlist has AAPL and so does the screener result. Fetched independently, that is two requests for one fact — and since /real-time is billed per symbol, two calls.

Two panels disagree about the same instrument. One took its price at 20:28, the other at 20:29. Both are correct and the page is inconsistent, which is worse than either being wrong.

"Selected" means three things. Selected-in-watchlist, selected-in-screener and being-backtested were separate concepts. On one surface a person expects clicking a row to mean something everywhere.

Storage keys multiply. Three tools, three localStorage keys, three shapes, and no migration path when one changes.

None of these is a bug in any tool. They are the cost of composition, and the whole course is about paying it deliberately.

The discipline: architecture and state

Build Your First Tool through Backtest Strategies gave you planning, review and testing. This one gives you the question those three cannot answer: where does each piece of state live, and who is allowed to change it?

Three places, and picking wrongly is what makes a dashboard unmaintainable:

  • Panel-local. Which column is sorted, whether a section is collapsed. Nobody else cares, so nobody else should see it.
  • Shared. The selected instrument, the date range, the cached quote for a symbol. More than one panel reads it, so exactly one thing owns it.
  • Persisted. Your watchlist, your saved screens, your layout. It must outlive this browser (another device, cleared site data), so it moves to the server, and that is unit 1's second half.

Decide from the bottom of that list up. Must it outlive this browser? Then it is persisted, however many panels read it. If not, does more than one panel read it? Shared. Otherwise panel-local. A sort order survives a reload in this browser and is still panel-local: only one panel reads it, and losing it on another laptop costs nothing.

The failure mode is putting shared state in a panel. It works, then a second panel needs it, so it gets passed down through three components, and eventually somebody caches a copy. That copy is the bug you will spend a Saturday on.

Rebuild the whole, not the parts

This is Build a Screener's discipline at a larger scale. The four questions again — what survives, what generalises, what is new, what dies — applied to three products at once.

Survives: the proxy, the transport layer, the error handling, the CI key scan. All of it, untouched.

Generalises: the table component you already generalised once. Now it has a third caller, which is when you find out whether the abstraction was right.

New: a layout, a shared store, an alert evaluator.

Dies: three separate page shells, and any code that assumed a tool owned the whole screen.

What you will have at the end

One page with configurable panels, layouts you can name and restore, alert rules that survive a reload, and a refresh budget you can defend — plus a wall you will hit that the previous three courses only pointed at.

The finance behind it

A cockpit exists to answer a question; the benchmark lesson is where that discipline comes from: What is a benchmark actually for?

Try it now

Before writing anything, list every piece of state in your three tools and mark each one panel-local, shared or persisted. The list will be longer than you expect, and the shared row is the design of this whole course.

The prompt

Mock mode on (EODHD_MOCK=1 in .env.local), plan mode on, and paste:

Read the three tools in this repo: the watchlist (src/app/page.tsx and
what it imports), the screen page and the backtest page. List every piece
of state they keep: each localStorage key, each cookie, each constant a
person edits by hand, each value a component holds. For each one, say
where it lives today and which tier it belongs to once the three share a
dashboard, with a one-line reason. Decide the tier in this order:
persisted if it must outlive this browser (another device, cleared site
data), however many panels read it; otherwise shared if more than one
panel reads it; otherwise panel-local. Then draft a Rebuild section for
the cockpit under survives (kept as it is), generalises (kept, but now
serving more callers), new and dies. Add both at the end of PLAN.md as
"## State" and "## Rebuild", and change nothing else. Change no code,
make no request, and show me the diff before saving.

A good answer changes one file, PLAN.md. Expect the saved screens, the shortlist and the notes under persisted, the sort order under panel-local, and the shared tier nearly empty: today no two tools read the same thing on one screen, and filling that row is this course.

Check it yourself

  1. git diff --stat names one file, PLAN.md.
  2. grep -rln writeStored src lists the files that write to this browser; every key they write is somewhere in your State section.
  3. The sort order sits under panel-local and the saved screens under persisted, each with a reason you would defend out loud. Persisted is decided first: the saved screens must outlive this browser, so they are persisted although one panel reads them. The sort order need not, and only one panel reads it, so it is panel-local wherever it is stored today.
  4. The Rebuild section puts the proxy and src/lib/market.ts under survives, and the shared table component (src/components/DataTable.tsx) under generalises.
Compare with ours
## State
- Sort order (localStorage): panel-local. Only the watchlist reads it.
- Saved screens, shortlist, notes (localStorage): persisted. Lesson 2 moves them.
- Watchlist tickers (src/lib/watchlist.ts and the added-tickers cookie): persisted.
- Threshold rules (src/lib/rules.ts): persisted. Unit 3 makes them documents.
- Selected instrument: shared. Does not exist yet: three tools, three meanings.
- Quotes and their age: shared. Fetched per page today; one owner from lesson 3.

The full state at the end of this unit is on the starter's branch ref/build-a-dashboard/u1. Our reference also adds an optional sign-in for one owner (a login page and DASHBOARD_PASSWORD); the course does not need it, and you can ignore those files.

Checkpoint

git status          # PLAN.md only, and no .env file
git add -A
git commit -m "PLAN.md: every piece of state placed before the cockpit exists"

Then answer this lesson's questions.