Skip to content

alexfdez1010/next-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Next.js Production-Ready Template

A production-grade Next.js template engineered with enterprise-level best practices, comprehensive testing infrastructure, and strict code quality standards. Built for teams that demand excellence in maintainability, scalability, and developer experience. This template is based in the practices used in ZeroChats.

Next.js React TypeScript TailwindCSS Prisma

🎯 Philosophy

This template embodies professional software engineering principles with a focus on:

  • SOLID Principles - Applied rigorously across all code
  • Design Pattern Driven - Appropriate patterns for maintainability and scalability
  • Documentation First - Comprehensive TSDoc/JSDoc for all functions, classes, and hooks
  • Testing as Priority - Unit, integration, and E2E tests with meaningful coverage
  • Code Quality - Strict linting, formatting, and file size limits (200 lines max)
  • Type Safety - Full TypeScript strict mode enforcement

See AGENTS.md for complete development guidelines and principles that are used to guide AI Agents.

✨ Features

Core Stack

Testing Infrastructure

  • Vitest - Fast unit and integration testing
  • Playwright - Reliable E2E testing across browsers
  • Comprehensive test setup - Separate unit, integration, and E2E test suites
  • Docker-based test database - Isolated test environment

Code Quality Tools

  • ESLint - Next.js and TypeScript linting rules
  • Prettier - Consistent code formatting
  • Pre-commit hooks - Automated testing and formatting before commits
  • Strict TypeScript - Maximum type safety configuration

Database & Infrastructure

  • PostgreSQL - Production-ready relational database
  • Docker Compose - Containerized development and test databases
  • Prisma migrations - Version-controlled database schema
  • Environment management - Secure configuration with .env files

πŸ“‹ Prerequisites

  • Node.js 20.x or higher
  • Bun 1.x or higher (install)
  • Docker and Docker Compose (for database)
  • Git for version control

πŸš€ Getting Started

1. Clone and Install

# Clone the repository
git clone https://github.com/alexfdez1010/next-template.git my-project
cd my-project

# Install dependencies
bun install

2. Environment Setup

# Copy environment template
cp .env.example .env

# Edit .env with your configuration
# DATABASE_URL="postgresql://postgres:postgres@localhost:5432/db"

3. Database Setup

# Start PostgreSQL container
bun run database

# Run migrations (in another terminal)
bun run database:dev

# Stop database when done
bun run database:down

4. Run Development Server

# Start development server with Turbopack
bun run dev

Open http://localhost:3000 to see your application.

πŸ“œ Available Scripts

Development

  • bun run dev - Start development server with database
  • bun run build - Build production bundle
  • bun run start - Start production server
  • bun run launch - Build and start with database

Code Quality

  • bun run lint - Run ESLint and Prisma formatting
  • bun run format - Format code with Prettier
  • bun run lint-format - Lint and format (required before commits)
  • bun run pre-commit - Run tests and code quality checks

Testing

  • bun run test - Run all tests (unit, integration, E2E)
  • bun run test:unit - Run unit tests only
  • bun run test:integration - Run integration tests only
  • bun run test:e2e - Run E2E tests with Playwright
  • bun run playwright - Open Playwright UI for debugging

Database

  • bun run database - Start PostgreSQL container
  • bun run database:down - Stop database container
  • bun run database:dev - Run migrations in development
  • bun run database:deploy - Deploy migrations to production
  • bun run database:studio - Open Prisma Studio
  • bun run database:test - Start test database

πŸ—οΈ Project Structure

next-template/
β”œβ”€β”€ src/
β”‚   └── app/              # Next.js App Router pages
β”‚       β”œβ”€β”€ layout.tsx    # Root layout
β”‚       β”œβ”€β”€ page.tsx      # Home page
β”‚       └── globals.css   # Global styles
β”œβ”€β”€ prisma/
β”‚   └── schema.prisma     # Database schema
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/             # Unit tests
β”‚   β”œβ”€β”€ integration/      # Integration tests
β”‚   β”œβ”€β”€ e2e/              # End-to-end tests
β”‚   └── setup.ts          # Test configuration
β”œβ”€β”€ public/               # Static assets
β”œβ”€β”€ generated/            # Generated Prisma client
β”œβ”€β”€ .vscode/              # VS Code settings
β”œβ”€β”€ compose.yml           # Development database
β”œβ”€β”€ compose-test.yml      # Test database (ephemeral)
β”œβ”€β”€ eslint.config.mjs     # ESLint configuration
β”œβ”€β”€ playwright.config.ts  # Playwright configuration
β”œβ”€β”€ vitest.config.ts      # Vitest configuration
β”œβ”€β”€ tsconfig.json         # TypeScript configuration
β”œβ”€β”€ tailwind.config.ts    # TailwindCSS configuration
β”œβ”€β”€ .prettierrc           # Prettier configuration
β”œβ”€β”€ .env.example          # Environment template
└── AGENTS.md             # AI Agents Development guidelines

πŸ§ͺ Testing Strategy

Unit Tests

Located in tests/unit/, these test individual functions and components in isolation.

bun run test:unit

Integration Tests

Located in tests/integration/, these test module interactions and API endpoints.

bun run test:integration

End-to-End Tests

Located in tests/e2e/, these test complete user flows across browsers.

bun run test:e2e

πŸ—„οΈ Database Management

Prisma Workflow

# Create a new migration
bun run database:dev

# Deploy migrations to production
bun run database:deploy

# Check migration status
bun run database:check

# Open Prisma Studio
bun run database:studio

Schema Changes

  1. Edit prisma/schema.prisma
  2. Run bun run database:dev to create migration
  3. Test with bun run database:test
  4. Commit schema and migration files

🚒 Deployment

Environment Variables

Ensure all required environment variables are set:

DATABASE_URL="postgresql://user:password@host:5432/database"

Build and Deploy

# Build production bundle
bun run build

# Run production server
bun run start

πŸ”§ Configuration Files

  • tsconfig.json - TypeScript strict mode, path aliases
  • eslint.config.mjs - Next.js and TypeScript rules
  • .prettierrc - Single quotes, trailing commas, 2-space tabs
  • vitest.config.ts - Node environment, 10s timeout
  • playwright.config.ts - Multi-browser E2E testing

πŸ“š Resources

Official Documentation

πŸ“„ Template Usage

This is a template repository. To use it:

  1. Click "Use this template" on GitHub
  2. Clone your new repository
  3. Remove or modify this README as needed
  4. Start building your application

About

Next.js template with support for AI Agents following best practices

Topics

Resources

Stars

Watchers

Forks

Contributors