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.
# 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# 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# 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# 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 startCopy-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]
- components/ui/ [owned]
- 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]
/**
* @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.
Explore the contract flow
One definition, carried end to end
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.
// 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']),
});// 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);// 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' });// 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.