# phkhanhtrinh23/translation_layoutrecovery architecture

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

- Interactive diagram: https://gitdiagram.com/phkhanhtrinh23/translation_layoutrecovery
- Repository: https://github.com/phkhanhtrinh23/translation_layoutrecovery

## Overview

##### Project Components
- Frontend: Built with NextJS, TailwindCSS, and NodeJS. It resides in the Frontend folder, includes pages for login, register, history, profile, etc., and communicates with the backend via API routes.
- Backend: Constructed using Django REST Framework (in the Backend folder). It contains separate apps like “account” and “translation” handling user management and translation logic.
- AI Core / Models: Managed mainly in the “Model” and “evaluate” directories. These include scripts and utilities for Neural Machine Translation (envit5-translation), Layout Recovery (MaskRCNN), and OCR (with several plugins like EasyOCR and others).
- Database & Storage: The technical overview specifies PostgreSQL for data persistence and Firebase Cloud Storage for storing files (such as uploaded PDFs and translated outputs).
- Deployment/Containers: Docker is used extensively—as evidenced by Dockerfile.frontend, Dockerfile.backend, and the docker-compose.yml file—to containerize and orchestrate the services.
- Additional Utilities: Environment files (.env-sample), configuration files, and build scripts are also part of the system to ease development and deployment.

##### Relationships and Interactions
- The user interacts with the Frontend web application (browser → NextJS).
- The Frontend sends HTTP requests (REST API calls) to the Backend (Django) for operations like user authentication, file uploads, translation requests, and history retrieval.
- The Backend, upon receiving requests, coordinates with:
- The AI/ML core for processing tasks such as OCR, NMT, and layout recovery.
- The PostgreSQL database for storing user data, session information, and process metadata.
- Firebase Cloud Storage to manage file uploads/downloads (e.g., original PDFs, translated documents).
- The Docker tooling allows you to containerize these interactions, ensuring each component (frontend, backend, possibly AI model services) runs in isolated containers, as coordinated by docker-compose.

##### Architectural Patterns & Technologies
- Separation of concerns is prevalent. The split between Frontend (NextJS) and Backend (Django REST) exemplifies the common full-stack separation.
- Microservice-like behavior is hinted at by the distinct folders for “translation,” “account,” and “services” in the Backend. Similarly, the independent Model and evaluate directories suggest modular handling of AI tasks.
- The design embraces containerization to manage dependencies and deployment via Docker.
- Specific AI/ML services (NMT, Layout Recovery using MaskRCNN, OCR with EasyOCR) indicate a layered approach where the Backend orchestrates requests and hands off data to the corresponding AI modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Components
    User["User Browser"]:::user
    FE["Frontend Service (NextJS)"]:::frontend
    BE["Backend Service (Django REST API)"]:::backend
    UModule["User Module (Account Management)"]:::backend
    TModule["Translation Module (Paper Translation Logic)"]:::backend
    DB["Database (PostgreSQL)"]:::datastore
    FS["File Storage (Firebase Cloud Storage)"]:::datastore
    AI_Model["AI Core: Models (NMT & Layout Recovery)"]:::ai
    AI_Eval["AI Core: Evaluation (OCR)"]:::ai
    DockerOrch["Docker Container Orchestrator"]:::deployment

    %% User interaction flow
    User -->|"UserRequests/UIInteractions"| FE
    FE -->|"APICalls"| BE

    %% Backend internal modules
    BE -->|"Auth&Translation"| UModule
    BE -->|"TranslationLogic"| TModule

    %% Persistence and File IO
    BE -->|"DataPersistence"| DB
    BE -->|"FileIO"| FS

    %% AI processing pipeline
    BE -->|"TranslationRequest"| AI_Model
    BE -->|"FileProcessing"| AI_Eval

    %% Docker orchestration relationships (dashed lines)
    DockerOrch ---|"Containerizes"| FE
    DockerOrch ---|"Containerizes"| BE
    DockerOrch ---|"Containerizes"| AI_Model
    DockerOrch ---|"Containerizes"| AI_Eval

    %% Deployment Configurations Subgraph
    subgraph "Docker Configurations"
        DFE["Dockerfile.frontend"]:::deployment
        DBE["Dockerfile.backend"]:::deployment
        DCompose["docker-compose.yml"]:::deployment
        EnvV[".env-sample"]:::deployment
    end

    DockerOrch --- DFE
    DockerOrch --- DBE
    DockerOrch --- DCompose
    DockerOrch --- EnvV

    %% Click Events
    click FE "https://github.com/phkhanhtrinh23/translation_layoutrecovery/tree/main/Frontend/"
    click BE "https://github.com/phkhanhtrinh23/translation_layoutrecovery/tree/main/Backend/"
    click UModule "https://github.com/phkhanhtrinh23/translation_layoutrecovery/tree/main/Backend/account/"
    click TModule "https://github.com/phkhanhtrinh23/translation_layoutrecovery/tree/main/Backend/translation/"
    click AI_Model "https://github.com/phkhanhtrinh23/translation_layoutrecovery/tree/main/Model/"
    click AI_Eval "https://github.com/phkhanhtrinh23/translation_layoutrecovery/tree/main/evaluate/"
    click DFE "https://github.com/phkhanhtrinh23/translation_layoutrecovery/blob/main/Dockerfile.frontend"
    click DBE "https://github.com/phkhanhtrinh23/translation_layoutrecovery/blob/main/Dockerfile.backend"
    click DCompose "https://github.com/phkhanhtrinh23/translation_layoutrecovery/blob/main/docker-compose.yml"
    click EnvV "https://github.com/phkhanhtrinh23/translation_layoutrecovery/blob/main/.env-sample"

    %% Styles
    classDef user fill:#f8c291,stroke:#333,stroke-width:2px
    classDef frontend fill:#74b9ff,stroke:#333,stroke-width:2px
    classDef backend fill:#55efc4,stroke:#333,stroke-width:2px
    classDef datastore fill:#ff7675,stroke:#333,stroke-width:2px
    classDef ai fill:#ffeaa7,stroke:#333,stroke-width:2px
    classDef deployment fill:#dfe6e9,stroke:#333,stroke-width:2px,stroke-dasharray:5, 5
```
