How amarkumar-verma-br/note-app works
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: notes.py Note routes · main.py FastAPI application · env.py Alembic migrations · auth.py Auth routes
Components 20
FastAPI API
- FastAPI application · Assembles the API routers.
note_app/app/main.py - Auth routes · Registration, login, and token flows.
note_app/app/routes/auth.py - Note routes · CRUD, search, soft deletion, and attachments.
note_app/app/routes/notes.py - User routes
note_app/app/routes/users.py - Note schemas · Translates note HTTP payloads.
note_app/app/schemas/note.py - User schemas
note_app/app/schemas/user.py
Identity
- JWT security · Validates bearer tokens for protected operations.
note_app/app/core/security.py - Keycloak integration · Keycloak settings and token contracts.
note_app/app/core/keyclock_config.py - Keycloak contracts
note_app/app/schemas/keyclock.py - Keycloak · Owns credentials, token issuance, and roles.
Data & storage
- Notes · Notes include tags and soft-delete state.
note_app/app/models/note.py - Attachments · File metadata linked to notes.
note_app/app/models/attachment.py - Local users · Links application users to external identity.
note_app/app/models/user.py - Database sessions
note_app/app/db/session.py - PostgreSQL · Stores application-owned note, attachment, and user data.
- MinIO/S3 storage · Optional attachment file storage.
- Boto3 storage client
note_app/app/minio/boto3_client.py
Schema evolution
- Alembic migrations · Applies relational schema history.
note_app/alembic/env.py - Initial tables
note_app/alembic/versions/96abb5c3e11f_initial_tables.py - Soft-delete migration · Adds soft deletion and attachment schema.
note_app/alembic/versions/90b57f1760ef_added_softdelete_and_attachment.py
Connections 24
- 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