# kanavgoyal898/chromavive architecture

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

- Interactive diagram: https://gitdiagram.com/kanavgoyal898/chromavive
- Repository: https://github.com/kanavgoyal898/chromavive

## Overview

##### Project type and purpose
- chromaVive is a full-stack web application (Flask/Python backend + HTML/CSS frontend) that lets users upload grayscale images and colorize them using one of two deep-learning models (ECCV16 for automatic colorization, SIGGRAPH17 for user-guided colorization).

##### File structure
- Top-level files:
- README.md, requirements.txt – project overview and dependencies
- test.ipynb – exploratory/testing notebook
- src/
- app.py – Flask application entrypoint and route definitions
- colorization/
– demo_release.py – orchestrates image I/O, model loading, and inference
– colorizers/ – Python modules implementing ECCV16 and SIGGRAPH17 pipelines
– imgs, imgs_out – sample input/output folders
- static/ – CSS and client-side assets
- templates/ – Jinja2 templates (index.html upload form, result.html display, base.html layout)

##### README for architecture clues
- Backend uses Flask with Flask-Session for request handling and session persistence
- Deep learning inference via PyTorch, loading pretrained models for ECCV16 and SIGGRAPH17
- Two operational modes: fully automatic vs. user-hint guided colorization
- Frontend is a thin UI layer sending images via HTTP POST to Flask endpoints

##### Main components
a. Client (Web Browser)
- UI: HTML templates, CSS assets, file chooser, hint-point drawing interface
b. Web Server (Flask)
- app.py: defines routes (/ , /colorize_auto, /colorize_guided)
- Session Manager: stores user hints and intermediate data
c. Colorization Service
- demo_release.py: receives image and hints, selects model
- Model Loader: loads ECCV16 or SIGGRAPH17 PyTorch weights
- Inference Engine: runs forward pass, returns colorized image
d. Data Stores
- Temporary file storage (imgs, imgs_out) or in-memory buffers
- Session store (Flask-Session)
e. External Libraries & Frameworks
- Flask, Flask-Session – HTTP server & session management
- PyTorch – loading and running neural nets
- Jinja2 – templating
f. (Optional) Notebook Environment
- test.ipynb – used for prototyping, not in production flow

##### Relationships and data flow
2. Browser issues HTTP POST to Flask endpoint
3. Flask route handler calls demo_release.py
4. demo_release loads appropriate colorizer class from colorizers/
5. Colorizer loads pretrained weights (PyTorch) and performs inference
6. demo_release saves or streams back the colorized image
7. Flask returns rendered result.html displaying output
8. Browser renders the colorized image

##### Architectural patterns and design principles
- MVC-like separation:
- Model = PyTorch networks & colorizers
- View = Jinja2 templates + static CSS
- Controller = Flask routes + demo_release orchestrator
- Single-process, synchronous inference for simplicity
- Modularity: each colorizer algorithm encapsulated under src/colorization/colorizers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Web Browser)" 
        direction TB
        UI_HTML_Index["index.html"]:::frontend
        UI_HTML_Result["result.html"]:::frontend
        UI_HTML_Base["base.html"]:::frontend
        UI_CSS["base.css"]:::frontend
        UI_Assets["assets"]:::frontend
    end

    %% Server Layer
    subgraph "Web Server (Flask)" 
        direction TB
        Flask_App["app.py"]:::backend
        Session_Manager["Session Manager"]:::backend
    end

    %% Colorization Service
    subgraph "Colorization Service" 
        direction TB
        Orchestrator["demo_release.py"]:::backend
        subgraph "Colorizers"
            direction TB
            Color_ECCV16["eccv16.py"]:::ml
            Color_SIG["siggraph17.py"]:::ml
            Color_Base["base_color.py"]:::ml
            Color_Util["util.py"]:::ml
        end
    end

    %% Data Stores
    subgraph "Data Stores" 
        direction TB
        Imgs_In(["imgs"]):::datastore
        Imgs_Out(["imgs_out"]):::datastore
        Session_Store(("Session Store")):::datastore
    end

    %% External Dependencies
    subgraph "External Dependencies" 
        direction TB
        Req["requirements.txt"]:::docs
    end

    %% Notebook & Docs
    Notebook["test.ipynb"]:::docs
    README["README.md"]:::docs

    %% Data Flows
    UI_HTML_Index -->|"POST /colorize_auto or /colorize_guided"| Flask_App
    UI_HTML_Result ---|renders| UI_HTML_Index
    UI_CSS -->|loads CSS| UI_HTML_Index
    UI_Assets -->|loads assets| UI_HTML_Index

    Flask_App -->|calls| Orchestrator
    Flask_App -->|manages sessions| Session_Manager
    Flask_App -.->|uses| Req

    Orchestrator -->|loads model| Color_ECCV16
    Orchestrator -->|loads model| Color_SIG
    Orchestrator -->|uses utilities| Color_Util
    Orchestrator -->|invokes base pipeline| Color_Base

    Color_ECCV16 -->|reads/writes| Imgs_In
    Color_SIG -->|reads/writes| Imgs_In
    Color_ECCV16 -->|writes| Imgs_Out
    Color_SIG -->|writes| Imgs_Out
    Session_Manager -->|stores hints| Session_Store

    Imgs_Out -->|returned image| Flask_App
    Flask_App -->|renders| UI_HTML_Result

    Notebook -->|prototype| Orchestrator
    README -->|docs| Flask_App

    %% Click Events
    click UI_HTML_Index "https://github.com/kanavgoyal898/chromavive/blob/main/src/templates/index.html"
    click UI_HTML_Result "https://github.com/kanavgoyal898/chromavive/blob/main/src/templates/result.html"
    click UI_HTML_Base "https://github.com/kanavgoyal898/chromavive/blob/main/src/templates/base.html"
    click UI_CSS "https://github.com/kanavgoyal898/chromavive/blob/main/src/static/css/base.css"
    click UI_Assets "https://github.com/kanavgoyal898/chromavive/tree/main/src/static/assets"
    click Flask_App "https://github.com/kanavgoyal898/chromavive/blob/main/src/app.py"
    click Orchestrator "https://github.com/kanavgoyal898/chromavive/blob/main/src/colorization/demo_release.py"
    click Color_ECCV16 "https://github.com/kanavgoyal898/chromavive/blob/main/src/colorization/colorizers/eccv16.py"
    click Color_SIG "https://github.com/kanavgoyal898/chromavive/blob/main/src/colorization/colorizers/siggraph17.py"
    click Color_Base "https://github.com/kanavgoyal898/chromavive/blob/main/src/colorization/colorizers/base_color.py"
    click Color_Util "https://github.com/kanavgoyal898/chromavive/blob/main/src/colorization/colorizers/util.py"
    click Imgs_In "https://github.com/kanavgoyal898/chromavive/tree/main/src/colorization/imgs"
    click Imgs_Out "https://github.com/kanavgoyal898/chromavive/tree/main/src/colorization/imgs_out"
    click Req "https://github.com/kanavgoyal898/chromavive/blob/main/requirements.txt"
    click Notebook "https://github.com/kanavgoyal898/chromavive/blob/main/test.ipynb"
    click README "https://github.com/kanavgoyal898/chromavive/blob/main/README.md"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0288D1,color:#000;
    classDef backend fill:#D0F2D7,stroke:#2E7D32,color:#000;
    classDef ml fill:#FFE0B2,stroke:#E65100,color:#000;
    classDef datastore fill:#FFF8E1,stroke:#F9A825,color:#000;
    classDef docs fill:#F0F0F0,stroke:#9E9E9E,color:#000;
```
