A modern, production-ready boilerplate for Next.js applications with TypeScript, Tailwind CSS, and essential tooling.
- ⚡ Next.js 15 with App Router
- 🔒 Authentication system with protected routes
- 🎨 Tailwind CSS for styling
- 📝 TypeScript for type safety
- ✅ Jest and React Testing Library for testing
- 🔍 ESLint and Prettier for code quality
- 🪝 Husky and lint-staged for Git hooks
- 🚨 Error Boundary for error handling
- 🔄 API Client with type-safe requests
- 📱 Responsive layout and components
- Node.js 18+ and npm
- Clone the repository:
git clone https://github.com/yourusername/nextjs-boilerplate.git
cd nextjs-boilerplate- Install dependencies:
npm install- Create a .env.localfile:
NEXT_PUBLIC_API_URL=your_api_url- Start the development server:
npm run devVisit http://localhost:3000 to see your application.
├── src/
│   ├── app/                   # App router pages
│   │   ├── (auth)/           # Authentication routes
│   │   └── (dashboard)/      # Protected dashboard routes
│   ├── components/           # React components
│   │   ├── forms/           # Form components
│   │   ├── layout/          # Layout components
│   │   └── ui/             # UI components
│   ├── hooks/              # Custom React hooks
│   ├── lib/               # Utility functions
│   │   ├── api/          # API client
│   │   └── auth/         # Authentication context
│   └── types/            # TypeScript types
├── public/              # Static files
├── tests/              # Test files
└── package.json
- npm run dev- Start development server
- npm run build- Build for production
- npm run start- Start production server
- npm run lint- Run ESLint
- npm run lint:fix- Fix ESLint errors
- npm run prettier- Format code
- npm run test- Run tests
- npm run test:watch- Run tests in watch mode
- npm run test:coverage- Run tests with coverage
- npm run type-check- Check TypeScript types
The boilerplate includes a complete authentication system with:
- Login and Register pages
- Protected routes middleware
- Authentication context
- Persistent sessions
- Type-safe API integration
Protected routes are automatically handled by the middleware. Add routes to the protectedPaths array in src/middleware.ts to make them require authentication.
Tests are set up with Jest and React Testing Library. Example test:
import { render, screen } from '@testing-library/react'
import { HomePage } from '@/app/page'
describe('HomePage', () => {
  it('renders welcome message', () => {
    render(<HomePage />)
    expect(screen.getByText('Welcome')).toBeInTheDocument()
  })
})The boilerplate includes a type-safe API client with:
- Automatic error handling
- TypeScript types for requests and responses
- Authentication header handling
- Request/response interceptors
Example usage:
import { api } from '@/lib/api/fetcher'
// Type-safe API calls
const data = await api.get<UserResponse>('/users')
const user = await api.post<User>('/users', { name: 'John' })Global error handling is implemented using:
- React Error Boundary
- API error interceptors
- Type-safe error responses
- ESLint with Next.js config
- Prettier for code formatting
- Husky for pre-commit hooks
- lint-staged for staged files
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.