# haris-khan-durrani/free-accounting-application architecture

> Architecture diagram of the GitHub repository haris-khan-durrani/free-accounting-application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haris-khan-durrani/free-accounting-application
- Repository: https://github.com/haris-khan-durrani/free-accounting-application

## Overview

This PHP application provides multi-tenant invoicing, payments, accounting, compliance reporting, and client self-service. The main workflow is workspace users creating invoices for clients, collecting payments through gateways, and recording transactions in the general ledger for reports and tax exports. The README documents recurring billing, OTP portal access, custom domains, templates, and integrations; the graph preserves these capabilities. Relationships are limited to calls visible in excerpts or the SOURCE INDEX, plus workflows stated in the README; unsampled implementations are represented by their exact paths without inferred call chains.

Main entry points: [`Services/AccountingService.php`](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/AccountingService.php) (General ledger), [`bootstrap.php`](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/bootstrap.php) (Application bootstrap), [`layout.php`](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/layout.php) (Workspace interface), [`Services/Mailer.php`](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/Mailer.php) (Email delivery)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Workspace and tenancy"]
  node_layout["Workspace interface<br/>[layout.php]"]
  node_tenant["Tenant context<br/>[Tenant.php]"]
  node_branding["Workspace branding<br/>[Branding.php]"]
  node_subaccounts["Workspaces and domains<br/>[subaccounts.php]"]
end

subgraph group_billing["Billing and client service"]
  node_invoices["Invoices and quotes<br/>[invoices.php]"]
  node_templates["Invoice templates"]
  node_recurring["Recurring invoices"]
  node_cron["Recurring worker<br/>[cron_recurring.php]"]
  node_portal["Client portal and OTP<br/>[client_portal.php]"]
  node_client_login["Client login<br/>[client_login.php]"]
  node_mailer["Email delivery<br/>[Mailer.php]"]
  node_gateway["Payment gateways"]
  node_webhooks["Gateway webhooks<br/>[stripe.php]"]
end

subgraph group_finance["Accounting and compliance"]
  node_ledger["General ledger"]
  node_expenses["Expense tracking<br/>[expenses.php]"]
  node_reports["Financial reports<br/>[reports_pnl.php]"]
  node_vat["VAT 201 return<br/>[reports_vat201.php]"]
  node_faf["FTA audit export<br/>[export_faf.php]"]
  node_corp_tax["Corporate tax"]
end

subgraph group_platform["API and integrations"]
  node_api["REST API<br/>[index.php]"]
  node_auth["API authentication"]
  node_mcp_api["MCP endpoint<br/>[mcp.php]"]
  node_mcp["MCP tools<br/>[McpService.php]"]
  node_automation["Automation engine"]
  node_whatsapp["WhatsApp service"]
end

subgraph group_foundation["Shared services"]
  node_bootstrap["Application bootstrap<br/>[bootstrap.php]"]
  node_security["Security utilities<br/>[Security.php]"]
  node_crypto["Cryptography<br/>[Crypto.php]"]
  node_currency["Currency engine<br/>[Currency.php]"]
  node_cache["Cache<br/>[Cache.php]"]
  node_commission["Commission calculations<br/>[Commission.php]"]
  node_plugin["Plugin engine<br/>[PluginEngine.php]"]
end

node_admin(("Workspace user"))
node_clients(("Client user"))

node_admin -->|"uses"| node_layout
node_layout -->|"navigates to"| node_invoices
node_layout -->|"navigates to"| node_subaccounts
node_layout -->|"loads context"| node_tenant
node_layout -->|"loads branding"| node_branding
node_invoices -->|"posts sales"| node_ledger
node_expenses -->|"posts expenses"| node_ledger
node_invoices -->|"renders with"| node_templates
node_recurring -->|"processed by"| node_cron
node_cron -->|"generates due"| node_invoices
node_cron -->|"posts entries"| node_ledger
node_clients -->|"requests access"| node_client_login
node_client_login -->|"sends OTP"| node_mailer
node_client_login -->|"authenticates to"| node_portal
node_portal -->|"initiates payment"| node_gateway
node_webhooks -->|"verifies payment"| node_gateway
node_webhooks -->|"records payment"| node_ledger
node_ledger -->|"feeds reports"| node_reports
node_ledger -->|"provides filing data"| node_vat
node_ledger -->|"provides audit data"| node_faf
node_ledger -->|"provides liability data"| node_corp_tax
node_api -->|"authenticates requests"| node_auth
node_mcp_api -->|"authenticates requests"| node_auth
node_mcp_api -->|"dispatches tools"| node_mcp
node_bootstrap -->|"initializes"| node_tenant
node_bootstrap -->|"loads"| node_branding
node_bootstrap -->|"loads"| node_currency
node_bootstrap -->|"loads"| node_security
node_bootstrap -->|"loads"| node_gateway
node_bootstrap -->|"loads"| node_mailer
node_bootstrap -->|"initializes"| node_plugin
node_branding -->|"resolves workspace"| node_tenant
node_branding -->|"invalidates"| node_cache
node_auth -->|"checks workspace"| node_tenant
node_mailer -->|"uses"| node_crypto
node_mailer -->|"uses"| node_security
node_gateway -->|"uses"| node_currency
node_gateway -->|"uses"| node_crypto
node_ledger -->|"scopes entries"| node_tenant
node_plugin -->|"uses"| node_security
node_mcp -->|"uses"| node_mailer
node_reports -->|"uses calculations"| node_commission
node_layout -.->|"offers automation"| node_automation
node_layout -.->|"offers messaging"| node_whatsapp

click node_layout "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/layout.php"
click node_tenant "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Tenant.php"
click node_branding "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Branding.php"
click node_subaccounts "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/subaccounts.php"
click node_invoices "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/invoices.php"
click node_templates "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/templates/invoices/custom_drag_drop.php"
click node_recurring "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/recurring_invoices.php"
click node_cron "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/cron_recurring.php"
click node_portal "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/client_portal.php"
click node_client_login "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/client_login.php"
click node_mailer "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/Mailer.php"
click node_gateway "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/PaymentGatewayService.php"
click node_webhooks "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/api/v1/webhooks/stripe.php"
click node_ledger "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/AccountingService.php"
click node_expenses "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/expenses.php"
click node_reports "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/reports_pnl.php"
click node_vat "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/reports_vat201.php"
click node_faf "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/export_faf.php"
click node_corp_tax "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/reports_corporate_tax.php"
click node_api "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/api/v1/index.php"
click node_auth "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/ApiAuthenticator.php"
click node_mcp_api "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/api/v1/mcp.php"
click node_mcp "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/McpService.php"
click node_automation "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/AutomationService.php"
click node_whatsapp "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/WhatsAppService.php"
click node_bootstrap "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/bootstrap.php"
click node_security "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Security.php"
click node_crypto "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Crypto.php"
click node_currency "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Currency.php"
click node_cache "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Cache.php"
click node_commission "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Commission.php"
click node_plugin "https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/PluginEngine.php"

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_layout,node_tenant,node_branding,node_subaccounts,node_admin,node_clients toneBlue
class node_invoices,node_templates,node_recurring,node_cron,node_portal,node_client_login,node_mailer,node_gateway,node_webhooks toneAmber
class node_ledger,node_expenses,node_reports,node_vat,node_faf,node_corp_tax toneMint
class node_api,node_auth,node_mcp_api,node_mcp,node_automation,node_whatsapp toneRose
class node_bootstrap,node_security,node_crypto,node_currency,node_cache,node_commission,node_plugin toneIndigo
```

## Components

### Workspace and tenancy

- [Workspace interface](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/layout.php): `layout.php`
- [Tenant context](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Tenant.php): `Core/Tenant.php`
- [Workspace branding](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Branding.php): `Core/Branding.php`
- [Workspaces and domains](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/subaccounts.php): `subaccounts.php`

### Billing and client service

- [Invoices and quotes](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/invoices.php): `invoices.php`
- [Invoice templates](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/templates/invoices/custom_drag_drop.php): `templates/invoices/custom_drag_drop.php`
- [Recurring invoices](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/recurring_invoices.php): `recurring_invoices.php`
- [Recurring worker](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/cron_recurring.php): `cron_recurring.php`
- [Client portal and OTP](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/client_portal.php): `client_portal.php`
- [Client login](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/client_login.php): `client_login.php`
- [Email delivery](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/Mailer.php): `Services/Mailer.php`
- [Payment gateways](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/PaymentGatewayService.php): `Services/PaymentGatewayService.php`
- [Gateway webhooks](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/api/v1/webhooks/stripe.php): `api/v1/webhooks/stripe.php`

### Accounting and compliance

- [General ledger](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/AccountingService.php): `Services/AccountingService.php`
- [Expense tracking](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/expenses.php): `expenses.php`
- [Financial reports](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/reports_pnl.php): `reports_pnl.php`
- [VAT 201 return](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/reports_vat201.php): `reports_vat201.php`
- [FTA audit export](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/export_faf.php): `export_faf.php`
- [Corporate tax](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/reports_corporate_tax.php): `reports_corporate_tax.php`

### API and integrations

- [REST API](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/api/v1/index.php): `api/v1/index.php`
- [API authentication](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/ApiAuthenticator.php): `Core/ApiAuthenticator.php`
- [MCP endpoint](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/api/v1/mcp.php): `api/v1/mcp.php`
- [MCP tools](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/McpService.php): `Services/McpService.php`
- [Automation engine](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/AutomationService.php): `Services/AutomationService.php`
- [WhatsApp service](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/WhatsAppService.php): `Services/WhatsAppService.php`

### Shared services

- [Application bootstrap](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/bootstrap.php): `bootstrap.php`
- [Security utilities](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Security.php): `Core/Security.php`
- [Cryptography](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Crypto.php): `Core/Crypto.php`
- [Currency engine](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Currency.php): `Core/Currency.php`
- [Cache](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Cache.php): `Core/Cache.php`
- [Commission calculations](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Core/Commission.php): `Core/Commission.php`
- [Plugin engine](https://github.com/haris-khan-durrani/free-accounting-application/blob/main/Services/PluginEngine.php): `Services/PluginEngine.php`

### Other components

- **Workspace user**
- **Client user**

## Connections

- Workspace user → Workspace interface: uses
- Workspace interface → Invoices and quotes: navigates to (evidence: `layout.php`)
- Workspace interface → Workspaces and domains: navigates to (evidence: `layout.php`)
- Workspace interface → Tenant context: loads context (evidence: `layout.php`)
- Workspace interface → Workspace branding: loads branding (evidence: `layout.php`)
- Invoices and quotes → General ledger: posts sales
- Expense tracking → General ledger: posts expenses
- Invoices and quotes → Invoice templates: renders with
- Recurring invoices → Recurring worker: processed by
- Recurring worker → Invoices and quotes: generates due
- Recurring worker → General ledger: posts entries
- Client user → Client login: requests access
- Client login → Email delivery: sends OTP (evidence: `client_login.php`)
- Client login → Client portal and OTP: authenticates to
- Client portal and OTP → Payment gateways: initiates payment
- Gateway webhooks → Payment gateways: verifies payment (evidence: `api/v1/webhooks/stripe.php`)
- Gateway webhooks → General ledger: records payment (evidence: `api/v1/webhooks/stripe.php`)
- General ledger → Financial reports: feeds reports
- General ledger → VAT 201 return: provides filing data
- General ledger → FTA audit export: provides audit data
- General ledger → Corporate tax: provides liability data
- REST API → API authentication: authenticates requests (evidence: `api/v1/index.php`)
- MCP endpoint → API authentication: authenticates requests (evidence: `api/v1/mcp.php`)
- MCP endpoint → MCP tools: dispatches tools (evidence: `api/v1/mcp.php`)
- Application bootstrap → Tenant context: initializes (evidence: `bootstrap.php`)
- Application bootstrap → Workspace branding: loads (evidence: `bootstrap.php`)
- Application bootstrap → Currency engine: loads (evidence: `bootstrap.php`)
- Application bootstrap → Security utilities: loads (evidence: `bootstrap.php`)
- Application bootstrap → Payment gateways: loads (evidence: `bootstrap.php`)
- Application bootstrap → Email delivery: loads (evidence: `bootstrap.php`)
- Application bootstrap → Plugin engine: initializes (evidence: `bootstrap.php`)
- Workspace branding → Tenant context: resolves workspace (evidence: `Core/Branding.php`)
- Workspace branding → Cache: invalidates (evidence: `Core/Branding.php`)
- API authentication → Tenant context: checks workspace (evidence: `Core/ApiAuthenticator.php`)
- Email delivery → Cryptography: uses (evidence: `Services/Mailer.php`)
- Email delivery → Security utilities: uses (evidence: `Services/Mailer.php`)
- Payment gateways → Currency engine: uses (evidence: `Services/PaymentGatewayService.php`)
- Payment gateways → Cryptography: uses (evidence: `Services/PaymentGatewayService.php`)
- General ledger → Tenant context: scopes entries (evidence: `Services/AccountingService.php`)
- Plugin engine → Security utilities: uses (evidence: `Services/PluginEngine.php`)
- MCP tools → Email delivery: uses (evidence: `Services/McpService.php`)
- Financial reports → Commission calculations: uses calculations
- Workspace interface → Automation engine: offers automation
- Workspace interface → WhatsApp service: offers messaging
