Skip to main content
Contafy follows Next.js App Router conventions with a clear separation of concerns and modular organization.

Root directory

app/ directory

The app/ 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 segment
  • loading.tsx: Loading UI for route segment
  • error.tsx: Error UI for route segment
  • not-found.tsx: 404 UI for route segment
  • route.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
Route-specific layouts: Can be added in any route folder to wrap child routes

components/ directory

Global reusable components shared across multiple routes.

Component organization principles

  1. Global components: Place in components/
  2. Route-specific components: Place in app/[route]/components/
  3. UI primitives: Place in components/ui/
  4. 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:
  1. Server version (*.ts): For Server Components
  2. Client version (*.client.ts): For Client Components
Example:
  • lib/api/invoices.ts - Server-side API calls
  • lib/api/invoices.client.ts - Client-side API calls

Type definitions

All API responses and data structures have TypeScript interfaces in lib/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.
All files in public/ are accessible at the root URL:

Configuration files

next.config.ts

Next.js configuration:
  • API proxy setup (/backendNEXT_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 in tsconfig.json:21-23:
Usage:

Import conventions

  1. External packages first
  2. Internal components second
  3. Types last
Example:

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

Build artifacts

See Data Fetching for how data flows through this structure.