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

Scaffold the chat app

This chapter creates the project the whole track builds on: a NetScript workspace with a Fresh frontend, the streams runtime that durable chat sessions live in, and your model key, all running under Aspire.

  1. 1 · Scaffold
  2. 2 · Durable chat route
  3. 3 · Chat UI
  4. 4 · Server-side tool call
  5. 5 · MCP tools & widgets
  6. 6 · Live streaming

What you will build

A chat-app/ workspace on disk: a Fresh app, the streams plugin wired for durable sessions, and Aspire orchestration. At the end, the Aspire dashboard at the URL Aspire prints shows every resource running, ANTHROPIC_API_KEY reaches the app process, and the workspace type-checks.

Before you begin

You need Deno, the Aspire CLI, Docker and an ANTHROPIC_API_KEY.

  1. Confirm the toolchain:

    Shell
    deno --version && aspire --version && docker info
    

    You should see a Deno 2.x version, an Aspire CLI version and Docker engine details. If any are missing, the quickstart walks through installing them.

  2. Install the NetScript CLI once:

    Shell
    deno install --global --allow-all --name netscript --minimum-dependency-age=0 jsr:@netscript/cli@0.0.9
    
  3. Confirm the CLI is on your PATH:

    Shell
    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 chat-app --dry-run

A clean dry run confirms your flags are valid.

Step 2 — Create the workspace

The chat route you write in chapter 2 is the only backend, so a plain Fresh workspace is enough; you don't need an example service:

Shell
netscript init chat-app
cd chat-app

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

Step 3 — Add the streams runtime

A durable chat session is one append-only stream, addressed through the streams runtime. Add the streams plugin so @netscript/fresh/ai has a runtime to resolve session URLs against:

Shell
netscript plugin install stream --name streams --samples

Step 4 — Set your model key

The chat route calls Anthropic directly, and the adapter reads ANTHROPIC_API_KEY from the app process environment. Put the key in the workspace's local environment file, where Aspire injects it:

Environment
# chat-app/.env  (add .env to .gitignore if it is not already)
ANTHROPIC_API_KEY=sk-ant-...

Step 5 — Bring up orchestration

Run Aspire from the aspire/ subfolder so the CLI finds apphost.mts:

Shell
cd aspire
aspire restore   # once: restores the Aspire SDK modules into .aspire/
aspire start     # starts the AppHost, the streams runtime, and the Fresh app

aspire start prints the allocated URL for the Aspire dashboard:

Plain text
the URL Aspire prints

Leave aspire start running in this terminal. It is your control plane for the rest of the track.

Verify your progress

  1. Open the Aspire dashboard and check that it lists the streams runtime and the Fresh app.

  2. In a second terminal, type-check the workspace from the project root:

    Shell
    deno task check
    

    A clean check confirms the scaffold and plugin wiring line up.

  • [ ] netscript --help lists the public command groups.
  • [ ] chat-app/ exists with apps/dashboard/ and a plugins/ entry for streams.
  • [ ] ANTHROPIC_API_KEY is set in the app environment.
  • [ ] aspire start is up; the dashboard at the URL Aspire prints lists the streams runtime and the Fresh app.
  • [ ] deno task check is clean.

What you built

A chat-app/ workspace with a Fresh app, the streams runtime for durable sessions and your model key wired to the app process, all orchestrated by Aspire. Next, you wire the durable chat route that turns a prompt into a persisted, streamed reply.

Search all documentation

Type a term to search the documentation.