Skip to content

Latest commit

 

History

History
419 lines (313 loc) · 13.2 KB

QUICKSTART.md

File metadata and controls

419 lines (313 loc) · 13.2 KB

Codebase — Local Development Guide

TL;DR — Clone → cp .env.example .env.local → fill in one LLM key → npm run dev:all → open http://localhost:3333


Table of Contents


Prerequisites

Requirement Version Notes
Git 2.13+ Submodule support required
Node.js 22+ LTS recommended (node -v)
npm 10+ Ships with Node 22 (npm -v)

That's all you need for local development. The following are production-only infrastructure — the app runs without them and gracefully degrades:

Service What it powers Required locally?
Redis 7.4 BullMQ build queue, TrailBase port allocation No
Convex Sessions, credits, gallery persistence No — runs anonymously
Garage S3 Project artifact storage & sync No — uses local filesystem
TrailBase Auto-provisioned app backends No
Docker Workers Sandboxed build execution No — builds run in-process

Clone & Submodules

This repository uses git submodules (e.g. convex-backend). Always clone with --recurse-submodules:

git clone --recurse-submodules https://github.com/codebase/codebase-oss.git
cd codebase-oss
Already cloned without the flag?
git submodule init
git submodule update

Repository Layout

codebase/
├── web/                          # Primary application
│   ├── app/                      # Next.js 15 App Router
│   │   ├── workspace/            # Builder UI — chat, preview, timeline
│   │   │   ├── components/       # Extracted workspace components
│   │   │   └── hooks/            # Route-specific hooks (WS, build state)
│   │   ├── projects/             # Projects listing page
│   │   ├── gallery/              # Community project gallery
│   │   └── pricing/              # Credit plans & tiers
│   │
│   ├── backend/                  # Express.js + tRPC + WebSocket (port 3001)
│   │   ├── agent/                # Agent loop, tool handlers, streaming
│   │   ├── glue/                 # Fast LLM intent classification layer
│   │   ├── providers/            # Multi-LLM provider registry
│   │   ├── ws/                   # WebSocket message routing
│   │   ├── routes/               # Express REST endpoints
│   │   └── services/             # Business logic (credits, projects, etc.)
│   │
│   ├── components/               # Shared React components
│   │   ├── layout/               # AppLayout, Header, Sidebar, UserMenu
│   │   ├── projects/             # ProjectCard, FolderTree
│   │   └── providers/            # ConvexClientProvider, etc.
│   │
│   ├── lib/hooks/                # Shared hooks barrel (useSpeech, useFavorites, etc.)
│   ├── convex/                   # Convex schema, queries, mutations
│   ├── convex-docker/            # Docker Compose for local Convex dev
│   ├── dev.sh                    # Local service manager (frontend + backend)
│   └── ecosystem.config.cjs      # PM2 production process manager
│
├── convex-backend/               # [git submodule] Convex self-hosted OSS backend
├── cli/                          # Go CLI — login, pull projects, inference proxy
└── QUICKSTART.md                 # ← You are here

Environment Configuration

cd web
cp .env.example .env.local

Minimum Viable .env.local

These are the only variables you need to get the app running locally:

# ── Backend Connection ──────────────────────────────
NEXT_PUBLIC_BACKEND_HOST=localhost
NEXT_PUBLIC_BACKEND_HTTP_PORT=3001
NEXT_PUBLIC_BACKEND_WS_PORT=3001
NEXT_PUBLIC_BACKEND_PROTOCOL=http
NEXT_PUBLIC_BACKEND_WS_PROTOCOL=ws

# ── NextAuth (required even without OAuth) ──────────
NEXTAUTH_SECRET=any-random-string-here
NEXTAUTH_URL=http://localhost:3333

# ── LLM Provider (at least one for AI features) ─────
# Uncomment and fill whichever provider(s) you have:
# OPENAI_API_KEY=sk-...
# OPENAI_BASE_URL=https://api.openai.com/v1
# MINIMAX_API_KEY=...
# ANTHROPIC_API_KEY=...
# QWEN_API_KEY=...

# ── Node ─────────────────────────────────────────────
NODE_ENV=development

No OAuth, no database, no Redis. The workspace works immediately — you'll be anonymous with free build turns.


Running Locally

Option A: One-Command Start (Recommended)

cd web
npm install
cd backend && npm install && cd ..
npm run dev:all
# ✅ Backend → http://localhost:3001
# ✅ Frontend → http://localhost:3333

npm run dev:all wraps the existing ./dev.sh service manager so future sessions do not forget the backend.

Option B: Manual Start (Two Terminals)

Terminal 1 — Backend:

cd web/backend
npm install
npm run build:trpc    # Compile tRPC TypeScript routers → dist/
npm run dev           # http://localhost:3001

Terminal 2 — Frontend:

cd web
npm install
npm run dev               # http://localhost:3333

Custom Port Overrides

If ports 3001/3333 conflict with other services, start the services manually:

# Backend
cd web/backend
PORT=4001 npm run dev

# Frontend
cd ../
npm run dev -- -p 4002

When using custom ports, update .env.local to match:

NEXT_PUBLIC_BACKEND_HTTP_PORT=4001
NEXT_PUBLIC_BACKEND_WS_PORT=4001
NEXTAUTH_URL=http://localhost:4002

Authentication

Local Development (No Setup Required)

The workspace works without login. You'll operate as anonymous with free build turns and no session persistence.

OAuth (Optional)

To enable Google and/or GitHub sign-in, add to .env.local:

# Google OAuth
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...

# GitHub OAuth
GITHUB_CLIENT_ID=...
GITHUB_CLIENT_SECRET=...

# Auth secret (generate with: openssl rand -base64 32)
AUTH_SECRET=...

Web3 Wallet (Optional)

RainbowKit + wagmi wallet authentication works out of the box. No additional configuration needed — users can connect any EVM wallet directly.


Convex (Optional)

Convex powers session persistence, credits, favorites, and gallery. Only needed if you want those features locally.

Cloud (Easiest)

# From web/ directory
npx convex dev
# This creates a dev deployment and watches for schema changes

Add the URL it gives you to .env.local:

CONVEX_URL=https://your-dev-project.convex.cloud
NEXT_PUBLIC_CONVEX_URL=https://your-dev-project.convex.cloud

Self-Hosted (Advanced)

A Docker Compose file is provided for running Convex locally:

cd web/convex-docker
docker compose up -d

The vendored convex-backend/ submodule contains the full Convex OSS backend. See its BUILD.md for compilation instructions.


CLI Tool (Go)

The codebase CLI provides terminal access to the platform:

cd cli
go build -o codebase .
Command Description
./codebase login OAuth PKCE login via browser
./codebase logout Clear local credentials
./codebase whoami Show current auth status
./codebase Interactive build mode
./codebase pull <id> Download a project from the platform

Production Deployment

Build

cd web
cd backend && npm run build:trpc && cd ..
npm run build          # Next.js production build

Run with PM2

pm2 start ecosystem.config.cjs

The ecosystem.config.cjs runs:

Process Mode Instances Port
codebase-backend fork 1 3001
codebase-frontend cluster 4 3002

Nginx

In production, Nginx handles TLS termination and routing:

https://your-domain.com/      → localhost:3002  (Next.js)
https://your-domain.com/api/* → localhost:3001  (Express + tRPC)
wss://your-domain.com/ws      → localhost:3001  (WebSocket upgrade)

Service Map

Service Default URL Override Protocol
Frontend http://localhost:3333 FRONTEND_PORT or npm run dev -- -p <port> HTTP
Backend API http://localhost:3001 PORT HTTP
WebSocket ws://localhost:3001/ws PORT WS
tRPC http://localhost:3001/trpc/* PORT HTTP

Environment Variable Reference

All supported variables (click to expand)

Connection & Routing

Variable Default Description
NEXT_PUBLIC_BACKEND_HOST localhost Backend hostname
NEXT_PUBLIC_BACKEND_HTTP_PORT 3001 Backend HTTP port
NEXT_PUBLIC_BACKEND_WS_PORT 3001 Backend WebSocket port
NEXT_PUBLIC_BACKEND_PROTOCOL http http or https
NEXT_PUBLIC_BACKEND_WS_PROTOCOL ws ws or wss
NEXT_PUBLIC_BACKEND_HTTP_BASE — Full backend URL override (production)
NEXT_PUBLIC_APP_URL — Public frontend URL (production)
NEXTAUTH_SECRET — NextAuth session encryption key
NEXTAUTH_URL http://localhost:3333 NextAuth callback base URL

LLM Providers

Variable Provider
OPENAI_API_KEY / OPENAI_BASE_URL OpenAI / OpenAI-compatible
MINIMAX_API_KEY MiniMax
ANTHROPIC_API_KEY Anthropic (Claude)
QWEN_API_KEY Alibaba Qwen (DashScope)
ZHIPU_API_KEY Z.AI / GLM
GLUE_API_KEY Glue LLM (intent routing)
GLUE_SMART_MODEL Smart-tier model name
GLUE_FAST_MODEL Fast-tier model name
DEFAULT_MODEL Default build model

OAuth

Variable Provider
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET Google OAuth
GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET GitHub OAuth
AUTH_SECRET NextAuth v5 secret

Convex

Variable Description
CONVEX_URL Convex deployment URL
NEXT_PUBLIC_CONVEX_URL Client-side Convex URL

Infrastructure

Variable Description
REDIS_URL Redis connection (BullMQ)
S3_ENDPOINT / S3_ACCESS_KEY / S3_SECRET_KEY Garage S3
TRAILBASE_ENV local, dev, or production; chooses sane TrailBase defaults when explicit URLs are absent
TRAILBASE_MODE single for the local Docker sidecar, control for dev/prod provisioners
TRAILBASE_CONTROL_BASE_URL Backend-to-TrailBase URL (http://127.0.0.1:4000 or http://trailbase:4000 locally, http://trailbase-dev:9000 in dev, http://trailbase-prod:9000 in production)
TRAILBASE_PUBLIC_BASE_URL Browser-facing TrailBase URL (http://localhost:4000 locally, https://dev.codebase.design/app-api or https://codebase.design/app-api when deployed)
NEXT_PUBLIC_TRAILBASE_PUBLIC_BASE_URL Frontend/server-route mirror of the browser-facing TrailBase base

Speech (Optional)

Variable Description
NEXT_PUBLIC_SPEECH_API_WS_URL Speech API WebSocket endpoint
NEXT_PUBLIC_SPEECH_API_HTTP_URL Speech API HTTP endpoint

Troubleshooting

Symptom Cause Fix
convex-backend/ directory is empty Submodules not initialized git submodule init && git submodule update
npm install fails with permission error npm cache lock npm install --cache ./tmp-cache
localStorage is not a function (SSR) Stale Next.js cache rm -rf .next && npm run dev
Port 3001 or 3002 already in use Another process on that port `lsof -ti :3001
CORS errors in browser console Port mismatch Ensure NEXT_PUBLIC_BACKEND_* ports match actual backend port
WebSocket won't connect Path mismatch Backend listens on /ws — check NEXT_PUBLIC_BACKEND_WS_PORT
tRPC calls return 404 Backend not built Run cd backend && npm run build:trpc
OAuth callback fails Wrong NEXTAUTH_URL Must match the URL you access in the browser (including port)
Build errors in agent loop No LLM key configured Set at least one *_API_KEY in .env.local
MODULE_NOT_FOUND on backend start Missing deps cd backend && npm install

Further Reading

Document Description
README.md Project overview & tech stack
web/AGENT-API.md REST API for programmatic builds