# itsomshree/unified-ai-api architecture

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

- Interactive diagram: https://gitdiagram.com/itsomshree/unified-ai-api
- Repository: https://github.com/itsomshree/unified-ai-api

## Overview

Unified AI Inference API: clients authenticate, upload images when needed, submit predictions, and retrieve results or history; async jobs are queued for worker execution and can trigger signed webhook notifications. The graph also covers authentication, rate limiting, tracing, metrics, and file handling. Relationships are based on README statements and SOURCE INDEX references; unsampled subsystem internals are represented only where the documented capabilities or indexed references support them.

Main entry points: [`app/services/inference_service.py`](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/inference_service.py) (Inference Service), [`app/tasks/celery_tasks.py`](https://github.com/itsomshree/unified-ai-api/blob/main/app/tasks/celery_tasks.py) (Celery Worker), [`app/core/dependencies.py`](https://github.com/itsomshree/unified-ai-api/blob/main/app/core/dependencies.py) (Credential Resolution), [`app/api/v1/inference.py`](https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/inference.py) (Inference Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Access"]
  node_auth_api["Auth Routes<br/>[auth.py]"]
  node_inference_api["Inference Routes<br/>[inference.py]"]
  node_history_api["History Routes<br/>[history.py]"]
  node_files_api["File Routes<br/>[files.py]"]
  node_webhooks_api["Webhook Routes<br/>[webhooks.py]"]
end

subgraph group_identity["Identity and Files"]
  node_auth_service["Auth Service<br/>[auth_service.py]"]
  node_auth_dependencies["Credential Resolution<br/>[dependencies.py]"]
  node_security["Security Primitives<br/>[security.py]"]
  node_file_service["File Service<br/>[file_service.py]"]
  node_user_model[("User Records<br/>[user.py]")]
  node_api_key_model[("API Key Records<br/>[api_key.py]")]
  node_uploaded_file_model[("Uploaded File Records<br/>[uploaded_file.py]")]
end

subgraph group_inference["Inference"]
  node_inference_service["Inference Service"]
  node_model_registry["Model Registry<br/>[registry.py]"]
  node_ml_models["Prediction Models"]
  node_prediction_model[("Prediction Records<br/>[prediction.py]")]
  node_history_service["History Service<br/>[history_service.py]"]
end

subgraph group_async["Async and Webhooks"]
  node_worker["Celery Worker<br/>[celery_tasks.py]"]
  node_notification_service["Webhook Delivery"]
  node_webhook_service["Webhook Management<br/>[webhook_service.py]"]
  node_webhook_model[("Webhook Records<br/>[webhook.py]")]
end

subgraph group_platform["Platform Services"]
  node_postgres[("PostgreSQL")]
  node_redis[("Redis")]
  node_rate_limit["Rate Limiting<br/>[rate_limit.py]"]
  node_observability["Tracing and Metrics<br/>[request_context.py]"]
end

node_client(("API Client"))

node_client -->|"registers or logs in"| node_auth_api
node_client -->|"submits predictions"| node_inference_api
node_client -->|"uploads images"| node_files_api
node_client -->|"requests history"| node_history_api
node_client -->|"manages webhooks"| node_webhooks_api
node_auth_api -->|"calls"| node_auth_service
node_auth_service -->|"uses"| node_security
node_auth_service -->|"creates and reads"| node_user_model
node_auth_service -->|"manages"| node_api_key_model
node_auth_api -->|"requires"| node_auth_dependencies
node_inference_api -->|"requires"| node_auth_dependencies
node_files_api -->|"requires"| node_auth_dependencies
node_webhooks_api -->|"requires"| node_auth_dependencies
node_auth_dependencies -->|"validates credentials"| node_security
node_auth_dependencies -->|"looks up users"| node_user_model
node_auth_dependencies -->|"looks up keys"| node_api_key_model
node_files_api -->|"calls"| node_file_service
node_file_service -->|"persists metadata"| node_uploaded_file_model
node_file_service -->|"reads and writes"| node_postgres
node_inference_api -->|"applies limits"| node_rate_limit
node_inference_api -->|"calls"| node_inference_service
node_inference_service -->|"selects model"| node_model_registry
node_model_registry -->|"registers models"| node_ml_models
node_inference_service -->|"records predictions"| node_prediction_model
node_inference_service -->|"writes prediction"| node_postgres
node_inference_service -->|"resolves image file"| node_file_service
node_inference_service -->|"queues async job"| node_worker
node_history_api -->|"calls"| node_history_service
node_history_api -->|"checks prediction status"| node_inference_service
node_history_service -->|"queries history"| node_prediction_model
node_worker -->|"loads and updates"| node_prediction_model
node_worker -->|"reads and writes"| node_postgres
node_worker -->|"selects model"| node_model_registry
node_worker -->|"triggers delivery"| node_notification_service
node_inference_service -->|"queues through broker"| node_redis
node_worker -->|"receives queued tasks"| node_redis
node_webhooks_api -->|"calls"| node_webhook_service
node_webhook_service -->|"manages registration"| node_webhook_model
node_notification_service -->|"loads recipient"| node_webhook_model
node_notification_service -->|"signs delivery"| node_security
node_rate_limit -->|"checks request windows"| node_redis
node_worker -->|"binds request ID"| node_observability
node_inference_service -->|"propagates request ID"| node_observability

click node_auth_api "https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/auth.py"
click node_inference_api "https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/inference.py"
click node_history_api "https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/history.py"
click node_files_api "https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/files.py"
click node_webhooks_api "https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/webhooks.py"
click node_auth_service "https://github.com/itsomshree/unified-ai-api/blob/main/app/services/auth_service.py"
click node_auth_dependencies "https://github.com/itsomshree/unified-ai-api/blob/main/app/core/dependencies.py"
click node_security "https://github.com/itsomshree/unified-ai-api/blob/main/app/core/security.py"
click node_file_service "https://github.com/itsomshree/unified-ai-api/blob/main/app/services/file_service.py"
click node_user_model "https://github.com/itsomshree/unified-ai-api/blob/main/app/models/user.py"
click node_api_key_model "https://github.com/itsomshree/unified-ai-api/blob/main/app/models/api_key.py"
click node_uploaded_file_model "https://github.com/itsomshree/unified-ai-api/blob/main/app/models/uploaded_file.py"
click node_inference_service "https://github.com/itsomshree/unified-ai-api/blob/main/app/services/inference_service.py"
click node_model_registry "https://github.com/itsomshree/unified-ai-api/blob/main/app/ml/registry.py"
click node_ml_models "https://github.com/itsomshree/unified-ai-api/tree/main/app/ml"
click node_prediction_model "https://github.com/itsomshree/unified-ai-api/blob/main/app/models/prediction.py"
click node_history_service "https://github.com/itsomshree/unified-ai-api/blob/main/app/services/history_service.py"
click node_worker "https://github.com/itsomshree/unified-ai-api/blob/main/app/tasks/celery_tasks.py"
click node_notification_service "https://github.com/itsomshree/unified-ai-api/blob/main/app/services/notification_service.py"
click node_webhook_service "https://github.com/itsomshree/unified-ai-api/blob/main/app/services/webhook_service.py"
click node_webhook_model "https://github.com/itsomshree/unified-ai-api/blob/main/app/models/webhook.py"
click node_rate_limit "https://github.com/itsomshree/unified-ai-api/blob/main/app/core/rate_limit.py"
click node_observability "https://github.com/itsomshree/unified-ai-api/blob/main/app/core/request_context.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_auth_api,node_inference_api,node_history_api,node_files_api,node_webhooks_api,node_client toneBlue
class node_auth_service,node_auth_dependencies,node_security,node_file_service,node_user_model,node_api_key_model,node_uploaded_file_model toneAmber
class node_inference_service,node_model_registry,node_ml_models,node_prediction_model,node_history_service toneMint
class node_worker,node_notification_service,node_webhook_service,node_webhook_model toneRose
class node_postgres,node_redis,node_rate_limit,node_observability toneIndigo
```

## Components

### API and Access

- [Auth Routes](https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/auth.py): `app/api/v1/auth.py`
- [Inference Routes](https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/inference.py): `app/api/v1/inference.py`
- [History Routes](https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/history.py): `app/api/v1/history.py`
- [File Routes](https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/files.py): `app/api/v1/files.py`
- [Webhook Routes](https://github.com/itsomshree/unified-ai-api/blob/main/app/api/v1/webhooks.py): `app/api/v1/webhooks.py`

### Identity and Files

- [Auth Service](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/auth_service.py): `app/services/auth_service.py`
- [Credential Resolution](https://github.com/itsomshree/unified-ai-api/blob/main/app/core/dependencies.py): `app/core/dependencies.py`
- [Security Primitives](https://github.com/itsomshree/unified-ai-api/blob/main/app/core/security.py): `app/core/security.py`
- [File Service](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/file_service.py): `app/services/file_service.py`
- [User Records](https://github.com/itsomshree/unified-ai-api/blob/main/app/models/user.py): `app/models/user.py`
- [API Key Records](https://github.com/itsomshree/unified-ai-api/blob/main/app/models/api_key.py): `app/models/api_key.py`
- [Uploaded File Records](https://github.com/itsomshree/unified-ai-api/blob/main/app/models/uploaded_file.py): `app/models/uploaded_file.py`

### Inference

- [Inference Service](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/inference_service.py): `app/services/inference_service.py`
- [Model Registry](https://github.com/itsomshree/unified-ai-api/blob/main/app/ml/registry.py): `app/ml/registry.py`
- [Prediction Models](https://github.com/itsomshree/unified-ai-api/tree/main/app/ml): `app/ml`
- [Prediction Records](https://github.com/itsomshree/unified-ai-api/blob/main/app/models/prediction.py): `app/models/prediction.py`
- [History Service](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/history_service.py): `app/services/history_service.py`

### Async and Webhooks

- [Celery Worker](https://github.com/itsomshree/unified-ai-api/blob/main/app/tasks/celery_tasks.py): `app/tasks/celery_tasks.py`
- [Webhook Delivery](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/notification_service.py): `app/services/notification_service.py`
- [Webhook Management](https://github.com/itsomshree/unified-ai-api/blob/main/app/services/webhook_service.py): `app/services/webhook_service.py`
- [Webhook Records](https://github.com/itsomshree/unified-ai-api/blob/main/app/models/webhook.py): `app/models/webhook.py`

### Platform Services

- **PostgreSQL**
- **Redis**
- [Rate Limiting](https://github.com/itsomshree/unified-ai-api/blob/main/app/core/rate_limit.py): `app/core/rate_limit.py`
- [Tracing and Metrics](https://github.com/itsomshree/unified-ai-api/blob/main/app/core/request_context.py): `app/core/request_context.py`

### Other components

- **API Client**

## Connections

- API Client → Auth Routes: registers or logs in
- API Client → Inference Routes: submits predictions
- API Client → File Routes: uploads images
- API Client → History Routes: requests history
- API Client → Webhook Routes: manages webhooks
- Auth Routes → Auth Service: calls (evidence: `app/api/v1/auth.py`)
- Auth Service → Security Primitives: uses (evidence: `app/services/auth_service.py`)
- Auth Service → User Records: creates and reads (evidence: `app/services/auth_service.py`)
- Auth Service → API Key Records: manages (evidence: `app/services/auth_service.py`)
- Auth Routes → Credential Resolution: requires (evidence: `app/api/v1/auth.py`)
- Inference Routes → Credential Resolution: requires (evidence: `app/api/v1/inference.py`)
- File Routes → Credential Resolution: requires (evidence: `app/api/v1/files.py`)
- Webhook Routes → Credential Resolution: requires (evidence: `app/api/v1/webhooks.py`)
- Credential Resolution → Security Primitives: validates credentials (evidence: `app/core/dependencies.py`)
- Credential Resolution → User Records: looks up users (evidence: `app/core/dependencies.py`)
- Credential Resolution → API Key Records: looks up keys (evidence: `app/core/dependencies.py`)
- File Routes → File Service: calls (evidence: `app/api/v1/files.py`)
- File Service → Uploaded File Records: persists metadata (evidence: `app/services/file_service.py`)
- File Service → PostgreSQL: reads and writes (evidence: `app/services/file_service.py`)
- Inference Routes → Rate Limiting: applies limits (evidence: `app/api/v1/inference.py`)
- Inference Routes → Inference Service: calls (evidence: `app/api/v1/inference.py`)
- Inference Service → Model Registry: selects model (evidence: `app/services/inference_service.py`)
- Model Registry → Prediction Models: registers models (evidence: `app/ml/loaders.py`)
- Inference Service → Prediction Records: records predictions (evidence: `app/services/inference_service.py`)
- Inference Service → PostgreSQL: writes prediction (evidence: `app/services/inference_service.py`)
- Inference Service → File Service: resolves image file (evidence: `app/services/inference_service.py`)
- Inference Service → Celery Worker: queues async job (evidence: `app/services/inference_service.py`)
- History Routes → History Service: calls (evidence: `app/api/v1/history.py`)
- History Routes → Inference Service: checks prediction status (evidence: `app/api/v1/history.py`)
- History Service → Prediction Records: queries history
- Celery Worker → Prediction Records: loads and updates (evidence: `app/tasks/celery_tasks.py`)
- Celery Worker → PostgreSQL: reads and writes (evidence: `app/tasks/celery_tasks.py`)
- Celery Worker → Model Registry: selects model (evidence: `app/tasks/celery_tasks.py`)
- Celery Worker → Webhook Delivery: triggers delivery (evidence: `app/tasks/celery_tasks.py`)
- Inference Service → Redis: queues through broker
- Celery Worker → Redis: receives queued tasks
- Webhook Routes → Webhook Management: calls (evidence: `app/api/v1/webhooks.py`)
- Webhook Management → Webhook Records: manages registration (evidence: `app/services/webhook_service.py`)
- Webhook Delivery → Webhook Records: loads recipient (evidence: `app/services/notification_service.py`)
- Webhook Delivery → Security Primitives: signs delivery (evidence: `app/services/notification_service.py`)
- Rate Limiting → Redis: checks request windows (evidence: `app/core/rate_limit.py`)
- Celery Worker → Tracing and Metrics: binds request ID (evidence: `app/tasks/celery_tasks.py`)
- Inference Service → Tracing and Metrics: propagates request ID (evidence: `app/services/inference_service.py`)
