Starter template** for building modern Next.js applications, bootstrapped with create-next-app
A unique feature of this template is its dual-router support. It comes configured with the modern App Router by default, while maintaining full compatibility with the traditional Pages Router. The modular architecture allows seamless switching between routing strategies without major refactoring.
- Dual Router Support:
- Modern App Router (default)
- Legacy Pages Router compatibility
- Easy switching between routing strategies
- Type Safety:
- TypeScript configured for maximum type safety
- Strict type checking enabled
- Testing Excellence:
- Vitest for lightning-fast unit testing
- Playwright for comprehensive E2E testing
- 100% code coverage setup and enforcement
- Code Quality:
- ESLint with strict preset
- Prettier for consistent formatting
- Husky for Git hooks
- Automated PR checks
- Performance:
- Developer Experience:
- Hot module replacement
- Fast refresh
- Intuitive folder structure
- Comprehensive documentation
The project follows a domain-driven, modular architecture optimized for scalability and maintainability. It adopts the "colocation" principle - test files are placed alongside their implementation in __tests__ folders, making the relationship between code and tests explicit and maintainable.
starter-template_nextjs-app/
┣ src/
┃ ┣ app/ # App Router routes
┃ ┃ ┣ (home)/ # Home page group
┃ ┃ ┣ about/ # About page
┃ ┃ ┣ api/ # API routes
┃ ┃ ┗ layout.tsx # Root layout
┃ ┣ _pages/ # Pages Router (optional)
┃ ┃ ┣ _app.tsx # App component
┃ ┃ ┗ index.tsx # Home page
┃ ┣ components/ # React components
┃ ┃ ┣ common/ # Shared components (Header, Footer)
┃ ┃ ┣ ui/ # UI components (Button, Input)
┃ ┃ ┗ view/ # Page-specific components
┃ ┣ lib/ # Shared utilities
┃ ┃ ┣ hooks/ # Custom React hooks
┃ ┃ ┗ utils/ # Helper functions
┃ ┣ server/ # Server-side code
┃ ┃ ┣ actions/ # Server actions
┃ ┃ ┗ db/ # Database operations
┃ ┗ styles/ # CSS modules and global styles
┣ public/ # Static assets
┣ playwright/ # E2E tests
┣ coverage/ # Test reports
┗ config files # Various configuration files
The template supports both routing strategies:
-
App Router (Default)
- Modern routing in
src/app/ - Server components by default
- Nested layouts
- Route groups
- Server actions
- Modern routing in
-
Pages Router
- Traditional routing in
src/_pages/ - Client-side navigation
- API routes
- Simple page-based routing
- Traditional routing in
To switch between routers:
- Move your pages from
app/to_pages/(or vice versa) - Update
next.config.tsconfiguration - Adjust components for the target router's patterns
- Clone and Install
git clone <your-repo-url>
cd starter-template_nextjs-app
npm install # or yarn, pnpm, bun- Set Up Environment
cp .env.example .env.local # Configure your environment variables- Start Development
npm run dev # or yarn dev, pnpm dev, bun devYour app will be running at http://localhost:3000.
-
Create New Pages
- App Router: Add new route in
src/app/ - Pages Router: Add new page in
src/_pages/
- App Router: Add new route in
-
Add Components
- UI components in
src/components/ui/ - Page components in
src/components/view/ - Shared components in
src/components/common/
- UI components in
-
Testing
- Add unit tests alongside components
- Write E2E tests in
playwright/ - Run tests frequently during development
# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
# Testing
npm run test # Run unit tests (Vitest)
npm run test:watch # Run tests in watch mode
npm run test:ui # Open Vitest UI
npm run coverage # Generate coverage report
npm run playwright:e2e # Run E2E tests
npm run playwright:ui # Open Playwright UI
# Code Quality
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint errors
npm run format # Format with Prettier
npm run type-check # TypeScript type checking
# Git Hooks (Husky)
npm run prepare # Install Husky hooksThe template implements a comprehensive testing strategy:
- Fast, parallel test execution
- React Testing Library integration
- Component, hook, and utility testing
- Watch mode for development
- Coverage reporting
npm run test # Run all tests
npm run test:watch # Development mode- Multi-browser testing
- Mobile viewport testing
- Visual regression tests
- Network interception
- Test recording
npm run playwright:e2e # Run all E2E tests
npm run playwright:ui # Open test explorernpm run lint # Check for issues
npm run format # Format codeThis template is optimized for deployment on various platforms:
npm run build
vercel deploy- AWS Amplify
- Netlify
- Docker containers
- Traditional hosting
See Next.js deployment documentation for platform-specific instructions.
We welcome contributions! Please see our Contributing Guide for:
- Code of Conduct
- Development workflow
- Pull request process
- Testing requirements
- Style guidelines
This project is open source under the MIT License.