# pizzeys/payday architecture

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

- Interactive diagram: https://gitdiagram.com/pizzeys/payday
- Repository: https://github.com/pizzeys/payday

## Overview

##### Project Type and Purpose
- Payday is a Ruby gem library designed for generating invoices – initially rendered as PDFs – with plans to support additional formats.
- Its focus is on invoice creation and management using the concepts of an Invoice and associated Line Items. It also provides mixin modules for integration with ActiveRecord or similar ORMs, making it flexible for use in full Rails applications.

##### Analyzing the File Structure
- Top-Level Files: The presence of files like Gemfile, Rakefile, and a dedicated gemspec (payday.gemspec) indicates that this is a packaged Ruby gem.
- assets Directory: Could include images or templates (like logos) used in invoice rendering.
- lib Directory: Holds the core source code:
- payday.rb is the library’s main entry point.
- The payday/ subdirectory contains separate Ruby files for configuration (config.rb), invoice handling (invoice.rb), line item support (line_item.rb), modules for making your own invoice and line item classes (invoiceable.rb and line_itemable.rb), a dedicated PDF renderer (pdf_renderer.rb), and version information (version.rb).
- test Directory: Contains unit tests for invoice and line items, helping to confirm the core functionality.

##### Main Components
a. Core Functionality:
- Payday::Invoice: Responsible for representing invoices and their collection of line items.
- Payday::LineItem: Models individual items on an invoice.
- Payday::PDFRenderer: Handles the translation of the invoice (and its parts) into a PDF format, leveraging the external Prawn gem.
- Payday::Config: Provides a means to customize default parameters (e.g., logo path, company details) and control aspects of invoice appearance.
b. Extension Modules:
- Payday::Invoiceable and Payday::LineItemable: Mixins that enable integration with ActiveRecord or other domain objects, providing helper methods to adapt external model data into a form that Payday uses.
c. External Dependencies and Enhancements:
- Prawn for generating PDFs.
- i18n for supporting internationalization (custom messages and labels).
- (Optionally) Rails integrations, as illustrated in the README examples (via MIME type configuration and controller methods).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Core Domain"
        INVOICE["Payday::Invoice"]:::core
        LINEITEM["Payday::LineItem"]:::core
    end

    subgraph "Rendering & Configuration"
        PDF["Payday::PDFRenderer"]:::service
        CONFIG["Payday::Config"]:::service
    end

    subgraph "Integration Modules"
        INV_MOD["Invoiceable Module"]:::integration
        LINE_MOD["LineItemable Module"]:::integration
    end

    subgraph "External Dependencies"
        PR["Prawn PDF Library"]:::external
        I18N["i18n Library"]:::external
    end

    %% Relationships
    INVOICE -->|"contains"| LINEITEM
    INVOICE -->|"render"| PDF
    CONFIG -->|"configures"| INVOICE
    CONFIG -->|"configures"| PDF
    INV_MOD -->|"extends"| INVOICE
    INV_MOD -->|"extends"| LINEITEM
    LINE_MOD -->|"extends"| INVOICE
    LINE_MOD -->|"extends"| LINEITEM
    PDF -->|"uses"| PR
    CONFIG -->|"supports"| I18N

    %% Click Events
    click INVOICE "https://github.com/pizzeys/payday/blob/master/lib/payday/invoice.rb"
    click LINEITEM "https://github.com/pizzeys/payday/blob/master/lib/payday/line_item.rb"
    click PDF "https://github.com/pizzeys/payday/blob/master/lib/payday/pdf_renderer.rb"
    click CONFIG "https://github.com/pizzeys/payday/blob/master/lib/payday/config.rb"
    click INV_MOD "https://github.com/pizzeys/payday/blob/master/lib/payday/invoiceable.rb"
    click LINE_MOD "https://github.com/pizzeys/payday/blob/master/lib/payday/line_itemable.rb"

    %% Styles
    classDef core fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef integration fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
```
