# kyrylolvov/invoice-builder architecture

> Architecture diagram of the GitHub repository kyrylolvov/invoice-builder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kyrylolvov/invoice-builder
- Repository: https://github.com/kyrylolvov/invoice-builder

## Overview

##### Main System Components

a) Client-Side Layer
- Next.js Frontend (App Router)
- Theme Management
- Form Components
- UI Components Library

b) Server-Side Layer
- Next.js API Routes
- PDF Generation Service

c) Core Features
- Invoice Generation
- PDF Processing
- Theme Switching
- Form Management

##### Component Organization

Frontend Components:
- Page Components
- Root Layout (layout.tsx)
- Home Page (page.tsx)
- Form Components
- Invoice Form
- Line Items
- Invoice Subtotal
- UI Components
- Button
- Form
- Inputs
- Text Area
- Theme Management
- Theme Provider

API Layer:
- /api
- /pdf
- Route Handler
- PDF Template
- PDF Utils

Use these visual elements:

- Blue: Client-side components
- Green: Server-side components
- Purple: Shared utilities
- Orange: External services/APIs

- Double lines: API calls

##### Key Relationships to Highlight

- How the Invoice Form component connects to the PDF generation API
- Theme context provider's influence on UI components
- Demonstrate the flow from form submission to PDF generation and download

##### Important Architectural Patterns

Emphasize:
- Next.js App Router architecture
- Server Components vs Client Components
- API Routes structure
- Context-based theme management

##### Technical Stack Indicators

- Next.js 13+
- TypeScript
- Tailwind CSS
- PDF Generation library

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        NextApp["Next.js App Router"]
        HomePage["Home Page"]:::page
        RootLayout["Root Layout"]:::layout
        
        subgraph UI["UI Layer"]
            direction TB
            ThemeProvider["Theme Provider"]:::theme
            ThemeSwitch["Theme Switch"]:::ui
            
            subgraph Forms["Form Components"]
                direction TB
                InvoiceForm["Invoice Form"]:::form
                LineItems["Line Items"]:::form
                InvoiceSubtotal["Invoice Subtotal"]:::form
            end
            
            subgraph UILib["UI Components"]
                direction TB
                Button["Button"]:::ui
                Form["Form"]:::ui
                Inputs["Inputs"]:::ui
                TextArea["Text Area"]:::ui
            end
        end
        
        DownloadBtn["Download Button"]:::ui
    end
    
    subgraph Server
        direction TB
        subgraph API["API Layer"]
            PDFRoute["PDF Route Handler"]:::api
            PDFTemplate["PDF Template"]:::api
            PDFUtils["PDF Utils"]:::api
        end
    end
    
    subgraph Shared["Shared Resources"]
        direction TB
        Types["Type Definitions"]:::types
        Utils["Utilities"]:::utils
        Constants["Constants"]:::utils
    end
    
    %% Relationships
    NextApp --> RootLayout
    RootLayout --> HomePage
    HomePage --> InvoiceForm
    ThemeProvider --> UILib
    ThemeProvider --> ThemeSwitch
    
    InvoiceForm --> LineItems
    InvoiceForm --> InvoiceSubtotal
    InvoiceForm --> UILib
    InvoiceForm --> Types
    
    Forms --> PDFRoute
    PDFRoute --> PDFTemplate
    PDFRoute --> PDFUtils
    PDFRoute --> DownloadBtn
    
    UILib --> Utils
    API --> Utils
    
    %% Styles
    classDef page fill:#4B5563
    classDef layout fill:#4B5563
    classDef theme fill:#9333EA
    classDef form fill:#3B82F6
    classDef ui fill:#3B82F6
    classDef api fill:#22C55E
    classDef types fill:#8B5CF6
    classDef utils fill:#8B5CF6
    
    %% Click Events
    click RootLayout "https://github.com/kyrylolvov/invoice-builder/blob/main/src/app/layout.tsx"
    click HomePage "https://github.com/kyrylolvov/invoice-builder/blob/main/src/app/page.tsx"
    click ThemeProvider "https://github.com/kyrylolvov/invoice-builder/blob/main/src/contexts/theme-provider.tsx"
    click InvoiceForm "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/invoice-form.tsx"
    click LineItems "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/line-item.tsx"
    click InvoiceSubtotal "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/invoice-subtotal.tsx"
    click ThemeSwitch "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/theme-switch.tsx"
    click Button "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/ui/button.tsx"
    click Form "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/ui/form.tsx"
    click Inputs "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/ui/inputs.tsx"
    click TextArea "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/ui/text-area.tsx"
    click DownloadBtn "https://github.com/kyrylolvov/invoice-builder/blob/main/src/components/download-button.tsx"
    click PDFRoute "https://github.com/kyrylolvov/invoice-builder/blob/main/src/app/api/pdf/route.tsx"
    click PDFTemplate "https://github.com/kyrylolvov/invoice-builder/blob/main/src/app/api/pdf/template.tsx"
    click PDFUtils "https://github.com/kyrylolvov/invoice-builder/blob/main/src/app/api/pdf/utils.ts"
    click Types "https://github.com/kyrylolvov/invoice-builder/blob/main/src/types/invoice.ts"
    click Utils "https://github.com/kyrylolvov/invoice-builder/blob/main/src/lib/utils.ts"
    click Constants "https://github.com/kyrylolvov/invoice-builder/blob/main/src/lib/constants.ts"
    click UILib "https://github.com/kyrylolvov/invoice-builder/tree/main/src/components/ui/"
```
