A modern, production-ready Next.js template featuring authentication, database integration, and a beautiful UI built with Chakra UI and Tailwind CSS.
- β‘ Next.js 15 - Latest version with App Router
- π Authentication - NextAuth.js with OAuth (GitHub, Google) and email/password
- πΎ Database - PostgreSQL with Prisma ORM
- π¨ UI Components - Chakra UI v3 with Tailwind CSS v4
- π Theme Support - Light/dark mode with next-themes
- π± Responsive Design - Mobile-first approach
- π Animations - Framer Motion for smooth transitions
- π§ Developer Experience - TypeScript, ESLint, Prettier
- π§ͺ Testing - Vitest with React Testing Library and coverage reports
- π CI/CD - GitHub Actions for automated testing on pull requests
- π³ Docker Support - Container setup with docker-compose
- Framework: Next.js 15 with App Router
- Language: TypeScript
- Database: PostgreSQL with Prisma ORM
- Authentication: NextAuth.js
- Styling: Chakra UI v3 + Tailwind CSS v4
- Typography: Outfit Google Font
- Animations: Framer Motion
- Icons: React Icons
- Testing: Vitest + React Testing Library
- CI/CD: GitHub Actions
- Code Quality: ESLint + Prettier + lint-staged
- Node.js 18+
- PostgreSQL database (or Docker for automatic setup)
- Git
Use our automated setup script for the fastest way to get started:
git clone <your-repo-url>
cd base-nextjs-template
./setup.shThe setup script will:
- β Check Docker and Docker Compose prerequisites
- β
Create
.envfile from template - β Start PostgreSQL with Docker Compose
- β Install npm dependencies
- β Generate Prisma client
- β Set up database schema
- β Seed database with sample data (including admin user)
If you prefer to set up manually or need custom configuration:
git clone <your-repo-url>
cd base-nextjs-template
npm installCopy the environment template and configure your variables:
cp env.example .envThe .env file will contain:
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/postgres?schema=public"
# NextAuth
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-secret-key-here-replace-in-production"
# Admin credentials (for seeding)
ADMIN_EMAIL="admin@admin.com"
ADMIN_PASSWORD="admin123"
# OAuth providers (optional)
# GITHUB_ID="your-github-client-id"
# GITHUB_SECRET="your-github-client-secret"
# GOOGLE_ID="your-google-client-id"
# GOOGLE_SECRET="your-google-client-secret"# Start PostgreSQL with Docker
docker compose up -d postgres
# Generate Prisma client
npm run db:generate
# Set up database schema
npm run db:push
# (Optional) Seed the database
npm run db:seednpm run devOpen http://localhost:3000 in your browser.
After running the setup script, you can log in with the default admin account:
- Email:
admin@admin.com - Password:
admin123
Note: Change these credentials in production by updating the
ADMIN_EMAILandADMIN_PASSWORDenvironment variables.
src/
βββ app/ # Next.js App Router pages
β βββ api/ # API routes
β β βββ auth/ # Authentication endpoints
β βββ auth/ # Authentication pages
βββ components/ # Reusable components
β βββ auth/ # Authentication components
β βββ providers/ # Context providers
β βββ site/ # Site layout components
β βββ ui/ # UI components
βββ lib/ # Utility libraries
βββ types/ # TypeScript type definitions
This template includes a complete authentication system with:
- OAuth Providers: GitHub, Google (easily extensible)
- Email/Password: Traditional authentication with secure password hashing
- Session Management: Database-backed sessions with NextAuth.js
- Protected Routes: Server and client-side protection
See AUTH_SETUP.md for detailed OAuth configuration instructions.
// Client-side authentication
import { useSession } from 'next-auth/react'
export function MyComponent() {
const { data: session, status } = useSession()
if (status === 'loading') return <div>Loading...</div>
if (!session) return <div>Please sign in</div>
return <div>Welcome {session.user?.name}!</div>
}// Server-side authentication
import { getServerSession } from 'next-auth/next'
import { authOptions } from '@/lib/auth'
export default async function Page() {
const session = await getServerSession(authOptions)
if (!session) {
return <div>Access denied</div>
}
return <div>Protected content</div>
}Built with Chakra UI v3 and Tailwind CSS v4:
- Design System: Consistent spacing, colors, and typography with Outfit font
- Responsive: Mobile-first responsive design
- Accessible: ARIA compliant components
- Themeable: Easy customization and branding
- Dark Mode: Built-in light/dark theme support
- Typography: Clean, modern Outfit Google Font
This project uses lint-staged with Husky to ensure code quality before commits:
- Pre-commit Hook: Automatically runs ESLint and Prettier on staged files
- Lint-staged Configuration: Only processes files that are staged for commit
- Automatic Fixing: ESLint will attempt to fix issues automatically
- Consistent Formatting: Prettier ensures consistent code style
The following git hooks are configured:
- pre-commit: Runs
lint-stagedto check and fix code before committing
You can also run lint-staged manually:
npm run lint-staged # Run linters on staged filesThis project uses Vitest for fast and reliable testing:
- Unit Tests: Test individual components and functions
- Integration Tests: Test component interactions
- Coverage Reports: Track test coverage with detailed reports
- Watch Mode: Automatic test re-runs during development
- UI Mode: Interactive test runner with web interface
Create test files with .test.tsx or .test.ts extensions:
// src/components/__tests__/Button.test.tsx
import { render, screen } from '@testing-library/react'
import { describe, it, expect } from 'vitest'
import { Button } from '../Button'
describe('Button', () => {
it('renders button with text', () => {
render(<Button>Click me</Button>)
expect(screen.getByRole('button')).toHaveTextContent('Click me')
})
})- React Testing Library: Test components the way users interact with them
- Vitest: Fast test runner with Jest-compatible API
- Coverage Reports: Built-in coverage analysis
- Mocking: Pre-configured mocks for Next.js, NextAuth, and Framer Motion
- Setup: Global test setup with custom matchers and utilities
- CI/CD Integration: Automated testing on pull requests
This project includes multiple GitHub Actions workflows for continuous integration:
- File:
.github/workflows/simple-test.yml - Triggers: Pull requests and pushes to
mainanddevelopbranches - Actions: Linting, formatting, tests, and coverage
- Reliable: No external dependencies or artifact uploads
- File:
.github/workflows/test.yml - Triggers: Pull requests to
mainanddevelopbranches - Actions: Runs Vitest tests with coverage reporting
- Artifacts: Attempts to upload coverage reports (with fallback)
- Node.js: Tests against Node.js 18 with npm caching
- File:
.github/workflows/ci.yml - Linting: ESLint code quality checks
- Formatting: Prettier code formatting verification
- Testing: Full test suite with coverage
- Building: Verifies successful production build
- Artifacts: Uploads build and coverage artifacts (with error handling)
You can test GitHub Actions workflows locally using act:
# macOS (using Homebrew)
brew install act
# Other platforms: https://github.com/nektos/act#installation# Test the simple workflow (recommended)
act pull_request -W .github/workflows/simple-test.yml
# Test the main CI workflow
act pull_request -W .github/workflows/ci.yml
# Test the test-only workflow
act pull_request -W .github/workflows/test.yml
# List all available workflows
act -l
# Run with verbose output
act pull_request -W .github/workflows/simple-test.yml -v- Docker Required:
actuses Docker to simulate GitHub runners - Environment Variables: Create
.envfile for secrets if needed - Artifact Uploads: May not work locally (hence our simple workflow)
- Resource Usage: Can be resource-intensive for complex workflows
- Test locally first:
act pull_request -W .github/workflows/simple-test.yml - Fix any issues: Update code and re-test
- Push to GitHub: Let the real workflows run
- Use simple workflow: Most reliable for both local and remote testing
# Check if act is installed
act --version
# Test the simple workflow immediately
act pull_request -W .github/workflows/simple-test.yml
# If you get Docker permission errors, you might need:
# sudo docker ps # or configure Docker for non-root users# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
# Code Quality
npm run lint # Run ESLint
npm run format # Format code with Prettier
npm run format:check # Check code formatting
npm run lint-staged # Run linters on staged files
# Testing
npm run test # Run tests in watch mode
npm run test:run # Run tests once
npm run test:ui # Run tests with UI
npm run test:coverage # Run tests with coverage
# Database
npm run db:generate # Generate Prisma client
npm run db:push # Push schema changes to database
npm run db:migrate # Run database migrations
npm run db:seed # Seed database with sample data
npm run db:studio # Open Prisma Studio# Install act (macOS)
brew install act
# Test workflows locally
act pull_request -W .github/workflows/simple-test.yml
act pull_request -W .github/workflows/ci.yml
act -l # List all workflowsnpm run db:studio # Open Prisma Studio
npm run db:generate # Generate Prisma client
npm run db:migrate # Run migrations
npm run db:push # Push schema changes
npm run db:seed # Seed database# Start with Docker Compose
docker compose up -d
# Stop services
docker compose downEnsure these are set in your production environment:
DATABASE_URL- PostgreSQL connection stringNEXTAUTH_URL- Your deployed app URLNEXTAUTH_SECRET- Strong secret key- OAuth credentials (if using OAuth)
- Vercel - Seamless Next.js deployment
- Railway - Full-stack deployment with database
- Netlify - Static site deployment
- Docker - Container deployment anywhere
We welcome contributions! Please see our Contributing Guide for details on:
- Development workflow
- Code standards
- Testing requirements
- Pull request process
Quick start:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Run tests (
npm run test:run) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- π Next.js Documentation
- π NextAuth.js Documentation
- ποΈ Prisma Documentation
- π¨ Chakra UI Documentation
Built with β€οΈ using Next.js