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.
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.
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.
create-next-app with SPFN flags, SVGR icons, then init — a project from zero.
Adds SPFN to an existing Next.js app — templates, RPC proxy, Docker, scripts.
Installs an ecosystem package and applies its pre-built migrations.
SPFN server + Next.js + codegen watcher; the server signals ready first.
Codegen, Next.js build, tsup-compiled server — then production from the output.
Drizzle Kit wrapped — generate, push, migrate, studio, backup, restore.
Generators from .spfnrc.ts — the route map the RPC proxy depends on.
Schema-driven env files and checks, generated keys, keychain + SOPS secrets.