# ellite/wallos architecture

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

- Interactive diagram: https://gitdiagram.com/ellite/wallos
- Repository: https://github.com/ellite/wallos

## Overview

#### Purpose and runtime
Wallos is a self-hosted PHP 8.3 subscription/recurring-expense tracker. It serves server-rendered pages plus JavaScript-driven actions, persists data in SQLite, and can run behind NGINX/Apache or in Docker. Main browser entry points include `index.php`, `subscriptions.php`, `calendar.php`, `stats.php`, `settings.php`, and `admin.php`. Container startup is defined by `Dockerfile`, `startup.sh`, and `docker-compose.yaml`.

#### Request, authentication, and persistence boundary
PHP pages and mutation endpoints share session/user validation and database connection infrastructure. Core boundaries are:
- SQLite access and endpoint-specific connections: `includes/connect.php`, `includes/connect_endpoint.php`, `db/wallos.empty.db`
- Session/login/user guards: `includes/checksession.php`, `includes/checkuser.php`, `includes/validate_endpoint.php`
- Schema evolution: `includes/run_migrations.php`, `endpoints/db/migrate.php`, `migrations/000001.php`

Initial registration creates the first account; migrations are runnable through web or CLI. Persistent Docker volumes retain the database and uploaded logos.

#### Subscription domain flow
Subscriptions are the central entity. UI pages load client behavior from `scripts/dashboard.js`, `scripts/subscriptions.js`, and `scripts/subscription-details.js`; these call server endpoints to create, fetch, modify, clone, renew, delete, and export subscription data:
- `endpoints/subscription/add.php`, `endpoints/subscription/get.php`, `endpoints/subscription/renew.php`
- `endpoints/subscriptions/get.php`, `endpoints/subscriptions/export.php`
- API equivalents under `api/subscriptions/get_subscriptions.php` and `api/subscriptions/set_subscriptions.php`

Supporting category, payment-method, household, budget-period, and currency data determine organization and cost reporting.

#### Presentation, reporting, and calendar
Server-rendered dashboards expose subscriptions through reusable calculations and listing logic. Statistics and budgets derive recurring costs from stored subscriptions; calendar feeds provide external-calendar integration:
- `includes/list_subscriptions.php`, `includes/stats_calculations.php`, `includes/budget_period_calculations.php`
- `stats.php`, `calendar.php`, `endpoints/subscription/exportcalendar.php`
- `api/subscriptions/get_ical_feed.php`, `includes/ical_helper.php`

Localization is split between PHP and browser translation catalogs under `includes/i18n/` and `scripts/i18n/`.

#### Scheduled operations and notifications
Cron scripts perform asynchronous maintenance rather than serving browser requests: next-payment recalculation, exchange-rate refresh, yearly-cost snapshots, update checks, account mail queues, notifications, and AI recommendation generation. Key jobs:
- `endpoints/cronjobs/updatenextpayment.php`, `endpoints/cronjobs/updateexchange.php`
- `endpoints/cronjobs/sendnotifications.php`, `endpoints/cronjobs/sendcancellationnotifications.php`
- `endpoints/cronjobs/generaterecommendations.php`

Notification configuration and test/send paths support email plus Discord, Gotify, Mattermost, ntfy, Pushover, Pushplus, ServerChan, Telegram, and generic webhooks under `endpoints/notifications/`.

#### External integrations and security controls
Fixer supplies currency rates; logo lookup uses web search; AI recommendations target ChatGPT, Gemini, or local Ollama. Relevant integration points are `includes/currency_rates.php`, `endpoints/currency/update_exchange.php`, `endpoints/logos/search.php`, and `includes/ai_client.php`.

Authentication supports password login, TOTP, and OIDC/OAuth. OIDC can source runtime settings from environment variables and performs discovery; outbound OIDC, SMTP, and webhook destinations are guarded against SSRF unless allowlisted:
- `includes/oidc/oidc_login.php`, `includes/oidc/handle_oidc_callback.php`
- `includes/ssrf_helper.php`, `includes/oidc_settings.php`
- `libs/OTPHP/TOTP.php`, `libs/PHPMailer/PHPMailer.php`

#### Administrative and programmatic interfaces
Admin controls manage users, registration/security policy, OIDC, SMTP, notifications, and cleanup. Publicly organized REST-like API routes mirror major settings and subscription operations:
- `admin.php`, `endpoints/admin/savesecuritysettings.php`, `endpoints/admin/enableoidc.php`
- `api/admin/set_oidc_settings.php`, `api/settings/set_settings.php`, `api/users/set_budget.php`

`health.php` is the operational health endpoint; NGINX configuration resides in `nginx.conf` and `nginx.default.conf`.

Main entry points: [`includes/connect.php`](https://github.com/ellite/wallos/blob/main/includes/connect.php) (SQLite access), [`endpoints/cronjobs/updatenextpayment.php`](https://github.com/ellite/wallos/blob/main/endpoints/cronjobs/updatenextpayment.php) (Scheduled jobs), [`index.php`](https://github.com/ellite/wallos/blob/main/index.php) (Browser pages), [`endpoints/subscription/add.php`](https://github.com/ellite/wallos/blob/main/endpoints/subscription/add.php) (Subscription endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_browser_pages["Browser pages<br/>PHP entry points<br/>[index.php]"]
  node_browser_js["Browser actions<br/>JavaScript<br/>[subscriptions.js]"]
  node_auth_guards["Session &amp; user guards<br/>PHP middleware<br/>[checksession.php]"]
  node_admin_api["Admin &amp; settings API<br/>REST-like API"]
end

subgraph group_domain["Subscription domain"]
  node_subscription_endpoints["Subscription endpoints<br/>PHP endpoints<br/>[add.php]"]
  node_subscription_api["Subscription API<br/>REST-like API"]
  node_subscription_logic["Subscription listings<br/>PHP domain logic"]
  node_reporting["Stats &amp; budgets<br/>PHP calculations"]
  node_calendar_feed["Calendar export<br/>iCalendar feed<br/>[get_ical_feed.php]"]
  node_database_access["SQLite access<br/>PHP persistence<br/>[connect.php]"]
  node_sqlite_db[("Wallos database<br/>SQLite<br/>[wallos.empty.db]")]
end

subgraph group_ops["Operations"]
  node_migrations["Schema migrations<br/>PHP migration runner<br/>[run_migrations.php]"]
  node_cron_jobs["Scheduled jobs<br/>PHP cron endpoints"]
  node_notifications["Notification delivery<br/>PHP notification endpoints"]
  node_container_runtime["Container runtime<br/>Docker startup"]
  node_health["Health endpoint<br/>Operational endpoint<br/>[health.php]"]
end

subgraph group_integrations["External services"]
  node_oidc_totp["OIDC &amp; TOTP login<br/>Authentication<br/>[oidc_login.php]"]
  node_ssrf_guard["Outbound SSRF guard<br/>Security control<br/>[ssrf_helper.php]"]
  node_currency_service["Currency rates<br/>External integration<br/>[currency_rates.php]"]
  node_ai_recommendations["AI recommendations<br/>External integration<br/>[ai_client.php]"]
end

node_browser_pages -->|"validates user"| node_auth_guards
node_browser_pages -->|"renders subscriptions"| node_subscription_logic
node_browser_pages -->|"renders stats and budgets"| node_reporting
node_browser_js -->|"mutations and fetches"| node_subscription_endpoints
node_subscription_endpoints -->|"validates endpoint access"| node_auth_guards
node_subscription_endpoints -->|"persists subscriptions"| node_database_access
node_subscription_api -->|"reads and writes"| node_database_access
node_subscription_logic -->|"loads subscriptions"| node_database_access
node_reporting -->|"derives costs"| node_database_access
node_calendar_feed -->|"exports schedule"| node_subscription_logic
node_database_access -->|"SQLite connection"| node_sqlite_db
node_migrations -->|"evolves schema"| node_sqlite_db
node_cron_jobs -->|"maintains stored data"| node_database_access
node_cron_jobs -->|"triggers delivery"| node_notifications
node_cron_jobs -->|"refreshes rates"| node_currency_service
node_cron_jobs -->|"generates recommendations"| node_ai_recommendations
node_notifications -->|"checks webhook targets"| node_ssrf_guard
node_oidc_totp -->|"checks OIDC destination"| node_ssrf_guard
node_admin_api -->|"updates administration settings"| node_database_access
node_container_runtime -.->|"persists volume"| node_sqlite_db

click node_browser_pages "https://github.com/ellite/wallos/blob/main/index.php"
click node_browser_js "https://github.com/ellite/wallos/blob/main/scripts/subscriptions.js"
click node_auth_guards "https://github.com/ellite/wallos/blob/main/includes/checksession.php"
click node_subscription_endpoints "https://github.com/ellite/wallos/blob/main/endpoints/subscription/add.php"
click node_subscription_api "https://github.com/ellite/wallos/blob/main/api/subscriptions/get_subscriptions.php"
click node_subscription_logic "https://github.com/ellite/wallos/blob/main/includes/list_subscriptions.php"
click node_reporting "https://github.com/ellite/wallos/blob/main/includes/stats_calculations.php"
click node_calendar_feed "https://github.com/ellite/wallos/blob/main/api/subscriptions/get_ical_feed.php"
click node_database_access "https://github.com/ellite/wallos/blob/main/includes/connect.php"
click node_sqlite_db "https://github.com/ellite/wallos/blob/main/db/wallos.empty.db"
click node_migrations "https://github.com/ellite/wallos/blob/main/includes/run_migrations.php"
click node_cron_jobs "https://github.com/ellite/wallos/blob/main/endpoints/cronjobs/updatenextpayment.php"
click node_container_runtime "https://github.com/ellite/wallos/blob/main/Dockerfile"
click node_admin_api "https://github.com/ellite/wallos/blob/main/api/admin/set_oidc_settings.php"
click node_oidc_totp "https://github.com/ellite/wallos/blob/main/includes/oidc/oidc_login.php"
click node_ssrf_guard "https://github.com/ellite/wallos/blob/main/includes/ssrf_helper.php"
click node_currency_service "https://github.com/ellite/wallos/blob/main/includes/currency_rates.php"
click node_ai_recommendations "https://github.com/ellite/wallos/blob/main/includes/ai_client.php"
click node_health "https://github.com/ellite/wallos/blob/main/health.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_browser_pages,node_browser_js,node_auth_guards,node_admin_api toneBlue
class node_subscription_endpoints,node_subscription_api,node_subscription_logic,node_reporting,node_calendar_feed,node_database_access,node_sqlite_db toneAmber
class node_migrations,node_cron_jobs,node_notifications,node_container_runtime,node_health toneMint
class node_oidc_totp,node_ssrf_guard,node_currency_service,node_ai_recommendations toneRose
```

## Components

### Web application

Server-rendered pages and browser actions.

- [Browser pages](https://github.com/ellite/wallos/blob/main/index.php): PHP entry points · Dashboards, subscriptions, calendar, stats, settings, and admin. · `index.php`
- [Browser actions](https://github.com/ellite/wallos/blob/main/scripts/subscriptions.js): JavaScript · Dashboard and subscription interactions call PHP endpoints. · `scripts/subscriptions.js`
- [Session & user guards](https://github.com/ellite/wallos/blob/main/includes/checksession.php): PHP middleware · Shared page and endpoint authentication validation. · `includes/checksession.php`
- [Admin & settings API](https://github.com/ellite/wallos/blob/main/api/admin/set_oidc_settings.php): REST-like API · Programmatic policy, OIDC, settings, and budget administration. · `api/admin/set_oidc_settings.php`

### Subscription domain

Core subscription and reporting behavior.

- [Subscription endpoints](https://github.com/ellite/wallos/blob/main/endpoints/subscription/add.php): PHP endpoints · Create, retrieve, renew, export, and mutate subscriptions. · `endpoints/subscription/add.php`
- [Subscription API](https://github.com/ellite/wallos/blob/main/api/subscriptions/get_subscriptions.php): REST-like API · Programmatic subscription read/write interface. · `api/subscriptions/get_subscriptions.php`
- [Subscription listings](https://github.com/ellite/wallos/blob/main/includes/list_subscriptions.php): PHP domain logic · Reusable subscription loading and listing calculations. · `includes/list_subscriptions.php`
- [Stats & budgets](https://github.com/ellite/wallos/blob/main/includes/stats_calculations.php): PHP calculations · Derives recurring costs and budget reporting. · `includes/stats_calculations.php`
- [Calendar export](https://github.com/ellite/wallos/blob/main/api/subscriptions/get_ical_feed.php): iCalendar feed · Produces external calendar data from subscriptions. · `api/subscriptions/get_ical_feed.php`
- [SQLite access](https://github.com/ellite/wallos/blob/main/includes/connect.php): PHP persistence · Page and endpoint database connection boundary. · `includes/connect.php`
- [Wallos database](https://github.com/ellite/wallos/blob/main/db/wallos.empty.db): SQLite · Persistent subscriptions, users, settings, and related data. · `db/wallos.empty.db`

### Operations

Scheduled work and deployment surfaces.

- [Schema migrations](https://github.com/ellite/wallos/blob/main/includes/run_migrations.php): PHP migration runner · Runnable through web or CLI migration endpoint. · `includes/run_migrations.php`
- [Scheduled jobs](https://github.com/ellite/wallos/blob/main/endpoints/cronjobs/updatenextpayment.php): PHP cron endpoints · Recalculates payments, rates, notifications, and recommendations. · `endpoints/cronjobs/updatenextpayment.php`
- **Notification delivery**: PHP notification endpoints · Email and webhook-channel test/send paths.
- [Container runtime](https://github.com/ellite/wallos/blob/main/Dockerfile): Docker startup · Persistent database and logo volumes are initialized at startup. · `Dockerfile`
- [Health endpoint](https://github.com/ellite/wallos/blob/main/health.php): Operational endpoint · `health.php`

### External services

Outbound providers and guarded clients.

- [OIDC & TOTP login](https://github.com/ellite/wallos/blob/main/includes/oidc/oidc_login.php): Authentication · Supports OIDC discovery and time-based one-time passwords. · `includes/oidc/oidc_login.php`
- [Outbound SSRF guard](https://github.com/ellite/wallos/blob/main/includes/ssrf_helper.php): Security control · Guards OIDC, SMTP, and webhook destinations unless allowlisted. · `includes/ssrf_helper.php`
- [Currency rates](https://github.com/ellite/wallos/blob/main/includes/currency_rates.php): External integration · Refreshes exchange rates from Fixer. · `includes/currency_rates.php`
- [AI recommendations](https://github.com/ellite/wallos/blob/main/includes/ai_client.php): External integration · Uses ChatGPT, Gemini, or local Ollama. · `includes/ai_client.php`

## Connections

- Browser pages → Session & user guards: validates user
- Browser pages → Subscription listings: renders subscriptions
- Browser pages → Stats & budgets: renders stats and budgets
- Browser actions → Subscription endpoints: mutations and fetches
- Subscription endpoints → Session & user guards: validates endpoint access
- Subscription endpoints → SQLite access: persists subscriptions
- Subscription API → SQLite access: reads and writes
- Subscription listings → SQLite access: loads subscriptions
- Stats & budgets → SQLite access: derives costs
- Calendar export → Subscription listings: exports schedule
- SQLite access → Wallos database: SQLite connection
- Schema migrations → Wallos database: evolves schema
- Scheduled jobs → SQLite access: maintains stored data
- Scheduled jobs → Notification delivery: triggers delivery
- Scheduled jobs → Currency rates: refreshes rates
- Scheduled jobs → AI recommendations: generates recommendations
- Notification delivery → Outbound SSRF guard: checks webhook targets
- OIDC & TOTP login → Outbound SSRF guard: checks OIDC destination
- Admin & settings API → SQLite access: updates administration settings
- Container runtime → Wallos database: persists volume
