# archidevil/hat architecture

> Architecture diagram of the GitHub repository archidevil/hat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/archidevil/hat
- Repository: https://github.com/archidevil/hat

## Overview

##### Main Components Identification

The system consists of four main components:
- Frontend (Vue.js application)
- Backend (FastAPI service)
- Worker (Background processing service)
- Database (PostgreSQL)

##### Key Architectural Elements

a) Frontend Layer:
- Vue.js based SPA with the following key modules:
- Document management (/src/stores/document.ts)
- Translation memory (/src/stores/tm.ts)
- Glossary management (/src/stores/glossary.ts)
- User management (/src/stores/user.ts)
- Authentication system

b) Backend Layer:
- FastAPI application with modular structure:
- Document processing (/app/documents)
- Translation memory (/app/translation_memory)
- Glossary management (/app/glossary)
- User management (/app/user)
- Authentication (/app/routers/auth.py)
- Machine translation integration (/app/translators)

c) Worker Component:
- Separate process for background tasks
- Handles document processing and analysis
- Integrates with machine translation services

d) Database Layer:
- PostgreSQL with multiple schemas (visible from alembic migrations)
- Handles various entities: documents, translation memories, glossaries, users

##### External Layer (User Interaction)
- Web Browser
- HTTP/HTTPS access point (Caddy reverse proxy on port 6916)

##### Application Layer
- ┌─────────────────────────────────────────────────────┐
- Reverse Proxy (Caddy)               │
- ┘
- ↓
- ┌─────────────────┐ ←→ ┌─────────────────┐
- Frontend (Vue)  │    │ Backend (FastAPI)│
- Documents    │    │ - Auth          │
- TM          │    │ - Documents     │
- Glossary    │    │ - TM            │
- Users       │    │ - Glossary      │
- ┘    └─────────────────┘
- ↕         ↕
- ┌─────────────┐   │
- Worker    │   │
- (Processing)│   │
- ┘   │
- ↕         ↕
- ┌─────────────────────────────────────────────────────┐
- PostgreSQL                       │
- Documents | TM | Glossary | Users | Auth Tables    │
- ┘

##### Additional Elements
- External service integration (Yandex Translator)
- Database migrations system (Alembic)
- Authentication flow
- Document processing pipeline
- Translation memory matching system

##### Important Notes
- Separation between development and production environments
- Docker container boundaries
- API endpoints groups
- Data flow for document processing
- Security boundaries

##### Specific Features to Highlight
- Translation memory system
- Glossary management
- Document processing pipeline
- User role system
- Machine translation integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        Browser["Web Browser"]
        YandexMT["Yandex MT API"]
    end

    subgraph Infrastructure
        Caddy["Reverse Proxy (Caddy)"]:::infra
        click Caddy "https://github.com/ArchiDevil/hat/tree/master/Caddyfile"
    end

    subgraph Frontend["Frontend Layer"]
        VueApp["Vue.js Application"]:::frontend
        DocStore["Document Store"]:::frontend
        TMStore["Translation Memory Store"]:::frontend
        GlossaryStore["Glossary Store"]:::frontend
        UserStore["User Store"]:::frontend
        Views["Vue Views"]:::frontend

        click DocStore "https://github.com/ArchiDevil/hat/blob/master/frontend/src/stores/document.ts"
        click TMStore "https://github.com/ArchiDevil/hat/blob/master/frontend/src/stores/tm.ts"
        click GlossaryStore "https://github.com/ArchiDevil/hat/blob/master/frontend/src/stores/glossary.ts"
        click UserStore "https://github.com/ArchiDevil/hat/blob/master/frontend/src/stores/user.ts"
        click Views "https://github.com/ArchiDevil/hat/tree/master/frontend/src/views/"
    end

    subgraph Backend["Backend Layer"]
        FastAPI["FastAPI Service"]:::backend
        AuthRouter["Auth Router"]:::backend
        DocRouter["Document Router"]:::backend
        TMRouter["TM Router"]:::backend
        GlossaryRouter["Glossary Router"]:::backend
        UserRouter["User Router"]:::backend
        MTService["MT Service"]:::backend

        click FastAPI "https://github.com/ArchiDevil/hat/blob/master/backend/app/db.py"
        click AuthRouter "https://github.com/ArchiDevil/hat/blob/master/backend/app/routers/auth.py"
        click DocRouter "https://github.com/ArchiDevil/hat/blob/master/backend/app/routers/document.py"
        click TMRouter "https://github.com/ArchiDevil/hat/blob/master/backend/app/routers/translation_memory.py"
        click GlossaryRouter "https://github.com/ArchiDevil/hat/blob/master/backend/app/routers/glossary.py"
        click UserRouter "https://github.com/ArchiDevil/hat/blob/master/backend/app/routers/user.py"
        click MTService "https://github.com/ArchiDevil/hat/blob/master/backend/app/translators/yandex.py"
    end

    subgraph Worker["Worker Layer"]
        WorkerService["Background Worker"]:::worker
        DocProcessor["Document Processor"]:::worker
        GlossaryTasks["Glossary Tasks"]:::worker

        click WorkerService "https://github.com/ArchiDevil/hat/blob/master/backend/worker.py"
        click GlossaryTasks "https://github.com/ArchiDevil/hat/blob/master/backend/app/glossary/tasks.py"
    end

    subgraph Database["Database Layer"]
        PostgreSQL["PostgreSQL Database"]:::db
        DocModels["Document Models"]:::db
        TMModels["TM Models"]:::db
        GlossaryModels["Glossary Models"]:::db
        UserModels["User Models"]:::db
        Migrations["Alembic Migrations"]:::db

        click DocModels "https://github.com/ArchiDevil/hat/blob/master/backend/app/documents/models.py"
        click TMModels "https://github.com/ArchiDevil/hat/blob/master/backend/app/translation_memory/models.py"
        click GlossaryModels "https://github.com/ArchiDevil/hat/blob/master/backend/app/glossary/models.py"
        click Migrations "https://github.com/ArchiDevil/hat/tree/master/backend/alembic/versions/"
    end

    Browser --> Caddy
    Caddy --> VueApp
    Caddy --> FastAPI

    VueApp --> DocStore
    VueApp --> TMStore
    VueApp --> GlossaryStore
    VueApp --> UserStore
    VueApp --> Views

    FastAPI --> AuthRouter
    FastAPI --> DocRouter
    FastAPI --> TMRouter
    FastAPI --> GlossaryRouter
    FastAPI --> UserRouter
    FastAPI --> MTService

    MTService --> YandexMT

    DocRouter --> WorkerService
    GlossaryRouter --> WorkerService
    WorkerService --> DocProcessor
    WorkerService --> GlossaryTasks

    AuthRouter --> PostgreSQL
    DocRouter --> PostgreSQL
    TMRouter --> PostgreSQL
    GlossaryRouter --> PostgreSQL
    UserRouter --> PostgreSQL

    PostgreSQL --> DocModels
    PostgreSQL --> TMModels
    PostgreSQL --> GlossaryModels
    PostgreSQL --> UserModels
    PostgreSQL --> Migrations

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef worker fill:#e67e22,stroke:#d35400,color:white
    classDef db fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef infra fill:#34495e,stroke:#2c3e50,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        Worker_L["Worker"]:::worker
        Database_L["Database"]:::db
        Infrastructure_L["Infrastructure"]:::infra
    end
```
