# hackice20/invoice-gen architecture

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

- Interactive diagram: https://gitdiagram.com/hackice20/invoice-gen
- Repository: https://github.com/hackice20/invoice-gen

## Overview

##### Main Components
- User Interface (UI) Container:
- Split-screen design with two main sections: the form section (left) and the live invoice preview (right).
- Form Components:
- Customer Details Form (collecting customer name, email, address, etc.)
- Business Details Form (with similar fields plus upload for a business stamp)
- Invoice Items form/component, which allows adding/removing items dynamically.
- Signature Upload if needed.
- Invoice Preview Component:
- Renders the professional layout of the invoice, integrating business stamp, itemized list, and totals in real-time.
- PDF Export Functionality:
- Managed in a utility module (src/utils/pdf.ts) using the html2pdf.js library.
- Supporting Modules:
- Reusable components and type definitions (in src/types).
- Styles and configuration (Tailwind, PostCSS) that affect how the UI is rendered.

##### Relationships and Data Flow
- The Form Section (on the left) collects user data. As values are entered or items are modified, the application’s state is updated.
- The Live Preview Section (on the right) consumes this updated state to render a dynamic invoice preview.
- On triggering a PDF export action (likely a button within the UI), the invoice preview data is passed to the PDF utility (using html2pdf.js) to generate and download the PDF.
- Data flow from form inputs to state management (React state, contexts, or props).
- State updates triggering re-renders in the preview component.
- User actions triggering the PDF export utility.

##### Architectural Patterns and Design Principles
- Component-Based Architecture:
- Each UI part is split into smaller, reusable components (e.g., InvoicePreview, PartyDetails, ProductList, SignatureUpload).
- Real-Time Data Binding:
- Forms and preview are tightly coupled via React’s state management, ensuring instant reflection of updates.
- Separation of Concerns:
- UI and business logic (i.e., PDF conversion) are cleanly separated. Utility functions (in src/utils) isolate the logic for PDF generation.
- Use of TypeScript:
- Ensures type-safety across components with definitions in the src/types directory.

##### Key Technologies
- React & React DOM: Core library for building the interactive UI.
- Vite: Development and bundling tool.
- TypeScript: For static typing and improved development experience.
- Tailwind CSS: For styling, as indicated by the tailwind.config.js and index.css.
- html2pdf.js: For converting the invoice HTML into a downloadable PDF.

##### Final Recommendations
- Critical elements: component boundaries, state management, data flows, and integration with third-party utilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["App Container"]:::ui
    subgraph "Forms Panel"
        B["Customer & Business Details Form"]:::ui
        C["Invoice Items Input Component"]:::ui
        D["Signature/Stamp Upload Component"]:::ui
    end
    S["State/Context: Invoice Data"]:::util
    E["Live Invoice Preview"]:::ui
    F["PDF Export Module"]:::util
    T["Type Definitions"]:::types

    %% App container renders UI components
    A -->|"renders"| B
    A -->|"renders"| C
    A -->|"renders"| D
    A -->|"renders"| E

    %% Forms update state
    B -->|"data_update"| S
    C -->|"data_update"| S
    D -->|"data_update"| S

    %% State triggers live preview update
    S -->|"state_sync"| E

    %% User action triggers PDF export from preview
    E -->|"PDF_export"| F

    %% Type definitions support various components
    T -.-> B
    T -.-> C
    T -.-> D
    T -.-> S
    T -.-> E

    %% Click Events
    click A "https://github.com/hackice20/invoice-gen/blob/main/src/App.tsx"
    click B "https://github.com/hackice20/invoice-gen/blob/main/src/components/PartyDetails.tsx"
    click C "https://github.com/hackice20/invoice-gen/blob/main/src/components/ProductList.tsx"
    click D "https://github.com/hackice20/invoice-gen/blob/main/src/components/SignatureUpload.tsx"
    click E "https://github.com/hackice20/invoice-gen/blob/main/src/components/InvoicePreview.tsx"
    click F "https://github.com/hackice20/invoice-gen/blob/main/src/utils/pdf.ts"
    click T "https://github.com/hackice20/invoice-gen/tree/main/src/types"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef util fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef types fill:#FFA500,stroke:#000,stroke-width:1px;
```
