This is our standard Next.js project structure and setup guidelines. Follow these to ensure consistency across our projects.
-
Project Structure:
- Only keep Next.js routing files in the
appdirectory - Implement dynamic imports for code splitting
- Create custom components in
components/
- Only keep Next.js routing files in the
-
Styling:
- Use Tailwind CSS for styling
- Use ShadCn UI components
- Restrict typography to the predefined font-size tokens (
xs,sm,base,lg,xl) defined intailwind.config.ts
-
Performance Optimization:
- Dynamically import components to improve performance through lazy loading
- Use server-side rendering when possible for better performance
- Use Next.js Image component for optimized images
- Always use
fetchy, a fetch wrapper function from @/lib/fetchy, for making HTTP requests
-
Forms and Validation:
- Use React Hook Form for form handling
- Use Zod for form validations
-
State Management:
- Use Zustand for global state management
- Utilize TanStack Query for server state management
-
Environment Variables:
- Use
.env.localfor local environment variables - Never commit
.env.localto version control - Album gallery requires the following Cloudinary variables:
NEXT_PUBLIC_CLOUDINARY_CLOUD_NAMECLOUDINARY_API_KEYCLOUDINARY_API_SECRETCLOUDINARY_FOLDER
- Use
To maintain typographic consistency, use the limited font-size scale below:
| Token | rem | px |
|---|---|---|
| xs | 0.75rem | 12px |
| sm | 0.875rem | 14px |
| base | 1rem | 16px |
| lg | 1.125rem | 18px |
| xl | 1.25rem | 20px |
- Clone the repo:
git clone https://github.com/CeyLabs/Next-ShadCN-Template.git - Install Dependencies:
bun i - Run the Development Server:
bun dev - Open http://localhost:3000 in your browser.
Before committing, ensure your code is properly formatted and builds without errors:
bun run format
bun run buildfeat: for new featuresfix: for bug fixesdocs: for documentation changesstyle: for formatting changesrefactor: for code refactoringtest: for adding or modifying testschore: for maintenance tasks
- Create a new branch for each feature or fix
- Submit a pull request for review before merging to the main branch
project-root/
├── src/
│ ├── app/
│ │ ├── layout.tsx
│ │ ├── page.tsx
│ │ └── [...route]/
│ │ └── page.tsx
│ ├── components/
│ │ ├── ui/
│ │ │ ├── Button.tsx
│ │ │ └── Input.tsx
│ │ └── layout/
│ │ ├── Header.tsx
│ │ └── Footer.tsx
│ ├── utils/
│ │ └── cn.ts
│ ├── hooks/
│ │ └── useCustomHook.ts
│ ├── styles/
│ │ └── theme.css
│ │ └── globals.css
│ └── types/
│ └── index.ts
├── public/
│ ├── images/
│ └── fonts/
├── tests/
│ └── componentName.test.tsx
├── .env.local
├── .gitignore
├── next.config.js
├── package.json
├── README.md
└── tsconfig.json