This skill provides guidance for initializing and structuring Next.js projects with modern best practices...
This skill provides guidance for initializing and structuring Next.js projects with modern best practices. It covers project setup, component organization, API integration, and development patterns following the specified architecture.
Initialize a new Next.js project with the recommended configuration:
npx create-next-app@latest project-name --yes --typescript --tailwind --app --src-dir --turbopack --eslint
Parameters Explanation:
--yes: Skip prompts and use default options--typescript: Include TypeScript support--tailwind: Add Tailwind CSS for styling--app: Use the App Router (app directory)--src-dir: Create a src directory--turbopack: Use Turbopack for faster builds (optional)--eslint: Include ESLint for lintingWith Tailwind CSS v4, there's no need to create a tailwind.config.ts file. The configuration is handled automatically.
After creating the project, initialize ShadCN UI components:
npx shadcn@latest init .
Add specific components as needed:
npx shadcn@latest add button card formand wha input label textarea select checkbox radio-group
user-profile.tsx, not UserProfile.tsx)// ā
Correct
export const UserProfile = () => {
return <div>Profile Component</div>;
}
// ā Incorrect
export default function UserProfile() {
return <div>Profile Component</div>;
}
lucide-react library// ā
Correct
import { ChatIcon, UserIcon, HomeIcon } from "lucide-react";
// ā Incorrect
import { Chat, User, Home } from "lucide-react";
useMutation for data modification operationsuseQuery for data fetching operationsuse[FeatureName]src/components/forms foldersrc/lib)src/lib/
āāā supabase/
ā āāā client.ts
ā āāā server.ts
āāā stripe/
ā āāā client.ts
ā āāā server.ts
āāā better-auth/
āāā client.ts
āāā server.ts
src/utils)src/utils/
āāā shadcn.ts
āāā date.ts
āāā price.ts
āāā format.ts
āāā validation.ts
src/features)src/features/
āāā auth/
ā āāā hooks.tsx
ā āāā queries.ts
ā āāā types.ts
ā āāā schema.ts
āāā feature-name/
āāā hooks.tsx # Mutation hooks
āāā queries.ts # GET queries
āāā types.ts # TypeScript interfaces/types
āāā schema.ts # Zod schemas
use[Feature] hooks directly instead of receiving callback functionssrc/features/[feature-name]/config.tshooks.tsx)import { useMutation, useQuery } from "@tanstack/react-query";
export const useFeature = () => {
const addFeature = useMutation({
mutationFn: (data: any) => {
// API call implementation
},
onSuccess: () => {},
onError: () => {},
});
const updateFeature = useMutation({
mutationFn: (data: any) => {},
onSuccess: () => {},
onError: (error) => {},
});
const deleteFeature = useMutation({
mutationFn: (data: any) => {},
onSuccess: () => {},
onError: (error) => {},
});
const getFeatures = useQuery({
queryKey: ['features'],
queryFn: () => {
// API call implementation
}
});
return {
addFeature,
updateFeature,
deleteFeature,
getFeatures
};
};
schema.ts)import { z } from "zod";
export const featureFormSchema = z.object({
id: z.string().optional(),
name: z.string().min(1, "Name is required"),
description: z.string().optional(),
// Add more fields as needed
});
export type FeatureFormData = z.infer<typeof featureFormSchema>;
types.ts)export interface Feature {
id: string;
name: string;
description?: string;
createdAt: string;
updatedAt: string;
}
queries.ts)import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { Feature } from "./types";
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3000/api";
export const fetchFeatures = async (): Promise<Feature[]> => {
const response = await fetch(`${API_BASE_URL}/features`);
if (!response.ok) throw new Error("Failed to fetch features");
return response.json();
};
export const createFeature = async (data: Partial<Feature>) => {
const response = await fetch(`${API_BASE_URL}/features`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (!response.ok) throw new Error("Failed to create feature");
return response.json();
};
src/components/forms folder# Initialize Next.js project
npx create-next-app@latest project-name --yes --typescript --tailwind --app --src-dir --turbopack --eslint
# Initialize ShadCN
npx shadcn@latest init .
# Add specific components
npx shadcn@latest add button card form input label textarea
# Start development server
npm run dev
# Build for production
npm run build
# Run linting
npm run lint
This skill provides a complete guide for setting up and maintaining Next.js projects following the specified architecture and best practices.