# ronmeruudesuu/alkansya architecture

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

- Interactive diagram: https://gitdiagram.com/ronmeruudesuu/alkansya
- Repository: https://github.com/ronmeruudesuu/alkansya

## Overview

Alkansya is an IoT coin-saving system: an ESP32 detects deposits and sends them to a local PHP/MySQL application, where the dashboard reports savings and users manage goals, history, corrections, and withdrawals. The graph covers those documented features and the sampled PHP implementations. The README documents the hardware-to-server workflow; unsampled browser-script/API wiring is shown only as unverified where needed.

Main entry points: [`config/database.php`](https://github.com/ronmeruudesuu/alkansya/blob/main/config/database.php) (Database connection), [`includes/functions.php`](https://github.com/ronmeruudesuu/alkansya/blob/main/includes/functions.php) (Savings data helpers), [`api/save_coin.php`](https://github.com/ronmeruudesuu/alkansya/blob/main/api/save_coin.php) (Deposit endpoint), [`api/get_data.php`](https://github.com/ronmeruudesuu/alkansya/blob/main/api/get_data.php) (Dashboard data API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["Coin device"]
  node_esp32["ESP32 counter"]
end

subgraph group_web["Web experience"]
  node_dashboard["Savings dashboard<br/>[index.php]"]
  node_browser_data["Dashboard polling<br/>[dashboard.js]"]
  node_goals_page["Goals page<br/>[goals_page.php]"]
  node_goals_ui["Goals interactions<br/>[goals.js]"]
  node_history_page["Transaction history<br/>[history.php]"]
  node_withdraw_page["Withdrawal page<br/>[withdraw_page.php]"]
  node_withdraw_ui["Withdrawal interactions<br/>[withdraw.js]"]
  node_clear_page["Clear history page<br/>[history_clear.php]"]
  node_clear_ui["Clear history controls<br/>[clear_history.js]"]
  node_preferences["Theme preferences<br/>[theme.js]"]
end

subgraph group_services["Application services"]
  node_coin_ingest["Deposit endpoint<br/>[save_coin.php]"]
  node_dashboard_api["Dashboard data API<br/>[get_data.php]"]
  node_goals_api["Goals API<br/>[goals.php]"]
  node_withdraw_api["Withdrawal API<br/>[withdraw.php]"]
  node_correction_api["Coin correction"]
  node_clear_api["History deletion API<br/>[clear_history.php]"]
  node_heartbeat_api["Device heartbeat<br/>[heartbeat.php]"]
  node_manual_api["Manual deposit API<br/>[manual_insert.php]"]
  node_shared_logic["Savings data helpers<br/>[functions.php]"]
end

subgraph group_storage["Persistence"]
  node_database_config["Database connection<br/>[database.php]"]
  node_schema["Relational schema<br/>[schema.sql]"]
  node_mysql[("MySQL / MariaDB")]
end

node_saver(("Coin saver"))
node_local_server["Local PHP server"]

node_saver -->|"selects and deposits"| node_esp32
node_esp32 -->|"sends coin data"| node_coin_ingest
node_coin_ingest -->|"validates and records"| node_shared_logic
node_coin_ingest -.->|"marks device seen"| node_heartbeat_api
node_coin_ingest -->|"opens connection"| node_database_config
node_shared_logic -.->|"queries connection"| node_database_config
node_dashboard -.->|"polls for updates"| node_browser_data
node_browser_data -->|"requests dashboard data"| node_dashboard_api
node_dashboard_api -->|"reads savings data"| node_shared_logic
node_dashboard_api -->|"opens connection"| node_database_config
node_goals_page -.->|"loads interactions"| node_goals_ui
node_goals_ui -.->|"manages goals"| node_goals_api
node_goals_api -->|"opens connection"| node_database_config
node_history_page -->|"loads filtered pages"| node_shared_logic
node_history_page -->|"opens connection"| node_database_config
node_withdraw_page -.->|"loads interactions"| node_withdraw_ui
node_withdraw_ui -.->|"submits withdrawals"| node_withdraw_api
node_withdraw_api -->|"checks inventory"| node_shared_logic
node_withdraw_api -->|"opens connection"| node_database_config
node_correction_api -->|"checks remaining coins"| node_shared_logic
node_correction_api -->|"opens connection"| node_database_config
node_clear_page -->|"loads controls"| node_clear_ui
node_clear_ui -.->|"requests deletion"| node_clear_api
node_clear_api -->|"opens connection"| node_database_config
node_heartbeat_api -->|"opens connection"| node_database_config
node_manual_api -->|"validates and marks seen"| node_shared_logic
node_manual_api -->|"opens connection"| node_database_config
node_preferences -.->|"sets display theme"| node_dashboard
node_schema -->|"defines tables"| node_mysql
node_database_config -->|"connects to"| node_mysql

click node_dashboard "https://github.com/ronmeruudesuu/alkansya/blob/main/index.php"
click node_browser_data "https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/dashboard.js"
click node_goals_page "https://github.com/ronmeruudesuu/alkansya/blob/main/goals_page.php"
click node_goals_ui "https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/goals.js"
click node_history_page "https://github.com/ronmeruudesuu/alkansya/blob/main/history.php"
click node_withdraw_page "https://github.com/ronmeruudesuu/alkansya/blob/main/withdraw_page.php"
click node_withdraw_ui "https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/withdraw.js"
click node_clear_page "https://github.com/ronmeruudesuu/alkansya/blob/main/history_clear.php"
click node_clear_ui "https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/clear_history.js"
click node_preferences "https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/theme.js"
click node_coin_ingest "https://github.com/ronmeruudesuu/alkansya/blob/main/api/save_coin.php"
click node_dashboard_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/get_data.php"
click node_goals_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/goals.php"
click node_withdraw_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/withdraw.php"
click node_correction_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/correct_last_coin.php"
click node_clear_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/clear_history.php"
click node_heartbeat_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/heartbeat.php"
click node_manual_api "https://github.com/ronmeruudesuu/alkansya/blob/main/api/manual_insert.php"
click node_shared_logic "https://github.com/ronmeruudesuu/alkansya/blob/main/includes/functions.php"
click node_database_config "https://github.com/ronmeruudesuu/alkansya/blob/main/config/database.php"
click node_schema "https://github.com/ronmeruudesuu/alkansya/blob/main/sql/schema.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_esp32 toneBlue
class node_dashboard,node_browser_data,node_goals_page,node_goals_ui,node_history_page,node_withdraw_page,node_withdraw_ui,node_clear_page,node_clear_ui,node_preferences toneAmber
class node_coin_ingest,node_dashboard_api,node_goals_api,node_withdraw_api,node_correction_api,node_clear_api,node_heartbeat_api,node_manual_api,node_shared_logic,node_local_server toneMint
class node_database_config,node_schema,node_mysql toneRose
class node_saver toneIndigo
```

## Components

### Coin device

- **ESP32 counter**

### Web experience

- [Savings dashboard](https://github.com/ronmeruudesuu/alkansya/blob/main/index.php): `index.php`
- [Dashboard polling](https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/dashboard.js): `assets/javascript/dashboard.js`
- [Goals page](https://github.com/ronmeruudesuu/alkansya/blob/main/goals_page.php): `goals_page.php`
- [Goals interactions](https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/goals.js): `assets/javascript/goals.js`
- [Transaction history](https://github.com/ronmeruudesuu/alkansya/blob/main/history.php): `history.php`
- [Withdrawal page](https://github.com/ronmeruudesuu/alkansya/blob/main/withdraw_page.php): `withdraw_page.php`
- [Withdrawal interactions](https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/withdraw.js): `assets/javascript/withdraw.js`
- [Clear history page](https://github.com/ronmeruudesuu/alkansya/blob/main/history_clear.php): `history_clear.php`
- [Clear history controls](https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/clear_history.js): `assets/javascript/clear_history.js`
- [Theme preferences](https://github.com/ronmeruudesuu/alkansya/blob/main/assets/javascript/theme.js): `assets/javascript/theme.js`

### Application services

- [Deposit endpoint](https://github.com/ronmeruudesuu/alkansya/blob/main/api/save_coin.php): `api/save_coin.php`
- [Dashboard data API](https://github.com/ronmeruudesuu/alkansya/blob/main/api/get_data.php): `api/get_data.php`
- [Goals API](https://github.com/ronmeruudesuu/alkansya/blob/main/api/goals.php): `api/goals.php`
- [Withdrawal API](https://github.com/ronmeruudesuu/alkansya/blob/main/api/withdraw.php): `api/withdraw.php`
- [Coin correction](https://github.com/ronmeruudesuu/alkansya/blob/main/api/correct_last_coin.php): `api/correct_last_coin.php`
- [History deletion API](https://github.com/ronmeruudesuu/alkansya/blob/main/api/clear_history.php): `api/clear_history.php`
- [Device heartbeat](https://github.com/ronmeruudesuu/alkansya/blob/main/api/heartbeat.php): `api/heartbeat.php`
- [Manual deposit API](https://github.com/ronmeruudesuu/alkansya/blob/main/api/manual_insert.php): `api/manual_insert.php`
- [Savings data helpers](https://github.com/ronmeruudesuu/alkansya/blob/main/includes/functions.php): `includes/functions.php`

### Persistence

- [Database connection](https://github.com/ronmeruudesuu/alkansya/blob/main/config/database.php): `config/database.php`
- [Relational schema](https://github.com/ronmeruudesuu/alkansya/blob/main/sql/schema.sql): `sql/schema.sql`
- **MySQL / MariaDB**

### Other components

- **Coin saver**
- **Local PHP server**

## Connections

- Coin saver → ESP32 counter: selects and deposits (evidence: `README.md`)
- ESP32 counter → Deposit endpoint: sends coin data (evidence: `README.md`)
- Deposit endpoint → Savings data helpers: validates and records (evidence: `api/save_coin.php`)
- Deposit endpoint → Device heartbeat: marks device seen
- Deposit endpoint → Database connection: opens connection (evidence: `api/save_coin.php`)
- Savings data helpers → Database connection: queries connection
- Savings dashboard → Dashboard polling: polls for updates
- Dashboard polling → Dashboard data API: requests dashboard data (evidence: `README.md`)
- Dashboard data API → Savings data helpers: reads savings data (evidence: `api/get_data.php`)
- Dashboard data API → Database connection: opens connection (evidence: `api/get_data.php`)
- Goals page → Goals interactions: loads interactions
- Goals interactions → Goals API: manages goals
- Goals API → Database connection: opens connection (evidence: `api/goals.php`)
- Transaction history → Savings data helpers: loads filtered pages (evidence: `history.php`)
- Transaction history → Database connection: opens connection (evidence: `history.php`)
- Withdrawal page → Withdrawal interactions: loads interactions
- Withdrawal interactions → Withdrawal API: submits withdrawals
- Withdrawal API → Savings data helpers: checks inventory (evidence: `api/withdraw.php`)
- Withdrawal API → Database connection: opens connection (evidence: `api/withdraw.php`)
- Coin correction → Savings data helpers: checks remaining coins (evidence: `api/correct_last_coin.php`)
- Coin correction → Database connection: opens connection (evidence: `api/correct_last_coin.php`)
- Clear history page → Clear history controls: loads controls (evidence: `history_clear.php`)
- Clear history controls → History deletion API: requests deletion
- History deletion API → Database connection: opens connection (evidence: `api/clear_history.php`)
- Device heartbeat → Database connection: opens connection (evidence: `api/heartbeat.php`)
- Manual deposit API → Savings data helpers: validates and marks seen (evidence: `api/manual_insert.php`)
- Manual deposit API → Database connection: opens connection (evidence: `api/manual_insert.php`)
- Theme preferences → Savings dashboard: sets display theme
- Relational schema → MySQL / MariaDB: defines tables (evidence: `README.md`)
- Database connection → MySQL / MariaDB: connects to (evidence: `config/database.php`)
