Compare service-backed web apps
These cases fit a Fresh and Preact app whose backend already has services, durable work and telemetry. Each excerpt shows a specific integration; the surrounding app still owns mounting, credentials and recovery policy. All scenarios remain readable without JavaScript.
Choose a scenario
A live operations dashboard
Show order changes without a separate polling loop in every widget.
The service publishes confirmed order changes after its business write. That write and the stream flush are not atomic; use an outbox when a missed update is unacceptable. Aspire supplies the producer’s streams reference and credentials. The shared State Protocol schema works with both the producer and Fresh StreamDB. Keep it in its own module so the island never imports or constructs the server producer. In a Fresh island, create one dashboard instance, await db.preload?.(), mount Orders, and call db.close?.() on disposal. streamsUrl is the authorized streams endpoint; use the URL Aspire prints. Expose only an appropriately authorized stream to the browser, never an internal producer credential. Handle db.status === failed with an explicit reload or recovery path: expired retained offsets do not replay automatically.
NetScript
import { createStateSchema } from '@durable-streams/state';
import { z } from 'zod';
export const schema = createStateSchema({
order: {
schema: z.object({ id: z.string(), status: z.string() }),
type: 'order',
primaryKey: 'id',
},
});
import { createServiceStreamProducer } from '@netscript/plugin-streams-core';
import { schema } from './schema.ts';
const producer = createServiceStreamProducer({
streamPath: '/ops/orders',
schema,
producerId: 'orders-service',
});
export async function publishOrder(id: string, status: string) {
producer.upsert('order', { id, status });
await producer.flush();
}
/** @jsxImportSource preact */
import { createNetScriptStreamDB, useLiveQuery } from '@netscript/fresh/streams';
import { schema } from './schema.ts';
// Create once per mounted dashboard, using the authorized streams endpoint.
export function createDashboard(streamsUrl: string) {
const db = createNetScriptStreamDB({
streamPath: '/ops/orders',
schema,
baseUrl: streamsUrl,
});
function Orders() {
const { data } = useLiveQuery((query) => query.from({ order: db.collections.order }));
return <ul>{data?.map((order) => <li key={order.id}>{order.id}: {order.status}</li>)}</ul>;
}
return { db, Orders };
}
Typical alternative
Next streams server-rendered regions and can read data in Server Components. A continuously changing operations board still needs a transport, client collection and reconnect policy, whether you choose SSE, WebSockets or a hosted realtime database. Those integrations may already be a better fit for an existing React app.
Sources: Next data fetching and streaming
Why it matters: When the backend already publishes NetScript durable streams, the dashboard consumes that same change protocol as typed reactive collections. Widgets can query local state instead of inventing their own pollers. This is a state feed with retention and failure states, distinct from streaming one HTML response.
A SaaS app consuming a versioned pricing service
Change a shared pricing response without silently breaking its callers.
A public quote example with separate contract, server router and consumer modules: the service composition must mount this contract and router as pricing v2 before the client can call it. Keep v1 mounted for callers you have not migrated. apiVersion selects an existing server mount; it does not create one. Inside Aspire the SDK resolves pricing through service discovery. Outside Aspire, provide the SDK URL resolver with the URL Aspire prints. Protected operations also need backend authentication/authorization and the generated session-client contribution.
NetScript
import { baseContract } from '@netscript/contracts';
import { z } from 'zod';
export const pricingV2 = {
quote: baseContract
.route({ method: 'GET', path: '/quote' })
.meta({ access: { authentication: 'none' } })
.input(z.object({ seats: z.number().int().positive() }))
.output(z.object({ totalCents: z.number().int(), currency: z.literal('USD') })),
};
import { implement } from '@orpc/server';
import { pricingV2 } from './contracts.ts';
const os = implement(pricingV2);
export const router = {
quote: os.quote.handler(({ input }) => ({ totalCents: input.seats * 1500, currency: 'USD' })),
};
import { createServiceClient } from '@netscript/sdk/client';
import { pricingV2 } from './contracts.ts';
const pricing = createServiceClient({
contract: pricingV2,
serviceName: 'pricing',
routerName: 'pricing',
apiVersion: 'v2',
});
export async function quoteForTeam(seats: number) {
return await pricing.quote({ seats });
}
Typical alternative
Hono RPC infers a typed client from the server’s route type. Encore also supplies typed service calls. Both avoid hand-maintained transport DTOs. With a separate service estate, your team still chooses how route versions, service addresses and consumer rollout are represented.
Sources: Hono RPC · Encore TypeScript SDK
Why it matters: NetScript lets each caller import a standalone contract object and select the matching API version through a discovery-aware SDK. That makes the migration boundary visible at the call site without importing a service implementation. Type checking covers callers you rebuild, not independently deployed old clients.
An internal admin form backed by an authenticated service
Validate an invitation once, show field errors, and trace the service mutation.
Bind inviteMember to the generated auth/bff.ts typed session client on the server, passing browserSessionContext(request). The members service must enforce authentication and its members:write scope using its authenticator and contract authorizer. This UI never decides who may invite. The page builder owns server validation, CSRF, form state, redirect and span naming. Mount the built definition in the Fresh route; replace the minimal HTML controls with generated Fresh UI controls in your app.
NetScript
/** @jsxImportSource preact */
import { definePage } from '@netscript/fresh/builders';
import type { RuntimeFormState } from '@netscript/fresh/form';
import { z } from 'zod';
const Invite = z.object({ email: z.string().email() });
function InviteForm(form: RuntimeFormState<z.input<typeof Invite>>) {
const email = form.fields.email;
return (
<form {...form.formProps}>
<input {...form.csrfInputProps} />
<label {...email.labelProps}>Team member email</label>
<input {...email.controlProps({ type: 'email' })} role={undefined} />
{email.error && <p {...email.errorProps}>{email.error}</p>}
{form.formErrors.map((message) => <p key={message}>{message}</p>)}
<button type='submit'>Invite</button>
</form>
);
}
// Application port: bind to the generated BFF's typed session client on the server.
export function invitePage(
inviteMember: (email: string, request: Request) => Promise<{ id: string }>,
) {
return definePage()
.withForm('invite', InviteForm, {
schema: Invite,
initial: () => ({ email: '' }),
mutate: (input, context) => inviteMember(input.email, context.req),
redirectTo: () => '/members',
spanName: 'admin.invite',
})
.build('/members/invite');
}
Typical alternative
Next Server Actions and SvelteKit form actions both support server-side form handling and progressive enhancement. In either stack you can validate with a schema and call an authenticated backend. Keep that setup when its routing, UI ecosystem and access model already fit the app.
Sources: Next forms · SvelteKit form actions
Why it matters: For an app already using NetScript services and telemetry, withForm declares validation, the typed mutation boundary and its trace name beside the route. The same RuntimeFormState supplies field values and accessible error props on a failed submission, including without browser JavaScript. Backend policy remains authoritative.
When another web stack is a better fit
Keep Next when React libraries, Server Components or its deployment ecosystem are the main constraint. SvelteKit already has a compact server-form model with progressive enhancement. Use Nuxt when your team and component library are built around Vue. A single-process web app may not need NetScript’s service discovery or durable runtime processes.
See the capability table and trade-offs.