Skip to main content
NetScriptdocs Search docs ⌘K v0.0.9
Browse documentation
View as Markdown

Scaffold the dashboard

In this chapter you create my-dashboard/, the workspace that grows into the order-queue dashboard from the track index: a Fresh frontend, an orders service and a Postgres database. Then you boot it under Aspire so the rest of the track has a running system.

  1. 1 · Scaffold
  2. 2 · Contract to service
  3. 3 · Cache-first query
  4. 4 · definePage + island
  5. 5 · Live stream
  6. 6 · Deploy

What you will build

A my-dashboard/ workspace: shared contracts, an example orders service at its allocated endpoint, a Fresh app and a Postgres database, all orchestrated by Aspire. At the end the Aspire dashboard at the URL Aspire prints shows every resource running, and you know which generated directory does what. Every later chapter builds on this workspace.

Before you begin

You need the toolchain from the track index. Confirm the CLI is installed and reachable:

Shell
deno install --global --allow-all --name netscript --minimum-dependency-age=0 jsr:@netscript/cli@0.0.9
netscript --help

The public command groups are agent, config, contract, db, deploy, generate, init, marketplace, plugin, service, tokens, ui:add, ui:init, ui:list, ui:remove and ui:update. If netscript is not found, add Deno's install directory to your PATH and open a new terminal.

Step 1 — Preview the scaffold with a dry run

--dry-run plans the scaffold and prints totals without writing to disk:

Shell
netscript init my-dashboard --dry-run

netscript init validates your options, then runs an ordered pipeline: the project root, Aspire orchestration, contracts, the Fresh app workspace, an empty plugin registry, and optionally a database workspace and an example service. The dry run reports file and directory totals per phase. It also confirms your flags are valid: the CLI rejects bad combinations, such as an unknown --db engine, before any file exists.

Step 2 — Create the workspace

Scaffold for real, with an example service named orders at its allocated endpoint and a Postgres database for the dashboard to read:

Shell
netscript init my-dashboard --service --service-name orders --db postgres
cd my-dashboard

The CLI writes my-dashboard/, formats the output with deno fmt, initializes a git repository, and prints a next steps summary for your options.

init options this track uses (run netscript init --help for the full list)
Name · TypeDescription
--service --service-name ordersflags Include an example oRPC service named orders — the read-model the dashboard consumes.
--db postgresflag Scaffold a Postgres database workspace. The orders read-model is persisted here. Postgres is this track's stack; swap --db postgres for mysql, mssql, or sqlite for a different engine.
--dry-runflag Plan the scaffold and print totals without writing any files (Step 1).

Step 3 — Tour what you got

The parts of my-dashboard/ this track uses:

  • apps/
    • dashboard/ # The Fresh frontend — defineFreshApp, your dashboard UI lives here
  • contracts/ # Shared oRPC + Zod contracts, versioned under versions/v1/
  • services/
    • orders/ # The example oRPC service (src/main.ts, router.ts, routers/)
  • plugins/ # Plugin registry + manifests — empty until you add one
  • aspire/
    • apphost.mts # Entry point for aspire start (TypeScript/Node, not C#)
  • appsettings.json # Infrastructure manifest Aspire reads
  • deno.json # Workspace root: members, tasks, dependency catalog
  • netscript.config.ts # Framework config (defineConfig)

The two directories this track lives in:

  • apps/dashboard/ — your Fresh app. Its entry point is main.ts, which calls defineFreshApp, and vite.config.ts configures its build. Chapters 4 and 5 add routes and islands here.
  • services/orders/ and contracts/ — the typed read-model your dashboard reads. You read them in chapter 2 and consume them from the Fresh app in chapters 3–5.

The Storefront scaffold chapter describes every generated directory.

Step 4 — Look at the Fresh app entry point

Two files define how the Fresh app starts. You don't edit them yet; read them as orientation for chapters 4 and 5.

The app entry point registers the KV adapter and creates the app. Order matters: the Redis/Garnet KV adapter import must run before any code that uses KV, so it sits at the top of the file:

apps/dashboard/main.tsTypeScript
// apps/dashboard/main.ts
// Register Redis/Garnet KV adapter — must run before any getKv() call.
import '@netscript/kv/redis';
import { defineFreshApp } from '@netscript/fresh/server';
import type { State } from '@app/utils.ts';

export const app = defineFreshApp<State>({ name: 'dashboard' });

The Vite config adds NetScript's Fresh build plugin next to the Fresh and Tailwind plugins. createNetScriptVitePlugin from @netscript/fresh/vite tells Vite about NetScript's route manifest, workspace aliases and watch paths:

apps/dashboard/vite.config.tsTypeScript
// apps/dashboard/vite.config.ts (trimmed to the NetScript-specific wiring)
import { fresh } from '@fresh/plugin-vite';
import tailwindCSS from '@tailwindcss/vite';
import { createNetScriptVitePlugin } from '@netscript/fresh/vite';
import { defineConfig } from 'vite';

export default defineConfig(() => ({
  plugins: [
    fresh(),
    tailwindCSS(),
    createNetScriptVitePlugin({
      appRoot,
      workspaceRoot,
      aliasEntries,
      watchPaths: [/* packages, contracts, plugins */],
      routeManifest: {},
    }),
  ],
}));

Step 5 — Bring up orchestration

Aspire provisions your database and cache, and you start it before any netscript db command. Run it from the aspire/ folder so the CLI finds apphost.mts:

Shell
cd aspire
aspire restore   # once: restores the Aspire SDK modules into .aspire/
aspire start       # starts the AppHost and every declared resource

aspire start brings up Postgres, the Redis cache, your orders service and the Fresh app, then prints the allocated URL for the Aspire dashboard:

Plain text
the URL Aspire prints

Leave aspire start running in this terminal for the rest of the track.

Verify your progress

In a second terminal, with aspire start still running in the first, check the orders service's health endpoint:

Shell
curl "$SERVICE_URL/health"

You get a healthy JSON response. Then type-check the workspace from the project root:

Shell
deno task check

A clean check confirms the scaffold, contracts, and service line up.

  • [ ] netscript --help lists the public command groups.
  • [ ] my-dashboard/ exists with apps/dashboard/, contracts/, and services/orders/.
  • [ ] aspire start is up; the dashboard at the URL Aspire prints lists postgres, redis, and orders.
  • [ ] curl "$SERVICE_URL/health" returns a healthy response.
  • [ ] deno task check is clean.

What you built

A NetScript workspace, my-dashboard/, with a Fresh app, an orders service at its allocated endpoint and a Postgres database, all orchestrated by Aspire and visible at the URL Aspire prints. Next, you shape the orders read-model that the dashboard displays.

Search all documentation

Type a term to search the documentation.