# diegojrobles/ai-server architecture

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

- Interactive diagram: https://gitdiagram.com/diegojrobles/ai-server
- Repository: https://github.com/diegojrobles/ai-server

## Overview

AI Server is a Flask REST API for sentiment analysis, with API-key protection, per-IP rate limiting, health and model-list endpoints, and lazy model loading. The principal workflow is a client request to /predict, through rate limiting and authentication, to model inference and a JSON prediction response. Environment settings configure the server, security, and inference. The README also describes a planned async multi-provider gateway; that is future work, not part of the current architecture. The map reflects sampled runtime source; unsampled integrations are omitted.

Main entry points: [`app/server.py`](https://github.com/diegojrobles/ai-server/blob/main/app/server.py) (Flask API routes), [`app/model_handler.py`](https://github.com/diegojrobles/ai-server/blob/main/app/model_handler.py) (Model handler), [`config/settings.py`](https://github.com/diegojrobles/ai-server/blob/main/config/settings.py) (Environment settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API layer"]
  node_server["Flask API routes<br/>[server.py]"]
  node_limiter["Rate limiting<br/>[server.py]"]
  node_auth["API-key auth<br/>[server.py]"]
end

subgraph group_inference["Inference"]
  node_handler["Model handler<br/>[model_handler.py]"]
  node_pipeline["Transformers pipeline"]
end

subgraph group_configuration["Configuration"]
  node_settings["Environment settings<br/>[settings.py]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"limits predictions"| node_limiter
node_limiter -->|"checks key"| node_auth
node_auth -->|"requests inference"| node_handler
node_handler -->|"loads and predicts"| node_pipeline
node_server -->|"reads settings"| node_settings
node_handler -->|"reads model config"| node_settings

click node_server "https://github.com/diegojrobles/ai-server/blob/main/app/server.py"
click node_limiter "https://github.com/diegojrobles/ai-server/blob/main/app/server.py"
click node_auth "https://github.com/diegojrobles/ai-server/blob/main/app/server.py"
click node_settings "https://github.com/diegojrobles/ai-server/blob/main/config/settings.py"
click node_handler "https://github.com/diegojrobles/ai-server/blob/main/app/model_handler.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_server,node_limiter,node_auth,node_client toneBlue
class node_handler,node_pipeline toneAmber
class node_settings toneMint
```

## Components

### API layer

- [Flask API routes](https://github.com/diegojrobles/ai-server/blob/main/app/server.py): `app/server.py`
- [Rate limiting](https://github.com/diegojrobles/ai-server/blob/main/app/server.py): `app/server.py`
- [API-key auth](https://github.com/diegojrobles/ai-server/blob/main/app/server.py): `app/server.py`

### Inference

- [Model handler](https://github.com/diegojrobles/ai-server/blob/main/app/model_handler.py): `app/model_handler.py`
- **Transformers pipeline**

### Configuration

- [Environment settings](https://github.com/diegojrobles/ai-server/blob/main/config/settings.py): `config/settings.py`

### Other components

- **API client**

## Connections

- API client → Flask API routes: sends requests
- Flask API routes → Rate limiting: limits predictions
- Rate limiting → API-key auth: checks key
- API-key auth → Model handler: requests inference
- Model handler → Transformers pipeline: loads and predicts
- Flask API routes → Environment settings: reads settings
- Model handler → Environment settings: reads model config
