A full-stack TypeScript monorepo built with Turborepo, featuring a Fastify API and Next.js web app.
- Node.js 18+
- pnpm 9+
# Install dependencies
pnpm install
# Set up environment variables
cp .env.example .env
# Edit .env with your actual values
# Generate Prisma client
pnpm prisma:generate
# Start development
pnpm devThis monorepo uses a single .env file at the root directory that is shared across all apps and packages using dotenv-cli.
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envwith your actual values:DATABASE_URL- PostgreSQL connection string for PrismaCLIENT_ORIGIN- Frontend URL for CORS (default: http://localhost:3000)API_PORT- Port for the Fastify API server (default: 3001)NEXT_PUBLIC_API_URL- API URL for the web app (default: http://localhost:3001)AUTH_SECRET- Secret key for authentication
All scripts in the monorepo are configured to use dotenv -e ../../.env (or appropriate path) to load the root .env file. This ensures consistent environment variable handling across:
- API app - All scripts load root .env automatically
- Web app - All scripts load root .env automatically
- Database package - Prisma commands load root .env automatically
- Root scripts - Prisma commands load root .env automatically
The Turborepo configuration also includes .env* in the build inputs for proper caching.
api- Fastify REST API with TypeScriptweb- Next.js app with TailwindCSS and shadcn/ui
auth- Better Auth shared authenticationdb- Prisma database schema and clientcontracts- Shared API contracts/typeseslint-config- Shared ESLint configurationstypescript-config- Shared TypeScript configurations
# Start all apps in development
pnpm dev
# Start specific app
pnpm dev --filter=web # Web app only
pnpm dev --filter=api # API only
# Database operations
pnpm prisma:migrate # Run migrations
pnpm prisma:generate # Generate Prisma client# Build all apps
pnpm build
# Build specific app
pnpm build --filter=web
# Production API start
cd apps/api && pnpm start
# Production web start
cd apps/web && pnpm startpnpm lint # Lint all packages
pnpm check-types # Type check all packages
pnpm clean # Clean all build outputs
pnpm fresh # Clean, install, and build