spfn 0.2.0-beta.61 → 0.2.0-beta.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -17
- package/dist/index.js +644 -315
- package/dist/templates/README.md +24 -11
- package/dist/templates/modes/full/src/app/auth/callback/page.tsx +1 -0
- package/dist/templates/modes/full/src/app/login/page.tsx +68 -0
- package/dist/templates/modes/full/src/i18n/catalogs.ts +16 -0
- package/dist/templates/modes/full/src/i18n/server.ts +9 -0
- package/dist/templates/modes/full/src/server/config/env.config.ts +23 -0
- package/dist/templates/modes/full/src/server/mcp.ts +75 -0
- package/dist/templates/modes/full/src/server/router.ts +32 -0
- package/dist/templates/modes/full/src/server/routes/examples.ts +94 -0
- package/dist/templates/modes/full/src/server/routes/health.ts +9 -0
- package/dist/templates/modes/full/src/server/routes/root.ts +15 -0
- package/dist/templates/modes/full/src/server/server.config.ts +14 -0
- package/dist/templates/vercel/npmrc +4 -0
- package/dist/templates/vercel/route.ts +53 -0
- package/dist/templates/vercel/vercel.json +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# spfn — the SPFN CLI (backend layer for Next.js)
|
|
2
2
|
|
|
3
|
-
`spfn`
|
|
4
|
-
It
|
|
5
|
-
|
|
3
|
+
`spfn` takes a Next.js idea from prototype to production with a consistent full-stack
|
|
4
|
+
architecture. It can scaffold either a core-only backend or a production baseline with
|
|
5
|
+
authentication, internationalization, and an agent-facing MCP endpoint, then runs the
|
|
6
|
+
dev/build/start lifecycle, database tooling, RPC codegen, and environment validation.
|
|
6
7
|
|
|
7
8
|
> Beta: install with the `@beta` tag (`spfn@beta`). The binary is `spfn`.
|
|
8
9
|
|
|
@@ -18,20 +19,25 @@ pnpm dlx spfn@beta <command>
|
|
|
18
19
|
Or add it as a project dependency (`spfn init`/`spfn create` do this for you), then
|
|
19
20
|
call it via `pnpm spfn <command>` / `npm run spfn:<script>`.
|
|
20
21
|
|
|
21
|
-
Requirements: Node.js 18.18
|
|
22
|
+
Requirements: Node.js 18.18+ for bare mode, Node.js 20+ for full mode's MCP server,
|
|
23
|
+
Next.js 15+ (App Router, `src/` dir), PostgreSQL (Redis optional).
|
|
22
24
|
|
|
23
25
|
## Usage
|
|
24
26
|
|
|
25
27
|
```bash
|
|
26
|
-
#
|
|
27
|
-
npx spfn@beta create my-app
|
|
28
|
+
# Prototype-to-Production baseline: core + auth + i18n + MCP
|
|
29
|
+
npx spfn@beta create my-app --mode full
|
|
28
30
|
cd my-app
|
|
29
31
|
docker compose up -d # Postgres + Redis
|
|
30
|
-
# .env.local & .env.server are generated —
|
|
32
|
+
# .env.local & .env.server are generated — keep both gitignored
|
|
33
|
+
pnpm spfn db migrate # Apply auth migrations
|
|
31
34
|
pnpm spfn:dev # Next.js :3790 + SPFN API :8790
|
|
32
35
|
|
|
36
|
+
# Core-only full-stack skeleton
|
|
37
|
+
npx spfn@beta create my-api --mode bare
|
|
38
|
+
|
|
33
39
|
# Add SPFN to an existing Next.js project
|
|
34
|
-
npx spfn@beta init
|
|
40
|
+
npx spfn@beta init --mode full
|
|
35
41
|
```
|
|
36
42
|
|
|
37
43
|
The package manager is auto-detected (pnpm > yarn > bun > npm) from lockfiles; override
|
|
@@ -49,24 +55,32 @@ Registered top-level commands: `create`, `init`, `add`, `dev`, `build`, `start`,
|
|
|
49
55
|
Runs `create-next-app` with SPFN-recommended flags (TypeScript, App Router, `src/`,
|
|
50
56
|
Tailwind, import alias `@/*`, no ESLint), sets up SVGR icons, then runs `init`.
|
|
51
57
|
|
|
58
|
+
Choose `full` for the recommended Prototype-to-Production baseline or `bare` for the
|
|
59
|
+
historical core-only skeleton. Without `--mode`, interactive runs show a mode selector
|
|
60
|
+
with `full` recommended. For backward compatibility, non-interactive `--yes` runs without
|
|
61
|
+
an explicit mode continue to generate `bare`; automation that wants full should always
|
|
62
|
+
pass `--mode full`.
|
|
63
|
+
|
|
52
64
|
| Option | Description |
|
|
53
65
|
|--------|-------------|
|
|
54
66
|
| `--pm <manager>` | Force package manager: `npm` \| `pnpm` \| `yarn` \| `bun` |
|
|
55
67
|
| `--shadcn` | Also run `shadcn init` |
|
|
68
|
+
| `--mode <mode>` | `bare` (core only) \| `full` (core, auth, i18n, MCP) |
|
|
56
69
|
| `--skip-install` | Skip dependency install |
|
|
57
70
|
| `--skip-git` | Skip `git init` |
|
|
58
71
|
| `-y, --yes` | Skip prompts, use defaults |
|
|
59
72
|
|
|
60
73
|
### `spfn init`
|
|
61
74
|
|
|
62
|
-
Adds SPFN to an existing Next.js project: copies the server templates, wires the RPC
|
|
75
|
+
Adds SPFN to an existing Next.js project: copies the selected server templates, wires the RPC
|
|
63
76
|
proxy route, Docker files, deploy + codegen config, updates `package.json` scripts/deps,
|
|
64
|
-
and installs.
|
|
77
|
+
and installs. Full mode also adds the `/_auth/:path*` → SPFN API rewrite to
|
|
65
78
|
`next.config` (OAuth callbacks return to the app origin; merged manually if a `rewrites()`
|
|
66
79
|
already exists). See [Scaffold structure](#scaffold-structure) for what lands on disk.
|
|
67
80
|
|
|
68
81
|
| Option | Description |
|
|
69
82
|
|--------|-------------|
|
|
83
|
+
| `--mode <mode>` | `bare` (core only) \| `full` (core, auth, i18n, MCP) |
|
|
70
84
|
| `-y, --yes` | Skip prompts, use defaults |
|
|
71
85
|
|
|
72
86
|
Generated projects pin `drizzle-orm` and `drizzle-kit` to `1.0.0-rc.4`, matching
|
|
@@ -280,7 +294,7 @@ Install and configure SVGR for SVG-as-component imports (Next.js only).
|
|
|
280
294
|
|
|
281
295
|
## Scaffold structure
|
|
282
296
|
|
|
283
|
-
|
|
297
|
+
Both modes produce the core full-stack skeleton:
|
|
284
298
|
|
|
285
299
|
```
|
|
286
300
|
src/
|
|
@@ -303,13 +317,37 @@ docker-compose.production.yml
|
|
|
303
317
|
Dockerfile, .dockerignore
|
|
304
318
|
next.config.ts # patched when auth is enabled: /_auth/:path* rewrite → SPFN API
|
|
305
319
|
.env.example # committed reference — every key, placeholder values
|
|
306
|
-
.env.local # generated, gitignored (Next.js
|
|
320
|
+
.env.local # generated, gitignored (values loaded by Next.js)
|
|
307
321
|
.env.server # generated, gitignored (server secrets: DB, cache)
|
|
308
322
|
```
|
|
309
323
|
|
|
324
|
+
Full mode overlays the Prototype-to-Production baseline:
|
|
325
|
+
|
|
326
|
+
```
|
|
327
|
+
src/
|
|
328
|
+
app/login/page.tsx # provider login starter UI
|
|
329
|
+
app/auth/callback/page.tsx # OAuth session handoff
|
|
330
|
+
i18n/catalogs.ts # application-owned en/ko starter messages
|
|
331
|
+
i18n/server.ts # configured server-side i18n registry
|
|
332
|
+
server/mcp.ts # authenticated /mcp endpoint + starter app_status tool
|
|
333
|
+
server/router.ts # authRouter + mcpRouter + global authenticate
|
|
334
|
+
server/server.config.ts # createAuthLifecycle + i18n startup
|
|
335
|
+
next.config.ts # /_auth/* callback rewrite
|
|
336
|
+
.env.local # generated auth session secret (gitignored)
|
|
337
|
+
.env.server # auth keyring + MCP operator key (gitignored)
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The full RPC proxy imports the auth interceptor and merges `authRouteMap`. Internal auth
|
|
341
|
+
and MCP keys are generated with cryptographic randomness in ignored local env files;
|
|
342
|
+
`.env.example` contains placeholders only. Add only the provider keys you use, then run
|
|
343
|
+
`pnpm spfn db migrate`. The starter MCP endpoint accepts `SPFN_MCP_API_KEY` as a Bearer
|
|
344
|
+
token for first-party operation; replace that validator with OAuth before third-party access.
|
|
345
|
+
|
|
310
346
|
`init` also patches `package.json` (scripts: `spfn:dev`, `spfn:server`, `spfn:next`,
|
|
311
347
|
`spfn:build`, `spfn:start`, `codegen`; deps: `@spfn/core`, `spfn`, `drizzle-orm`,
|
|
312
|
-
`@sinclair/typebox`, `concurrently`, etc
|
|
348
|
+
`@sinclair/typebox`, `concurrently`, etc.; full also adds `@spfn/auth`, `@spfn/i18n`,
|
|
349
|
+
`@spfn/mcp`, auth's `@spfn/notification` peer, and a Node `>=20.0.0` engine when the
|
|
350
|
+
existing range still permits older Node versions), excludes `src/server` from the root
|
|
313
351
|
`tsconfig.json` (Vercel compat), and adds `.spfn/`, `.env.local`, `.env.server` to
|
|
314
352
|
`.gitignore`.
|
|
315
353
|
|
|
@@ -387,8 +425,9 @@ type ships from `spfn` (`@type {import('spfn').SpfnConfig}`).
|
|
|
387
425
|
|
|
388
426
|
## Pitfalls
|
|
389
427
|
|
|
390
|
-
- **`.env.server` is gitignored and server-only.** Put DB/secret values there,
|
|
391
|
-
|
|
428
|
+
- **`.env.server` is gitignored and server-only.** Put backend-only DB/secret values there,
|
|
429
|
+
not in `.env` (committed). Full mode's session-cookie secret is the intentional exception:
|
|
430
|
+
it lives in gitignored `.env.local` because Next.js must encrypt the cookie. There is no
|
|
392
431
|
`.env.server.local`. `spfn init` generates `.env.server`; put DB/secret values there.
|
|
393
432
|
Load order is the standard dotenv chain ending with `.env.server`.
|
|
394
433
|
- **Never commit secrets in `spfn.config.js`.** It's checked into Git; its `env` block is
|
|
@@ -406,6 +445,9 @@ type ships from `spfn` (`@type {import('spfn').SpfnConfig}`).
|
|
|
406
445
|
- **Package manager is auto-detected from lockfiles.** If detection is wrong (e.g. mixed
|
|
407
446
|
lockfiles), pass `--pm` to `create`. In a pnpm workspace, `create` installs from the
|
|
408
447
|
workspace root, not the new project dir.
|
|
448
|
+
- **Make scaffold mode explicit in automation.** Interactive runs recommend `full`, while
|
|
449
|
+
historical `--yes` calls without `--mode` remain `bare`. Pass `--mode full` or
|
|
450
|
+
`--mode bare` so scripts state their intended architecture.
|
|
409
451
|
- **Regenerate the route map after route changes outside dev.** If
|
|
410
452
|
`src/generated/route-map.ts` is missing or stale, run `spfn codegen run` — the RPC proxy
|
|
411
453
|
depends on it.
|
|
@@ -416,5 +458,3 @@ type ships from `spfn` (`@type {import('spfn').SpfnConfig}`).
|
|
|
416
458
|
|
|
417
459
|
- `@spfn/core` — server, route DSL, codegen, db, client runtime.
|
|
418
460
|
- Project root README — framework overview and getting started.
|
|
419
|
-
</content>
|
|
420
|
-
</invoke>
|