FUNCTIONS / SPFN CLI — THE BACKEND LAYER FOR NEXT.JS

One binary,
whole lifecycle.

The spfn CLI scaffolds and runs a Hono-based backend that lives inside your Next.js project. It creates the server structure, drives the dev/build/start lifecycle, manages the database with Drizzle Kit, generates the RPC route map, and validates environment variables. No global install — run it through npx or your package manager's dlx.

Read the reference Get started $ npx spfn@beta create my-app
01
The premise

The backend lives
inside the Next.js project.

SPFN doesn't put your API in a second repo. spfn create runs create-next-app with SPFN-recommended flags and then init — which lays down the server templates, wires the RPC proxy route, adds the Docker and codegen config, and patches package.json. From there one binary covers every phase: spfn dev runs the SPFN server and Next.js together, spfn build compiles both, spfn start serves the built output. The server must report ready before Next.js launches in dev, and start hard-fails without a prior build.

create
dev :3790 + :8790
build
start
FIG 01 — ONE PROJECT, TWO SERVERS · NEXT.JS :3790 · SPFN API :8790
02
Core technique

The router's type
is the contract.

There is no separate contract layer to maintain. Routes are defined with the route builder and collected by defineRouter; the client is just createApi<AppRouter>(), inferring every call from the router's type. The one generated piece is the route map: the default @spfn/core:route-map generator emits src/generated/route-map.ts from src/server/router.ts, so the Next.js RPC proxy at /api/rpc/[routeName] can resolve and forward routes — with cookie forwarding and interceptors — without ever importing server code. Generators run automatically during spfn dev and spfn build, and .spfnrc.ts lets you add your own via the Generator interface.

router.ts
codegen
route-map.ts
rpc proxy resolves
FIG 02 — NO CONTRACT LAYER · PROXY NEVER IMPORTS SERVER CODE · AUTO-RUNS IN DEV + BUILD
03
What's inside

Eleven commands,
one surface.

Run it.