jonnifyelixir
F6 · Phoenix Framework / F6.09 · the live dashboard

F6 · the capstone lab · module 9

The live dashboard

This is the lab where the whole course converges. The goal is a real-time operations dashboard: a single screen that shows how many courses and enrollments exist, a live feed of what is happening, and how many people are watching right now — all updating the instant anything changes, for everyone at once, with no reload. Nothing here is new machinery. The dashboard is a LiveView (F6.06) holding a small read model on its socket: counts seeded from the contexts (F6.04) at mount, plus a capped stream for the activity feed. It comes alive because the engine emits domain events (F5) and the domain broadcasts them on a topic (F6.07); the dashboard subscribes on its connected mount and, in handle_info/2, folds each event into the read model — bump a count, prepend a feed row. Because one broadcast fans out to every subscribed LiveView, every open dashboard updates together, and Presence turns “who is subscribed” into a live viewer count. Protected by the auth from F6.08 and clustered across nodes in production, it is the same supervised system you have built all along — now observing itself in real time.

Three dives: build the dashboard as a read model, broadcast engine events into it, and serve many clients live — F5, F6.04, F6.06, F6.07, and F6.08, wired into one screen.

One event, every dashboard live

F5 ENGINE enroll/2 emits an event :event broadcast "events" DASHBOARD — READ MODEL handle_info/2 folds the event enrollments 41 ACTIVITY FEED · stream enrollment created course published CLIENTS client A 41 client B 41 client C 41 Presence — watching 3 FOLDED 0 events

read model — enrollments 41, 3 clients live
Emit an event: the engine broadcasts on "events", handle_info/2 folds it, and every client mirrors the new count.

Three moves of the lab

The lab is three moves, one per dive. Build the dashboard LiveView and seed its read model from the contexts. Broadcast engine events and fold them in as they arrive. Serve many clients so every viewer stays in sync, with a live count. Select a move.

The lab · select a move

BUILD a LiveView read model — counts seeded from the contexts F6.09.1 BROADCAST fold engine events in — handle_info bumps counts & feed F6.09.2 MANY CLIENTS every dashboard in sync — Presence counts the viewers F6.09.3

move: build

does: a read model seeded from contexts

The dashboard writes nothing. It seeds from the read side of the domain and then keeps itself current by listening — a projection over the event stream, not another source of truth.

Where the course converges

Follow one event all the way through. The F5 engine records a fact; the context broadcasts it on the "events" topic the moment the write succeeds; PubSub fans that one message out to every subscribed dashboard; each dashboard’s handle_info/2 folds it into its read model and pushes a diff to its browser; and Presence keeps the viewer count honest. Every layer you built has a place in this single path.

engine → broadcast → every dashboard, folded & live

F5 engine emits an event context broadcast "events" PubSub fan-out dashboard A fold → diff dashboard B fold → diff dashboard C fold → diff Presence counts the dashboards — a live "watching" number F5 emits · F6.07 broadcasts · F6.06 folds & renders · F6.08 protects & clusters

There is no orchestrator in the middle deciding who needs what. Each dashboard independently folds the same event into its own view, and the runtime delivers the message to all of them. That is the BEAM model, end to end.

Three deep dives

In order: build the dashboard and seed its read model; broadcast engine events and fold them in; and serve many clients with a live viewer count, clustered for production.

F6.09.1
Build the dashboard
A LiveView read model: counts seeded from the F6.04 contexts at mount, a capped stream for the feed, and the render.
F6.09.2
Broadcast engine events
Subscribe on the connected mount, then fold each broadcast into the read model in handle_info/2.
F6.09.3
Many clients, live
One broadcast, every dashboard; a Presence viewer count; read-only, clustered across nodes.

eight modules of parts

an engine, contexts, routing, templates, LiveView, PubSub, and a deploy.

one live screen

the dashboard assembles them into a real-time view of the running system.

Start with building the dashboard, then broadcasting engine events, then many clients, live. This is the final module of the Phoenix chapter and of the course — the capstone over everything in F6 and the F5 engine beneath it.

References

Live state over a socket, handling broadcasts, streams for collections, and the built-in dashboard as a real-world example of the pattern.

Sources

Related in this course