# lynx479/billing_software architecture

> Architecture diagram of the GitHub repository lynx479/billing_software, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lynx479/billing_software
- Repository: https://github.com/lynx479/billing_software

## Overview

#### Purpose and Runtime

This is a server-rendered PHP accounting application for invoices, credit notes, parties/sellers, inventory items, payments, bank accounts, settlements, and financial/tax reports. The public HTTP entry point is `public/index.php`; Apache rewrite behavior is defined in `public/.htaccess`. UI is PHP views with Bootstrap, ApexCharts, Flatpickr, and local CSS/JS assets.

#### Application Dispatch and MVC Base

Requests enter `public/index.php`, are resolved by the custom router, then dispatched to controller actions. `app/core/Router.php` is the routing/control boundary. `app/core/Controller.php` provides controller-level rendering/request behavior, while `app/core/Model.php` anchors database-backed domain access. Controllers mediate all major use cases and select views.

Paths:
- `public/index.php`
- `app/core/Router.php`
- `app/core/Controller.php`

#### Financial Document Lifecycle

Invoices and credit notes are the primary transactional document flow: listing, creation/editing, and printable/preview output. Invoice behavior is concentrated in `app/controllers/InvoicesController.php` and `app/models/Invoice.php`; credit-note operations have a separate controller and view set but are visibly linked through `app/views/invoices/credit-note-create.php`.

Paths:
- `app/controllers/InvoicesController.php`
- `app/controllers/CreditNotesController.php`
- `app/models/Invoice.php`

#### Parties, Items, and Reference Data

Parties represent business counterparts, including seller-specific views and account statements. Items support catalog management and history. Settings manages reference data—taxes, units, categories, currencies, and customization—which forms a dependency boundary for document entry and reporting.

Paths:
- `app/controllers/PartiesController.php`
- `app/models/Party.php`
- `app/controllers/ItemsController.php`

#### Cash, Banking, and Settlement Flow

Payments support distinct pay-in and pay-out workflows, with creation, editing, indexes, and previews. Bank accounts expose account-level views. Settlements provide a separate process, likely reconciling seller or financial positions after transactions. These flows are represented by dedicated controllers/models rather than embedded in invoice handling.

Paths:
- `app/controllers/PaymentsController.php`
- `app/controllers/BankAccountsController.php`
- `app/controllers/SettlementsController.php`

#### Reporting and Dashboard Read Models

The dashboard is the high-level operational summary. Reports expose financial, sales, GST R1, reconciliation, commissions, advertising, subscriptions, users, and seller-settlement views. `Report` is the reporting data boundary, separating aggregate/read-oriented queries from transactional models.

Paths:
- `app/controllers/DashboardController.php`
- `app/controllers/ReportsController.php`
- `app/models/Report.php`

#### Persistence, Validation, and Presentation

Database connectivity is configured in `app/config/database.php`; SQL schema and evolution artifacts are under `database/`, including `database/lx_accounting.sql` and `database/migrations_2026_09.sql`. Domain inputs should pass through common validation and monetary/currency handling before persistence. Controllers render feature views inside shared layout fragments and theme configuration.

Paths:
- `app/config/database.php`
- `app/core/Validation.php`
- `app/core/Currency.php`

Main entry points: [`app/controllers/InvoicesController.php`](https://github.com/lynx479/billing_software/blob/main/app/controllers/InvoicesController.php) (Invoices), [`app/core/Controller.php`](https://github.com/lynx479/billing_software/blob/main/app/core/Controller.php) (Controller base), [`app/config/database.php`](https://github.com/lynx479/billing_software/blob/main/app/config/database.php) (Database connection), [`app/controllers/PaymentsController.php`](https://github.com/lynx479/billing_software/blob/main/app/controllers/PaymentsController.php) (Payments)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP &amp; MVC"]
  node_entry{{"Public entry<br/>PHP entry point<br/>[index.php]"}}
  node_router["Router<br/>routing boundary<br/>[Router.php]"]
  node_controller_base["Controller base<br/>MVC base<br/>[Controller.php]"]
  node_validation["Validation &amp; currency<br/>input rules<br/>[Validation.php]"]
end

subgraph group_documents["Transaction flows"]
  node_invoice_controller["Invoices<br/>controller"]
  node_credit_notes["Credit notes<br/>controller"]
  node_invoice_model["Invoice model<br/>transaction model<br/>[Invoice.php]"]
end

subgraph group_operations["Operational domains"]
  node_payments["Payments<br/>controller"]
  node_bank_accounts["Bank accounts<br/>controller"]
  node_settlements["Settlements<br/>controller"]
  node_parties["Parties<br/>controller"]
  node_party_model["Party model<br/>domain model<br/>[Party.php]"]
  node_items["Items<br/>controller"]
end

subgraph group_insight["Reporting &amp; persistence"]
  node_dashboard["Dashboard<br/>controller"]
  node_reports["Reports<br/>controller"]
  node_report_model["Report model<br/>read model<br/>[Report.php]"]
  node_database_config[("Database connection<br/>persistence config<br/>[database.php]")]
  node_schema[("Schema &amp; migrations<br/>database evolution<br/>[lx_accounting.sql]")]
end

node_entry -->|"dispatches"| node_router
node_router -->|"resolves actions"| node_controller_base
node_controller_base -->|"base for"| node_invoice_controller
node_controller_base -->|"base for"| node_payments
node_controller_base -->|"base for"| node_parties
node_controller_base -->|"base for"| node_dashboard
node_invoice_controller -->|"validates input"| node_validation
node_invoice_controller -->|"manages"| node_invoice_model
node_credit_notes -->|"linked document flow"| node_invoice_controller
node_payments -->|"uses accounts"| node_bank_accounts
node_settlements -->|"reconciles transactions"| node_payments
node_parties -->|"manages"| node_party_model
node_invoice_controller -->|"references counterparts"| node_parties
node_invoice_controller -->|"references catalog"| node_items
node_dashboard -->|"reads summaries"| node_report_model
node_reports -->|"queries aggregates"| node_report_model
node_invoice_model -->|"persists through"| node_database_config
node_party_model -->|"persists through"| node_database_config
node_report_model -->|"reads through"| node_database_config
node_database_config -.->|"uses schema"| node_schema

click node_entry "https://github.com/lynx479/billing_software/blob/main/public/index.php"
click node_router "https://github.com/lynx479/billing_software/blob/main/app/core/Router.php"
click node_controller_base "https://github.com/lynx479/billing_software/blob/main/app/core/Controller.php"
click node_validation "https://github.com/lynx479/billing_software/blob/main/app/core/Validation.php"
click node_invoice_controller "https://github.com/lynx479/billing_software/blob/main/app/controllers/InvoicesController.php"
click node_credit_notes "https://github.com/lynx479/billing_software/blob/main/app/controllers/CreditNotesController.php"
click node_invoice_model "https://github.com/lynx479/billing_software/blob/main/app/models/Invoice.php"
click node_payments "https://github.com/lynx479/billing_software/blob/main/app/controllers/PaymentsController.php"
click node_bank_accounts "https://github.com/lynx479/billing_software/blob/main/app/controllers/BankAccountsController.php"
click node_settlements "https://github.com/lynx479/billing_software/blob/main/app/controllers/SettlementsController.php"
click node_parties "https://github.com/lynx479/billing_software/blob/main/app/controllers/PartiesController.php"
click node_party_model "https://github.com/lynx479/billing_software/blob/main/app/models/Party.php"
click node_items "https://github.com/lynx479/billing_software/blob/main/app/controllers/ItemsController.php"
click node_dashboard "https://github.com/lynx479/billing_software/blob/main/app/controllers/DashboardController.php"
click node_reports "https://github.com/lynx479/billing_software/blob/main/app/controllers/ReportsController.php"
click node_report_model "https://github.com/lynx479/billing_software/blob/main/app/models/Report.php"
click node_database_config "https://github.com/lynx479/billing_software/blob/main/app/config/database.php"
click node_schema "https://github.com/lynx479/billing_software/blob/main/database/lx_accounting.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_router,node_controller_base,node_validation toneBlue
class node_invoice_controller,node_credit_notes,node_invoice_model toneAmber
class node_payments,node_bank_accounts,node_settlements,node_parties,node_party_model,node_items toneMint
class node_dashboard,node_reports,node_report_model,node_database_config,node_schema toneRose
```

## Components

### HTTP & MVC

- [Public entry](https://github.com/lynx479/billing_software/blob/main/public/index.php): PHP entry point · `public/index.php`
- [Router](https://github.com/lynx479/billing_software/blob/main/app/core/Router.php): routing boundary · `app/core/Router.php`
- [Controller base](https://github.com/lynx479/billing_software/blob/main/app/core/Controller.php): MVC base · Provides request and rendering behavior. · `app/core/Controller.php`
- [Validation & currency](https://github.com/lynx479/billing_software/blob/main/app/core/Validation.php): input rules · Validates domain input and monetary values. · `app/core/Validation.php`

### Transaction flows

- [Invoices](https://github.com/lynx479/billing_software/blob/main/app/controllers/InvoicesController.php): controller · `app/controllers/InvoicesController.php`
- [Credit notes](https://github.com/lynx479/billing_software/blob/main/app/controllers/CreditNotesController.php): controller · Separate credit-note lifecycle linked to invoice entry. · `app/controllers/CreditNotesController.php`
- [Invoice model](https://github.com/lynx479/billing_software/blob/main/app/models/Invoice.php): transaction model · `app/models/Invoice.php`

### Operational domains

- [Payments](https://github.com/lynx479/billing_software/blob/main/app/controllers/PaymentsController.php): controller · Pay-in and pay-out workflows. · `app/controllers/PaymentsController.php`
- [Bank accounts](https://github.com/lynx479/billing_software/blob/main/app/controllers/BankAccountsController.php): controller · `app/controllers/BankAccountsController.php`
- [Settlements](https://github.com/lynx479/billing_software/blob/main/app/controllers/SettlementsController.php): controller · Reconciles seller or financial positions. · `app/controllers/SettlementsController.php`
- [Parties](https://github.com/lynx479/billing_software/blob/main/app/controllers/PartiesController.php): controller · `app/controllers/PartiesController.php`
- [Party model](https://github.com/lynx479/billing_software/blob/main/app/models/Party.php): domain model · `app/models/Party.php`
- [Items](https://github.com/lynx479/billing_software/blob/main/app/controllers/ItemsController.php): controller · Catalog management and item history. · `app/controllers/ItemsController.php`

### Reporting & persistence

- [Dashboard](https://github.com/lynx479/billing_software/blob/main/app/controllers/DashboardController.php): controller · Operational summary read model. · `app/controllers/DashboardController.php`
- [Reports](https://github.com/lynx479/billing_software/blob/main/app/controllers/ReportsController.php): controller · Financial, tax, reconciliation, and seller reporting. · `app/controllers/ReportsController.php`
- [Report model](https://github.com/lynx479/billing_software/blob/main/app/models/Report.php): read model · Aggregate and read-oriented query boundary. · `app/models/Report.php`
- [Database connection](https://github.com/lynx479/billing_software/blob/main/app/config/database.php): persistence config · `app/config/database.php`
- [Schema & migrations](https://github.com/lynx479/billing_software/blob/main/database/lx_accounting.sql): database evolution · SQL schema and migration artifacts. · `database/lx_accounting.sql`

## Connections

- Public entry → Router: dispatches
- Router → Controller base: resolves actions
- Controller base → Invoices: base for
- Controller base → Payments: base for
- Controller base → Parties: base for
- Controller base → Dashboard: base for
- Invoices → Validation & currency: validates input
- Invoices → Invoice model: manages
- Credit notes → Invoices: linked document flow
- Payments → Bank accounts: uses accounts
- Settlements → Payments: reconciles transactions
- Parties → Party model: manages
- Invoices → Parties: references counterparts
- Invoices → Items: references catalog
- Dashboard → Report model: reads summaries
- Reports → Report model: queries aggregates
- Invoice model → Database connection: persists through
- Party model → Database connection: persists through
- Report model → Database connection: reads through
- Database connection → Schema & migrations: uses schema
