# achouvardas/elefthero architecture

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

- Interactive diagram: https://gitdiagram.com/achouvardas/elefthero
- Repository: https://github.com/achouvardas/elefthero

## Overview

#### Purpose and runtime

Elefthero is a self-hosted Greek small-business invoicing system that creates invoices, validates business/customer data, submits myDATA XML to AADE, and preserves submission evidence. The application is a Python/Flask server, principally entered through `app.py`, rendering server-side HTML from `templates/`. SQLite is the local system of record; no frontend build pipeline is present.

#### Application boundary and UI

`app.py` is the central application boundary: it serves setup, authentication, settings, invoices, clients, templates, logs, and administration. Browser workflows are server-rendered through shared layout and feature pages such as `templates/base.html`, `templates/invoice_form.html`, and `templates/dashboard.html`. The first-run setup path is represented by `templates/setup.html`; subsequent configuration is managed through authenticated settings pages.

#### Identity, setup, and operational security

First-run setup establishes the local business and administrator context. Authentication supports login, roles, optional TOTP challenge/enrollment, rate limiting, CSRF protection, and optional Turnstile. Relevant UI boundaries are `templates/login.html`, `templates/two_factor_setup.html`, and `templates/users.html`. Secrets for AADE and optional integrations are configured in-app and encrypted locally; bootstrap/runtime environment values are exemplified in `.env.example`.

#### Invoice lifecycle and myDATA submission

The core control flow is invoice draft creation/editing, validation of document/VAT/classification/payment rules, myDATA XML construction, and explicit Test or Production AADE REST submission. AADE results—MARK, UID, QR URL, response payload, and failures—feed back into the invoice record and audit trail. Invoice list/detail/form paths are grounded in `templates/invoices.html`, `templates/invoice_detail.html`, and `templates/invoice_form.html`. Cancellation, credit-document reuse, templates, and resend operate on this persisted invoice lifecycle.

#### Records, auditability, and outputs

SQLite retains business data, clients, invoices, configuration, and inspectable sent/received AADE XML. Developer-facing submission/audit history is exposed at `templates/logs.html`, while invoice delivery artifacts are rendered as inline PDFs and can be resent through Resend. PDF generation uses ReportLab; XML and AADE identifiers remain associated with invoice detail rather than being delegated to an opaque external platform.

#### Client and reporting domain

Client records support saved counterparties, addresses, VIES VAT validation, and optional ΓΕΜΗ enrichment before invoice use. Client management and analytical views are represented by `templates/clients.html` and `templates/client_invoices.html`. Dashboard aggregation and customer/invoice statistics are surfaced through `templates/dashboard.html`; reusable invoice patterns are managed at `templates/templates.html`.

#### Deployment and external infrastructure

Production is intended to run Flask behind Gunicorn under systemd, with Cloudflare Tunnel exposing the service rather than requiring a separate web application tier. Service definitions are `deploy/systemd/myaade.service` and `deploy/systemd/myaade-cloudflared.service`; tunnel configuration is based on `cloudflared/config.example.yml` and `scripts/run-tunnel.sh`. External boundaries are AADE myDATA REST/XML, VIES, optional ΓΕΜΗ, Resend email, optional Cloudflare Turnstile, and Cloudflare Tunnel.

Main entry points: [`app.py`](https://github.com/achouvardas/elefthero/blob/main/app.py) (Flask routes), [`deploy/systemd/myaade.service`](https://github.com/achouvardas/elefthero/blob/main/deploy/systemd/myaade.service) (Gunicorn / systemd), [`deploy/systemd/myaade-cloudflared.service`](https://github.com/achouvardas/elefthero/blob/main/deploy/systemd/myaade-cloudflared.service) (Cloudflare Tunnel), [`templates/base.html`](https://github.com/achouvardas/elefthero/blob/main/templates/base.html) (Shared layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Flask application"]
  node_flask["Flask routes<br/>Python server<br/>[app.py]"]
  node_auth{{"Setup &amp; access control<br/>security flow"}}
  node_invoice_lifecycle["Invoice lifecycle<br/>domain workflow"]
  node_mydata_builder["myDATA XML builder<br/>XML integration"]
  node_pdf_output["PDF output<br/>ReportLab renderer"]
end

subgraph group_ui["Server-rendered UI"]
  node_shared_ui["Shared layout<br/>HTML templates<br/>[base.html]"]
  node_invoice_ui["Invoice pages<br/>HTML templates<br/>[invoice_form.html]"]
  node_admin_ui["Setup, auth &amp; admin pages<br/>HTML templates<br/>[setup.html]"]
  node_dashboard_ui["Dashboard &amp; reporting<br/>HTML templates<br/>[dashboard.html]"]
  node_audit_logs["Submission audit history<br/>HTML templates<br/>[logs.html]"]
end

subgraph group_data["Local records"]
  node_sqlite[("SQLite system of record<br/>SQLite database")]
end

subgraph group_external["External services"]
  node_aade{{"AADE myDATA<br/>REST/XML service"}}
  node_vat_services{{"VIES &amp; ΓΕΜΗ<br/>business registries"}}
  node_resend{{"Resend<br/>email service"}}
  node_turnstile{{"Cloudflare Turnstile<br/>optional bot protection"}}
end

subgraph group_deploy["Deployment"]
  node_gunicorn["Gunicorn / systemd<br/>production runtime<br/>[myaade.service]"]
  node_cloudflare_tunnel["Cloudflare Tunnel<br/>ingress tunnel"]
end

node_browser(("Browser user"))

node_browser -->|"HTTPS access"| node_cloudflare_tunnel
node_cloudflare_tunnel -->|"forwards traffic"| node_gunicorn
node_gunicorn -->|"runs"| node_flask
node_browser -->|"server requests"| node_flask
node_flask -->|"applies"| node_auth
node_flask -->|"renders"| node_shared_ui
node_flask -->|"renders"| node_invoice_ui
node_flask -->|"renders"| node_admin_ui
node_flask -->|"renders"| node_dashboard_ui
node_flask -->|"renders"| node_audit_logs
node_flask -->|"drives"| node_invoice_lifecycle
node_invoice_lifecycle -->|"persists invoices and evidence"| node_sqlite
node_invoice_lifecycle -->|"validates and builds XML"| node_mydata_builder
node_mydata_builder -->|"submits Test or Production XML"| node_aade
node_aade -->|"MARK, UID, QR and responses"| node_sqlite
node_invoice_lifecycle -->|"renders invoice PDF"| node_pdf_output
node_invoice_lifecycle -->|"sends invoice email"| node_resend
node_flask -->|"validates/enriches clients"| node_vat_services
node_auth -->|"stores local context and encrypted secrets"| node_sqlite
node_auth -.->|"optional challenge"| node_turnstile

click node_flask "https://github.com/achouvardas/elefthero/blob/main/app.py"
click node_shared_ui "https://github.com/achouvardas/elefthero/blob/main/templates/base.html"
click node_invoice_ui "https://github.com/achouvardas/elefthero/blob/main/templates/invoice_form.html"
click node_admin_ui "https://github.com/achouvardas/elefthero/blob/main/templates/setup.html"
click node_dashboard_ui "https://github.com/achouvardas/elefthero/blob/main/templates/dashboard.html"
click node_audit_logs "https://github.com/achouvardas/elefthero/blob/main/templates/logs.html"
click node_gunicorn "https://github.com/achouvardas/elefthero/blob/main/deploy/systemd/myaade.service"
click node_cloudflare_tunnel "https://github.com/achouvardas/elefthero/blob/main/deploy/systemd/myaade-cloudflared.service"

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_flask,node_auth,node_invoice_lifecycle,node_mydata_builder,node_pdf_output toneBlue
class node_shared_ui,node_invoice_ui,node_admin_ui,node_dashboard_ui,node_audit_logs toneAmber
class node_sqlite toneMint
class node_aade,node_vat_services,node_resend,node_turnstile toneRose
class node_gunicorn,node_cloudflare_tunnel toneIndigo
class node_browser toneNeutral
```

## Components

### Flask application

- [Flask routes](https://github.com/achouvardas/elefthero/blob/main/app.py): Python server · Central setup, auth, invoicing, administration, and API boundary. · `app.py`
- **Setup & access control**: security flow · Establishes business/admin context and enforces roles, TOTP, CSRF, and rate limits.
- **Invoice lifecycle**: domain workflow · Draft, validate, submit, resend, cancel, and credit-document handling.
- **myDATA XML builder**: XML integration · Builds validated invoice XML and records submission outcomes.
- **PDF output**: ReportLab renderer · Renders invoice delivery artifacts inline.

### Server-rendered UI

- [Shared layout](https://github.com/achouvardas/elefthero/blob/main/templates/base.html): HTML templates · `templates/base.html`
- [Invoice pages](https://github.com/achouvardas/elefthero/blob/main/templates/invoice_form.html): HTML templates · Invoice list, detail, and editor pages. · `templates/invoice_form.html`
- [Setup, auth & admin pages](https://github.com/achouvardas/elefthero/blob/main/templates/setup.html): HTML templates · Includes setup, login, two-factor enrollment, and users. · `templates/setup.html`
- [Dashboard & reporting](https://github.com/achouvardas/elefthero/blob/main/templates/dashboard.html): HTML templates · `templates/dashboard.html`
- [Submission audit history](https://github.com/achouvardas/elefthero/blob/main/templates/logs.html): HTML templates · Inspectable sent/received XML and submission history. · `templates/logs.html`

### Local records

- **SQLite system of record**: SQLite database · Stores business, clients, invoices, encrypted settings, XML, and audit evidence.

### External services

- **AADE myDATA**: REST/XML service · Test and Production invoice submission endpoint.
- **VIES & ΓΕΜΗ**: business registries · VAT validation and optional client enrichment.
- **Resend**: email service
- **Cloudflare Turnstile**: optional bot protection

### Deployment

- [Gunicorn / systemd](https://github.com/achouvardas/elefthero/blob/main/deploy/systemd/myaade.service): production runtime · `deploy/systemd/myaade.service`
- [Cloudflare Tunnel](https://github.com/achouvardas/elefthero/blob/main/deploy/systemd/myaade-cloudflared.service): ingress tunnel · `deploy/systemd/myaade-cloudflared.service`

### Other components

- **Browser user**: user

## Connections

- Browser user → Cloudflare Tunnel: HTTPS access
- Cloudflare Tunnel → Gunicorn / systemd: forwards traffic
- Gunicorn / systemd → Flask routes: runs
- Browser user → Flask routes: server requests
- Flask routes → Setup & access control: applies
- Flask routes → Shared layout: renders
- Flask routes → Invoice pages: renders
- Flask routes → Setup, auth & admin pages: renders
- Flask routes → Dashboard & reporting: renders
- Flask routes → Submission audit history: renders
- Flask routes → Invoice lifecycle: drives
- Invoice lifecycle → SQLite system of record: persists invoices and evidence
- Invoice lifecycle → myDATA XML builder: validates and builds XML
- myDATA XML builder → AADE myDATA: submits Test or Production XML
- AADE myDATA → SQLite system of record: MARK, UID, QR and responses
- Invoice lifecycle → PDF output: renders invoice PDF
- Invoice lifecycle → Resend: sends invoice email
- Flask routes → VIES & ΓΕΜΗ: validates/enriches clients
- Setup & access control → SQLite system of record: stores local context and encrypted secrets
- Setup & access control → Cloudflare Turnstile: optional challenge
