Skip to content

feat(cli): add Nitro backend - #1177

Open
AmanVarshney01 wants to merge 2 commits into
mainfrom
aman/add-nitro-backend
Open

AmanVarshney01 wants to merge 2 commits into
mainfrom
aman/add-nitro-backend

Conversation

@AmanVarshney01

@AmanVarshney01 AmanVarshney01 commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • add Nitro 3 as an experimental backend using its native file routes and .output artifacts
  • support oRPC, tRPC, Better Auth, Clerk, databases, ORMs, Polar, AI, web/native clients, and the stack builder
  • support Docker, Prisma Compute, Vercel Services, and Cloudflare Workers
  • build Cloudflare deployments with Nitro's official cloudflare_module preset and Alchemy's public Command.Build + prebuilt Cloudflare.Worker APIs
  • document the generated structure and deployment behavior

Verification

  • bun run check
  • bun run build
  • CLI: 709 passed, 38 skipped, 0 failed
  • generated Bun, npm, and pnpm projects installed, built, typechecked, and served
  • live Docker, Prisma, Vercel, and Cloudflare deployments passed route probes
  • Cloudflare D1, Better Auth, oRPC, CORS, web-to-server URL wiring, and destroy were verified

Summary by CodeRabbit

  • New Features

    • Added experimental Nitro 3 as a backend option with file-based routing and native runtime support.
    • Added compatibility with tRPC, oRPC, Better Auth, Clerk, AI features, databases, and payment routes.
    • Added Docker, Prisma, Vercel, and Cloudflare deployment support.
  • Bug Fixes

    • Improved validation for unsupported database provider selections and runtime combinations.
  • Documentation

    • Updated CLI and deployment guides with Nitro setup, routing, runtime, and deployment details.

@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
create-better-t-stack-web Ready Ready Preview Aug 15, 2026 9:00pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR adds experimental Nitro 3 support across CLI selection, configuration validation, native project generation, API and authentication integrations, Docker, Prisma, Vercel, and Cloudflare deployment, generated-build verification, and documentation.

Changes

Nitro backend support

Layer / File(s) Summary
Backend selection and compatibility
apps/cli/src/..., apps/web/src/..., packages/types/src/schemas.ts
Adds Nitro to backend choices and schema values. Adds runtime, requirement, deployment, authentication, database, and addon compatibility rules.
Native Nitro generation
packages/template-generator/src/..., packages/template-generator/templates/...
Generates Nitro configuration, dependencies, scripts, file-routed handlers, API contexts, authentication routes, CORS middleware, AI routes, and Polar routes.
Deployment and build outputs
packages/template-generator/src/generators/..., packages/template-generator/src/processors/..., packages/template-generator/templates/deploy/...
Uses Nitro’s .output artifact and server/index.mjs entrypoint for Docker, Prisma, Vercel, and Cloudflare paths. Updates Turbo and ignore patterns.
Generated project verification
apps/cli/test/..., apps/web/test/...
Tests Nitro structure, integrations, deployment contracts, runtime behavior, compatibility rules, database combinations, frontend composition, and generated outputs.
Documentation and feature specification
apps/web/content/docs/..., openspec/changes/add-nitro-backend/...
Documents Nitro selection, structure, integrations, deployment support, Cloudflare behavior, and verification requirements.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding Nitro backend support to the CLI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d03cc6f-9f76-4b1a-9f03-43107ddb6a60

📥 Commits

Reviewing files that changed from the base of the PR and between 0668cf6 and 8bac6c2.

⛔ Files ignored due to path filters (1)
  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (59)
  • apps/cli/src/prompts/backend.ts
  • apps/cli/src/prompts/database-setup.ts
  • apps/cli/src/prompts/server-deploy.ts
  • apps/cli/src/utils/compatibility-rules.ts
  • apps/cli/src/utils/config-validation.ts
  • apps/cli/src/utils/display-config.ts
  • apps/cli/src/utils/requirements.ts
  • apps/cli/test/addons.test.ts
  • apps/cli/test/api.test.ts
  • apps/cli/test/auth.test.ts
  • apps/cli/test/backend-runtime.test.ts
  • apps/cli/test/deployment.test.ts
  • apps/cli/test/generated-builds.test.ts
  • apps/cli/test/nitro.test.ts
  • apps/cli/test/requirements.test.ts
  • apps/web/content/docs/cli/compatibility.mdx
  • apps/web/content/docs/cli/index.mdx
  • apps/web/content/docs/cli/options.mdx
  • apps/web/content/docs/guides/cloudflare-alchemy.mdx
  • apps/web/content/docs/guides/docker.mdx
  • apps/web/content/docs/guides/vercel.mdx
  • apps/web/content/docs/index.mdx
  • apps/web/content/docs/project-structure.mdx
  • apps/web/src/app/(home)/new/_components/utils.ts
  • apps/web/src/lib/constant.ts
  • apps/web/test/stack-builder-compatibility.test.ts
  • openspec/changes/add-nitro-backend/.openspec.yaml
  • openspec/changes/add-nitro-backend/design.md
  • openspec/changes/add-nitro-backend/proposal.md
  • openspec/changes/add-nitro-backend/specs/nitro-backend/spec.md
  • openspec/changes/add-nitro-backend/tasks.md
  • packages/template-generator/src/generators/alchemy/server.ts
  • packages/template-generator/src/post-process/vercel-config.ts
  • packages/template-generator/src/processors/api-deps.ts
  • packages/template-generator/src/processors/auth-deps.ts
  • packages/template-generator/src/processors/backend-deps.ts
  • packages/template-generator/src/processors/readme-generator.ts
  • packages/template-generator/src/processors/runtime-deps.ts
  • packages/template-generator/src/processors/turbo-generator.ts
  • packages/template-generator/src/processors/workspace-deps.ts
  • packages/template-generator/src/template-handlers/backend.ts
  • packages/template-generator/src/utils/generated-ignore-patterns.ts
  • packages/template-generator/templates/api/orpc/server/src/context.ts.hbs
  • packages/template-generator/templates/api/trpc/server/src/context.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/ai/server/routes/ai.post.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/base/_gitignore
  • packages/template-generator/templates/backend/server/nitro/base/nitro.config.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/base/package.json.hbs
  • packages/template-generator/templates/backend/server/nitro/base/server/middleware/cors.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/base/server/routes/index.get.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/base/tsconfig.json.hbs
  • packages/template-generator/templates/backend/server/nitro/better-auth/server/routes/api/auth/[...all].ts.hbs
  • packages/template-generator/templates/backend/server/nitro/native-polar/server/routes/polar/success.get.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/orpc/server/routes/api-reference/[...].ts.hbs
  • packages/template-generator/templates/backend/server/nitro/orpc/server/routes/rpc/[...].ts.hbs
  • packages/template-generator/templates/backend/server/nitro/trpc/server/routes/trpc/[...].ts.hbs
  • packages/template-generator/templates/deploy/docker/server/Dockerfile.hbs
  • packages/template-generator/templates/packages/env/src/server.ts.hbs
  • packages/types/src/schemas.ts

Comment thread apps/web/content/docs/project-structure.mdx Outdated
@AmanVarshney01

Copy link
Copy Markdown
Owner Author

Cloudflare support is now included in 97c1caec.

The generated stack builds Nitro's official cloudflare_module output with Command.Build, then deploys the prebuilt entrypoint and public assets through Cloudflare.Worker. It keeps Alchemy's real workerd lifecycle and bindings for local development.

Verified locally and on a disposable live Cloudflare stage: web, Nitro server, oRPC, Better Auth, CORS, D1 reads/writes, deployed server URL wiring, and destroy. The full CLI suite remains clean at 709 passed, 38 skipped, 0 failed. All review threads are resolved.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 44f250e2-2976-4fa0-a616-13593154aadf

📥 Commits

Reviewing files that changed from the base of the PR and between 8bac6c2 and 97c1cae.

⛔ Files ignored due to path filters (1)
  • packages/template-generator/src/templates.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (29)
  • apps/cli/src/prompts/runtime.ts
  • apps/cli/src/utils/compatibility-rules.ts
  • apps/cli/src/utils/config-validation.ts
  • apps/cli/test/backend-runtime.test.ts
  • apps/cli/test/generated-builds.test.ts
  • apps/cli/test/matrix/oracle.ts
  • apps/cli/test/nitro.test.ts
  • apps/web/content/docs/cli/compatibility.mdx
  • apps/web/content/docs/guides/cloudflare-alchemy.mdx
  • apps/web/content/docs/project-structure.mdx
  • apps/web/src/app/(home)/new/_components/utils.ts
  • apps/web/test/stack-builder-compatibility.test.ts
  • openspec/changes/add-nitro-backend/design.md
  • openspec/changes/add-nitro-backend/proposal.md
  • openspec/changes/add-nitro-backend/specs/nitro-backend/spec.md
  • openspec/changes/add-nitro-backend/tasks.md
  • packages/template-generator/src/generators/alchemy/env.ts
  • packages/template-generator/src/generators/alchemy/render.ts
  • packages/template-generator/src/generators/alchemy/server.ts
  • packages/template-generator/src/processors/env-vars.ts
  • packages/template-generator/src/processors/runtime-deps.ts
  • packages/template-generator/templates/api/orpc/server/src/context.ts.hbs
  • packages/template-generator/templates/api/trpc/server/src/context.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/base/_gitignore
  • packages/template-generator/templates/backend/server/nitro/base/nitro.config.ts.hbs
  • packages/template-generator/templates/backend/server/nitro/base/tsconfig.json.hbs
  • packages/template-generator/templates/backend/server/nitro/better-auth/server/routes/api/auth/[...all].ts.hbs
  • packages/template-generator/templates/extras/env.d.ts.hbs
  • packages/template-generator/templates/packages/env/src/server.ts.hbs
🚧 Files skipped from review as they are similar to previous changes (12)
  • packages/template-generator/templates/backend/server/nitro/base/tsconfig.json.hbs
  • packages/template-generator/templates/backend/server/nitro/base/_gitignore
  • packages/template-generator/src/processors/runtime-deps.ts
  • apps/web/content/docs/project-structure.mdx
  • apps/web/test/stack-builder-compatibility.test.ts
  • apps/web/content/docs/cli/compatibility.mdx
  • apps/cli/test/nitro.test.ts
  • packages/template-generator/templates/api/orpc/server/src/context.ts.hbs
  • openspec/changes/add-nitro-backend/proposal.md
  • packages/template-generator/templates/api/trpc/server/src/context.ts.hbs
  • apps/cli/test/generated-builds.test.ts
  • openspec/changes/add-nitro-backend/tasks.md

Comment on lines +25 to +34
"main: Output.map(build.outdir, (outdir) => `${outdir}/server/index.mjs`),",
);
writer.writeLine("bundle: false,");
writeObject(
writer,
"assets: {",
() => {
writer.writeLine('directory: "../../apps/server/.output/public",');
},
"},",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

ast-grep outline packages/template-generator/src/generators/alchemy/server.ts --items all
rg -n -C 4 'Command\.Build|build\.outdir|Output\.map|assets:|directory:' \
  packages/template-generator/src/generators/alchemy/server.ts \
  packages/template-generator/src \
  apps/cli/test

fd -a 'nitro.config.ts.hbs' packages/template-generator/templates -x sed -n '1,180p' {}

Repository: AmanVarshney01/create-better-t-stack

Length of output: 14851


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- server generator ---'
cat -n packages/template-generator/src/generators/alchemy/server.ts | sed -n '1,115p'

printf '%s\n' '--- Alchemy dependency and API references ---'
rg -n -C 5 'Command\.Build|interface.*Build|type.*Build|outdir|assets:\s*\{|directory:' \
  package.json packages/*/package.json pnpm-lock.yaml packages apps \
  -g '*.ts' -g '*.tsx' -g '*.json' -g '*.yaml' -g '*.yml' -g '*.md' \
  | head -n 500

printf '%s\n' '--- generated fixtures and deployment documentation ---'
rg -n -C 8 'server-build|\.output/public|Cloudflare\.Worker|Command\.Build' . \
  -g '!packages/template-generator/src/templates.generated.ts' \
  -g '!node_modules' | head -n 500

Repository: AmanVarshney01/create-better-t-stack

Length of output: 36990


🌐 Web query:

Alchemy Effect Command.Build outdir Cloudflare.Worker assets directory API

💡 Result:

In the Alchemy framework, Command.Build is a resource that executes a shell command to generate an output directory (outdir), which can then be consumed by downstream resources like a Cloudflare Worker for static asset deployment [1][2]. When using Command.Build, you define the build process and specify the resulting directory as follows: const build = yield* Command.Build("build-name", { command: "npm run build", cwd: "./frontend", outdir: "dist", // The directory produced by the build command }); Downstream, a Cloudflare Worker resource can reference this outdir to serve static assets. In the Alchemy Cloudflare provider, this is typically handled via the assets configuration [3][4]. For example, when creating a Cloudflare Worker, you can map the build output to the assets directory: export default Cloudflare.Worker("Worker", { assets: { directory: build.outdir, // Consumes the output from the Command.Build resource run_worker_first: false, }, }); Alchemy effectively bridges the gap between build-time artifacts and deployment-time configuration by tracking the outdir in state and verifying its existence after the command execution [5][2]. This ensures that your Cloudflare Worker is always deploying the latest version of your assets produced by the specified build process [6][2]. For more complex requirements, Alchemy also provides a higher-level abstraction, Cloudflare.Website.StaticSite, which combines a build command and static asset deployment into a single resource [6]. It is important to note that Cloudflare's underlying asset layer handles the actual file serving [7][8]. The directory specified (e.g.,./dist or./public) is what gets uploaded to Cloudflare's infrastructure during deployment [7][9]. You can further configure behavior such as 404 handling or specific routing patterns (run_worker_first) within the assets object [3][7][10].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from urllib.request import Request, urlopen

urls = [
    "https://alchemy.run/providers/command/build/",
    "https://alchemy.run/cloudflare/compute/workers/",
]
needles = ("outdir", "assets", "directory", "Command.Build")

for url in urls:
    print(f"--- {url} ---")
    request = Request(url, headers={"User-Agent": "Mozilla/5.0"})
    try:
        text = urlopen(request, timeout=20).read().decode("utf-8", "replace")
    except Exception as error:
        print(f"fetch error: {error}")
        continue

    lower = text.lower()
    for needle in needles:
        start = 0
        found = 0
        while found < 3:
            index = lower.find(needle.lower(), start)
            if index < 0:
                break
            print(text[max(0, index - 180):index + 300].replace("\n", " ")[:500])
            start = index + len(needle)
            found += 1
PY

printf '%s\n' '--- path relationship in the generator and tests ---'
python3 - <<'PY'
from pathlib import Path

source = Path("packages/template-generator/src/generators/alchemy/server.ts").read_text()
test = Path("apps/cli/test/nitro.test.ts").read_text()

required_source = [
    'outdir: ".output"',
    'main: Output.map(build.outdir, (outdir) => `${outdir}/server/index.mjs`)',
    'directory: "../../apps/server/.output/public"',
]
required_test = [
    'outdir: ".output"',
    '`${outdir}/server/index.mjs`',
    'directory: "../../apps/server/.output/public"',
]

for label, text, required in [
    ("generator", source, required_source),
    ("test", test, required_test),
]:
    print(label)
    for item in required:
        print(f"{item!r}: {item in text}")
PY

Repository: AmanVarshney01/create-better-t-stack

Length of output: 925


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for url in \
  "https://alchemy.run/providers/command/build/" \
  "https://alchemy.run/cloudflare/compute/workers/" \
  "https://raw.githubusercontent.com/alchemy-run/alchemy/main/packages/cloudflare/src/worker.ts"
do
  printf '%s\n' "--- $url ---"
  curl -k -L --max-time 20 -sS "$url" \
    | tr '\n' ' ' \
    | grep -oE '.{0,220}(Command\.Build|build\.outdir|assets|directory|outdir).{0,320}' \
    | head -n 12 || true
done

Repository: AmanVarshney01/create-better-t-stack

Length of output: 12689


Derive the asset directory from build.outdir.

Set directory to Output.map(build.outdir, (outdir) => ${outdir}/public). This keeps static assets and main within the same Command.Build artifact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant