# flaviocavalcantet/vaultgate architecture

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

- Interactive diagram: https://gitdiagram.com/flaviocavalcantet/vaultgate
- Repository: https://github.com/flaviocavalcantet/vaultgate

## Overview

VaultGate is a self-hosted organizational file vault. Users authenticate through an identity provider and use the API to register files, obtain transfer intents, manage folders and shares, and apply access policies; file bytes flow through a separate streaming gateway for encryption and object storage. Uploaded files are scanned asynchronously, with verdicts reported to the API, while security actions are recorded in an append-only audit log. The README documents the service-level flow; source excerpts and the index support the shown internal links, but not every unsampled subsystem’s wiring.

Main entry points: [`gateway/src/vaultgate_gateway/app.py`](https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/app.py) (Streaming gateway), [`api/src/vaultgate_api/main.py`](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/main.py) (FastAPI control plane), [`api/src/vaultgate_api/routers/files.py`](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/routers/files.py) (File routes), [`scanner/internal/worker/worker.go`](https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/worker/worker.go) (Scan worker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_api["FastAPI control plane<br/>[main.py]"]
  node_file_routes["File routes<br/>[files.py]"]
  node_share_routes["Share routes<br/>[shares.py]"]
  node_folders["Folder management<br/>[folders.py]"]
  node_policies["Access policies<br/>[policies.py]"]
  node_models["Metadata models<br/>[models.py]"]
  node_database[("PostgreSQL<br/>[db.py]")]
  node_scanner_api["Internal scan reporting<br/>[scans.py]"]
end

subgraph group_transfer["Encrypted transfers"]
  node_gateway["Streaming gateway<br/>[app.py]"]
  node_crypto["Stream encryption<br/>[crypto.py]"]
  node_storage["Object storage access<br/>[storage.py]"]
  node_s3[("S3")]
  node_key_management["Data key handling<br/>[keys.py]"]
  node_kms["AWS KMS"]
end

subgraph group_scan["PII scanning"]
  node_scanner_worker["Scan worker<br/>[worker.go]"]
  node_scan_pipeline["Extraction and scanning<br/>[scan.go]"]
  node_extract["Document extraction<br/>[extract.go]"]
  node_detect["PII detectors<br/>[detect.go]"]
  node_queue["SQS scan queue"]
end

subgraph group_security["Identity and audit"]
  node_auth["OIDC token validation<br/>[auth.py]"]
  node_idp["Identity provider"]
  node_audit[("Append-only audit<br/>[audit.py]")]
end

node_user(("User / browser"))

node_user -->|"calls JSON API"| node_api
node_user -->|"signs in"| node_idp
node_api -->|"validates requests"| node_auth
node_auth -->|"fetches signing keys"| node_idp
node_api -->|"mounts routes"| node_file_routes
node_api -->|"mounts routes"| node_share_routes
node_file_routes -->|"uses folder checks"| node_folders
node_file_routes -->|"reads and writes"| node_models
node_share_routes -->|"reads and writes"| node_models
node_policies -.->|"evaluates against"| node_models
node_api -->|"serves metadata"| node_database
node_user -->|"streams file bytes"| node_gateway
node_gateway -->|"validates upload intent"| node_api
node_gateway -->|"encrypts chunks"| node_crypto
node_gateway -->|"writes and reads objects"| node_storage
node_storage -->|"stores ciphertext"| node_s3
node_gateway -->|"generates data key"| node_key_management
node_key_management -->|"wraps data key"| node_kms
node_gateway -->|"publishes upload event"| node_queue
node_queue -->|"provides scan requests"| node_scanner_worker
node_scanner_worker -->|"reads encrypted objects"| node_storage
node_scanner_worker -->|"scans file content"| node_scan_pipeline
node_scan_pipeline -->|"extracts text"| node_extract
node_scan_pipeline -->|"detects PII"| node_detect
node_scanner_worker -->|"reports verdict"| node_scanner_api
node_file_routes -->|"records actions"| node_audit
node_share_routes -->|"records share events"| node_audit

click node_api "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/main.py"
click node_file_routes "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/routers/files.py"
click node_share_routes "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/routers/shares.py"
click node_folders "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/folders.py"
click node_policies "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/policies.py"
click node_models "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/models.py"
click node_database "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/db.py"
click node_gateway "https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/app.py"
click node_crypto "https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/crypto.py"
click node_storage "https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/storage.py"
click node_key_management "https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/keys.py"
click node_scanner_worker "https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/worker/worker.go"
click node_scan_pipeline "https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/scan/scan.go"
click node_extract "https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/extract/extract.go"
click node_detect "https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/detect/detect.go"
click node_scanner_api "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/scans.py"
click node_auth "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/auth.py"
click node_audit "https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/audit.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_api,node_file_routes,node_share_routes,node_folders,node_policies,node_models,node_database,node_scanner_api,node_user toneBlue
class node_gateway,node_crypto,node_storage,node_s3,node_key_management,node_kms toneAmber
class node_scanner_worker,node_scan_pipeline,node_extract,node_detect,node_queue toneMint
class node_auth,node_idp,node_audit toneRose
```

## Components

### Control plane

- [FastAPI control plane](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/main.py): `api/src/vaultgate_api/main.py`
- [File routes](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/routers/files.py): `api/src/vaultgate_api/routers/files.py`
- [Share routes](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/routers/shares.py): `api/src/vaultgate_api/routers/shares.py`
- [Folder management](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/folders.py): `api/src/vaultgate_api/folders.py`
- [Access policies](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/policies.py): `api/src/vaultgate_api/policies.py`
- [Metadata models](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/models.py): `api/src/vaultgate_api/models.py`
- [PostgreSQL](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/db.py): `api/src/vaultgate_api/db.py`
- [Internal scan reporting](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/scans.py): `api/src/vaultgate_api/scans.py`

### Encrypted transfers

- [Streaming gateway](https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/app.py): `gateway/src/vaultgate_gateway/app.py`
- [Stream encryption](https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/crypto.py): `gateway/src/vaultgate_gateway/crypto.py`
- [Object storage access](https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/storage.py): `gateway/src/vaultgate_gateway/storage.py`
- **S3**
- [Data key handling](https://github.com/flaviocavalcantet/vaultgate/blob/main/gateway/src/vaultgate_gateway/keys.py): `gateway/src/vaultgate_gateway/keys.py`
- **AWS KMS**

### PII scanning

- [Scan worker](https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/worker/worker.go): `scanner/internal/worker/worker.go`
- [Extraction and scanning](https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/scan/scan.go): `scanner/internal/scan/scan.go`
- [Document extraction](https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/extract/extract.go): `scanner/internal/extract/extract.go`
- [PII detectors](https://github.com/flaviocavalcantet/vaultgate/blob/main/scanner/internal/detect/detect.go): `scanner/internal/detect/detect.go`
- **SQS scan queue**

### Identity and audit

- [OIDC token validation](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/auth.py): `api/src/vaultgate_api/auth.py`
- **Identity provider**
- [Append-only audit](https://github.com/flaviocavalcantet/vaultgate/blob/main/api/src/vaultgate_api/audit.py): `api/src/vaultgate_api/audit.py`

### Other components

- **User / browser**

## Connections

- User / browser → FastAPI control plane: calls JSON API
- User / browser → Identity provider: signs in
- FastAPI control plane → OIDC token validation: validates requests (evidence: `api/src/vaultgate_api/main.py`)
- OIDC token validation → Identity provider: fetches signing keys (evidence: `api/src/vaultgate_api/auth.py`)
- FastAPI control plane → File routes: mounts routes (evidence: `api/src/vaultgate_api/main.py`)
- FastAPI control plane → Share routes: mounts routes (evidence: `api/src/vaultgate_api/main.py`)
- File routes → Folder management: uses folder checks (evidence: `api/src/vaultgate_api/routers/files.py`)
- File routes → Metadata models: reads and writes (evidence: `api/src/vaultgate_api/routers/files.py`)
- Share routes → Metadata models: reads and writes (evidence: `api/src/vaultgate_api/routers/shares.py`)
- Access policies → Metadata models: evaluates against
- FastAPI control plane → PostgreSQL: serves metadata
- User / browser → Streaming gateway: streams file bytes
- Streaming gateway → FastAPI control plane: validates upload intent
- Streaming gateway → Stream encryption: encrypts chunks (evidence: `gateway/src/vaultgate_gateway/app.py`)
- Streaming gateway → Object storage access: writes and reads objects (evidence: `gateway/src/vaultgate_gateway/app.py`)
- Object storage access → S3: stores ciphertext
- Streaming gateway → Data key handling: generates data key (evidence: `gateway/src/vaultgate_gateway/app.py`)
- Data key handling → AWS KMS: wraps data key
- Streaming gateway → SQS scan queue: publishes upload event
- SQS scan queue → Scan worker: provides scan requests
- Scan worker → Object storage access: reads encrypted objects
- Scan worker → Extraction and scanning: scans file content (evidence: `scanner/internal/worker/worker.go`)
- Extraction and scanning → Document extraction: extracts text (evidence: `scanner/internal/scan/scan.go`)
- Extraction and scanning → PII detectors: detects PII (evidence: `scanner/internal/scan/scan.go`)
- Scan worker → Internal scan reporting: reports verdict
- File routes → Append-only audit: records actions (evidence: `api/src/vaultgate_api/routers/files.py`)
- Share routes → Append-only audit: records share events (evidence: `api/src/vaultgate_api/routers/shares.py`)
