Skip to content
/ CleanStack Public template

Full-stack Next.js monorepo boilerplate featuring TypeScript, Drizzle ORM, PostgreSQL, and modern development tools. Built with clean architecture principles and ready for production use.

License

Notifications You must be signed in to change notification settings

axelhamil/CleanStack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸ—οΈ CleanStack

Production-ready Next.js monorepo with Clean Architecture and Domain-Driven Design

A comprehensive starter template implementing Clean Architecture and DDD patterns. Built with Next.js 16, TypeScript, Turborepo, Drizzle ORM, and a complete DDD toolkit. Designed for scalable enterprise applications with AI-friendly codebase architecture.

Next.js TypeScript License

Built with Claude Code | Documentation | Features | Quick Start

✨ Features

πŸ›οΈ Architecture & Patterns

  • Clean Architecture - Separation of concerns with clear layer boundaries
  • Domain-Driven Design - Comprehensive DDD toolkit with Entities, Value Objects, Aggregates
  • Result Pattern - Type-safe error handling without exceptions
  • Option Pattern - Eliminate null/undefined with functional patterns
  • Use Cases - Encapsulated business logic following single responsibility
  • Domain Events - Event-driven architecture with type-safe handlers

⚑ Technology Stack

  • Next.js 16 - App Router, React Server Components, Server Actions
  • TypeScript 5.9 - Strict mode with comprehensive type safety
  • Turborepo - High-performance build system for monorepos
  • Drizzle ORM - Type-safe SQL with PostgreSQL
  • shadcn/ui - Beautiful, accessible component system
  • Tailwind CSS 4 - Modern utility-first CSS framework
  • Biome - Fast linter and formatter (replaces ESLint + Prettier)
  • Vitest - Lightning-fast unit testing
  • PNPM - Efficient package management

πŸ€– AI-Friendly Development

  • Claude Code Integration - Optimized for AI-assisted development
  • Comprehensive Documentation - CLAUDE.md with full codebase context
  • .cursorrules - AI coding guidelines and patterns
  • VS Code Configuration - Pre-configured for optimal AI assistance
  • Helper Scripts - Generate Value Objects, Use Cases, and more

πŸ“¦ Project Structure

cleanstack/
β”œβ”€β”€ apps/
β”‚   └── nextjs/              # Main Next.js application
β”‚       β”œβ”€β”€ app/             # App Router pages & layouts
β”‚       β”œβ”€β”€ common/          # DI container, translations, providers
β”‚       └── src/             # Clean Architecture layers
β”‚           β”œβ”€β”€ adapters/    # Controllers, presenters, repositories
β”‚           β”œβ”€β”€ application/ # Use cases & business logic
β”‚           β”œβ”€β”€ domain/      # Entities, value objects, aggregates
β”‚           └── infrastructure/ # Database, external APIs
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ ddd-kit/         # DDD primitives (Entity, ValueObject, Aggregate, Result, Option)
β”‚   β”œβ”€β”€ drizzle/         # Database schema & migrations
β”‚   β”œβ”€β”€ ui/              # shadcn/ui components + brutalist design system
β”‚   └── test/            # Shared test utilities

Clean Architecture Layers

CleanStack follows Clean Architecture with strict dependency rules:

Infrastructure β†’ Adapters β†’ Application β†’ Domain
     ↓              ↓           ↓
   Database    Controllers   Use Cases   Entities & Value Objects
   External    Presenters                Aggregates & Events
   APIs        Repositories

Dependencies flow inward only. The domain layer has zero external dependencies.

πŸš€ Quick Start

Prerequisites

  • Node.js β‰₯ 24.12.0
  • PNPM 10.26.2
  • Docker & Docker Compose

Installation

# 1. Clone and install dependencies
git clone https://github.com/axelhamil/nextjs-clean-architecture-starter cleanstack
cd cleanstack
pnpm install

# 2. Setup database
cp .env.example .env
docker-compose up -d
pnpm db:push

# 3. Start development server
pnpm dev

Visit http://localhost:3000 to see your app.

First Steps

  1. Read CLAUDE.md - Comprehensive guide to the architecture
  2. Check .cursorrules - AI coding guidelines and patterns
  3. Explore @packages/ddd-kit - Learn the DDD primitives
  4. Try helper scripts - Generate Use Cases and Value Objects

🌐 Services

Service URL
Next.js http://localhost:3000

πŸ—οΈ Development

Available Commands

# Development
pnpm dev           # Start development server
pnpm build         # Build for production
pnpm start         # Start production server

# Code Quality
pnpm validate      # Full validation (type-check + lint + test)
pnpm quick-check   # Fast check (type-check + lint)
pnpm type-check    # TypeScript type checking
pnpm check         # Biome lint & format check
pnpm format        # Format code with Biome
pnpm test          # Run all tests with Vitest

# Database
pnpm db            # Start PostgreSQL container
pnpm db:push       # Push schema changes
pnpm db:generate   # Generate migrations
pnpm db:migrate    # Run migrations
pnpm db:studio     # Open Drizzle Studio

# Utilities
pnpm clean         # Clean build artifacts
pnpm ui:add        # Add shadcn/ui components

πŸ“š Documentation

Essential Reading

  • CLAUDE.md - Complete architecture guide and codebase context
  • .cursorrules - AI coding guidelines and architectural patterns
  • @packages/ddd-kit - DDD primitives documentation

Key Concepts

Result Pattern

const emailOrError = Email.create("user@example.com");
if (emailOrError.isFailure) {
  return Result.fail(emailOrError.getError());
}
const email = emailOrError.getValue();

Value Objects

export class Email extends ValueObject<EmailProps> {
  protected validate(props: EmailProps): Result<EmailProps> {
    if (!emailRegex.test(props.value)) {
      return Result.fail("Invalid email");
    }
    return Result.ok(props);
  }
}

Use Cases

export class CreateUserUseCase implements UseCase<CreateUserInput, User> {
  async execute(input: CreateUserInput): Promise<Result<User>> {
    // Business logic here
  }
}

πŸ€– AI-Assisted Development

CleanStack is optimized for AI coding assistants:

Claude Code / Cursor

  • CLAUDE.md provides complete codebase context
  • .cursorrules defines architectural patterns and anti-patterns
  • Helper scripts generate boilerplate code
  • Comprehensive comments in DDD primitives

Getting Started with AI

  1. Open CLAUDE.md in your AI assistant
  2. Ask it to read .cursorrules for coding guidelines
  3. Use helper scripts: ./scripts/create-use-case.sh MyUseCase
  4. Follow Result and Option patterns consistently

πŸ“– Tech Stack

Next.js TypeScript Turborepo Drizzle PostgreSQL Tailwind Biome

🎯 When to Use CleanStack

Perfect for:

  • Enterprise applications requiring maintainable architecture
  • Scalable systems with complex business logic
  • Teams wanting clear architectural boundaries
  • AI-assisted development with Claude Code or Cursor
  • Long-term projects where testability matters

Not ideal for:

  • Simple CRUD apps or MVPs
  • Prototypes requiring rapid iteration
  • Projects with minimal business logic

🀝 Contributing

Contributions are welcome! Please read CLAUDE.md to understand the architecture before submitting PRs.

πŸ“ License

MIT Β© AxelHamil


Built with Claude Code | Give it a ⭐ if you find it useful!

About

Full-stack Next.js monorepo boilerplate featuring TypeScript, Drizzle ORM, PostgreSQL, and modern development tools. Built with clean architecture principles and ready for production use.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks