# dlcastra/api_file_processing architecture

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

- Interactive diagram: https://gitdiagram.com/dlcastra/api_file_processing
- Repository: https://github.com/dlcastra/api_file_processing

## Overview

This is a FastAPI file-processing and analysis API. Clients authenticate, upload and manage files, then request conversion, parsing, or tonality analysis; processing requests are queued, workers return results through webhooks, and the API waits for cached results. The graph includes the documented worker capabilities, but their implementations are absent from the tree. Relationships for the main request flow are supported by excerpts; worker callbacks and some infrastructure behavior are based on the README.

Main entry points: [`src/app/file_management/routers.py`](https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/routers.py) (File routes), [`src/app/webhooks/routers.py`](https://github.com/dlcastra/api_file_processing/blob/main/src/app/webhooks/routers.py) (Webhook routes), [`src/app/auth/routers.py`](https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/routers.py) (Auth routes), [`src/app/file_management/services.py`](https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/services.py) (File service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and authentication"]
  node_application["FastAPI application<br/>[application.py]"]
  node_auth_routes["Auth routes<br/>[routers.py]"]
  node_auth_service["Auth service<br/>[services.py]"]
  node_auth_models["User models<br/>[models.py]"]
  node_session_utils["Session utilities<br/>[utils.py]"]
end

subgraph group_files["File management"]
  node_file_routes["File routes<br/>[routers.py]"]
  node_file_service["File service<br/>[services.py]"]
  node_file_models["File models<br/>[models.py]"]
  node_file_validation["File validation<br/>[file_validation.py]"]
  node_response_generator["Response generation<br/>[generator.py]"]
end

subgraph group_async["Async processing"]
  node_webhook_routes["Webhook routes<br/>[routers.py]"]
  node_cache_wait["Cache waiting<br/>[utils.py]"]
  node_converter_worker["Conversion worker"]
  node_analyser_worker["Analysis workers"]
end

subgraph group_platform["Persistence and infrastructure"]
  node_aws_clients["AWS clients<br/>[clients.py]"]
  node_sqs_utils["SQS messaging<br/>[utils.py]"]
  node_sqs["AWS SQS"]
  node_redis[("Redis cache")]
  node_database[("PostgreSQL database")]
  node_s3[("AWS S3")]
end

node_client(("Client"))

node_client -->|"sends requests"| node_application
node_application -->|"registers routes"| node_auth_routes
node_application -->|"registers routes"| node_file_routes
node_application -->|"registers routes"| node_webhook_routes
node_auth_routes -->|"calls"| node_auth_service
node_auth_service -->|"queries and creates"| node_auth_models
node_auth_routes -->|"manages sessions"| node_session_utils
node_auth_routes -->|"reads and writes"| node_database
node_auth_routes -->|"stores sessions"| node_redis
node_auth_service -->|"reads and writes"| node_database
node_file_routes -->|"validates uploads"| node_file_validation
node_file_routes -->|"calls"| node_file_service
node_file_routes -->|"enqueues tasks"| node_sqs_utils
node_file_routes -->|"waits for results"| node_cache_wait
node_file_routes -->|"formats results"| node_response_generator
node_file_service -->|"queries and updates"| node_file_models
node_file_service -->|"reads and writes"| node_database
node_file_service -->|"uses S3 client"| node_aws_clients
node_aws_clients -.->|"accesses objects"| node_s3
node_sqs_utils -.->|"sends messages"| node_sqs
node_sqs -->|"dispatches tasks"| node_converter_worker
node_sqs -->|"dispatches tasks"| node_analyser_worker
node_converter_worker -->|"posts results"| node_webhook_routes
node_analyser_worker -->|"posts results"| node_webhook_routes
node_webhook_routes -->|"updates file record"| node_file_service
node_webhook_routes -->|"commits updates"| node_database
node_webhook_routes -->|"caches results"| node_redis
node_cache_wait -->|"polls results"| node_redis

click node_application "https://github.com/dlcastra/api_file_processing/blob/main/application.py"
click node_auth_routes "https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/routers.py"
click node_auth_service "https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/services.py"
click node_auth_models "https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/models.py"
click node_session_utils "https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/utils.py"
click node_file_routes "https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/routers.py"
click node_file_service "https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/services.py"
click node_file_models "https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/models.py"
click node_file_validation "https://github.com/dlcastra/api_file_processing/blob/main/src/app/validators/file_validation.py"
click node_response_generator "https://github.com/dlcastra/api_file_processing/blob/main/src/app/responses/generator.py"
click node_aws_clients "https://github.com/dlcastra/api_file_processing/blob/main/src/app/aws/clients.py"
click node_sqs_utils "https://github.com/dlcastra/api_file_processing/blob/main/src/app/aws/utils.py"
click node_webhook_routes "https://github.com/dlcastra/api_file_processing/blob/main/src/app/webhooks/routers.py"
click node_cache_wait "https://github.com/dlcastra/api_file_processing/blob/main/src/app/webhooks/utils.py"
click node_converter_worker "https://github.com/dlcastra/api_file_processing/tree/main/src/external/services/converter"
click node_analyser_worker "https://github.com/dlcastra/api_file_processing/tree/main/src/external/services/analyser"

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_application,node_auth_routes,node_auth_service,node_auth_models,node_session_utils,node_client toneBlue
class node_file_routes,node_file_service,node_file_models,node_file_validation,node_response_generator toneAmber
class node_webhook_routes,node_cache_wait,node_converter_worker,node_analyser_worker toneMint
class node_aws_clients,node_sqs_utils,node_sqs,node_redis,node_database,node_s3 toneRose
```

## Components

### API and authentication

- [FastAPI application](https://github.com/dlcastra/api_file_processing/blob/main/application.py): `application.py`
- [Auth routes](https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/routers.py): `src/app/auth/routers.py`
- [Auth service](https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/services.py): `src/app/auth/services.py`
- [User models](https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/models.py): `src/app/auth/models.py`
- [Session utilities](https://github.com/dlcastra/api_file_processing/blob/main/src/app/auth/utils.py): `src/app/auth/utils.py`

### File management

- [File routes](https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/routers.py): `src/app/file_management/routers.py`
- [File service](https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/services.py): `src/app/file_management/services.py`
- [File models](https://github.com/dlcastra/api_file_processing/blob/main/src/app/file_management/models.py): `src/app/file_management/models.py`
- [File validation](https://github.com/dlcastra/api_file_processing/blob/main/src/app/validators/file_validation.py): `src/app/validators/file_validation.py`
- [Response generation](https://github.com/dlcastra/api_file_processing/blob/main/src/app/responses/generator.py): `src/app/responses/generator.py`

### Async processing

- [Webhook routes](https://github.com/dlcastra/api_file_processing/blob/main/src/app/webhooks/routers.py): `src/app/webhooks/routers.py`
- [Cache waiting](https://github.com/dlcastra/api_file_processing/blob/main/src/app/webhooks/utils.py): `src/app/webhooks/utils.py`
- [Conversion worker](https://github.com/dlcastra/api_file_processing/tree/main/src/external/services/converter): `src/external/services/converter`
- [Analysis workers](https://github.com/dlcastra/api_file_processing/tree/main/src/external/services/analyser): `src/external/services/analyser`

### Persistence and infrastructure

- [AWS clients](https://github.com/dlcastra/api_file_processing/blob/main/src/app/aws/clients.py): `src/app/aws/clients.py`
- [SQS messaging](https://github.com/dlcastra/api_file_processing/blob/main/src/app/aws/utils.py): `src/app/aws/utils.py`
- **AWS SQS**
- **Redis cache**
- **PostgreSQL database**
- **AWS S3**

### Other components

- **Client**

## Connections

- Client → FastAPI application: sends requests (evidence: `application.py`)
- FastAPI application → Auth routes: registers routes (evidence: `application.py`)
- FastAPI application → File routes: registers routes (evidence: `application.py`)
- FastAPI application → Webhook routes: registers routes (evidence: `application.py`)
- Auth routes → Auth service: calls (evidence: `src/app/auth/routers.py`)
- Auth service → User models: queries and creates (evidence: `src/app/auth/services.py`)
- Auth routes → Session utilities: manages sessions (evidence: `src/app/auth/routers.py`)
- Auth routes → PostgreSQL database: reads and writes (evidence: `src/app/auth/routers.py`)
- Auth routes → Redis cache: stores sessions (evidence: `src/app/auth/routers.py`)
- Auth service → PostgreSQL database: reads and writes (evidence: `src/app/auth/services.py`)
- File routes → File validation: validates uploads (evidence: `src/app/file_management/routers.py`)
- File routes → File service: calls (evidence: `src/app/file_management/routers.py`)
- File routes → SQS messaging: enqueues tasks (evidence: `src/app/file_management/routers.py`)
- File routes → Cache waiting: waits for results (evidence: `src/app/file_management/routers.py`)
- File routes → Response generation: formats results (evidence: `src/app/file_management/routers.py`)
- File service → File models: queries and updates (evidence: `src/app/file_management/services.py`)
- File service → PostgreSQL database: reads and writes (evidence: `src/app/file_management/services.py`)
- File service → AWS clients: uses S3 client (evidence: `src/app/file_management/services.py`)
- AWS clients → AWS S3: accesses objects
- SQS messaging → AWS SQS: sends messages
- AWS SQS → Conversion worker: dispatches tasks (evidence: `README.md`)
- AWS SQS → Analysis workers: dispatches tasks (evidence: `README.md`)
- Conversion worker → Webhook routes: posts results (evidence: `README.md`)
- Analysis workers → Webhook routes: posts results (evidence: `README.md`)
- Webhook routes → File service: updates file record (evidence: `src/app/webhooks/routers.py`)
- Webhook routes → PostgreSQL database: commits updates (evidence: `src/app/webhooks/routers.py`)
- Webhook routes → Redis cache: caches results (evidence: `src/app/webhooks/routers.py`)
- Cache waiting → Redis cache: polls results (evidence: `README.md`)
