Architecture

Project Structure

Understanding the OpenInvoice codebase structure

Overview

OpenInvoice follows a feature-based architecture for better organization and scalability. The codebase is organized into logical modules and features.

Directory Structure

src/
├── app/                      # Next.js App Router
│   ├── api/                 # API routes
│   │   ├── invoices/        # Invoice API endpoints
│   │   ├── payments/        # Payment API endpoints
│   │   ├── webhooks/        # Webhook handlers
│   │   └── ...
│   ├── dashboard/           # Dashboard pages
│   │   ├── invoices/       # Invoice pages
│   │   ├── customers/      # Customer pages
│   │   ├── products/       # Product pages
│   │   └── ...
│   ├── (auth)/             # Auth pages
│   └── layout.tsx          # Root layout
│
├── components/              # Shared components
│   ├── ui/                 # Shadcn UI components
│   ├── layout/             # Layout components
│   └── forms/              # Form components
│
├── features/               # Feature modules
│   ├── invoicing/         # Invoice features
│   │   ├── components/    # Invoice components
│   │   ├── hooks/        # Invoice hooks
│   │   └── utils/        # Invoice utilities
│   ├── kanban/           # Kanban features
│   └── overview/         # Dashboard features
│
├── lib/                    # Core utilities
│   ├── db.ts             # Prisma client
│   ├── format.ts         # Formatting utilities
│   └── utils.ts          # General utilities
│
├── config/                 # Configuration files
│   ├── nav-config.ts     # Navigation configuration
│   └── ...
│
└── types/                  # TypeScript types
    └── index.ts          # Type definitions

Key Directories

/app - Next.js App Router

Contains all routes and API endpoints:

  • API Routes - Server-side API endpoints
  • Dashboard Pages - User-facing pages
  • Layouts - Page layouts and wrappers

/components - Shared Components

Reusable UI components:

  • UI Components - Shadcn UI components
  • Layout Components - Sidebar, header, etc.
  • Form Components - Reusable form elements

/features - Feature Modules

Feature-based organization:

  • Invoicing - Invoice-related code
  • Kanban - Kanban board features
  • Overview - Dashboard analytics

/lib - Utilities

Core utilities and helpers:

  • Database - Prisma client setup
  • Formatting - Currency, date formatting
  • Utils - General helper functions

File Naming Conventions

  • Components: PascalCase (e.g., InvoiceForm.tsx)
  • Hooks: camelCase with use prefix (e.g., useInvoices.ts)
  • Utils: camelCase (e.g., formatCurrency.ts)
  • Types: PascalCase (e.g., Invoice.ts)
  • API Routes: route.ts (Next.js convention)

Code Organization Principles

  1. Feature-Based - Group related code by feature
  2. Co-location - Keep related files together
  3. Separation of Concerns - Separate UI, logic, and data
  4. Reusability - Extract common patterns
  5. Type Safety - Use TypeScript throughout

Next Steps