# a-amin-gabr/note-taking-app architecture

> Architecture diagram of the GitHub repository a-amin-gabr/note-taking-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/a-amin-gabr/note-taking-app
- Repository: https://github.com/a-amin-gabr/note-taking-app

## Overview

1. **System shape**
   - This is a classic server-rendered Flask application with a browser-based UI, a MariaDB relational backend, and optional AWS integrations. The main runtime path is: browser → Nginx → Gunicorn → Flask app → MariaDB / AWS services.

2. **Backend application boundary**
   - `app.py` is the central orchestration layer. It contains the HTTP routes, note/category/profile operations, JSON APIs, markdown preview, import/export, attachment handling, and sharing logic.
   - `auth.py` is a separate authentication boundary for AWS Cognito plus guest-mode fallback, keeping login/session concerns isolated from note CRUD logic.

3. **Presentation layer**
   - The UI is server-rendered with Jinja templates in `templates/` (`index.html`, `login.html`, `profile.html`, `categories.html`, `shared.html`).
   - `static/app.js` adds client-side behavior such as modals, search, keyboard shortcuts, theme toggling, and async interactions with JSON endpoints.
   - Styling is split across `static/style.css`, `static/attachment-styles.css`, and `static/icons.css`.

4. **Primary user flows**
   - Authenticated or guest users land on `/` for the dashboard, where they create/edit/delete notes, pin/archive them, and manage categories.
   - The app exposes JSON endpoints for note details, stats, markdown preview, and share-token management, which the frontend likely calls via fetch/XHR instead of full-page reloads.

5. **Data model and persistence**
   - `schema.sql` defines four core tables: `users`, `categories`, `notes`, and `attachments`.
   - The schema enforces relationships from users to categories and notes, notes to attachments, and a nullable category reference on notes. A trigger auto-creates default categories for new users.
   - MariaDB is the authoritative store for all note metadata, content, share state, profile data, and attachment references.

6. **Authentication and identity**
   - AWS Cognito is the preferred identity provider, used through hosted UI/session-based login.
   - If Cognito is not configured, the app falls back to guest mode while still preserving full note functionality. This makes auth an optional external dependency rather than a hard runtime requirement.

7. **File attachment subsystem**
   - Attachments are uploaded per note and referenced in the database. The app supports AWS S3 as the storage target, with local storage fallback when S3 is unavailable or unconfigured.
   - This creates a two-part attachment path: metadata in MariaDB, file blobs in S3 or local disk.

8. **Sharing and public access**
   - Notes can be published through unique share tokens exposed at `/shared/<token>`.
   - The shared-note view is intentionally separate from the authenticated dashboard, which is important for diagramming a public read-only access boundary.

9. **Import/export and markdown rendering**
   - Export/import endpoints let users move notes in and out as JSON or plain text, which is a data interchange layer distinct from the normal CRUD flow.
   - Markdown preview is handled server-side through `/api/preview-markdown`, so rendered HTML is generated by Flask rather than entirely in the browser.

10. **Profile and organization features**
   - Profile management stores display name, bio, avatar, and timezone preferences.
   - Categories are per-user organizational metadata with color coding, and the UI exposes a dedicated management page for them.

11. **Deployment runtime**
   - Production deployment is designed for RHEL 10 on EC2: Nginx is the public edge, Gunicorn hosts Flask, and the app runs as a systemd service defined in `notes-app.service`.
   - `deploy.sh` and the `scripts/` directory break setup into discrete infrastructure steps: OS dependencies, database setup, app environment, systemd, Nginx, backup volume preparation, and backup scheduling.

12. **Backup and restore**
   - `backup.sh` performs daily MariaDB dumps, compressed and stored on a dedicated EBS-mounted backup volume under `/backup`.
   - `restore.sh` is an operational recovery path that can restore from selected backups and creates a safety backup first, so backup/restore is a separate operational subsystem worth showing in the architecture.

13. **Important boundaries to draw**
   - Separate the browser UI from the Flask backend.
   - Separate Flask from external services: MariaDB, Cognito, and S3.
   - Separate authenticated app usage from public shared-note access.
   - Separate primary application data from backup storage on EBS.

Main entry points: [`app.py`](https://github.com/a-amin-gabr/note-taking-app/blob/main/app.py) (Flask app), [`schema.sql`](https://github.com/a-amin-gabr/note-taking-app/blob/main/schema.sql) (MariaDB), [`deploy.sh`](https://github.com/a-amin-gabr/note-taking-app/blob/main/deploy.sh) (Deploy script), [`notes-app.service`](https://github.com/a-amin-gabr/note-taking-app/blob/main/notes-app.service) (Gunicorn)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_browser(("Browser<br/>client"))
  node_nginx["Nginx<br/>edge proxy"]
  node_gunicorn["Gunicorn<br/>app server<br/>[notes-app.service]"]
  node_templates["Jinja UI<br/>server templates<br/>[index.html]"]
  node_static["Client assets<br/>JS/CSS<br/>[app.js]"]
end

subgraph group_application["Application"]
  node_appcore["Flask app<br/>routes & workflows<br/>[app.py]"]
  node_auth["Auth boundary<br/>login/session<br/>[auth.py]"]
  node_crud{{"Notes CRUD<br/>workspace flow"}}
  node_preview{{"Markdown preview<br/>rendering API"}}
  node_sharing{{"Shared notes<br/>public access"}}
  node_importexport{{"Import/Export<br/>data interchange"}}
  node_profilecats{{"Profile & categories<br/>organization"}}
end

subgraph group_data["Data & Integrations"]
  node_mariadb[("MariaDB<br/>relational store<br/>[schema.sql]")]
  node_schema["Schema<br/>DDL<br/>[schema.sql]"]
  node_cognito(("Cognito<br/>identity provider"))
  node_s3[("S3 storage<br/>object storage")]
  node_backupvol[("Backup volume<br/>EBS storage")]
end

subgraph group_ops["Operations"]
  node_deploy["Deploy script<br/>provisioning<br/>[deploy.sh]"]
  node_scripts["Setup scripts<br/>install & config<br/>[01_install_deps.sh]"]
  node_backup["Backup<br/>ops script<br/>[backup.sh]"]
  node_restore["Restore<br/>recovery script<br/>[restore.sh]"]
  node_service["Systemd service<br/>runtime unit<br/>[notes-app.service]"]
end

node_browser -->|"HTTP"| node_nginx
node_nginx -->|"proxy"| node_gunicorn
node_gunicorn -->|"WSGI"| node_appcore
node_appcore -->|"render"| node_templates
node_appcore -->|"assets"| node_static
node_static -.->|"fetch"| node_appcore
node_appcore -->|"core flow"| node_crud
node_appcore -->|"api"| node_preview
node_appcore -->|"public view"| node_sharing
node_appcore -->|"data exchange"| node_importexport
node_appcore -->|"settings"| node_profilecats
node_appcore -->|"session"| node_auth
node_auth -->|"login"| node_cognito
node_appcore -->|"read/write"| node_mariadb
node_schema -->|"defines"| node_mariadb
node_appcore -->|"attachments"| node_s3
node_mariadb -->|"dump"| node_backupvol
node_deploy -->|"orchestrates"| node_scripts
node_deploy -->|"installs"| node_service
node_backup -->|"stores"| node_backupvol
node_restore -->|"reads"| node_backupvol
node_scripts -->|"configures"| node_service

click node_gunicorn "https://github.com/a-amin-gabr/note-taking-app/blob/main/notes-app.service"
click node_templates "https://github.com/a-amin-gabr/note-taking-app/blob/main/templates/index.html"
click node_static "https://github.com/a-amin-gabr/note-taking-app/blob/main/static/app.js"
click node_appcore "https://github.com/a-amin-gabr/note-taking-app/blob/main/app.py"
click node_auth "https://github.com/a-amin-gabr/note-taking-app/blob/main/auth.py"
click node_mariadb "https://github.com/a-amin-gabr/note-taking-app/blob/main/schema.sql"
click node_schema "https://github.com/a-amin-gabr/note-taking-app/blob/main/schema.sql"
click node_deploy "https://github.com/a-amin-gabr/note-taking-app/blob/main/deploy.sh"
click node_scripts "https://github.com/a-amin-gabr/note-taking-app/blob/main/scripts/01_install_deps.sh"
click node_backup "https://github.com/a-amin-gabr/note-taking-app/blob/main/backup.sh"
click node_restore "https://github.com/a-amin-gabr/note-taking-app/blob/main/restore.sh"
click node_service "https://github.com/a-amin-gabr/note-taking-app/blob/main/notes-app.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_browser,node_nginx,node_gunicorn,node_templates,node_static toneBlue
class node_appcore,node_auth,node_crud,node_preview,node_sharing,node_importexport,node_profilecats toneAmber
class node_mariadb,node_schema,node_cognito,node_s3,node_backupvol toneMint
class node_deploy,node_scripts,node_backup,node_restore,node_service toneRose
```

## Components

### Presentation

Browser-facing UI and assets

- **Browser**: client · User-facing web client
- **Nginx**: edge proxy · Public HTTP entry point
- [Gunicorn](https://github.com/a-amin-gabr/note-taking-app/blob/main/notes-app.service): app server · WSGI process hosting Flask · `notes-app.service`
- [Jinja UI](https://github.com/a-amin-gabr/note-taking-app/blob/main/templates/index.html): server templates · Rendered pages for dashboard, login, profile, categories, and shared note view · `templates/index.html`
- [Client assets](https://github.com/a-amin-gabr/note-taking-app/blob/main/static/app.js): JS/CSS · Browser behavior and styling for the web UI · `static/app.js`

### Application

Flask request handling and app workflows

- [Flask app](https://github.com/a-amin-gabr/note-taking-app/blob/main/app.py): routes & workflows · Main HTTP orchestration for notes, categories, profiles, sharing, preview, and import/export · `app.py`
- [Auth boundary](https://github.com/a-amin-gabr/note-taking-app/blob/main/auth.py): login/session · Cognito login with guest-mode fallback · `auth.py`
- **Notes CRUD**: workspace flow · Create, edit, delete, pin, archive, and list notes
- **Markdown preview**: rendering API · Server-side markdown-to-HTML preview endpoint
- **Shared notes**: public access · Token-based read-only shared note view
- **Import/Export**: data interchange · Move notes in and out as JSON or plain text
- **Profile & categories**: organization · Profile fields and per-user category management

### Data & Integrations

Database, identity, storage, and shared-note access

- [MariaDB](https://github.com/a-amin-gabr/note-taking-app/blob/main/schema.sql): relational store · Authoritative persistence for users, categories, notes, and attachments · `schema.sql`
- [Schema](https://github.com/a-amin-gabr/note-taking-app/blob/main/schema.sql): DDL · Table definitions, relationships, and default category trigger · `schema.sql`
- **Cognito**: identity provider · Optional hosted login and session identity source
- **S3 storage**: object storage · Optional attachment blob storage
- **Backup volume**: EBS storage · Dedicated /backup volume for compressed database dumps

### Operations

Deployment, backup, and restore tooling

- [Deploy script](https://github.com/a-amin-gabr/note-taking-app/blob/main/deploy.sh): provisioning · Main deployment entrypoint for environment setup · `deploy.sh`
- [Setup scripts](https://github.com/a-amin-gabr/note-taking-app/blob/main/scripts/01_install_deps.sh): install & config · Stepwise server, database, app, nginx, and backup setup · `scripts/01_install_deps.sh`
- [Backup](https://github.com/a-amin-gabr/note-taking-app/blob/main/backup.sh): ops script · Daily MariaDB dump and compression workflow · `backup.sh`
- [Restore](https://github.com/a-amin-gabr/note-taking-app/blob/main/restore.sh): recovery script · Operational restore path with safety backup · `restore.sh`
- [Systemd service](https://github.com/a-amin-gabr/note-taking-app/blob/main/notes-app.service): runtime unit · Service definition for running the Flask app under Gunicorn · `notes-app.service`

## Connections

- Browser → Nginx: HTTP · User traffic enters the public edge
- Nginx → Gunicorn: proxy · Nginx forwards requests to the application server
- Gunicorn → Flask app: WSGI · Gunicorn hosts the Flask application
- Flask app → Jinja UI: render · Server-rendered pages are produced from Jinja templates
- Flask app → Client assets: assets · Frontend code and styles support interactive UI
- Client assets → Flask app: fetch · Client-side interactions call JSON endpoints
- Flask app → Notes CRUD: core flow · Main dashboard actions operate on notes
- Flask app → Markdown preview: api · Markdown preview is exposed as a server endpoint
- Flask app → Shared notes: public view · Shared-note access is separated from authenticated usage
- Flask app → Import/Export: data exchange · Import and export endpoints move note data in and out
- Flask app → Profile & categories: settings · Profile and category management live in the app boundary
- Flask app → Auth boundary: session · Authentication gates the app while allowing guest fallback
- Auth boundary → Cognito: login · Preferred identity provider for hosted login
- Flask app → MariaDB: read/write · Application state is persisted in MariaDB
- Schema → MariaDB: defines · DDL describes the relational model used by the database
- Flask app → S3 storage: attachments · Attachment blobs can be stored in object storage
- MariaDB → Backup volume: dump · Database backups are written to dedicated backup storage
- Deploy script → Setup scripts: orchestrates · Deployment is broken into setup stages
- Deploy script → Systemd service: installs · Deployment configures the systemd runtime unit
- Backup → Backup volume: stores · Compressed backups are placed on the EBS-mounted volume
- Restore → Backup volume: reads · Restore selects backups from the backup volume
- Setup scripts → Systemd service: configures · Setup scripts provision the runtime service
