# appacta/acta-import-api architecture

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

- Interactive diagram: https://gitdiagram.com/appacta/acta-import-api
- Repository: https://github.com/appacta/acta-import-api

## Overview

ACTA Import API accepts PDCA attachments, validates and records them, then processes uploads asynchronously and exposes their status. The main flow is documented in the README and visible in the route, service, and worker excerpts. Authentication has separate user-token and AI-token paths. The graph also includes the distinct text-validation and upload-job stages. Some implementation details are unsampled; documented relationships are cited to the README where needed.

Main entry points: [`app/services/anexos.py`](https://github.com/appacta/acta-import-api/blob/main/app/services/anexos.py) (Attachment service), [`app/routes/anexos.py`](https://github.com/appacta/acta-import-api/blob/main/app/routes/anexos.py) (Attachment routes), [`app/services/jobs.py`](https://github.com/appacta/acta-import-api/blob/main/app/services/jobs.py) (Upload processor), [`app/services/autenticacao.py`](https://github.com/appacta/acta-import-api/blob/main/app/services/autenticacao.py) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_routes["Attachment routes<br/>[anexos.py]"]
  node_auth["Authentication<br/>[autenticacao.py]"]
end

subgraph group_intake["Attachment intake"]
  node_types["Attachment types<br/>[enums.py]"]
  node_schemas["Request and job models<br/>[schemas.py]"]
  node_intake_service["Attachment service<br/>[anexos.py]"]
  node_validation["File validation<br/>[validacao.py]"]
  node_text_validation["Text validation<br/>[sem_magic_bytes.py]"]
end

subgraph group_async["Async processing"]
  node_redis_queue["Upload queue<br/>[fila.py]"]
  node_redis[("Redis<br/>[redis.py]")]
  node_worker["Queue worker<br/>[worker.py]"]
  node_job_processor["Upload processor<br/>[jobs.py]"]
end

subgraph group_storage["Persistence and files"]
  node_postgres[("PostgreSQL<br/>[postgres.py]")]
  node_cloudinary_service["Cloudinary client<br/>[cloudinary.py]"]
end

node_client(("ACTA client"))
node_pgapi["acta-pg-api"]
node_cloudinary["Cloudinary"]

node_client -->|"submits or queries"| node_routes
node_routes -->|"resolves identity"| node_auth
node_auth -->|"queries user"| node_pgapi
node_auth -->|"checks AI user"| node_postgres
node_routes -->|"dispatches upload"| node_intake_service
node_routes -->|"requests status"| node_intake_service
node_intake_service -->|"validates file"| node_validation
node_validation -->|"validates text"| node_text_validation
node_intake_service -->|"checks and records"| node_postgres
node_intake_service -->|"enqueues job"| node_redis_queue
node_redis_queue -->|"uses connection"| node_redis
node_worker -->|"consumes jobs"| node_redis_queue
node_worker -->|"runs job"| node_job_processor
node_job_processor -->|"reads and updates"| node_postgres
node_job_processor -->|"uploads file"| node_cloudinary_service
node_cloudinary_service -->|"stores file"| node_cloudinary
node_intake_service -->|"builds job"| node_schemas
node_intake_service -->|"sets status"| node_types
node_job_processor -->|"updates status"| node_types
node_intake_service -->|"returns receipt or status"| node_client

click node_routes "https://github.com/appacta/acta-import-api/blob/main/app/routes/anexos.py"
click node_auth "https://github.com/appacta/acta-import-api/blob/main/app/services/autenticacao.py"
click node_types "https://github.com/appacta/acta-import-api/blob/main/app/models/enums.py"
click node_schemas "https://github.com/appacta/acta-import-api/blob/main/app/schemas.py"
click node_intake_service "https://github.com/appacta/acta-import-api/blob/main/app/services/anexos.py"
click node_validation "https://github.com/appacta/acta-import-api/blob/main/app/utils/validacao.py"
click node_text_validation "https://github.com/appacta/acta-import-api/blob/main/app/utils/sem_magic_bytes.py"
click node_postgres "https://github.com/appacta/acta-import-api/blob/main/app/database/postgres.py"
click node_redis_queue "https://github.com/appacta/acta-import-api/blob/main/app/services/fila.py"
click node_redis "https://github.com/appacta/acta-import-api/blob/main/app/database/redis.py"
click node_worker "https://github.com/appacta/acta-import-api/blob/main/worker.py"
click node_job_processor "https://github.com/appacta/acta-import-api/blob/main/app/services/jobs.py"
click node_cloudinary_service "https://github.com/appacta/acta-import-api/blob/main/app/services/cloudinary.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_routes,node_auth,node_client toneBlue
class node_types,node_schemas,node_intake_service,node_validation,node_text_validation toneAmber
class node_redis_queue,node_redis,node_worker,node_job_processor,node_pgapi toneMint
class node_postgres,node_cloudinary_service toneRose
class node_cloudinary toneIndigo
```

## Components

### API and identity

- [Attachment routes](https://github.com/appacta/acta-import-api/blob/main/app/routes/anexos.py): `app/routes/anexos.py`
- [Authentication](https://github.com/appacta/acta-import-api/blob/main/app/services/autenticacao.py): `app/services/autenticacao.py`

### Attachment intake

- [Attachment types](https://github.com/appacta/acta-import-api/blob/main/app/models/enums.py): `app/models/enums.py`
- [Request and job models](https://github.com/appacta/acta-import-api/blob/main/app/schemas.py): `app/schemas.py`
- [Attachment service](https://github.com/appacta/acta-import-api/blob/main/app/services/anexos.py): `app/services/anexos.py`
- [File validation](https://github.com/appacta/acta-import-api/blob/main/app/utils/validacao.py): `app/utils/validacao.py`
- [Text validation](https://github.com/appacta/acta-import-api/blob/main/app/utils/sem_magic_bytes.py): `app/utils/sem_magic_bytes.py`

### Async processing

- [Upload queue](https://github.com/appacta/acta-import-api/blob/main/app/services/fila.py): `app/services/fila.py`
- [Redis](https://github.com/appacta/acta-import-api/blob/main/app/database/redis.py): `app/database/redis.py`
- [Queue worker](https://github.com/appacta/acta-import-api/blob/main/worker.py): `worker.py`
- [Upload processor](https://github.com/appacta/acta-import-api/blob/main/app/services/jobs.py): `app/services/jobs.py`

### Persistence and files

- [PostgreSQL](https://github.com/appacta/acta-import-api/blob/main/app/database/postgres.py): `app/database/postgres.py`
- [Cloudinary client](https://github.com/appacta/acta-import-api/blob/main/app/services/cloudinary.py): `app/services/cloudinary.py`

### Other components

- **ACTA client**
- **acta-pg-api**
- **Cloudinary**

## Connections

- ACTA client → Attachment routes: submits or queries (evidence: `README.md`)
- Attachment routes → Authentication: resolves identity (evidence: `app/routes/anexos.py`)
- Authentication → acta-pg-api: queries user (evidence: `app/services/autenticacao.py`)
- Authentication → PostgreSQL: checks AI user (evidence: `app/services/autenticacao.py`)
- Attachment routes → Attachment service: dispatches upload (evidence: `app/routes/anexos.py`)
- Attachment routes → Attachment service: requests status (evidence: `app/routes/anexos.py`)
- Attachment service → File validation: validates file (evidence: `app/services/anexos.py`)
- File validation → Text validation: validates text (evidence: `app/utils/validacao.py`)
- Attachment service → PostgreSQL: checks and records (evidence: `app/services/anexos.py`)
- Attachment service → Upload queue: enqueues job (evidence: `app/services/anexos.py`)
- Upload queue → Redis: uses connection (evidence: `app/services/fila.py`)
- Queue worker → Upload queue: consumes jobs (evidence: `worker.py`)
- Queue worker → Upload processor: runs job (evidence: `README.md`)
- Upload processor → PostgreSQL: reads and updates (evidence: `app/services/jobs.py`)
- Upload processor → Cloudinary client: uploads file (evidence: `app/services/jobs.py`)
- Cloudinary client → Cloudinary: stores file (evidence: `README.md`)
- Attachment service → Request and job models: builds job (evidence: `app/services/anexos.py`)
- Attachment service → Attachment types: sets status (evidence: `app/services/anexos.py`)
- Upload processor → Attachment types: updates status (evidence: `app/services/jobs.py`)
- Attachment service → ACTA client: returns receipt or status (evidence: `README.md`)
