# kanagarajsck/react-flask-docker-app architecture

> Architecture diagram of the GitHub repository kanagarajsck/react-flask-docker-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kanagarajsck/react-flask-docker-app
- Repository: https://github.com/kanagarajsck/react-flask-docker-app

## Overview

##### Project Type & Purpose
- Type: Full-stack web application, composed of a React/Vite frontend (“client”) and a Flask-based inference backend (“server”), both containerized via Docker and orchestrated via docker-compose.
- Purpose: Accept user image uploads in the browser, send them to the backend for face detection and age/gender inference, then display the results.

##### File Structure
- Top-level:
- docker-compose.yml — defines two services: client and server
- client/ — React app (Vite build, ESLint config)
- server/ — Flask app, Python inference scripts, pre-trained Caffe/OpenCV models
- Patterns:
- client/src/components → UploadForm.jsx handles file input & API call
- server/app.py → Flask endpoints
- server/face_detector.py → inference logic loading .prototxt/.caffemodel files
- server/models/ → contains Caffe & OpenCV face/age/gender models

##### Extract Key README Insights
- Confirms React-Flask-Docker stack
- Mentions age-gender detection functionality

##### Main Components & Their Interactions
a. Frontend (React/Vite container)
- UploadForm component captures image
- Sends HTTP POST to Flask API
- Receives JSON { age:…, gender:… }
- Renders results
b. Backend API (Flask container)
- /detect endpoint in app.py
- Delegates to face_detector.py
- face_detector loads models from server/models
- Runs OpenCV face detector → crops faces → age_net/gender_net inference
- Returns JSON response
c. Docker & Host
- docker-compose orchestrates both containers
- Port-mapping: client:80→5173, server:5000→5000
- Networks: client ↔ server on internal network
d. External Dependencies
- OpenCV (cv2), Caffe .prototxt/.caffemodel
- Python packages in requirements.txt
- Vite, React, other npm packages

##### Architectural Patterns & Design Principles
- Separation of concerns: UI vs. inference logic
- Containerization: isolates front and back, ensures reproducible environments
- Stateless API: no persistent storage; each request is independent
- Model abstraction: face_detector module encapsulates ML inference

##### Detailed Capture
- Flask API layer
- Inference module (face_detector.py)
- Model storage (server/models)
- HTTP layer separately from the ML layer
- Technology stacks next to each component:
- React, Vite, Node.js — client
- Python, Flask, OpenCV, Caffe — server

- How the user’s image flows through the system
- How containers communicate internally
- Where and how the ML models are applied
- The clear separation of frontend, backend API, and inference layers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Browser Interaction
    Browser["Browser"]:::frontend

    %% Frontend Layer
    subgraph "Frontend (Client)"
        FS["Frontend Service (React/Vite)"]:::frontend
        FDocker["Dockerfile"]:::config

        UploadFormComp["UploadForm Component"]:::frontend
        UploadFormCSS["UploadForm.css"]:::frontend

        subgraph "Main Entry Points"
            mainjsx["main.jsx"]:::frontend
            appjsx["App.jsx"]:::frontend
            indexhtml["index.html"]:::frontend
        end

        subgraph "Frontend Configuration"
            vitecfg["vite.config.js"]:::config
            eslintcfg["eslint.config.js"]:::config
            pkgjson["package.json"]:::config
        end
    end

    %% Backend Layer
    subgraph "Backend (Server)"
        BS["Backend Service (Flask API)"]:::backend
        BDocker["Dockerfile"]:::config
        FlaskApp["app.py (Flask Application Layer)"]:::backend
        Inference["face_detector.py (Inference Module)"]:::backend
        Dependencies["requirements.txt"]:::backend

        subgraph "Model Storage"
            mdl1["age_deploy.prototxt"]:::models
            mdl2["age_net.caffemodel"]:::models
            mdl3["gender_deploy.prototxt"]:::models
            mdl4["gender_net.caffemodel"]:::models
            mdl5["opencv_face_detector.pbtxt"]:::models
            mdl6["opencv_face_detector_uint8.pb"]:::models
        end
    end

    %% Orchestration
    DockerCompose["docker-compose.yml"]:::docker

    %% Flow of Data
    Browser --> UploadFormComp
    mainjsx --> appjsx --> UploadFormComp
    UploadFormComp -->|"POST /detect"| FlaskApp
    FlaskApp --> Inference
    Inference --> mdl1 & mdl2 & mdl3 & mdl4 & mdl5 & mdl6
    FlaskApp --> Dependencies

    %% Container & Config Relations
    DockerCompose --> FS
    DockerCompose --> BS
    FS --> FDocker
    BS --> BDocker
    FS --> vitecfg & eslintcfg & pkgjson

    %% Internal Network
    FS --- BS

    %% Click Events
    click FS "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/docker-compose.yml"
    click BDocker "https://github.com/kanagarajsck/react-flask-docker-app/tree/main/server/Dockerfile"
    click FDocker "https://github.com/kanagarajsck/react-flask-docker-app/tree/main/client/Dockerfile"
    click UploadFormComp "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/src/components/UploadForm.jsx"
    click UploadFormCSS "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/src/components/UploadForm.css"
    click mainjsx "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/src/main.jsx"
    click appjsx "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/src/App.jsx"
    click indexhtml "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/index.html"
    click vitecfg "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/vite.config.js"
    click eslintcfg "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/eslint.config.js"
    click pkgjson "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/client/package.json"
    click BS "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/docker-compose.yml"
    click FlaskApp "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/app.py"
    click Inference "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/face_detector.py"
    click Dependencies "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/requirements.txt"
    click mdl1 "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/models/age_deploy.prototxt"
    click mdl2 "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/models/age_net.caffemodel"
    click mdl3 "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/models/gender_deploy.prototxt"
    click mdl4 "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/models/gender_net.caffemodel"
    click mdl5 "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/models/opencv_face_detector.pbtxt"
    click mdl6 "https://github.com/kanagarajsck/react-flask-docker-app/blob/main/server/models/opencv_face_detector_uint8.pb"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef backend fill:#90ee90,stroke:#333,stroke-width:1px;
    classDef models fill:#d3d3d3,stroke:#333,stroke-width:1px;
    classDef config fill:#f0e68c,stroke:#333,stroke-width:1px;
    classDef docker fill:#e0e0e0,stroke:#333,stroke-width:1px;
```
