Skip to content

Commit eb19dbd

Browse files
feat(cli): add internal packages, catalogs, fullstack nextjs (#601)
1 parent dab2557 commit eb19dbd

File tree

168 files changed

+3519
-1640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+3519
-1640
lines changed

CATALOG_IMPLEMENTATION.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# Catalog Implementation Summary
2+
3+
## Overview
4+
Implemented support for Bun and pnpm catalogs to reduce duplication of dependency versions across monorepo packages.
5+
6+
## What are Catalogs?
7+
Catalogs allow you to define dependency versions once in a central location and reference them across multiple packages using the `catalog:` protocol. This ensures version consistency and makes updates easier.
8+
9+
## Implementation Details
10+
11+
### Files Created/Modified
12+
13+
1. **`apps/cli/src/utils/setup-catalogs.ts`** (NEW)
14+
- Main implementation file for catalog functionality
15+
- Scans all workspace packages for dependencies:
16+
- apps/server
17+
- apps/web
18+
- packages/api
19+
- packages/db
20+
- packages/auth
21+
- packages/backend (for Convex)
22+
- Identifies duplicated dependencies (those appearing in 2+ packages)
23+
- Creates catalog entries for Bun or pnpm
24+
- Updates package.json files to use `catalog:` protocol
25+
26+
2. **`apps/cli/src/helpers/core/create-project.ts`** (MODIFIED)
27+
- Added `setupCatalogs()` call after `updatePackageConfigurations()`
28+
- Catalogs are set up after all dependencies are added but before deployment setup
29+
30+
3. **`apps/cli/package.json`** (MODIFIED)
31+
- Added `yaml` dependency for pnpm-workspace.yaml parsing
32+
33+
4. **`apps/cli/test/catalogs.test.ts`** (NEW)
34+
- Comprehensive test suite covering:
35+
- Bun catalog setup
36+
- pnpm catalog setup
37+
- npm (no catalog) behavior
38+
- Convex backend catalog support
39+
- Selective cataloging (only duplicates)
40+
41+
## How It Works
42+
43+
### For Bun
44+
- Catalogs are added to `package.json` under `workspaces.catalog`
45+
- If `workspaces` is an array, it's converted to object format:
46+
47+
**Before (array format)**:
48+
```json
49+
{
50+
"workspaces": ["apps/*", "packages/*"]
51+
}
52+
```
53+
54+
**After (object format with catalog)**:
55+
```json
56+
{
57+
"workspaces": {
58+
"packages": ["apps/*", "packages/*"],
59+
"catalog": {
60+
"dotenv": "^16.4.7",
61+
"zod": "^4.1.11",
62+
"tsdown": "^0.15.4"
63+
}
64+
}
65+
}
66+
```
67+
68+
### For pnpm
69+
- Catalogs are added to `pnpm-workspace.yaml`:
70+
```yaml
71+
packages:
72+
- "apps/*"
73+
- "packages/*"
74+
catalog:
75+
dotenv: ^16.4.7
76+
zod: ^4.1.11
77+
tsdown: ^0.15.4
78+
```
79+
80+
### For npm
81+
- No catalogs are created (npm doesn't support this feature)
82+
- Dependencies keep their actual version numbers
83+
84+
### Package References
85+
- Package.json files in workspace packages use `catalog:` protocol:
86+
```json
87+
{
88+
"dependencies": {
89+
"dotenv": "catalog:",
90+
"zod": "catalog:"
91+
}
92+
}
93+
```
94+
95+
## Behavior
96+
97+
### When Catalogs Are Created
98+
- Package manager is Bun or pnpm
99+
- At least one dependency appears in multiple packages
100+
- Works for both regular server backends (Hono, Elysia) and Convex backends
101+
102+
### What Gets Cataloged
103+
- Only external dependencies (not workspace packages like `@project-name/db`)
104+
- Only dependencies that appear in 2+ of these packages:
105+
- apps/server
106+
- apps/web
107+
- packages/api
108+
- packages/db
109+
- packages/auth
110+
- packages/backend (for Convex)
111+
112+
### What Doesn't Get Cataloged
113+
- Workspace dependencies (those starting with `@project-name/`)
114+
- Dependencies with `workspace:` protocol
115+
- Dependencies appearing in only one package
116+
- Any dependencies when npm is the package manager
117+
118+
## Benefits
119+
120+
1. **Version Consistency**: All packages use the same version of shared dependencies
121+
2. **Easier Updates**: Update a dependency version in one place instead of multiple
122+
3. **Reduced Duplication**: Less repetition in package.json files
123+
4. **Better Maintenance**: Clear view of which dependencies are standardized
124+
125+
## Example Output
126+
127+
For a project using Bun with hono backend, better-auth, and trpc:
128+
129+
**Root package.json (Bun)**:
130+
```json
131+
{
132+
"workspaces": {
133+
"catalog": {
134+
"dotenv": "^16.4.7",
135+
"zod": "^4.1.11",
136+
"tsdown": "^0.15.4"
137+
}
138+
}
139+
}
140+
```
141+
142+
**packages/db/package.json**:
143+
```json
144+
{
145+
"dependencies": {
146+
"dotenv": "catalog:",
147+
"zod": "catalog:"
148+
},
149+
"devDependencies": {
150+
"tsdown": "catalog:"
151+
}
152+
}
153+
```
154+
155+
**packages/auth/package.json**:
156+
```json
157+
{
158+
"dependencies": {
159+
"dotenv": "catalog:",
160+
"zod": "catalog:",
161+
"@my-app/db": "workspace:*"
162+
},
163+
"devDependencies": {
164+
"tsdown": "catalog:"
165+
}
166+
}
167+
```
168+
169+
## Testing
170+
171+
Run tests with:
172+
```bash
173+
cd apps/cli
174+
bun test catalogs.test.ts
175+
```
176+
177+
Tests verify:
178+
- Bun catalog creation and references
179+
- pnpm catalog creation and references
180+
- npm skips catalog creation
181+
- Convex backend catalog support (packages/backend)
182+
- Only duplicated dependencies are cataloged
183+
- Web app dependencies are included in catalogs
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Fullstack Backend Implementation
2+
3+
## Overview
4+
Implemented `--backend self` option to support fullstack frameworks (Next.js, Nuxt, SvelteKit, TanStack Start) that have their own backend capabilities.
5+
6+
## Key Changes
7+
8+
### 1. Updated Backend Schema
9+
**File:** `apps/cli/src/types.ts`
10+
- Removed `"next"` from backend options (no longer needed as separate backend)
11+
- Added `"self"` to backend options: `["hono", "express", "fastify", "elysia", "convex", "self", "none"]`
12+
13+
### 2. Updated Backend Prompt
14+
**File:** `apps/cli/src/prompts/backend.ts`
15+
- Shows "Self (Fullstack)" option when a fullstack-capable frontend is selected (next, nuxt, svelte, tanstack-start)
16+
- Makes "self" the default when a fullstack frontend is chosen
17+
- Hides "self" option when non-fullstack frontends are selected
18+
19+
### 3. Added Validation
20+
**File:** `apps/cli/src/utils/compatibility-rules.ts`
21+
- New function: `validateSelfBackendCompatibility()`
22+
- Ensures `--backend self` only works with fullstack frontends
23+
- Prevents using multiple frontends with `--backend self`
24+
- Provides clear error messages
25+
26+
**File:** `apps/cli/src/utils/config-validation.ts`
27+
- Added validation call in `validateFullConfig()`
28+
29+
### 4. Updated Prompts
30+
**File:** `apps/cli/src/prompts/api.ts`
31+
- Still prompts for API choice (tRPC, oRPC, or none)
32+
- Fullstack frameworks can use tRPC/oRPC for type-safe client-server communication
33+
34+
**File:** `apps/cli/src/prompts/runtime.ts`
35+
- Returns `"none"` when `backend === "self"` (fullstack frameworks handle their own runtime)
36+
37+
### 5. Updated Project Creation
38+
**File:** `apps/cli/src/helpers/core/create-project.ts`
39+
- Skips `apps/server` creation when `backend === "self"`
40+
- Skips backend framework setup when `backend === "self"`
41+
- Still creates packages (api, auth, db) for shared business logic
42+
43+
### 6. Updated Package Configuration
44+
**File:** `apps/cli/src/helpers/core/project-config.ts`
45+
- Skips `dev:server` script when `backend === "self"`
46+
- Doesn't try to update `apps/server/package.json` when it doesn't exist
47+
48+
### 7. Updated Workspace Setup
49+
**File:** `apps/cli/src/helpers/core/workspace-setup.ts`
50+
- When `backend === "self"`, adds api/auth/db package dependencies to `apps/web` instead of `apps/server`
51+
- Automatically handles missing `apps/server` directory
52+
53+
## Project Structure
54+
55+
### With `--backend self` (Fullstack)
56+
```
57+
my-app/
58+
├── apps/
59+
│ └── web/ # Fullstack app (Next/Nuxt/SvelteKit/TanStack Start)
60+
│ └── package.json # Depends on @my-app/api, @my-app/auth, @my-app/db
61+
├── packages/
62+
│ ├── api/ # API layer / business logic
63+
│ ├── auth/ # Auth configuration & logic
64+
│ └── db/ # Database schema & queries
65+
└── package.json
66+
```
67+
68+
### With traditional backend (hono, express, etc.)
69+
```
70+
my-app/
71+
├── apps/
72+
│ ├── web/ # Frontend
73+
│ └── server/ # Backend server
74+
├── packages/
75+
│ ├── api/ # API layer
76+
│ ├── auth/ # Auth logic
77+
│ └── db/ # Database layer
78+
└── package.json
79+
```
80+
81+
## Usage Examples
82+
83+
### Full Stack Next.js with tRPC
84+
```bash
85+
create-better-t-stack my-app --frontend next --backend self --api trpc --database postgres --orm drizzle --auth better-auth
86+
```
87+
88+
### Full Stack Nuxt with oRPC
89+
```bash
90+
create-better-t-stack my-app --frontend nuxt --backend self --api orpc --database sqlite --orm drizzle
91+
```
92+
93+
### Full Stack SvelteKit with oRPC
94+
```bash
95+
create-better-t-stack my-app --frontend svelte --backend self --api orpc --database postgres --orm prisma
96+
```
97+
98+
### Full Stack TanStack Start with tRPC
99+
```bash
100+
create-better-t-stack my-app --frontend tanstack-start --backend self --api trpc --database mysql --orm drizzle
101+
```
102+
103+
### Full Stack Next.js without API layer (using Server Actions only)
104+
```bash
105+
create-better-t-stack my-app --frontend next --backend self --api none --database postgres --orm drizzle
106+
```
107+
108+
### Error Cases
109+
```bash
110+
# ❌ Error: self backend requires fullstack frontend
111+
create-better-t-stack my-app --frontend tanstack-router --backend self
112+
113+
# ❌ Error: self backend requires single frontend
114+
create-better-t-stack my-app --frontend next --frontend native-nativewind --backend self
115+
116+
# ❌ Error: self backend requires fullstack frontend
117+
create-better-t-stack my-app --frontend solid --backend self
118+
```
119+
120+
## Benefits
121+
122+
1. **Clear Separation**: Distinguishes between fullstack frameworks and separate backend servers
123+
2. **No Duplication**: Avoids having both `apps/server` and fullstack framework handling backend
124+
3. **Shared Packages**: Still maintains clean separation of concerns with packages/api, packages/auth, packages/db
125+
4. **Better DX**: Makes intent explicit - you're choosing a fullstack architecture
126+
5. **Maintainable**: Easier to understand and maintain than having "next" as both frontend and backend
127+
128+
## Behavior
129+
130+
### When `backend === "self"`
131+
- ✅ Creates `apps/web` with fullstack framework
132+
- ✅ Creates `packages/api`, `packages/auth`, `packages/db`
133+
- ❌ Skips `apps/server` creation
134+
- ❌ No `dev:server` script
135+
- ✅ API prompts for choice (tRPC, oRPC, or none) - can use type-safe APIs!
136+
- ✅ Runtime set to "none" (framework manages runtime)
137+
- ✅ Web app depends on all workspace packages
138+
- ✅ Catalog support works correctly
139+
140+
### Supported Fullstack Frontends
141+
- **Next.js**: App Router with Server Actions, API Routes, Route Handlers
142+
- **Nuxt**: Nuxt Server Routes and Server API
143+
- **SvelteKit**: SvelteKit Endpoints and Form Actions
144+
- **TanStack Start**: Server Functions and API Routes
145+
146+
## Testing
147+
148+
To test the implementation:
149+
150+
```bash
151+
# Build CLI
152+
cd apps/cli && bun run build
153+
154+
# Test fullstack setup
155+
cd ../..
156+
bun dist/cli.js test-next --frontend next --backend self --database postgres --orm drizzle
157+
158+
# Verify structure
159+
ls -la test-next/apps # Should only have 'web'
160+
ls -la test-next/packages # Should have 'api', 'auth', 'db'
161+
```
162+
163+
## Migration Guide
164+
165+
### For existing projects using "next" as backend:
166+
The old `--backend next` is no longer supported. Instead:
167+
168+
**Old:**
169+
```bash
170+
create-better-t-stack my-app --backend next
171+
```
172+
173+
**New:**
174+
```bash
175+
create-better-t-stack my-app --frontend next --backend self
176+
```
177+
178+
This makes the intent clearer - you're creating a fullstack Next.js app, not a separate Next.js backend server.

apps/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"tinyglobby": "^0.2.15",
7878
"trpc-cli": "^0.11.0",
7979
"ts-morph": "^27.0.0",
80+
"yaml": "^2.7.0",
8081
"zod": "^4.1.11"
8182
},
8283
"devDependencies": {
@@ -88,4 +89,4 @@
8889
"typescript": "^5.9.2",
8990
"vitest": "^3.2.4"
9091
}
91-
}
92+
}

0 commit comments

Comments
 (0)