Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/cli/src/prompts/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { DEFAULT_CONFIG } from "../constants";
import { exitCancelled } from "../utils/errors";
import { isCancel, navigableSelect } from "./navigable";

// Temporarily restrict to Next.js and TanStack Start only for backend="self"
// Frontends that support backend="self" (fullstack mode with built-in server routes)
const FULLSTACK_FRONTENDS: readonly Frontend[] = [
"next",
"tanstack-start",
// "nuxt", // TODO: Add support in future update
"nuxt",
// "svelte", // TODO: Add support in future update
] as const;

Expand Down
8 changes: 4 additions & 4 deletions apps/cli/src/utils/compatibility-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export function ensureSingleWebAndNative(frontends: Frontend[]) {
}
}

// Temporarily restrict to Next.js and TanStack Start only for backend="self"
// Frontends that support backend="self" (fullstack mode with built-in server routes)
const FULLSTACK_FRONTENDS: readonly Frontend[] = [
"next",
"tanstack-start",
// "nuxt", // TODO: Add support in future update
"nuxt",
// "svelte", // TODO: Add support in future update
] as const;

Expand All @@ -66,7 +66,7 @@ export function validateSelfBackendCompatibility(

if (!hasSupportedWeb) {
exitWithError(
"Backend 'self' (fullstack) currently only supports Next.js and TanStack Start frontends. Please use --frontend next or --frontend tanstack-start. Support for Nuxt and SvelteKit will be added in a future update.",
"Backend 'self' (fullstack) currently only supports Next.js, TanStack Start, and Nuxt frontends. Please use --frontend next, --frontend tanstack-start, or --frontend nuxt. Support for SvelteKit will be added in a future update.",
);
}

Expand All @@ -80,7 +80,7 @@ export function validateSelfBackendCompatibility(
const hasFullstackFrontend = frontends.some((f) => FULLSTACK_FRONTENDS.includes(f));
if (providedFlags.has("backend") && !hasFullstackFrontend && backend === "self") {
exitWithError(
"Backend 'self' (fullstack) currently only supports Next.js and TanStack Start frontends. Please use --frontend next or --frontend tanstack-start or choose a different backend. Support for Nuxt and SvelteKit will be added in a future update.",
"Backend 'self' (fullstack) currently only supports Next.js, TanStack Start, and Nuxt frontends. Please use --frontend next, --frontend tanstack-start, --frontend nuxt, or choose a different backend. Support for SvelteKit will be added in a future update.",
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/test/backend-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ describe("Backend and Runtime Combinations", () => {

expectError(
result,
"Backend 'self' (fullstack) currently only supports Next.js and TanStack Start frontends. Please use --frontend next or --frontend tanstack-start. Support for Nuxt and SvelteKit will be added in a future update.",
"Backend 'self' (fullstack) currently only supports Next.js, TanStack Start, and Nuxt frontends. Please use --frontend next, --frontend tanstack-start, or --frontend nuxt. Support for SvelteKit will be added in a future update.",
);
});

Expand Down
44 changes: 44 additions & 0 deletions apps/cli/test/frontend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,50 @@ describe("Frontend Configurations", () => {
});
});

describe("Nuxt with Self Backend", () => {
it("should work with Nuxt and self backend", async () => {
const result = await runTRPCTest({
projectName: "nuxt-self-backend",
frontend: ["nuxt"],
backend: "self",
runtime: "none",
database: "sqlite",
orm: "drizzle",
auth: "better-auth",
api: "orpc",
addons: ["none"],
examples: ["none"],
dbSetup: "none",
webDeploy: "none",
serverDeploy: "none",
install: false,
});

expectSuccess(result);
});

it("should work with Nuxt and traditional backend", async () => {
const result = await runTRPCTest({
projectName: "nuxt-traditional-backend",
frontend: ["nuxt"],
backend: "hono",
runtime: "bun",
database: "sqlite",
orm: "drizzle",
auth: "none",
api: "orpc",
addons: ["none"],
examples: ["none"],
dbSetup: "none",
webDeploy: "none",
serverDeploy: "none",
install: false,
});

expectSuccess(result);
});
});

describe("Web Deploy Constraints", () => {
it("should work with web frontend + web deploy", async () => {
const result = await runTRPCTest({
Expand Down
43 changes: 37 additions & 6 deletions apps/web/src/app/(home)/new/_components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ export const analyzeStackCompatibility = (stack: StackState): CompatibilityResul
}

// Self (fullstack) backend constraints
if (nextStack.backend === "self-next" || nextStack.backend === "self-tanstack-start") {
if (
nextStack.backend === "self-next" ||
nextStack.backend === "self-tanstack-start" ||
nextStack.backend === "self-nuxt"
) {
// Fullstack uses frontend's API routes, no separate runtime needed
if (nextStack.runtime !== "none") {
nextStack.runtime = "none";
Expand Down Expand Up @@ -231,6 +235,14 @@ export const analyzeStackCompatibility = (stack: StackState): CompatibilityResul
message: "Frontend set to 'TanStack Start' (required for TanStack Start fullstack)",
});
}
if (nextStack.backend === "self-nuxt" && !nextStack.webFrontend.includes("nuxt")) {
nextStack.webFrontend = ["nuxt"];
changed = true;
changes.push({
category: "backend",
message: "Frontend set to 'Nuxt' (required for Nuxt fullstack)",
});
}
}

// ============================================
Expand Down Expand Up @@ -266,13 +278,14 @@ export const analyzeStackCompatibility = (stack: StackState): CompatibilityResul
});
}

// Runtime "none" only for convex, self-next, self-tanstack-start
// Runtime "none" only for convex, self-next, self-tanstack-start, self-nuxt
if (
nextStack.runtime === "none" &&
nextStack.backend !== "convex" &&
nextStack.backend !== "none" &&
nextStack.backend !== "self-next" &&
nextStack.backend !== "self-tanstack-start"
nextStack.backend !== "self-tanstack-start" &&
nextStack.backend !== "self-nuxt"
) {
nextStack.runtime = DEFAULT_STACK.runtime;
changed = true;
Expand Down Expand Up @@ -610,7 +623,7 @@ export const analyzeStackCompatibility = (stack: StackState): CompatibilityResul

if (
nextStack.serverDeploy !== "none" &&
["none", "convex", "self-next", "self-tanstack-start"].includes(nextStack.backend)
["none", "convex", "self-next", "self-tanstack-start", "self-nuxt"].includes(nextStack.backend)
) {
nextStack.serverDeploy = "none";
changed = true;
Expand Down Expand Up @@ -741,6 +754,21 @@ export const getDisabledReason = (
}
}

if (currentStack.backend === "self-nuxt") {
if (category === "runtime" && optionId !== "none") {
return "Nuxt fullstack uses built-in server routes";
}
if (category === "webFrontend" && optionId !== "nuxt" && optionId !== "none") {
return "Nuxt fullstack requires Nuxt frontend";
}
if (category === "serverDeploy" && optionId !== "none") {
return "Fullstack uses frontend deployment";
}
if (category === "api" && optionId === "trpc") {
return "tRPC is not compatible with Nuxt (use oRPC)";
}
}

if (currentStack.backend === "self-tanstack-start") {
if (category === "runtime" && optionId !== "none") {
return "TanStack Start fullstack uses built-in API routes";
Expand All @@ -766,6 +794,9 @@ export const getDisabledReason = (
) {
return "Requires TanStack Start frontend";
}
if (optionId === "self-nuxt" && !currentStack.webFrontend.includes("nuxt")) {
return "Requires Nuxt frontend";
}
if (optionId === "convex" && currentStack.webFrontend.includes("solid")) {
return "Convex is not compatible with Solid";
}
Expand All @@ -783,7 +814,7 @@ export const getDisabledReason = (
return "Workers requires Hono backend";
}
if (optionId === "none") {
const allowedBackends = ["convex", "none", "self-next", "self-tanstack-start"];
const allowedBackends = ["convex", "none", "self-next", "self-tanstack-start", "self-nuxt"];
if (!allowedBackends.includes(currentStack.backend)) {
return "Runtime 'None' only for Convex or fullstack backends";
}
Expand Down Expand Up @@ -964,7 +995,7 @@ export const getDisabledReason = (
if (currentStack.backend !== "hono") return "Cloudflare requires Hono backend";
}
if (optionId !== "none") {
const noServerDeploy = ["none", "convex", "self-next", "self-tanstack-start"];
const noServerDeploy = ["none", "convex", "self-next", "self-tanstack-start", "self-nuxt"];
if (noServerDeploy.includes(currentStack.backend)) {
return "Server deployment not needed for this backend";
}
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/lib/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ export const TECH_OPTIONS: Record<
icon: `${ICON_BASE_URL}/tanstack.svg`,
color: "from-purple-400 to-purple-600",
},
{
id: "self-nuxt",
name: "Fullstack Nuxt",
description: "Use Nuxt's built-in server routes",
icon: `${ICON_BASE_URL}/nuxt.svg`,
color: "from-green-400 to-green-700",
},
{
id: "none",
name: "No Backend",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/stack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function generateStackCommand(stack: StackState) {

// Map web interface backend IDs to CLI backend flags
const mapBackendToCli = (backend: string) => {
if (backend === "self-next" || backend === "self-tanstack-start") {
if (backend === "self-next" || backend === "self-tanstack-start" || backend === "self-nuxt") {
return "self";
}
return backend;
Expand Down
27 changes: 27 additions & 0 deletions packages/template-generator/src/post-process/package-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function processPackageConfigs(vfs: VirtualFileSystem, config: ProjectCon
updateConfigPackageJson(vfs, config);
updateEnvPackageJson(vfs, config);
updateInfraPackageJson(vfs, config);
renameDevScriptsForAlchemy(vfs, config);

if (config.backend === "convex") {
updateConvexPackageJson(vfs, config);
Expand Down Expand Up @@ -304,3 +305,29 @@ function updateConvexPackageJson(vfs: VirtualFileSystem, config: ProjectConfig):
pkgJson.scripts = pkgJson.scripts || {};
vfs.writeJson("packages/backend/package.json", pkgJson);
}

function renameDevScriptsForAlchemy(vfs: VirtualFileSystem, config: ProjectConfig): void {
const { serverDeploy, webDeploy, backend } = config;

// Rename server dev script to dev:bare when serverDeploy is cloudflare
if (serverDeploy === "cloudflare" && backend !== "self") {
const serverPkgPath = "apps/server/package.json";
const serverPkg = vfs.readJson<PackageJson>(serverPkgPath);
if (serverPkg?.scripts?.dev) {
serverPkg.scripts["dev:bare"] = serverPkg.scripts.dev;
delete serverPkg.scripts.dev;
vfs.writeJson(serverPkgPath, serverPkg);
}
}

// Rename web dev script to dev:bare when webDeploy is cloudflare
if (webDeploy === "cloudflare") {
const webPkgPath = "apps/web/package.json";
const webPkg = vfs.readJson<PackageJson>(webPkgPath);
if (webPkg?.scripts?.dev) {
webPkg.scripts["dev:bare"] = webPkg.scripts.dev;
delete webPkg.scripts.dev;
vfs.writeJson(webPkgPath, webPkg);
}
}
}
4 changes: 2 additions & 2 deletions packages/template-generator/src/processors/api-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ function addSelfBackendWebDeps(
vfs: VirtualFileSystem,
api: API,
backend: Backend,
frontendType: FrontendType,
_frontendType: FrontendType,
): void {
if (backend !== "self") return;

const webPath = "apps/web/package.json";
if (!vfs.exists(webPath) || !frontendType.hasReactWeb) return;
if (!vfs.exists(webPath)) return;

// When backend is "self", add server deps to web too
if (api === "trpc") {
Expand Down
3 changes: 2 additions & 1 deletion packages/template-generator/src/processors/db-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ function processPrismaDeps(
deps.push("@prisma/adapter-neon", "@neondatabase/serverless", "ws");
devDeps.push("@types/ws");
} else if (dbSetup === "prisma-postgres") {
deps.push("@prisma/adapter-pg");
deps.push("@prisma/adapter-pg", "pg");
devDeps.push("@types/pg");
} else {
deps.push("@prisma/adapter-pg", "pg");
devDeps.push("@types/pg");
Expand Down
4 changes: 2 additions & 2 deletions packages/template-generator/src/processors/env-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function addEnvVariablesToContent(currentContent: string, variables: EnvVariable
envContent += contentToAdd;
}

return envContent.trimEnd();
return `${envContent.trimEnd()}\n`;
}

function writeEnvFile(vfs: VirtualFileSystem, envPath: string, variables: EnvVariable[]): void {
Expand Down Expand Up @@ -196,7 +196,7 @@ function buildNativeVars(
let serverUrl = "http://localhost:3000";

if (backend === "self") {
// Both TanStack Start and Next.js use port 3001 for fullstack
// TanStack Start, Next.js, and Nuxt use port 3001 for fullstack
serverUrl = "http://localhost:3001";
}

Expand Down
22 changes: 20 additions & 2 deletions packages/template-generator/src/template-handlers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ProjectConfig } from "@better-t-stack/types";

import type { VirtualFileSystem } from "../core/virtual-fs";

import { type TemplateData, processTemplatesFromPrefix } from "./utils";
import { type TemplateData, processTemplatesFromPrefix, processSingleTemplate } from "./utils";

export async function processApiTemplates(
vfs: VirtualFileSystem,
Expand Down Expand Up @@ -46,7 +46,25 @@ export async function processApiTemplates(
);
}
} else if (hasNuxtWeb && config.api === "orpc") {
processTemplatesFromPrefix(vfs, templates, `api/${config.api}/web/nuxt`, "apps/web", config);
if (config.backend === "self") {
processTemplatesFromPrefix(
vfs,
templates,
`api/${config.api}/fullstack/nuxt`,
"apps/web",
config,
);
// Only include vue-query from web templates, skip generic orpc.ts
processSingleTemplate(
vfs,
templates,
`api/${config.api}/web/nuxt/app/plugins/vue-query.ts`,
"apps/web/app/plugins/vue-query.ts",
config,
);
} else {
processTemplatesFromPrefix(vfs, templates, `api/${config.api}/web/nuxt`, "apps/web", config);
}
} else if (hasSvelteWeb && config.api === "orpc") {
processTemplatesFromPrefix(vfs, templates, `api/${config.api}/web/svelte`, "apps/web", config);
} else if (hasSolidWeb && config.api === "orpc") {
Expand Down
9 changes: 9 additions & 0 deletions packages/template-generator/src/template-handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ export async function processAuthTemplates(
}
}
} else if (hasNuxtWeb) {
if (config.backend === "self") {
processTemplatesFromPrefix(
vfs,
templates,
`auth/${authProvider}/fullstack/nuxt`,
"apps/web",
config,
);
}
processTemplatesFromPrefix(vfs, templates, `auth/${authProvider}/web/nuxt`, "apps/web", config);
} else if (hasSvelteWeb) {
processTemplatesFromPrefix(
Expand Down
9 changes: 9 additions & 0 deletions packages/template-generator/src/template-handlers/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export async function processExampleTemplates(
}
}
} else if (hasNuxtWeb) {
if (config.backend === "self") {
processTemplatesFromPrefix(
vfs,
templates,
`examples/${example}/fullstack/nuxt`,
"apps/web",
config,
);
}
processTemplatesFromPrefix(
vfs,
templates,
Expand Down
Loading