A highly opinionated, clean-architecture foundation for modern web applications.
Designed for teams who value maintainability over shortcuts.
This is not just another "Hello World" template. This repository implements a real-world engineering standard for Next.js applications.
It solves the common problems of spaghetti code, scattered API calls, and loose typing by enforcing a Feature-Based Modular Architecture. It is pre-configured with RTK Query for data fetching, Zod for runtime validation, and a strict separation between UI, Logic, and Data layers.
We built this kit based on principles that ensure the codebase remains healthy as it scales from 10 to 100+ components.
| Decision | Why is this necessary? |
|---|---|
Feature Modules (/modules) |
Instead of organizing by file type (e.g., all components in one folder), we organize by domain (e.g., modules/auth). This keeps related logic co-located and easy to extract or refactor. |
| Centralized Endpoints | Hardcoding API URLs in components leads to "magic strings" and refactoring nightmares. We use a single registry (constants/endpoints.ts) to manage all API routes. |
| Zod as Single Source of Truth | We don't manually write TypeScript interfaces for API responses. We define Zod Schemas and infer TypeScript types from them. This ensures runtime validation matches compile-time types. |
| Service Layer (RTK Query) | The UI should never trigger fetch() directly. Data fetching, caching, deduplication, and loading states are handled entirely by Redux Toolkit Query, keeping components pure. |
| Mocked Auth (Demo Mode) | To allow immediate UI development without a backend, the auth system is fully mocked. It simulates latency, token storage, and protection logic, making it "Backend-Ready" when you need it. |
src/
├── app/ # Next.js App Router (Routing only)
│ ├── (public)/ # Routes accessible without login
│ ├── (protected)/ # Routes requiring authentication
│ └── layout.tsx
│
├── modules/ # 🟢 THE CORE: Feature-based architecture
│ └── auth/ # Example Module
│ ├── components/ # UI components specific to Auth
│ ├── hooks/ # Business logic for Auth
│ ├── schemas/ # Zod validation schemas
│ ├── types/ # TS types inferred from Zod
│ └── index.ts # Public API for this module
│
├── services/ # API Layer (RTK Query)
│ ├── baseApi.ts # Network configuration (Interceptors, etc.)
│ └── auth.endpoints.ts # Endpoint definitions
│
├── store/ # Redux Store Configuration
├── components/ # Shared/Global UI Components (Buttons, Inputs)
├── hooks/ # Global reusable hooks
├── utils/ # Helpers (Token management, Formatting)
└── constants/ # App-wide constants (Routes, API paths)
All backend routes are defined in one place. This allows for easy versioning and refactoring without hunting through component files.
// src/constants/endpoints.ts
export const endpoints = {
auth: {
login: '/auth/login',
refresh: '/auth/refresh',
logout: '/auth/logout',
},
// Add other domains here...
}There is no backend connected by default. For development and demonstration purposes, the authentication flow is mocked at the hook level.
- Login Logic: Simulates API latency and validates against hardcoded demo credentials.
- Storage: Stores a fake token in
localStorageto persist the session. - Protection: Routes in
(protected)check for this token and redirect if missing.
Email:
demo@demo.com
Password:password123
When you are ready for a real backend, simply update the useAuth hook to call your actual API endpoint.
Clone the repository and install dependencies:
git clone https://github.com/henabakos/nextjs-advanced-starter.git
cd nextjs-advanced-starter
npm installnpm run devThen open http://localhost:3000 to see the app.
| Component | Technology |
|---|---|
| Framework | Next.js (App Router) |
| Language | TypeScript |
| State Management | Redux Toolkit |
| Data Fetching | RTK Query |
| Validation | Zod |
| Styling | Tailwind CSS (Recommended) |
This starter kit is ideal for:
✓ SaaS dashboards – Build scalable, interactive dashboard interfaces
✓ Admin panels – Create powerful admin interfaces with robust tooling
✓ Internal tools – Develop internal applications with enterprise-grade architecture
✓ Learning real-world frontend architecture – Study production-ready patterns and practices
✓ Teams that care about clean code – Maintain consistent code quality across projects
This project is open source and available under the MIT License.
Built with ❤️ by Hena
Code less, Architect more.