A modern, well-structured Next.js template with TypeScript, Tailwind CSS, and a scalable architecture. This template provides a solid foundation for building production-ready web applications with clear organization patterns and best practices.
- Node.js 18+
- pnpm
- Clone this repository or use it as a template
- Install dependencies:
pnpm install- Run the development server:
pnpm dev- Open http://localhost:3000 in your browser
This template follows a modular, scalable architecture with clear separation of concerns:
src/
βββ app/ # Next.js App Router pages and layouts
β βββ api/ # API route handlers
β βββ layout.tsx # Root layout
β βββ page.tsx # Home page
βββ components/ # React components
β βββ ui/ # Reusable UI components (shadcn/ui)
βββ contexts/ # React Context API for global state
βββ hooks/ # Custom React hooks
βββ lib/ # Shared utilities and libraries
β βββ api/ # API client functions
β βββ utils/ # Utility functions
βββ providers/ # Context providers and wrapper components
βββ server/ # Server-side code
β βββ config/ # Server configuration
β βββ repositories/ # Data access layer
β βββ services/ # Business logic services
βββ types/ # TypeScript type definitions
Each folder contains a .gitkeep file with detailed organization guidelines. Here's a quick overview:
Next.js App Router directory. Contains pages, layouts, and API routes.
app/api/: API route handlers organized by endpoint- Create subfolders for each route:
api/users/route.ts,api/products/route.ts - Each subfolder contains a
route.tsfile with HTTP method handlers
- Create subfolders for each route:
React components organized by feature or type.
components/ui/: Reusable UI components (shadcn/ui components)- Create feature-specific components in separate files or subfolders
React Context API contexts for global state management.
- Create separate files for each context domain:
auth-context.tsx,theme-context.tsx - Each context should export both the context and its provider
Custom React hooks for reusable logic.
- Use the
use-prefix:use-auth.ts,use-api.ts - Organize by domain: authentication, data fetching, UI interactions, etc.
Context providers and wrapper components.
- Create separate files per provider:
theme-provider.tsx,auth-provider.tsx - Consider a root provider that combines multiple providers
TypeScript type definitions and interfaces.
- Organize by domain:
user.ts,product.ts,order.ts - Or by category:
models.ts,api.ts,common.ts - Use index files to re-export related types
API client functions and HTTP request handlers.
- Organize by resource:
users.ts,products.ts,auth.ts - Keep API client configuration in separate files if needed
Utility functions and helper methods.
- Organize by category:
date.ts,string.ts,validation.ts,formatting.ts - Keep utilities pure and framework-agnostic when possible
Server-side business logic services.
- Create separate files per domain:
user-service.ts,order-service.ts - Services orchestrate between repositories and handle business rules
Data access layer for database operations.
- Create separate files per entity:
user-repository.ts,product-repository.ts - Each repository handles CRUD operations for a single entity type
Server configuration files.
- Common files:
database.ts,env.ts,constants.ts - Keep configuration files focused and single-purpose
This template follows a layered architecture pattern:
- Presentation Layer (
app/,components/): UI and user interactions - Application Layer (
hooks/,contexts/,providers/): Application logic and state - Domain Layer (
server/services/): Business logic and rules - Data Layer (
server/repositories/): Data access and persistence
Component β Hook β API Client β API Route β Service β Repository β Database
This template includes shadcn/ui. To add new components:
pnpm ui:add [component-name]- One file per entity/resource: Keep related code together
- Clear naming conventions: Use descriptive, consistent names
- Separation of concerns: Keep business logic separate from UI
- Type safety: Leverage TypeScript for type safety
- Components: Keep components small and focused on a single responsibility
- Hooks: Extract reusable logic into custom hooks
- Types: Define types close to where they're used, or in
types/for shared types - Services: Keep business logic in services, not in components or API routes
- Repositories: Keep data access logic in repositories, not in services
- Framework: Next.js 16 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- UI Components: shadcn/ui (Radix UI + Tailwind)
- Animations: Framer Motion
- Icons: Lucide React
The easiest way to deploy is using Vercel:
- Push your code to GitHub
- Import your repository in Vercel
- Vercel will automatically detect Next.js and configure the build
This template can be deployed to any platform that supports Next.js:
- Netlify
- AWS Amplify
- Railway
- Docker containers
- Next.js Documentation
- Next.js App Router
- TypeScript Documentation
- Tailwind CSS Documentation
- shadcn/ui Documentation
- Each folder contains a
.gitkeepfile with detailed organization guidelines - This is a template repository - customize it to fit your project needs
- Remove
.gitkeepfiles once you add actual files to the folders
This is a template repository. Feel free to fork and customize it for your needs!
See the LICENSE file for details.