Skip to Content
ExamplesIssue tracker

Issue tracker, Foldkit with Views

Run the Foldkit issue tracker with a browser-local circuit for derived rows and counts.

This issue tracker client uses a single View.live circuit to maintain the workspace's projects, joined issues, comments, project totals, and status counts. It uses the base server's State route and JSON write API.

The source lives in examples/issue-tracker-demo-foldkit-views.

Run it

Install and build from the repository root.

bun install --frozen-lockfile
bun run build

Start the API and the browser app in separate terminals.

bun run --cwd examples/issue-tracker-demo-foldkit-views dev:api
bun run --cwd examples/issue-tracker-demo-foldkit-views dev

Open http://localhost:1338. Vite proxies /api and /streams to the base server on port 1339. Set ISSUE_TRACKER_DB on the API process to persist workspaces in a SQLite file.

Maintain rows and counts in one circuit

The browser declares the same workspace route and row schemas as the server. Group counts by project and status so UI selections can reuse the circuit. The excerpt paths are relative to the example directory.

src/workspace-views.ts
const projects = View.from(Workspaces, "project");

const issues = View.from(Workspaces, "issue");

const comments = View.from(Workspaces, "comment");

export const workspaceViews = View.live({
  id: "issue-tracker-page",
  params: Workspaces.paramCodecs,
  views: {
    projects,
    visibleIssues: issues.join(projects, {
      as: "project",
      on: (issue, project) => issue.projectId.eq(project.id),
    }),
    commentsOn: comments,
    issueCountByProject: issues
      .groupBy((issue) => ({ projectId: issue.projectId }))
      .aggregate(() => ({ count: View.count() })),
    statusCounts: issues
      .groupBy((issue) => ({ projectId: issue.projectId, status: issue.status }))
      .aggregate(() => ({ count: View.count() })),
  },
});

Open the reader in a subscription

workspaceMessages supplies the remote State service and opens a reader in the Foldkit subscription's scope. The reader keeps its own memory state and checkpoints. Each snapshot supplies all five views and the workspace offset. Foldkit applies the lists and counts in one ReceivedViews message and shows the tracker once caughtUp is true.

src/subscription.ts
    const inputs = RemoteStreams.layer(Streamsy.group(Workspaces), { baseUrl }).pipe(
      Layer.provide(FetchHttpClient.layer),
    );

    return Effect.gen(function* () {
      const live = yield* workspaceViews.at({ workspaceId });

      yield* live.snapshots.pipe(
        Stream.map(({ rows, offsets, caughtUp }) =>
          Message.ReceivedViews({
            caughtUp,
            offset: offsets[Workspaces.key] ?? ZERO_OFFSET,
// ...

Confirm writes

SendWrite decodes the API's Written response and dispatches SucceededSendWrite with its awaitOffset. The model compares that offset with the latest workspace snapshot. When the response arrives first, the model saves awaitOffset on the pending write and removes it when a snapshot reaches that offset. When the snapshot arrives first, the model removes the pending write as soon as the response arrives. If the server accepted the write but its response does not decode, the command answers with the zero offset, so the model drops the pending write with no notice. While the response is in flight, the optimistic row overlays the committed row with the same ID.

A terminal startup or follower fault reaches the workspace error display. Leaving the page closes the reader.

Replay and build measurements

Each page load replays the workspace from the beginning. With the earlier reader and separate write confirmation subscription, a local preview measured elapsed time from navigation until the filter count showed 300 and all 300 issue rows appeared in the DOM. The first load took 559 ms. Four reloads took 379–425 ms.

That earlier Vite production build measured the main JavaScript chunk at 701,553 bytes minified and 198,978 bytes gzipped. The Foldkit variant measured 401,930 bytes minified and 129,711 bytes gzipped in the same comparison.

Run bun run smoke:issue-tracker-foldkit-views from the repository root to check replay, live writes, errors, and cancellation against the base API.

On this page