# amarkumar-verma-br/note-app architecture

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

- Interactive diagram: https://gitdiagram.com/amarkumar-verma-br/note-app
- Repository: https://github.com/amarkumar-verma-br/note-app

## Overview

#### Purpose and Entry Point
This repository is a Python/FastAPI backend for authenticated note management: CRUD notes, tag/title search, soft deletion, and file attachments. The ASGI entry point is `note_app/app/main.py`, started as `uvicorn app.main:app --reload`.

#### HTTP API Composition
Route modules expose the service boundary:
- Authentication registration/login and token-oriented flows: `note_app/app/routes/auth.py`
- Protected note CRUD, search, pagination/limits, soft delete, and multipart attachment handling: `note_app/app/routes/notes.py`
- Current-user or user-facing operations: `note_app/app/routes/users.py`

`note_app/app/main.py` assembles these routers into the FastAPI application.

#### Identity and Authorization Boundary
Keycloak is the external identity provider. Auth endpoints communicate with Keycloak, while protected routes validate bearer JWTs through the application security layer. Keycloak-specific settings and request/response contracts are isolated in:
- `note_app/app/core/keyclock_config.py`
- `note_app/app/core/security.py`
- `note_app/app/schemas/keyclock.py`

This separates application-owned note data from externally managed credentials, user registration, token issuance, and role-based authorization.

#### Domain and Persistence Layer
SQLAlchemy models define the persistent domain:
- Notes and their tags/status fields: `note_app/app/models/note.py`
- Uploaded-file metadata and note association: `note_app/app/models/attachment.py`
- Local user representation/linkage: `note_app/app/models/user.py`

Database engine/session lifecycle is centralized in `note_app/app/db/session.py`, with model metadata/base setup in `note_app/app/db/base.py`. Routes translate HTTP input through Pydantic schemas before operating on these models, notably `note_app/app/schemas/note.py` and `note_app/app/schemas/user.py`.

#### Note Lifecycle and Query Flow
An authenticated request reaches `routes/notes.py`, is authorized via the security dependency, then uses a database session to create, retrieve, update, search, or soft-delete only the caller’s relevant note records. Search filters title and tags; list/search support offset/limit. Soft deletion is a data-state transition rather than physical row removal, reflected by schema evolution in `note_app/alembic/versions/90b57f1760ef_added_softdelete_and_attachment.py`.

#### Attachment Storage Boundary
Attachment metadata belongs in PostgreSQL through the attachment model, while file object storage is abstracted behind a MinIO-compatible Boto3 client:
- `note_app/app/minio/boto3_client.py`
- `note_app/app/models/attachment.py`
- `note_app/app/routes/notes.py`

MinIO is optional infrastructure; the repository also contains `note_app/uploads/`, suggesting local upload-related support or experimentation.

#### Configuration, Migrations, and Runtime Dependencies
Environment-driven settings are loaded from `note_app/app/core/config.py` (with `note_app/.env` present locally). Material services are PostgreSQL, Keycloak, and optionally MinIO/S3-compatible storage. Alembic owns relational schema versioning through `note_app/alembic/env.py` and migration history under `note_app/alembic/versions/`; the initial schema is `note_app/alembic/versions/96abb5c3e11f_initial_tables.py`.

Main entry points: [`note_app/app/routes/notes.py`](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/notes.py) (Note routes), [`note_app/app/main.py`](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/main.py) (FastAPI application), [`note_app/alembic/env.py`](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/env.py) (Alembic migrations), [`note_app/app/routes/auth.py`](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/auth.py) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["FastAPI API"]
  node_app["FastAPI application<br/>ASGI entry point<br/>[main.py]"]
  node_auth_routes["Auth routes<br/>HTTP routes<br/>[auth.py]"]
  node_note_routes["Note routes<br/>protected HTTP routes<br/>[notes.py]"]
  node_user_routes["User routes<br/>HTTP routes<br/>[users.py]"]
  node_note_schemas["Note schemas<br/>Pydantic schemas<br/>[note.py]"]
  node_user_schemas["User schemas<br/>Pydantic schemas<br/>[user.py]"]
end

subgraph group_identity["Identity"]
  node_security["JWT security<br/>authorization dependency<br/>[security.py]"]
  node_keycloak_config["Keycloak integration<br/>identity configuration<br/>[keyclock_config.py]"]
  node_keycloak_schemas["Keycloak contracts<br/>Pydantic schemas<br/>[keyclock.py]"]
  node_keycloak{{"Keycloak<br/>external identity provider"}}
end

subgraph group_data["Data &amp; storage"]
  node_note_model[("Notes<br/>SQLAlchemy model<br/>[note.py]")]
  node_attachment_model[("Attachments<br/>SQLAlchemy model<br/>[attachment.py]")]
  node_user_model[("Local users<br/>SQLAlchemy model<br/>[user.py]")]
  node_db_session["Database sessions<br/>SQLAlchemy session lifecycle<br/>[session.py]"]
  node_postgres[("PostgreSQL<br/>relational database")]
  node_object_storage{{"MinIO/S3 storage<br/>object storage"}}
  node_boto_client["Boto3 storage client<br/>object storage adapter<br/>[boto3_client.py]"]
end

subgraph group_schema["Schema evolution"]
  node_alembic["Alembic migrations<br/>schema migration runner<br/>[env.py]"]
  node_initial_migration["Initial tables<br/>Alembic migration"]
  node_soft_delete_migration["Soft-delete migration<br/>Alembic migration"]
end

node_app -->|"mounts"| node_auth_routes
node_app -->|"mounts"| node_note_routes
node_app -->|"mounts"| node_user_routes
node_auth_routes -->|"uses"| node_keycloak_config
node_auth_routes -->|"uses"| node_keycloak_schemas
node_keycloak_config -->|"connects to"| node_keycloak
node_note_routes -->|"authorizes via"| node_security
node_security -->|"validates JWTs against"| node_keycloak
node_note_routes -->|"validates payloads"| node_note_schemas
node_user_routes -->|"validates payloads"| node_user_schemas
node_note_routes -->|"uses"| node_db_session
node_user_routes -->|"uses"| node_db_session
node_db_session -->|"connects to"| node_postgres
node_note_routes -->|"creates, queries, updates"| node_note_model
node_note_routes -->|"records metadata"| node_attachment_model
node_note_model -->|"associates"| node_attachment_model
node_note_routes -->|"uploads attachments"| node_boto_client
node_boto_client -->|"stores objects"| node_object_storage
node_note_model -->|"persists"| node_postgres
node_attachment_model -->|"persists"| node_postgres
node_user_model -->|"persists"| node_postgres
node_alembic -->|"runs"| node_initial_migration
node_alembic -->|"runs"| node_soft_delete_migration
node_alembic -->|"migrates"| node_postgres

click node_app "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/main.py"
click node_auth_routes "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/auth.py"
click node_note_routes "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/notes.py"
click node_user_routes "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/users.py"
click node_security "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/core/security.py"
click node_keycloak_config "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/core/keyclock_config.py"
click node_keycloak_schemas "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/schemas/keyclock.py"
click node_note_schemas "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/schemas/note.py"
click node_user_schemas "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/schemas/user.py"
click node_note_model "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/models/note.py"
click node_attachment_model "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/models/attachment.py"
click node_user_model "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/models/user.py"
click node_db_session "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/db/session.py"
click node_boto_client "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/minio/boto3_client.py"
click node_alembic "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/env.py"
click node_initial_migration "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/versions/96abb5c3e11f_initial_tables.py"
click node_soft_delete_migration "https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/versions/90b57f1760ef_added_softdelete_and_attachment.py"

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_app,node_auth_routes,node_note_routes,node_user_routes,node_note_schemas,node_user_schemas toneBlue
class node_security,node_keycloak_config,node_keycloak_schemas,node_keycloak toneAmber
class node_note_model,node_attachment_model,node_user_model,node_db_session,node_postgres,node_object_storage,node_boto_client toneMint
class node_alembic,node_initial_migration,node_soft_delete_migration toneRose
```

## Components

### FastAPI API

- [FastAPI application](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/main.py): ASGI entry point · Assembles the API routers. · `note_app/app/main.py`
- [Auth routes](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/auth.py): HTTP routes · Registration, login, and token flows. · `note_app/app/routes/auth.py`
- [Note routes](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/notes.py): protected HTTP routes · CRUD, search, soft deletion, and attachments. · `note_app/app/routes/notes.py`
- [User routes](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/routes/users.py): HTTP routes · `note_app/app/routes/users.py`
- [Note schemas](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/schemas/note.py): Pydantic schemas · Translates note HTTP payloads. · `note_app/app/schemas/note.py`
- [User schemas](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/schemas/user.py): Pydantic schemas · `note_app/app/schemas/user.py`

### Identity

- [JWT security](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/core/security.py): authorization dependency · Validates bearer tokens for protected operations. · `note_app/app/core/security.py`
- [Keycloak integration](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/core/keyclock_config.py): identity configuration · Keycloak settings and token contracts. · `note_app/app/core/keyclock_config.py`
- [Keycloak contracts](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/schemas/keyclock.py): Pydantic schemas · `note_app/app/schemas/keyclock.py`
- **Keycloak**: external identity provider · Owns credentials, token issuance, and roles.

### Data & storage

- [Notes](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/models/note.py): SQLAlchemy model · Notes include tags and soft-delete state. · `note_app/app/models/note.py`
- [Attachments](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/models/attachment.py): SQLAlchemy model · File metadata linked to notes. · `note_app/app/models/attachment.py`
- [Local users](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/models/user.py): SQLAlchemy model · Links application users to external identity. · `note_app/app/models/user.py`
- [Database sessions](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/db/session.py): SQLAlchemy session lifecycle · `note_app/app/db/session.py`
- **PostgreSQL**: relational database · Stores application-owned note, attachment, and user data.
- **MinIO/S3 storage**: object storage · Optional attachment file storage.
- [Boto3 storage client](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/app/minio/boto3_client.py): object storage adapter · `note_app/app/minio/boto3_client.py`

### Schema evolution

- [Alembic migrations](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/env.py): schema migration runner · Applies relational schema history. · `note_app/alembic/env.py`
- [Initial tables](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/versions/96abb5c3e11f_initial_tables.py): Alembic migration · `note_app/alembic/versions/96abb5c3e11f_initial_tables.py`
- [Soft-delete migration](https://github.com/amarkumar-verma-br/note-app/blob/main/note_app/alembic/versions/90b57f1760ef_added_softdelete_and_attachment.py): Alembic migration · Adds soft deletion and attachment schema. · `note_app/alembic/versions/90b57f1760ef_added_softdelete_and_attachment.py`

## Connections

- FastAPI application → Auth routes: mounts
- FastAPI application → Note routes: mounts
- FastAPI application → User routes: mounts
- Auth routes → Keycloak integration: uses
- Auth routes → Keycloak contracts: uses
- Keycloak integration → Keycloak: connects to
- Note routes → JWT security: authorizes via
- JWT security → Keycloak: validates JWTs against
- Note routes → Note schemas: validates payloads
- User routes → User schemas: validates payloads
- Note routes → Database sessions: uses
- User routes → Database sessions: uses
- Database sessions → PostgreSQL: connects to
- Note routes → Notes: creates, queries, updates
- Note routes → Attachments: records metadata
- Notes → Attachments: associates
- Note routes → Boto3 storage client: uploads attachments
- Boto3 storage client → MinIO/S3 storage: stores objects
- Notes → PostgreSQL: persists
- Attachments → PostgreSQL: persists
- Local users → PostgreSQL: persists
- Alembic migrations → Initial tables: runs
- Alembic migrations → Soft-delete migration: runs
- Alembic migrations → PostgreSQL: migrates
