Skip to content

nass59/turborepo-nextjs

Repository files navigation

Next.js 15 - AI Turborepo Starter

A production-ready monorepo showcasing modern web development with Next.js 15, React 19, and a thoughtfully-architected feature module system.

🌐 Live Demo

turborepo-nextjs.vercel.app


🎯 What Makes This Special?

Architecture First

Clear separation between presentation, business logic, and data. Feature modules follow a strict no-barrel-files convention to prevent bundle bloat and maintain clear server/client boundaries in React Server Components.

Type Safety Everywhere

End-to-end type safety with tRPCβ€”from database queries to API responses to client components. If it compiles, it works.

Production Ready

Includes authentication (Clerk), background jobs (Inngest), database (PostgreSQL + Prisma on NeonDB), AI integration (OpenAI + E2B sandboxes), and comprehensive error handling.


πŸ› οΈ Tech Stack

Core Framework

  • Next.js 15 β€” App Router, React Server Components, Turbopack
  • React 19 β€” Latest concurrent features and optimizations
  • TypeScript β€” Strict mode, zero compromises
  • Turborepo β€” Monorepo with intelligent caching

Data & API

  • tRPC β€” End-to-end typesafe APIs with superjson transformer
  • PostgreSQL + Prisma β€” Relational database with type-safe ORM, hosted on NeonDB (serverless Postgres)
  • TanStack Query β€” Server state management, caching, & synchronization

Authentication & Background Jobs

  • Clerk β€” Complete auth with GitHub OAuth, middleware-protected routes
  • Inngest β€” Durable async workflows and background processing

UI & Styling

Developer Experience

  • Biome β€” Blazing fast linting & formatting (replaces ESLint + Prettier)
  • Sherif β€” Validates monorepo dependencies
  • Storybook β€” Component documentation & visual testing

AI & Integrations


πŸ“ Architecture

Monorepo Structure

turborepo-nextjs/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ web/                    # Main Next.js application
β”‚   β”‚   β”œβ”€β”€ app/                # App Router (route groups & pages)
β”‚   β”‚   β”‚   β”œβ”€β”€ (home)/         # Public routes: /, /pricing, /auth
β”‚   β”‚   β”‚   β”œβ”€β”€ api/            # API routes: tRPC, webhooks, Inngest
β”‚   β”‚   β”‚   └── projects/       # Protected routes: /projects/*
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ modules/            # 🎯 Feature modules (domain-driven)
β”‚   β”‚   β”‚   β”œβ”€β”€ home/           # Home page features
β”‚   β”‚   β”‚   β”œβ”€β”€ projects/       # Project management
β”‚   β”‚   β”‚   β”œβ”€β”€ messages/       # Message handling
β”‚   β”‚   β”‚   β”œβ”€β”€ usage/          # Usage tracking
β”‚   β”‚   β”‚   └── layout/         # Shared layout components
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ trpc/               # tRPC setup & routers
β”‚   β”‚   β”œβ”€β”€ inngest/            # Background job definitions
β”‚   β”‚   β”œβ”€β”€ prisma/             # Database schema & migrations (PostgreSQL)
β”‚   β”‚   β”œβ”€β”€ middleware.ts       # Auth protection (Clerk)
β”‚   β”‚   └── env.mjs             # Type-safe environment variables
β”‚   β”‚
β”‚   └── storybook/              # Component playground (60+ stories)
β”‚       └── stories/            # Visual documentation for all UI components
β”‚
└── packages/
    β”œβ”€β”€ design-system/          # Shared UI library
    β”‚   └── src/
    β”‚       β”œβ”€β”€ components/     # Shadcn UI components (ui/ & magicui/)
    β”‚       β”œβ”€β”€ hooks/          # Reusable React hooks
    β”‚       └── lib/            # Utilities (cn, etc.)
    β”‚
    └── typescript-config/      # Shared TypeScript configurations
        β”œβ”€β”€ base.json           # Base strict config
        β”œβ”€β”€ nextjs.json         # Next.js specific
        └── react-library.json  # For packages

πŸš€ Getting Started

Prerequisites

  • Node.js 24.6.0+ (LTS recommended)
  • pnpm 10.14.0+
  • PostgreSQL database (NeonDB recommended, or local/Docker)

Quick Start

# 1. Clone the repository
git clone https://github.com/nass59/turborepo-nextjs.git
cd turborepo-nextjs

# 2. Install dependencies
pnpm install

# 3. Set up environment variables
cp apps/web/.env.example apps/web/.env.local
# Then edit apps/web/.env.local with your keys

# 4. Set up database & generate Prisma client
cd apps/web && pnpm prisma generate && pnpm prisma db push && cd ../..

# 5. Start all development servers
pnpm dev

That's it! Your apps will be running:


πŸ“¦ Available Commands

Root Workspace

# Development
pnpm dev              # Start all apps (web + storybook)
pnpm build            # Build all packages & apps for production
pnpm typecheck        # Run TypeScript checks across workspace
pnpm lint             # Lint all code with Biome
pnpm format           # Auto-format code with Biome

# Dependencies
pnpm check-dependencies  # Validate with Sherif
pnpm bump-deps          # Update all dependencies (except geist)
pnpm bump-ui            # Sync Shadcn UI components to design-system

# Cleanup
pnpm clean             # Remove build artifacts & caches

Individual Apps

# Web App (apps/web)
cd apps/web
pnpm dev              # Start with Turbopack (fast refresh)
pnpm build            # Production build
pnpm start            # Start production server
pnpm typecheck        # Type check this app

# Storybook (apps/storybook)
cd apps/storybook
pnpm dev              # Start Storybook dev server
pnpm build            # Build static Storybook site
pnpm chromatic        # Deploy to Chromatic (visual testing)

πŸ—οΈ Development Workflow

Creating a New Feature

  1. Add a new module in apps/web/modules/your-feature/

    modules/your-feature/
    β”œβ”€β”€ ui/              # Components
    β”œβ”€β”€ server/          # Server functions
    β”œβ”€β”€ types.ts         # Types
    └── constants.ts     # Config
    
  2. Create tRPC procedures in apps/web/trpc/routers/your-feature.ts

    import { protectedProcedure } from '../trpc';
    
    export const yourFeatureRouter = {
      list: protectedProcedure.query(async ({ ctx }) => {
        // Server-side logic with ctx.clerkUserId
      }),
    };
  3. Use in components via tRPC hooks

    'use client';
    import { useTRPC } from '@/trpc/client';
    
    export function YourComponent() {
      const { data } = useQuery(trpc.yourFeature.yourAction.queryOptions());
      // ...
    }

Adding UI Components

  1. Add to design system via Shadcn CLI

    pnpm bump-ui  # Syncs latest Shadcn components
  2. Create Storybook story in apps/storybook/stories/

    import type { Meta, StoryObj } from '@storybook/react';
    import { YourComponent } from '@workspace/design-system/components/ui/your-component';
    
    const meta: Meta<typeof YourComponent> = {
      title: 'UI/YourComponent',
      component: YourComponent,
    };
  3. Use in your app

    import { YourComponent } from '@workspace/design-system/components/ui/your-component';

Background Jobs

Define Inngest functions in apps/web/inngest/functions.ts:

import { inngest } from './client';

export const processTask = inngest.createFunction(
  { id: 'process-task' },
  { event: 'app/task.process' },
  async ({ event, step }) => {
    // Durable async workflow
  }
);

πŸ€– AI-Optimized Development

This project includes comprehensive documentation for AI assistants:

  • docs/AI-DEVELOPMENT-GUIDE.md β€” Guidelines for AI pair programming
  • .github/copilot-instructions.md β€” GitHub Copilot specific instructions
  • ADRs β€” Architectural Decision Records in docs/adr/
  • JSDoc β€” All public APIs documented

Helpful Scripts:

./scripts/ai-analysis.sh       # Generate project analysis
./scripts/adr-helper.sh new    # Create new ADR
./scripts/debug-helper.sh      # Debug assistance

πŸ“š Key Documentation

Essential ADRs


🎨 Design System

The @workspace/design-system package exports 60+ accessible components built on:

  • Radix UI primitives
  • Tailwind CSS 4 styling
  • CVA (class-variance-authority) for variants
  • Lucide Icons for iconography

Usage:

// Direct imports (no barrel files)
import { Button } from '@workspace/design-system/components/ui/button';
import { cn } from '@workspace/design-system/lib/utils';

Explore components:

cd apps/storybook && pnpm dev
# Visit http://localhost:6006

🚒 Deployment

Vercel (Recommended)

# Connect your repo to Vercel
vercel

# Add environment variables in Vercel dashboard
# Deploy!
vercel --prod

Docker

# Build
docker build -t turborepo-nextjs .

# Run
docker run -p 3000:3000 turborepo-nextjs

Environment Variables

Ensure all required env vars are set in your deployment platform. Turborepo will automatically pass them through during build (configured in turbo.json).


πŸ“„ License

This project is licensed under the MIT License β€” see LICENSE.md for details.


πŸ™ Acknowledgments

Built with amazing open source tools:

  • Vercel β€” Hosting & deployment platform
  • Shadcn β€” UI component design
  • Turborepo Team β€” Monorepo tooling
  • Next.js Team β€” The React framework
  • Biome β€” Fast, unified toolchain
  • tRPC β€” End-to-end type safety
  • Clerk β€” Beautiful authentication

🎯 What's Next?

  • Add comprehensive test coverage
  • Implement E2E testing with Playwright
  • Add performance monitoring (Sentry)
  • Add CI/CD workflows
  • Internationalization (i18n)

Built with ❀️ by nass190

About

A production-ready Next.js 15 monorepo with React 19, TypeScript, tRPC, and Prisma.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •