# senacen/anaglyph-ai architecture

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

- Interactive diagram: https://gitdiagram.com/senacen/anaglyph-ai
- Repository: https://github.com/senacen/anaglyph-ai

## Overview

##### Main Components
- Frontend: A React/Vite application written mainly in TypeScript. It contains components such as AnaglyphEditor, ImageUpload, Footer, and App. This part handles the user interface for uploading images, setting parameters (e.g., disparity strength, zero parallax options), and displaying results.
- Backend: A Flask-based Python application with files such as app.py, anaglyph_generator.py, depth_map_generator.py, and a notebook for random image processing. This layer handles the core logic of depth map generation (using a model like DepthAnythingV2), stereo pair generation, image shifting, inpainting using OpenCV, and merging to produce the final anaglyph.
- External Services & Libraries:
- An external depth estimation model (DepthAnythingV2).
- OpenCV inpainting functions.
- NumPy for numerical operations.
- Docker & Deployment: Both the frontend and backend have separate Dockerfiles along with .env files, indicating containerized deployment and likely orchestration for a production environment.

##### Relationships & Data Flow
- User Interface (Browser/Client) → Frontend React Application: The user interacts with the web application, uploads images, tweaks parameters (like disparity strength, pop in/pop out, minimise retinal rivalry).
- Frontend → API Calls to Backend: Once an image is uploaded or settings are adjusted, the frontend sends a REST (or HTTP) API request to the Flask backend.
- Backend Processing:
- Receives the image and command parameters.
- Generates a depth map using the depth estimation module.
- Computes the stereo image pair through pixel shift calculation based on the depth data.
- Applies OpenCV inpainting to fill missing pixels (or holes) in the generated eye images.
- Backend → Frontend Response: The processed 3D anaglyph image is then returned to the frontend to be displayed.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Distinct separation between the frontend (user interface) and backend (image processing and API logic).
- Containerization: Each layer is containerized (frontend and backend have Dockerfiles and proper environment configurations), suggesting microservice-friendly modularity.
- Modular Processing: The backend comprises separate Python scripts (e.g., depth_map_generator.py for depth estimation, anaglyph_generator.py for merging images) capturing specific stages of processing. This modular design aids in easier debugging and scalability.

##### Technologies and Frameworks to Highlight
- Frontend: React with TypeScript, Vite (for development/build), CSS modules for component styling, and ESLint for code quality.
- Backend: Flask as the web framework; Python libraries such as NumPy for image manipulation, OpenCV for inpainting, and integration with external depth estimation models.
- Deployment: Docker for containerization; possible orchestration when deployed in production.
- Data Input/Output: HTTP endpoints for communication between frontend and backend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        UB("User Browser (Client)"):::client
    end

    subgraph "Frontend"
        FDC("Frontend Docker Container"):::frontend
        RFA("React Frontend Application"):::frontend
        AE("AnaglyphEditor Component"):::module
        IU("ImageUpload Component"):::module
        FT("Footer Component"):::module
        MA("Main Application Component"):::module
        FDC --> RFA
        RFA --> AE
        RFA --> IU
        RFA --> FT
        RFA --> MA
    end

    subgraph "Backend"
        BDC("Backend Docker Container"):::backend
        FBA("Flask Backend API"):::backend
        DMG("Depth Map Generation Module"):::module
        SPC("Stereo Pair Creator"):::module
        IP("Inpainting Module (OpenCV)"):::module
        AM("Anaglyph Merger & Color Correction"):::module
        RIP("Random Image Processing Notebook"):::module
        BDC --> FBA
        FBA --> DMG
        DMG --> SPC
        SPC --> IP
        IP --> AM
        AM --> FBA
    end

    ED("External Depth Estimation Model"):::external

    %% Data Flow
    UB -->|"User_Interactions"| RFA
    RFA -->|"HTTP_API_call"| FBA
    DMG -->|"Uses_Depth_Model"| ED
    FBA -->|"API_response"| RFA
    RFA -->|"Display_3D_Anaglyph"| UB

    %% Click Events
    click RFA "https://github.com/senacen/anaglyph-ai/tree/master/frontend/"
    click AE "https://github.com/senacen/anaglyph-ai/blob/master/frontend/src/AnaglyphEditor.tsx"
    click IU "https://github.com/senacen/anaglyph-ai/blob/master/frontend/src/ImageUpload.tsx"
    click FT "https://github.com/senacen/anaglyph-ai/blob/master/frontend/src/Footer.tsx"
    click MA "https://github.com/senacen/anaglyph-ai/blob/master/frontend/src/App.tsx"
    click FBA "https://github.com/senacen/anaglyph-ai/blob/master/backend/app.py"
    click AM "https://github.com/senacen/anaglyph-ai/blob/master/backend/anaglyph_generator.py"
    click DMG "https://github.com/senacen/anaglyph-ai/blob/master/backend/depth_map_generator.py"
    click RIP "https://github.com/senacen/anaglyph-ai/blob/master/backend/processing_random_images.ipynb"
    click BDC "https://github.com/senacen/anaglyph-ai/tree/master/backend/Dockerfile"
    click FDC "https://github.com/senacen/anaglyph-ai/tree/master/frontend/Dockerfile"

    %% Styles
    classDef client fill:#cce5ff,stroke:#0066CC,stroke-width:2px;
    classDef frontend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef backend fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef module fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
