Root directory
app/ directory
Theapp/ directory contains all routes and pages using Next.js App Router conventions.
Route structure
File naming conventions
page.tsx: Route page component (required for route)layout.tsx: Shared layout for route segmentloading.tsx: Loading UI for route segmenterror.tsx: Error UI for route segmentnot-found.tsx: 404 UI for route segmentroute.ts: API route handler
Layout hierarchy
Root layout (app/layout.tsx):
- Sets up global providers (ReactQueryProvider, TokenRefresher)
- Loads fonts (Geist Sans, Geist Mono)
- Applies dark theme
- Wraps all pages
components/ directory
Global reusable components shared across multiple routes.Component organization principles
- Global components: Place in
components/ - Route-specific components: Place in
app/[route]/components/ - UI primitives: Place in
components/ui/ - Feature components: Group by feature in subdirectories
Example: Dashboard components
lib/ directory
Business logic, utilities, type definitions, and helper functions.API client organization
Each API module has two versions:- Server version (
*.ts): For Server Components - Client version (
*.client.ts): For Client Components
lib/api/invoices.ts- Server-side API callslib/api/invoices.client.ts- Client-side API calls
Type definitions
All API responses and data structures have TypeScript interfaces inlib/types/:
Utilities organization
- General utilities:
lib/utils.ts(cn function) - Feature-specific utilities:
lib/utils/[feature].ts - Constants:
lib/constants/ - Custom hooks:
lib/hooks/
public/ directory
Static assets served directly by Next.js.public/ are accessible at the root URL:
Configuration files
next.config.ts
Next.js configuration:- API proxy setup (
/backend→NEXT_PUBLIC_API_URL) - Build optimization settings
tsconfig.json
TypeScript configuration:- Strict mode enabled
- Path aliases:
@/*→ project root - Target: ES2017
tailwind.config.ts
Tailwind CSS configuration:- Custom theme colors
- Dark mode setup
- Custom plugins
postcss.config.mjs
PostCSS configuration:- Tailwind CSS plugin
- Autoprefixer
eslint.config.mjs
ESLint configuration:- Next.js recommended rules
- Prettier integration
components.json
Shadcn/ui configuration:- Component installation settings
- Path aliases
- Style preferences
Module resolution
Path aliases configured intsconfig.json:21-23:
Import conventions
- External packages first
- Internal components second
- Types last
Code splitting
Next.js automatically code-splits:- Each route: Separate bundle per route
- Client Components: Only sent when needed
- Server Components: Zero client JavaScript
- Dynamic imports: Manual code splitting with
next/dynamic