# belmarbelmar/storage_service architecture

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

- Interactive diagram: https://gitdiagram.com/belmarbelmar/storage_service
- Repository: https://github.com/belmarbelmar/storage_service

## Overview

This repository implements a Zero-Trust file-storage API: users request and verify an email OTP, then use a JWT to upload, list, download, or delete files. Uploads are validated and stored as MinIO objects while metadata is persisted in PostgreSQL; downloads use pre-signed URLs. The README also documents Nginx routing and centralized logging/visualization. Source excerpts establish the API’s calls to authentication, storage, and metadata code; infrastructure relationships are included only where documented in the README.

Main entry points: [`api/main.py`](https://github.com/belmarbelmar/storage_service/blob/main/api/main.py) (API routes), [`api/auth.py`](https://github.com/belmarbelmar/storage_service/blob/main/api/auth.py) (OTP and JWT), [`api/storage.py`](https://github.com/belmarbelmar/storage_service/blob/main/api/storage.py) (Storage service), [`api/database.py`](https://github.com/belmarbelmar/storage_service/blob/main/api/database.py) (Metadata access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflow"]
  node_api_routes["API routes<br/>[main.py]"]
  node_settings["Configuration<br/>[config.py]"]
  node_file_validation["File validation<br/>[main.py]"]
end

subgraph group_auth["Identity"]
  node_otp_jwt["OTP and JWT<br/>[auth.py]"]
end

subgraph group_storage["File storage"]
  node_storage_service["Storage service<br/>[storage.py]"]
  node_minio[("MinIO objects")]
  node_metadata["Metadata access<br/>[database.py]"]
end

subgraph group_platform["Platform services"]
  node_proxy["Nginx proxy<br/>[zerotrust.conf]"]
  node_smtp["SMTP / MailHog"]
  node_postgres[("PostgreSQL")]
  node_log_collection["Log collection"]
  node_log_store[("Loki<br/>[loki-config.yml]")]
  node_log_viewer["Grafana"]
end

node_user(("User"))

node_user -->|"sends requests"| node_proxy
node_proxy -->|"routes requests"| node_api_routes
node_api_routes -->|"requests or verifies OTP"| node_otp_jwt
node_otp_jwt -->|"sends OTP email"| node_smtp
node_api_routes -->|"validates JWT"| node_otp_jwt
node_api_routes -->|"validates uploads"| node_file_validation
node_api_routes -->|"stores and retrieves objects"| node_storage_service
node_storage_service -->|"reads and writes objects"| node_minio
node_api_routes -->|"writes and queries metadata"| node_metadata
node_metadata -->|"persists metadata"| node_postgres
node_api_routes -->|"reads settings"| node_settings
node_log_collection -.->|"ships logs"| node_log_store
node_log_viewer -.->|"visualizes logs"| node_log_store

click node_proxy "https://github.com/belmarbelmar/storage_service/blob/main/nginx/conf.d/zerotrust.conf"
click node_api_routes "https://github.com/belmarbelmar/storage_service/blob/main/api/main.py"
click node_settings "https://github.com/belmarbelmar/storage_service/blob/main/api/config.py"
click node_otp_jwt "https://github.com/belmarbelmar/storage_service/blob/main/api/auth.py"
click node_file_validation "https://github.com/belmarbelmar/storage_service/blob/main/api/main.py"
click node_storage_service "https://github.com/belmarbelmar/storage_service/blob/main/api/storage.py"
click node_metadata "https://github.com/belmarbelmar/storage_service/blob/main/api/database.py"
click node_log_collection "https://github.com/belmarbelmar/storage_service/blob/main/nginx/promtail-config.yml"
click node_log_store "https://github.com/belmarbelmar/storage_service/blob/main/nginx/loki-config.yml"

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_api_routes,node_settings,node_file_validation,node_user toneBlue
class node_otp_jwt toneAmber
class node_storage_service,node_minio,node_metadata toneMint
class node_proxy,node_smtp,node_postgres,node_log_collection,node_log_store,node_log_viewer toneRose
```

## Components

### API workflow

- [API routes](https://github.com/belmarbelmar/storage_service/blob/main/api/main.py): `api/main.py`
- [Configuration](https://github.com/belmarbelmar/storage_service/blob/main/api/config.py): `api/config.py`
- [File validation](https://github.com/belmarbelmar/storage_service/blob/main/api/main.py): `api/main.py`

### Identity

- [OTP and JWT](https://github.com/belmarbelmar/storage_service/blob/main/api/auth.py): `api/auth.py`

### File storage

- [Storage service](https://github.com/belmarbelmar/storage_service/blob/main/api/storage.py): `api/storage.py`
- **MinIO objects**
- [Metadata access](https://github.com/belmarbelmar/storage_service/blob/main/api/database.py): `api/database.py`

### Platform services

- [Nginx proxy](https://github.com/belmarbelmar/storage_service/blob/main/nginx/conf.d/zerotrust.conf): `nginx/conf.d/zerotrust.conf`
- **SMTP / MailHog**
- **PostgreSQL**
- [Log collection](https://github.com/belmarbelmar/storage_service/blob/main/nginx/promtail-config.yml): `nginx/promtail-config.yml`
- [Loki](https://github.com/belmarbelmar/storage_service/blob/main/nginx/loki-config.yml): `nginx/loki-config.yml`
- **Grafana**

### Other components

- **User**

## Connections

- User → Nginx proxy: sends requests (evidence: `README.md`)
- Nginx proxy → API routes: routes requests (evidence: `README.md`)
- API routes → OTP and JWT: requests or verifies OTP (evidence: `api/main.py`)
- OTP and JWT → SMTP / MailHog: sends OTP email (evidence: `api/auth.py`)
- API routes → OTP and JWT: validates JWT (evidence: `api/main.py`)
- API routes → File validation: validates uploads (evidence: `api/main.py`)
- API routes → Storage service: stores and retrieves objects (evidence: `api/main.py`)
- Storage service → MinIO objects: reads and writes objects (evidence: `api/storage.py`)
- API routes → Metadata access: writes and queries metadata (evidence: `api/main.py`)
- Metadata access → PostgreSQL: persists metadata (evidence: `api/database.py`)
- API routes → Configuration: reads settings (evidence: `api/main.py`)
- Log collection → Loki: ships logs (evidence: `README.md`)
- Grafana → Loki: visualizes logs (evidence: `README.md`)
