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

Deno meta-framework · v0.0.9

Define the public boundary once. NetScript carries it through the stack.

NetScript is a meta-framework for Deno. It composes Fresh, Hono, oRPC, and Aspire into one workspace. A database-backed shape can flow from a generated model schema into a versioned contract, through the service, to the rendered page, and the whole system runs as one observed resource graph.

Frameworks supply the web layer, the service layer, or the orchestrator, and leave the boundaries between them to the application. At those boundaries, request types diverge, durable work shrinks to a local retry loop, and incident evidence splits across logs, resource state, and traces. NetScript gives each operation one versioned public contract. It types the handler and the client from that contract and generates the OpenAPI description from it, so nothing derived from the contract can drift from it. The contract narrows or extends a generated model schema when one exists; otherwise you write it directly.

Quickstart

Scaffold and run a workspace

Scaffold a Fresh app, a typed oRPC service, a database, and a shared cache, then start the resource graph with Aspire. You learn where the files live and which generators to use before you write a feature by hand.

Read the quickstart →

my-app/ — workspace root Shell
postgresmy-app/ — workspace rootShell
# 1 · Scaffold the workspace
netscript init my-app --db postgres --yes
cd my-app
netscript service add --name users --with-client

# 2 · Bring up the resource graph
cd aspire
aspire restore
aspire start

mysqlmy-app/ — workspace rootShell
# 1 · Scaffold the workspace
netscript init my-app --db mysql --yes
cd my-app
netscript service add --name users --with-client

# 2 · Bring up the resource graph
cd aspire
aspire restore
aspire start

mssqlmy-app/ — workspace rootShell
# 1 · Scaffold the workspace
netscript init my-app --db mssql --yes
cd my-app
netscript service add --name users --with-client

# 2 · Bring up the resource graph
cd aspire
aspire restore
aspire start

sqlitemy-app/ — workspace rootShell
# 1 · Scaffold the workspace
netscript init my-app --db sqlite --yes
cd my-app
netscript service add --name users --with-client

# 2 · Bring up the resource graph
cd aspire
aspire restore
aspire start

Copy-source

Know what you own

Every scaffolded file carries an ownership tag. [owned] files hold your product code, a generator rewrites [generated] files, and [guidance] files describe the local conventions for people and coding agents. The quickstart shows the full tree.

  • my-app/
    • AGENTS.md [guidance]
    • apps/dashboard/
      • components/ui/ [owned]
        • button.tsx [owned]
      • routes/ [owned]
      • assets/tokens.css [owned]
      • .generated/ [generated]
    • contracts/versions/v1/ [owned]
    • services/users/src/ [owned]
    • database/postgres/
      • schema/schema.prisma [owned]
      • schema/.generated/ [generated]
    • aspire/apphost.mts [generated]
    • deno.json # workspace config [owned]
apps/dashboard/components/ui/button.tsxTypeScript
/**
 * @component Button
 * @layer 2
 * @depends theme-seed
 * @description Generic action primitive for forms and navigation.
 */

export type ButtonVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'destructive';

export type ButtonSize = 'sm' | 'md' | 'lg' | 'icon';

export type ButtonElementType = 'button' | 'submit' | 'reset';

What the framework carries for you

For the UI path, go directly to server-validated forms, optimistic mutations, cache-first SDK bridge, or partial updates. For work beyond a request, compare worker jobs with durable streams. Follow a running system in the Aspire dashboard or expose its contract through the Scalar task.

Learn

Build a real system

The storefront tutorial builds one system end to end, chapter by chapter.

  1. Scaffold the storefront
  2. A typed catalog service
  3. Cart, contract-first
  4. Durable checkout
  5. A verified shipping webhook
  6. The storefront page
  7. Run the storefront under Aspire
Explore the contract flow

One definition, carried end to end

typed from the contract
optional for DB-backed products
db generate
narrow / extend
service handler
hand-written logic
contract-locked input/output
OpenAPI document
generated
SDK client + query keys
derived
DB model
db generate
@database/zod
narrowed / extended versioned API schema + oc.route
the public boundary
page loader + island
consume contract-derived types
DB-backed products normally narrow or extend generated model schemas before defining the public contract; DB-less products start at the versioned API schema. From the contract onward, the handler, OpenAPI document, SDK, and page share its types.

The tabs show one operation at four points in a DB-backed stack. Tab 0 is the optional generation and narrowing step; DB-less products start at tab 1. The contract owns the public input and output shapes. The handler and the page stay application code, but their boundary types come from the contract.

TypeScript
0 · The database (optional)contracts/versions/v1/users.schemas.tsTypeScript
// From the workspace root:
// netscript db generate --db postgres

// contracts/versions/v1/users.schemas.ts
import { UserSchema as DatabaseUserSchema } from '@database/zod';
import { z } from 'zod';

export const UsersListItemSchemaV1 = DatabaseUserSchema
  .pick({ id: true, name: true })
  .extend({
    status: z.enum(['active', 'invited']),
  });

1 · The contractcontracts/versions/v1/users.contract.tsTypeScript
// contracts/versions/v1/users.contract.ts
import { z } from 'zod';
import { oc } from '@orpc/contract';
import { implement } from '@orpc/server';
import { UsersListItemSchemaV1 } from './users.schemas.ts'; // derived in tab 0, or hand-authored without a database

export const UsersListInputSchemaV1 = z.object({
  limit: z.number().int().positive().max(100).default(20),
});

// The contract binds method + input + output. No handler yet.
export const UsersContractV1 = {
  list: oc.route({ method: 'POST' })
    .input(UsersListInputSchemaV1)
    .output(z.object({ items: z.array(UsersListItemSchemaV1) })),
};

export const UsersV1 = implement(UsersContractV1);

2 · The serviceservices/users/src/routers/v1.tsTypeScript
// services/users/src/routers/v1.ts
import { UsersV1 as usersContract } from '@my-app/contracts';

// `input` is typed from the contract. The return value must
// satisfy the contract's output schema — or it does not compile.
export const UsersV1 = {
  list: usersContract.list.handler(async ({ input }) => {
    const items = await listUsers({ limit: input.limit });
    return { items };
  }),
};

// services/users/src/main.ts
// defineService() serves the router with OpenAPI, typed RPC,
// health endpoints, and request logging wired in.
import { defineService } from '@netscript/service';
import { router } from './router.ts';

await defineService(router, { auth: { public: true, reason: 'Public example service; add guards before exposing private data' }, name: 'users', version: '1.0.0' });

3 · The pageapps/dashboard/lib/users.tsTypeScript
// apps/dashboard/lib/users.ts
import { createServiceClient } from '@netscript/sdk/client';
import { createQueryFactories } from '@netscript/sdk/query';
import { UsersContractV1 } from '@my-app/contracts';

export const usersName = 'users';
export const usersRouterName = 'users';
export const usersContract = UsersContractV1;
export const usersClient = createServiceClient<typeof usersContract>({
  contract: usersContract,
  serviceName: usersName,
  routerName: usersRouterName,
});
export const usersQueries = createQueryFactories({
  service: { contract: usersContract, client: usersClient },
}).service;

// apps/dashboard/routes/users/index.tsx
import { definePage } from '@netscript/fresh/builders';
import { z } from 'zod';
import { usersQueries } from '@app/lib/users.ts';
import { routes } from '@app/router.ts';
import UsersTable from './(_islands)/UsersTable.tsx';

export const usersPage = definePage()
  .withRoute(routes.users.$route)
  .withSearchParams(z.object({
    limit: z.coerce.number().int().positive().max(100).default(20),
  }))
  .withLayer('users', UsersTable, {
    loader: async (ctx) => {
      const input = { limit: ctx.search.limit };
      // Server-only: the action owns cache policy; getCachedEntry then
      // reads the persisted pair (null if the write did not land).
      const users = await usersQueries.list(input, { preferFreshOnStale: true });
      const entry = await usersQueries.list.getCachedEntry(input);
      return entry
        ? { users: entry.data, cachedAt: entry.cachedAt }
        : { users, cachedAt: Date.now() };
    },
  })
  .withLayout((slots) => <main class='ns-page'>{slots.users()}</main>)
  .build();

export const { default: page } = usersPage;
export { page as default };

Change the database model and regenerate in tab 0, or change the public schema in tab 1. Handler code in tab 2 that no longer matches stops compiling, the OpenAPI document updates, and the loader in tab 3 sees the new types before anything reaches a browser. That propagation is what the meta-framework adds: it owns the seams between libraries you already know. How the type flow works · how pages consume it.

Where to go

Search all documentation

Type a term to search the documentation.