How a-amin-gabr/note-taking-app works
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 Flask app · schema.sql MariaDB · deploy.sh Deploy script · notes-app.service Gunicorn
Components 22
Presentation
Browser-facing UI and assets
- Browser · User-facing web client
- Nginx · Public HTTP entry point
- Gunicorn · WSGI process hosting Flask
notes-app.service - Jinja UI · Rendered pages for dashboard, login, profile, categories, and shared note view
templates/index.html - Client assets · Browser behavior and styling for the web UI
static/app.js
Application
Flask request handling and app workflows
- Flask app · Main HTTP orchestration for notes, categories, profiles, sharing, preview, and import/export
app.py - Auth boundary · Cognito login with guest-mode fallback
auth.py - Notes CRUD · Create, edit, delete, pin, archive, and list notes
- Markdown preview · Server-side markdown-to-HTML preview endpoint
- Shared notes · Token-based read-only shared note view
- Import/Export · Move notes in and out as JSON or plain text
- Profile & categories · Profile fields and per-user category management
Data & Integrations
Database, identity, storage, and shared-note access
- MariaDB · Authoritative persistence for users, categories, notes, and attachments
schema.sql - Schema · Table definitions, relationships, and default category trigger
schema.sql - Cognito · Optional hosted login and session identity source
- S3 storage · Optional attachment blob storage
- Backup volume · Dedicated /backup volume for compressed database dumps
Operations
Deployment, backup, and restore tooling
- Deploy script · Main deployment entrypoint for environment setup
deploy.sh - Setup scripts · Stepwise server, database, app, nginx, and backup setup
scripts/01_install_deps.sh - Backup · Daily MariaDB dump and compression workflow
backup.sh - Restore · Operational restore path with safety backup
restore.sh - Systemd service · Service definition for running the Flask app under Gunicorn
notes-app.service
Connections 22
- 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