# laraveldaily/laravel-invoices architecture

> Architecture diagram of the GitHub repository laraveldaily/laravel-invoices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/laraveldaily/laravel-invoices
- Repository: https://github.com/laraveldaily/laravel-invoices

## Overview

##### Project type and purpose
- This is a Laravel-compatible Composer package, not a standalone app.
- Purpose: provide an easy, chainable API to generate invoice PDFs (stream, download, save) with support for templates, locales, taxes, discounts, etc.

##### File structure
- src/InvoiceServiceProvider.php: Laravel Service Provider that registers bindings, publishes config/views/translations, and registers Artisan commands (InstallCommand, UpdateCommand).
- src/Facades/Invoice.php: Facade alias for the main Invoice builder class.
- src/Invoice.php: Core “Invoice builder” class: methods to set seller, buyer, items, calculations.
- src/Classes (Buyer, Party, Seller, InvoiceItem): Data-model classes that implement PartyContract or define line items.
- src/Services/PricingService.php: Encapsulates tax, discount, subtotal, total calculations.
- src/Traits: Shared logic (date formatting, currency formatting, serial number, file saving, invoice helpers).
- resources/views/templates/*.blade.php: Blade templates used to render HTML for PDF conversion.
- config/invoices.php: Default configuration (dates, serial numbers, currency, paper, seller defaults).
- public/ & resources/: assets and published views/translations.
- tests/: PHPUnit tests for core functionality.

##### README for additional insights
- Usage examples show how the Facade → Invoice builder → set up Parties and Items → stream/download/save flows.
- It mentions publishing assets via Artisan (`invoices:install`, `invoices:update`) and underlying use of Laravel’s filesystem and view engine.

##### Essential detail
- Config file as a separate component that ServiceProvider reads.
- Translations directory feeding into Builder/Blade for localization.
- Traits as attached to the Invoice Builder or PricingService.
- Where customization occurs (template selection, overrides via publish).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Laravel Application
    subgraph "Host Laravel Application"
        App["Laravel App"]:::framework
    end

    %% Invoice Package Components
    subgraph "Invoice Package"
        ISP["InvoiceServiceProvider"]:::core
        Facade["Facade: Invoice"]:::core
        Builder["Invoice Builder"]:::core
        Pricing["PricingService"]:::core
        Party["Party (Base)"]:::core
        Buyer["Buyer"]:::core
        Seller["Seller"]:::core
        Item["InvoiceItem"]:::core
        Traits["Traits (Formatting, Helpers)"]:::core
        Config["Config File"]:::storage
        Templates["Blade Templates"]:::storage
        Translations["Translation Files"]:::storage
        Install["InstallCommand"]:::core
        Update["UpdateCommand"]:::core
    end

    %% External Libraries and Services
    PDF["PDF Generator"]:::external
    FS["Filesystem"]:::framework
    HTTP["HTTP Response"]:::framework

    %% Application Bootstrap and Registration
    App -->|"bootstraps"| ISP
    ISP -->|"publishes"| Config
    ISP -->|"publishes"| Templates
    ISP -->|"publishes"| Translations
    ISP -->|"registers"| Facade
    ISP -->|"registers"| Install
    ISP -->|"registers"| Update

    %% Invoice Generation Flow
    Facade -->|"make()"| Builder
    Builder -->|"uses"| Pricing
    Builder -->|"uses"| Party
    Builder -->|"creates"| Buyer
    Builder -->|"creates"| Seller
    Builder -->|"adds"| Item
    Builder -->|"includes"| Traits
    Builder -->|"renders"| Templates
    Templates -->|"HTML"| PDF
    Builder -->|"sends HTML"| PDF
    PDF -->|"stream"| HTTP
    PDF -->|"save"| FS
    FS -->|"URL"| HTTP

    %% CLI Flow
    Install -->|"executes"| ISP
    Update -->|"executes"| ISP

    %% Click Events
    click ISP "https://github.com/laraveldaily/laravel-invoices/blob/master/src/InvoiceServiceProvider.php"
    click Facade "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Facades/Invoice.php"
    click Builder "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Invoice.php"
    click Buyer "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Classes/Buyer.php"
    click Seller "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Classes/Seller.php"
    click Party "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Classes/Party.php"
    click Item "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Classes/InvoiceItem.php"
    click Pricing "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Services/PricingService.php"
    click Traits "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Traits/CurrencyFormatter.php"
    click Traits "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Traits/DateFormatter.php"
    click Traits "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Traits/InvoiceHelpers.php"
    click Traits "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Traits/SavesFiles.php"
    click Traits "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Traits/SerialNumberFormatter.php"
    click Install "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Console/InstallCommand.php"
    click Update "https://github.com/laraveldaily/laravel-invoices/blob/master/src/Console/UpdateCommand.php"
    click Config "https://github.com/laraveldaily/laravel-invoices/blob/master/config/invoices.php"
    click Templates "https://github.com/laraveldaily/laravel-invoices/blob/master/resources/views/templates/default.blade.php"
    click Translations "https://github.com/laraveldaily/laravel-invoices/blob/master/lang/*/invoice.php"

    %% Styles
    classDef core fill:#AED6F1,stroke:#2E86C1,color:#000;
    classDef framework fill:#A9DFBF,stroke:#28B463,color:#000;
    classDef external fill:#F9E79F,stroke:#B9770E,color:#000;
    classDef storage fill:#ECECEC,stroke:#A6ACAF,color:#000;
```
