# youssefontys/secure-application architecture

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

- Interactive diagram: https://gitdiagram.com/youssefontys/secure-application
- Repository: https://github.com/youssefontys/secure-application

## Overview

This repository is a secure notes web application, with account registration and password login, optional TOTP two-factor authentication, account management, and private encrypted notes. A browser request enters the Flask app, which applies CSRF checks and dispatches to authentication, account, or notes handlers; those handlers use shared security services and PostgreSQL. The app also emits security events. Separate user-facing scripts support local or Azure deployment and teardown. Relationships among sampled app modules are supported by excerpts and the SOURCE INDEX; deployment capabilities are partly documented in the README, so unsampled internals are not expanded.

Main entry points: [`app/auth.py`](https://github.com/youssefontys/secure-application/blob/main/app/auth.py) (Authentication), [`app/account.py`](https://github.com/youssefontys/secure-application/blob/main/app/account.py) (Account management), [`app/app.py`](https://github.com/youssefontys/secure-application/blob/main/app/app.py) (Flask app), [`app/db.py`](https://github.com/youssefontys/secure-application/blob/main/app/db.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_flask["Flask app<br/>[app.py]"]
  node_pages["Web pages"]
  node_auth["Authentication<br/>[auth.py]"]
  node_account["Account management<br/>[account.py]"]
  node_notes["Notes<br/>[notes.py]"]
end

subgraph group_security["Security services"]
  node_csrf["CSRF protection<br/>[csrf.py]"]
  node_passwords["Password rules<br/>[passwords.py]"]
  node_throttle["Login throttling<br/>[throttle.py]"]
  node_totp["TOTP<br/>[totp.py]"]
  node_encryption["Data encryption<br/>[encryption.py]"]
end

subgraph group_storage["Persistence and events"]
  node_dbhelper["Database access<br/>[db.py]"]
  node_database[("PostgreSQL<br/>[schema.sql]")]
  node_events["Security events<br/>[events.py]"]
end

subgraph group_operations["Deployment operations"]
  node_deploy["Deployment CLI<br/>[deployment.py]"]
  node_local["Local deployment<br/>[deploy_local.py]"]
  node_azure["Azure deployment<br/>[deploy_azure.py]"]
  node_bootstrap["Azure bootstrap<br/>[setup_azure.py]"]
  node_undo["Teardown<br/>[undo.py]"]
  node_compose["Compose stack<br/>[compose.yaml]"]
  node_terraform["Azure resources"]
end

node_visitor(("Visitor"))
node_authenticator["Authenticator app"]

node_visitor -->|"uses"| node_flask
node_flask -->|"checks requests"| node_csrf
node_flask -->|"registers routes"| node_auth
node_flask -->|"registers routes"| node_account
node_flask -->|"registers routes"| node_notes
node_flask -->|"renders"| node_pages
node_auth -->|"queries"| node_dbhelper
node_auth -->|"checks passwords"| node_passwords
node_auth -->|"limits attempts"| node_throttle
node_auth -->|"checks codes"| node_totp
node_auth -->|"uses"| node_encryption
node_auth -->|"records events"| node_events
node_account -->|"queries"| node_dbhelper
node_account -->|"encrypts secrets"| node_encryption
node_account -->|"checks passwords"| node_passwords
node_account -->|"limits attempts"| node_throttle
node_account -->|"uses codes"| node_totp
node_account -->|"records events"| node_events
node_notes -->|"queries"| node_dbhelper
node_notes -->|"seals notes"| node_encryption
node_notes -->|"records events"| node_events
node_throttle -->|"stores limits"| node_dbhelper
node_dbhelper -->|"queries"| node_database
node_authenticator -->|"provides codes"| node_auth
node_deploy -->|"starts"| node_local
node_deploy -->|"starts"| node_azure
node_deploy -->|"starts"| node_undo
node_local -->|"starts stack"| node_compose
node_azure -->|"runs if needed"| node_bootstrap
node_azure -->|"applies resources"| node_terraform
node_undo -->|"destroys resources"| node_terraform

click node_flask "https://github.com/youssefontys/secure-application/blob/main/app/app.py"
click node_pages "https://github.com/youssefontys/secure-application/tree/main/app/web/templates"
click node_auth "https://github.com/youssefontys/secure-application/blob/main/app/auth.py"
click node_account "https://github.com/youssefontys/secure-application/blob/main/app/account.py"
click node_notes "https://github.com/youssefontys/secure-application/blob/main/app/notes.py"
click node_csrf "https://github.com/youssefontys/secure-application/blob/main/app/csrf.py"
click node_passwords "https://github.com/youssefontys/secure-application/blob/main/app/passwords.py"
click node_throttle "https://github.com/youssefontys/secure-application/blob/main/app/throttle.py"
click node_totp "https://github.com/youssefontys/secure-application/blob/main/app/totp.py"
click node_encryption "https://github.com/youssefontys/secure-application/blob/main/app/encryption.py"
click node_dbhelper "https://github.com/youssefontys/secure-application/blob/main/app/db.py"
click node_database "https://github.com/youssefontys/secure-application/blob/main/db/schema.sql"
click node_events "https://github.com/youssefontys/secure-application/blob/main/app/events.py"
click node_deploy "https://github.com/youssefontys/secure-application/blob/main/scripts/deployment.py"
click node_local "https://github.com/youssefontys/secure-application/blob/main/scripts/deploy_local.py"
click node_azure "https://github.com/youssefontys/secure-application/blob/main/scripts/deploy_azure.py"
click node_bootstrap "https://github.com/youssefontys/secure-application/blob/main/scripts/setup_azure.py"
click node_undo "https://github.com/youssefontys/secure-application/blob/main/scripts/undo.py"
click node_compose "https://github.com/youssefontys/secure-application/blob/main/compose.yaml"
click node_terraform "https://github.com/youssefontys/secure-application/tree/main/terraform"

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_pages,node_auth,node_account,node_notes toneBlue
class node_csrf,node_passwords,node_throttle,node_totp,node_encryption toneAmber
class node_dbhelper,node_database,node_events toneMint
class node_deploy,node_local,node_azure,node_bootstrap,node_undo,node_compose,node_terraform toneRose
class node_visitor,node_authenticator toneIndigo
```

## Components

### Web application

- [Flask app](https://github.com/youssefontys/secure-application/blob/main/app/app.py): `app/app.py`
- [Web pages](https://github.com/youssefontys/secure-application/tree/main/app/web/templates): `app/web/templates`
- [Authentication](https://github.com/youssefontys/secure-application/blob/main/app/auth.py): `app/auth.py`
- [Account management](https://github.com/youssefontys/secure-application/blob/main/app/account.py): `app/account.py`
- [Notes](https://github.com/youssefontys/secure-application/blob/main/app/notes.py): `app/notes.py`

### Security services

- [CSRF protection](https://github.com/youssefontys/secure-application/blob/main/app/csrf.py): `app/csrf.py`
- [Password rules](https://github.com/youssefontys/secure-application/blob/main/app/passwords.py): `app/passwords.py`
- [Login throttling](https://github.com/youssefontys/secure-application/blob/main/app/throttle.py): `app/throttle.py`
- [TOTP](https://github.com/youssefontys/secure-application/blob/main/app/totp.py): `app/totp.py`
- [Data encryption](https://github.com/youssefontys/secure-application/blob/main/app/encryption.py): `app/encryption.py`

### Persistence and events

- [Database access](https://github.com/youssefontys/secure-application/blob/main/app/db.py): `app/db.py`
- [PostgreSQL](https://github.com/youssefontys/secure-application/blob/main/db/schema.sql): `db/schema.sql`
- [Security events](https://github.com/youssefontys/secure-application/blob/main/app/events.py): `app/events.py`

### Deployment operations

- [Deployment CLI](https://github.com/youssefontys/secure-application/blob/main/scripts/deployment.py): `scripts/deployment.py`
- [Local deployment](https://github.com/youssefontys/secure-application/blob/main/scripts/deploy_local.py): `scripts/deploy_local.py`
- [Azure deployment](https://github.com/youssefontys/secure-application/blob/main/scripts/deploy_azure.py): `scripts/deploy_azure.py`
- [Azure bootstrap](https://github.com/youssefontys/secure-application/blob/main/scripts/setup_azure.py): `scripts/setup_azure.py`
- [Teardown](https://github.com/youssefontys/secure-application/blob/main/scripts/undo.py): `scripts/undo.py`
- [Compose stack](https://github.com/youssefontys/secure-application/blob/main/compose.yaml): `compose.yaml`
- [Azure resources](https://github.com/youssefontys/secure-application/tree/main/terraform): `terraform`

### Other components

- **Visitor**
- **Authenticator app**

## Connections

- Visitor → Flask app: uses (evidence: `README.md`)
- Flask app → CSRF protection: checks requests (evidence: `app/app.py`)
- Flask app → Authentication: registers routes (evidence: `app/app.py`)
- Flask app → Account management: registers routes (evidence: `app/app.py`)
- Flask app → Notes: registers routes (evidence: `app/app.py`)
- Flask app → Web pages: renders (evidence: `README.md`)
- Authentication → Database access: queries (evidence: `app/auth.py`)
- Authentication → Password rules: checks passwords (evidence: `app/auth.py`)
- Authentication → Login throttling: limits attempts (evidence: `app/auth.py`)
- Authentication → TOTP: checks codes (evidence: `app/auth.py`)
- Authentication → Data encryption: uses (evidence: `app/auth.py`)
- Authentication → Security events: records events (evidence: `app/auth.py`)
- Account management → Database access: queries (evidence: `app/account.py`)
- Account management → Data encryption: encrypts secrets (evidence: `app/account.py`)
- Account management → Password rules: checks passwords (evidence: `app/account.py`)
- Account management → Login throttling: limits attempts (evidence: `app/account.py`)
- Account management → TOTP: uses codes (evidence: `app/account.py`)
- Account management → Security events: records events (evidence: `app/account.py`)
- Notes → Database access: queries (evidence: `app/notes.py`)
- Notes → Data encryption: seals notes (evidence: `app/notes.py`)
- Notes → Security events: records events (evidence: `app/notes.py`)
- Login throttling → Database access: stores limits (evidence: `app/throttle.py`)
- Database access → PostgreSQL: queries (evidence: `app/db.py`)
- Authenticator app → Authentication: provides codes (evidence: `README.md`)
- Deployment CLI → Local deployment: starts (evidence: `scripts/deployment.py`)
- Deployment CLI → Azure deployment: starts (evidence: `scripts/deployment.py`)
- Deployment CLI → Teardown: starts (evidence: `scripts/deployment.py`)
- Local deployment → Compose stack: starts stack (evidence: `README.md`)
- Azure deployment → Azure bootstrap: runs if needed (evidence: `scripts/deploy_azure.py`)
- Azure deployment → Azure resources: applies resources (evidence: `scripts/deploy_azure.py`)
- Teardown → Azure resources: destroys resources (evidence: `scripts/undo.py`)
