# swagath18/multilingual-content-translation-api architecture

> Architecture diagram of the GitHub repository swagath18/multilingual-content-translation-api, 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/swagath18/multilingual-content-translation-api
- Repository: https://github.com/swagath18/multilingual-content-translation-api

## Overview

##### Main Components
- Frontend (Presentation Layer):
- Component Label: "Streamlit Frontend (app.py)"
- Purpose: Provides the user interface for file uploads, language selection, and displaying translation results.
- Backend (Business Logic Layer):
- Component Label: "FastAPI Backend (backend/main.py)"
- Purpose: Handles API requests, processes file uploads, and orchestrates text extraction and translation.
- Services:
- Component Label: "Translation Service (backend/services/translation_service.py)"
- Purpose: Contains the translation logic using OpenAI's GPT API.
- Utilities:
- Component Labels:
▪ "Text Extraction Utils (backend/utils/text_extraction.py)"
▪ "Language Map Utils (backend/utils/language_map.py)"
- Purpose: Manage file parsing logic for PDF, PPT/PPTX, TXT, and HTML using libraries like PyPDF2, python-pptx, and BeautifulSoup.
- External Integration:
- Component Label: "OpenAI API (GPT-3/4)"
- Purpose: Provides AI translation services upon requests from the backend.

##### Relationships and Data Flow
- The user interacts with the Streamlit frontend.
- Inside the backend:
- The "Translation Service" sends requests to the "OpenAI API" to convert extracted text into the requested language.
- Finally, the translated text is passed back from the "Translation Service" to the "FastAPI Backend" and then returned to the "Streamlit Frontend" for display.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear delimitation between the Streamlit frontend and FastAPI backend supports independent scalability and maintenance.
- Modularization: By having dedicated modules for translation (services) and text processing (utils), the design promotes reusability and ease of future enhancements.
- API-Centric Integration: The backend acts as an intermediary between the frontend and external OpenAI translation services, establishing a clean API layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI("User Interface"):::external
    FE("Streamlit Frontend (app.py)"):::frontend
    BE("FastAPI Backend (backend/main.py)"):::backend
    TE("Text Extraction Utils (backend/utils/text_extraction.py)"):::utils
    LM("Language Map Utils (backend/utils/language_map.py)"):::utils
    TS("Translation Service (backend/services/translation_service.py)"):::service
    OA("OpenAI API (GPT-3/4)"):::external

    UI -->|"file_upload"| FE
    FE -->|"API_request"| BE
    BE -->|"extract_text"| TE
    BE -->|"language_map"| LM
    BE -->|"translation_request"| TS
    TS -->|"call_translation"| OA
    OA -->|"translation_response"| TS
    TS -->|"translated_text"| BE
    BE -->|"response_data"| FE

    click FE "https://github.com/swagath18/multilingual-content-translation-api/blob/main/app.py"
    click BE "https://github.com/swagath18/multilingual-content-translation-api/blob/main/backend/main.py"
    click TS "https://github.com/swagath18/multilingual-content-translation-api/blob/main/backend/services/translation_service.py"
    click TE "https://github.com/swagath18/multilingual-content-translation-api/blob/main/backend/utils/text_extraction.py"
    click LM "https://github.com/swagath18/multilingual-content-translation-api/blob/main/backend/utils/language_map.py"

    classDef frontend fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef service fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef utils fill:#ffff99,stroke:#000,stroke-width:2px;
    classDef external fill:#dda0dd,stroke:#000,stroke-width:2px;
```
