https://github.com/aceiny/nextjs-starter-kit
A modern Next.js starter kit with flexible, reusable, and schema-validated forms featuring built-in error handling. Includes API clients, React Query, Zustand state management, toast notifications, centralized paths/messages, and a clear folder structure , Production-ready and developer-friendly.
https://github.com/aceiny/nextjs-starter-kit
axios nextjs nodejs react-hook-form reactjs reactquery sonner toast-notifications zustand
Last synced: about 1 month ago
JSON representation
A modern Next.js starter kit with flexible, reusable, and schema-validated forms featuring built-in error handling. Includes API clients, React Query, Zustand state management, toast notifications, centralized paths/messages, and a clear folder structure , Production-ready and developer-friendly.
- Host: GitHub
- URL: https://github.com/aceiny/nextjs-starter-kit
- Owner: aceiny
- Created: 2025-11-20T22:03:41.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-11-20T23:06:24.000Z (about 1 month ago)
- Last Synced: 2025-11-21T00:19:47.096Z (about 1 month ago)
- Topics: axios, nextjs, nodejs, react-hook-form, reactjs, reactquery, sonner, toast-notifications, zustand
- Language: TypeScript
- Homepage: https://next-js-starter-kit-qztr.vercel.app/
- Size: 211 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Next.js Production-Ready Starter
A comprehensive, production-ready Next.js 16 starter template with TypeScript, featuring a complete form system, state management, API clients, and dark mode support.
[](https://nextjs.org/)
[](https://www.typescriptlang.org/)
[](https://react.dev/)
[](LICENSE)
---
## ๐งน Fresh Start - Cleanup Script
If you want to start with a clean slate, delete all documentation and examples:
```bash
npm run cleanup
```
Or directly with bash:
```bash
bash scripts/cleanup.sh
```
This script will:
- โ Delete `/docs` directory
- โ Delete `/examples` directory
- โ๏ธ Reset `app/page.tsx` to a minimal home page
- โ๏ธ Reset `README.md` to a basic template
**Note:** This action is tracked by Git, so you can undo with `git checkout .`
---
## ๐ Table of Contents
- [Features](#-features)
- [Tech Stack](#-tech-stack)
- [Getting Started](#-getting-started)
- [Project Structure](#-project-structure)
- [Documentation](#-documentation)
- [Examples](#-examples)
- [For Developers](#-for-developers)
- [Contributing](#-contributing)
- [License](#-license)
---
## โจ Features
### ๐จ **UI & Theming**
- โ
**Dark Mode Support** - Seamless theme switching with `next-themes`
- โ
**Tailwind CSS v4** - Modern utility-first styling
- โ
**shadcn/ui Integration** - Beautiful, accessible components
- โ
**Responsive Design** - Mobile-first approach
- โ
**Theme Toggle Component** - Multiple variants (slide & click-small)
### ๐ **Form System**
- โ
**React Hook Form** - Performant form validation
- โ
**13 Pre-built Components** - Input, Select, Upload, Checkbox, Radio, OTP, etc.
- โ
**Shadcn-style OTP** - Individual character input boxes
- โ
**Auto-floating Labels** - Smart label behavior
- โ
**Password Toggle** - Built-in visibility control
- โ
**Theme Support** - All components support light/dark themes
### ๐ฏ **Modal/Dialog System**
- โ
**useDialog Hook** - Complete dialog state management (recommended)
- โ
**DialogCreator Component** - Direct component usage for simple dialogs
- โ
**Per-Button Loading** - Individual loading states for each button
- โ
**Async Handlers** - Automatic loading during async operations
- โ
**Three Button Types** - Cancel, Middle (optional), and Action buttons
- โ
**Button Variants** - Multiple styles (default, destructive, outline, secondary, ghost)
- โ
**Size Options** - Small, Medium, Large, Extra Large dialogs
- โ
**Form Support** - Built-in custom form integration
- โ
**TypeScript Support** - Full type safety with complete interfaces
### ๐๏ธ **State Management**
- โ
**Zustand** - Lightweight state management
- โ
**React Query (TanStack)** - Server state & caching
- โ
**Persistent Storage** - Auto-save to localStorage
- โ
**Pre-configured Stores** - Auth & UI stores ready to use
### ๐ **API Integration**
- โ
**Axios Clients** - Separate internal & external API clients
- โ
**Request/Response Interceptors** - Auto-error handling
- โ
**Cookie Support** - Session management ready
- โ
**TypeScript Types** - Full type safety
### ๐ฏ **Developer Experience**
- โ
**TypeScript** - Full type safety throughout
- โ
**Path Constants** - Centralized route management
- โ
**Toast Notifications** - Beautiful Sonner toasts
- โ
**Comprehensive Docs** - Complete documentation for all features
- โ
**Example Page** - Live examples of forms & toasts
---
## ๐ ๏ธ Tech Stack
| Technology | Purpose | Version |
| ------------------- | ------------------- | ------- |
| **Next.js** | React framework | 16.0.3 |
| **React** | UI library | 19.2.0 |
| **TypeScript** | Type safety | 5.0 |
| **Tailwind CSS** | Styling | 4.0 |
| **React Hook Form** | Form management | 7.66.1 |
| **Zustand** | State management | 5.0.8 |
| **TanStack Query** | Server state | 5.90.10 |
| **Axios** | HTTP client | 1.13.2 |
| **Zod** | Schema validation | 4.1.12 |
| **Sonner** | Toast notifications | 2.0.7 |
| **next-themes** | Theme management | 0.4.6 |
| **shadcn/ui** | Component library | Latest |
| **Lucide React** | Icons | 0.554.0 |
---
## ๐ Getting Started
### Prerequisites
- **Node.js** 20+ and npm/yarn/pnpm
- **Git** for version control
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
# or
pnpm dev
```
2. **Install dependencies**
```bash
npm install
# or
yarn install
# or
pnpm install
```
3. **Set up environment variables**
Create a `.env.local` file in the root directory:
```bash
# External API Base URL (required)
API_URL=https://api.example.com # require for the app to run if u dont have one use a fake one to run the app or remove its use from next.config.ts
# External API Base URL (optional)
NEXT_PUBLIC_EXTERNAL_API_URL=https://api.yourdomain.com
# Add other environment variables as needed
```
4. **Run the development server**
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```
5. **Open your browser**
Navigate to [http://localhost:3000](http://localhost:3000) to see your application.
---
## ๐ Project Structure
```
โโโ app/ # Next.js app directory
โ โโโ layout.tsx # Root layout with providers
โ โโโ page.tsx # Home page
โ โโโ example/ # Example page with forms & toasts
โ โโโ globals.css # Global styles
โ
โโโ components/
โ โโโ form/ # React Hook Form components
โ โ โโโ RHFUniversalInput.tsx # Universal input (text, password, OTP, etc.)
โ โ โโโ RHFSelect.tsx # Select dropdown
โ โ โโโ RHFUpload.tsx # File upload
โ โ โโโ RHFCheckbox.tsx # Single checkbox
โ โ โโโ RHFCheckboxGroup.tsx # Multiple checkboxes
โ โ โโโ RHFSearchableCheckboxGroup.tsx
โ โ โโโ RHFRadioGroup.tsx # Radio buttons
โ โ โโโ ... # Other form components
โ โ
โ โโโ ui/ # shadcn/ui components
โ โ โโโ button.tsx
โ โ โโโ input.tsx
โ โ โโโ select.tsx
โ โ โโโ sonner.tsx # Toast component
โ โ โโโ ...
โ โ
โ โโโ ThemeToggle.tsx # Dark mode toggle
โ
โโโ stores/ # Zustand stores
โ โโโ auth.store.ts # Authentication state
โ โโโ ui.store.ts # UI state (sidebar, modal, notifications)
โ โโโ index.ts # Central export
โ
โโโ lib/
โ โโโ http/
โ โ โโโ internal-api.ts # Internal API client (Next.js routes)
โ โ โโโ external-api.ts # External API client
โ โ
โ โโโ utils/
โ โ โโโ error.utils.ts # Error extraction utilities
โ โ
โ โโโ query-client.ts # React Query client
โ โโโ utils.ts # General utilities
โ
โโโ providers/
โ โโโ react-query.provider.tsx # React Query provider
โ โโโ theme.provider.tsx # Theme provider
โ
โโโ shared/
โ โโโ constants/
โ โโโ paths.ts # Centralized route paths
โ โโโ toast-messages.ts # Toast message constants
โ
โโโ schema/
โ โโโ auth.schema.ts # Zod validation schemas
โ
โโโ types/
โ โโโ index.ts # TypeScript type definitions
โ
โโโ config/
โ โโโ query.client.config.ts # React Query configuration
โ
โโโ docs/ # Comprehensive documentation
โโโ FORM_SYSTEM_DOCUMENTATION.md
โโโ MODAL_DIALOG_DOCUMENTATION.md
โโโ API_DOCUMENTATION.md
โโโ STATE_AND_UTILITIES.md
```
---
## ๐ Documentation
Comprehensive guides for all features:
| Documentation | Description | Link |
| --------------------- | -------------------------------------------------------------------------- | ------------------------------------------------- |
| **Form System** | Complete guide to all 13 form components, input types, validation, theming | [View Docs](./docs/FORM_SYSTEM_DOCUMENTATION.md) |
| **Modal/Dialog** | Dialog system with per-button loading, async handlers, and customization | [View Docs](./docs/MODAL_DIALOG_DOCUMENTATION.md) |
| **API & Axios** | HTTP clients setup, interceptors, error handling, authentication | [View Docs](./docs/API_DOCUMENTATION.md) |
| **State & Utilities** | Zustand stores, React Query, Toasts, Path constants | [View Docs](./docs/STATE_AND_UTILITIES.md) |
### Quick Links
- **๐จ Form Components** - [Form System Documentation](./docs/FORM_SYSTEM_DOCUMENTATION.md)
- **๐ฏ Modal/Dialog** - [Modal & Dialog Documentation](./docs/MODAL_DIALOG_DOCUMENTATION.md)
- **๐ API Calls** - [API Documentation](./docs/API_DOCUMENTATION.md)
- **๐๏ธ State Management** - [State & Utilities Documentation](./docs/STATE_AND_UTILITIES.md)
---
## ๐ฏ Examples
### Live Examples
Visit the **[/example](http://localhost:3000/example)** page to see:
- โ
**All Form Components** in action
- Text inputs with auto-floating labels
- Password inputs with visibility toggle
- Shadcn-style OTP with individual character boxes
- File uploads (default, avatar, button styles)
- Select dropdowns (single & multi-select)
- Checkboxes & radio groups
- Date & time pickers
- โ
**Toast Notifications**
- Success, error, info, warning toasts
- Promise-based toasts for async operations
- Custom toast messages
- โ
**Dark Mode Toggle**
- Seamless theme switching
- All components support both themes
### Code Examples
#### Authentication with Zustand
```tsx
import { useAuthStore } from "@/stores";
import { internalAPI } from "@/lib/http/internal-api";
import { toast } from "sonner";
function LoginForm() {
const { login } = useAuthStore();
async function handleLogin(data: LoginDto) {
try {
const response = await internalAPI.post("/auth/login", data);
login(response.data.user);
toast.success("Login successful!");
} catch (error) {
toast.error(error);
}
}
return ...;
}
```
#### Data Fetching with React Query
```tsx
import { useQuery } from "@tanstack/react-query";
import { internalAPI } from "@/lib/http/internal-api";
function UserList() {
const { data: users, isLoading } = useQuery({
queryKey: ["users"],
queryFn: async () => {
const response = await internalAPI.get("/users");
return response.data;
},
});
if (isLoading) return
Loading...;
return (
{users.map((user) => (
))}
);
}
```
#### Form with Validation
```tsx
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { RHFUniversalInput } from "@/components/form";
import { loginSchema } from "@/schema/auth.schema";
function LoginForm() {
const { control, handleSubmit } = useForm({
resolver: zodResolver(loginSchema),
});
return (
Login
);
}
```
#### Modal/Dialog Management
```tsx
import { useDialog } from "@/hooks/useDialog";
import { toast } from "sonner";
function UserManagement() {
const deleteDialog = useDialog({
title: "Delete User",
subtitle: "This action cannot be undone.",
size: "md",
cancelButton: {
label: "Cancel",
},
actionButton: {
label: "Delete",
variant: "destructive",
onClick: async () => {
try {
await internalAPI.delete(`/users/${userId}`);
toast.success("User deleted successfully");
} catch (error) {
toast.error("Failed to delete user");
}
},
},
});
return (
Delete User
{deleteDialog.dialog}
);
}
```
**Features:**
- โ
Automatic loading state during async operations
- โ
Per-button loading control
- โ
Type-safe dialog configuration
- โ
Easy to override config when opening
- โ
Built-in form support
- โ
Multiple button variants
**[โ Full Modal Documentation](./docs/MODAL_DIALOG_DOCUMENTATION.md)**
---
## ๐จโ๐ป For Developers
### Development Workflow
1. **Start development server**
```bash
npm run dev
```
2. **View example page**
- Navigate to [http://localhost:3000/example](http://localhost:3000/example)
- See all form components and toasts in action
3. **Read the documentation**
- [Form System](./docs/FORM_SYSTEM_DOCUMENTATION.md) - Learn about all form components
- [API Integration](./docs/API_DOCUMENTATION.md) - Set up API calls
- [State Management](./docs/STATE_AND_UTILITIES.md) - Use Zustand & React Query
4. **Build your features**
- Use pre-built components
- Follow the established patterns
- Refer to examples in `/example`
### Available Scripts
```bash
# Development
npm run dev # Start dev server
# Production
npm run build # Build for production
npm run start # Start production server
# Code Quality
npm run lint # Run ESLint
```
### Adding New Features
#### Create a New Page
```tsx
// app/dashboard/page.tsx
export default function DashboardPage() {
return
Dashboard;
}
```
#### Create a New API Service
```typescript
// lib/services/post.service.ts
import { internalAPI } from "@/lib/http/internal-api";
export const postService = {
async getAll() {
const response = await internalAPI.get("/posts");
return response.data;
},
// Add more methods...
};
```
#### Create a New Store
```typescript
// stores/post.store.ts
import { create } from "zustand";
export const usePostStore = create((set) => ({
posts: [],
setPosts: (posts) => set({ posts }),
}));
```
#### Add New Path Constants
```typescript
// shared/constants/paths.ts
export const APP_PATHS = {
// ... existing paths
DASHBOARD: "/dashboard",
SETTINGS: "/settings",
};
```
---
## ๐จ Theme Toggle Component
The `ThemeToggle` component provides flexible theme switching with multiple variants.
### Basic Usage
```tsx
import { ThemeToggle } from "@/components/ThemeToggle";
export default function Header() {
return (
);
}
```
### Variants
#### Click-Small (Default)
```tsx
```
- Compact button design
- Perfect for headers/navigation
- Single click to toggle theme
#### Slide
```tsx
```
- Animated slide switch design
- More prominent visual feedback
- Great for settings pages
### Props
| Prop | Type | Default | Description |
| --------- | -------------------------- | --------------- | ------------------ |
| `variant` | `"slide" \| "click-small"` | `"click-small"` | Theme toggle style |
### How It Works
1. Uses `next-themes` for theme management
2. Syncs across all browser tabs
3. Persists theme preference to localStorage
4. Respects system theme preference on first visit
5. Hydration-safe (prevents hydration mismatch)
### Theme-Aware Components
All form components automatically respond to theme changes:
- Text inputs, selects, textareas
- OTP input boxes
- File uploads
- Checkboxes and radio groups
- Labels and error messages
- Editor with syntax highlighting on links
### Customizing Themes
Edit your Tailwind config to customize light/dark mode colors:
```javascript
// tailwind.config.js
export default {
darkMode: "class",
theme: {
extend: {
colors: {
// Custom colors for light mode
// Custom colors for dark mode
},
},
},
};
```
### Programmatic Theme Control
```tsx
import { useTheme } from "next-themes";
export function ThemeController() {
const { theme, setTheme } = useTheme();
return (
Current theme: {theme}
setTheme("light")}>Light
setTheme("dark")}>Dark
);
}
```
---
## ๐ค Contributing
Contributions are welcome! If you'd like to improve this starter template:
1. **Fork the repository**
2. **Create a feature branch** (`git checkout -b feature/amazing-feature`)
3. **Commit your changes** (`git commit -m 'Add some amazing feature'`)
4. **Push to the branch** (`git push origin feature/amazing-feature`)
5. **Open a Pull Request**
---
## ๐ Learn More
- [Next.js Documentation](https://nextjs.org/docs)
- [React Hook Form](https://react-hook-form.com/)
- [Zustand](https://docs.pmnd.rs/zustand/getting-started/introduction)
- [TanStack Query](https://tanstack.com/query/latest)
- [Tailwind CSS](https://tailwindcss.com/docs)
- [shadcn/ui](https://ui.shadcn.com/)
---
## โญ Star This Project
If you find this starter helpful, please consider giving it a star on GitHub! It helps others discover this template.
**[โญ Star on GitHub](https://github.com/aceiny/NextJs-Starter-Kit)**
---
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## ๐ Acknowledgments
- **Next.js Team** - For the amazing framework
- **shadcn** - For the beautiful component library
- **TanStack** - For React Query
- **Sonner** - For beautiful toasts
---
**Built with โค๏ธ by developers, for developers**
**Ready to start building?** [View Examples โ](http://localhost:3000/example)