# luler/image_classification architecture

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

- Interactive diagram: https://gitdiagram.com/luler/image_classification
- Repository: https://github.com/luler/image_classification

## Overview

##### Project Type and Purpose
- This is a full-stack image-classification web application.
- Purpose: let users create/manage categories and images, then run live image-recognition via Baidu’s PaddlePaddle “PP-Shitu” models.

##### File-Structure Analysis
- Top-level:
- config/nginx – Nginx reverse-proxy & static-file serving
- api/ + app.py + route.py – Flask application, defines REST endpoints (login, label, image, common)
- deploy/ – ML-inference component (model files, preprocess/postprocess, predictor wrappers)
- migrations/ + orator_database.py – relational DB schema and Orator ORM setup
- static/ – stored galleries & uploaded images
- tool/ – shared utilities (JWT, validation, logging)
- web/ – Ant Design Pro v5 React frontend (source in web/src, build output in web/dist)
- docker-compose.yml & Dockerfile – container definitions

##### README Insights
- Backend: Flask; Frontend: Ant Design Pro; ML: PP-Shitu
- Key features: category (label) management, category-image management, “recognition experience” UI
- Deploy via Docker Compose, Nginx serves at port 5566

a. Main Components
1. User’s Browser / Client (React SPA)
2. Nginx Reverse Proxy & Static Server
3. Frontend (Ant Design Pro React app)
4. Flask Backend
– Authentication (JWT via tool/jwt_tool.py)
– Label, Image, Login, Common APIs
– ORM (Orator → Relational DB)
– File storage (static/predict_images, static/gallery)
5. ML Inference Engine (“deploy” microservice or module)
– Preprocess, Predictor, Postprocess (deploy/python & deploy/utils)
– PaddlePaddle models (deploy/models/**/*.pdmodel, .pdiparams, configs)
6. Relational Database (MySQL/Postgres via Orator)
7. Optional: Logging subsystem

b. Relationships & Data Flows
- Browser → (HTTP/HTTPS) → Nginx
- Nginx → serves static files (React bundle) and proxies /api/* → Flask
- Flask → reads/writes metadata to DB
- Flask → saves/uploads raw images to disk storage
- Flask → invokes Inference Engine (in-process import or separate service) for classification
- Inference Engine → loads PaddlePaddle models from disk → returns predictions
- Flask → returns JSON results → Browser

c. Architectural Patterns & Principles
- MVC-style separation: React UI (View) ↔ Flask (Controller + Model)
- Modular services: distinct API modules, deploy/python for ML logic
- Containerized microservice approach: Nginx + Flask + Inference + DB
- Configuration-as-code: Docker Compose, Nginx conf.d, Orator config

d. Key Technologies & Frameworks
- Frontend: React, Ant Design Pro, UmiJS, Webpack
- Backend: Flask, Orator ORM, PyJWT, Orator migrations
- Inference: PaddlePaddle (PP-Shitu), custom preprocess/postprocess scripts
- Infrastructure: Docker, Docker Compose, Nginx

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    Browser["User Browser"]:::frontend

    %% Infrastructure Layer
    Nginx["Nginx Reverse Proxy<br/>& Static Server"]:::backend
    click Nginx "https://github.com/luler/image_classification/blob/master/config/nginx/conf.d/80_web.conf"

    %% Frontend Layer
    subgraph "Frontend (Ant Design Pro React App)"
        direction TB
        FE_SRC["Source Code"]:::frontend
        click FE_SRC "https://github.com/luler/image_classification/tree/master/web/src/"
        FE_CFG["Configuration"]:::frontend
        click FE_CFG "https://github.com/luler/image_classification/tree/master/web/config/"
        FE_PKG["package.json"]:::frontend
        click FE_PKG "https://github.com/luler/image_classification/blob/master/web/package.json"
        FE_DIST["Build Output"]:::frontend
        click FE_DIST "https://github.com/luler/image_classification/tree/master/web/dist/"
    end

    %% Backend Layer
    subgraph "Flask Backend"
        direction TB
        APP["app.py<br/>(Entry Point)"]:::backend
        click APP "https://github.com/luler/image_classification/blob/master/app.py"
        ROUTE["route.py<br/>(Routing)"]:::backend
        click ROUTE "https://github.com/luler/image_classification/blob/master/route.py"
        subgraph "APIs"
            direction TB
            LoginAPI["Login API"]:::backend
            click LoginAPI "https://github.com/luler/image_classification/blob/master/api/login_api.py"
            LabelAPI["Label API"]:::backend
            click LabelAPI "https://github.com/luler/image_classification/blob/master/api/label_api.py"
            ImageAPI["Image API"]:::backend
            click ImageAPI "https://github.com/luler/image_classification/blob/master/api/image_api.py"
            CommonAPI["Common API"]:::backend
            click CommonAPI "https://github.com/luler/image_classification/blob/master/api/common_api.py"
        end
        Auth["JWT Auth Utility"]:::backend
        click Auth "https://github.com/luler/image_classification/blob/master/tool/jwt_tool.py"
        subgraph "ORM & Migrations"
            direction TB
            OratorCfg["Orator Config"]:::backend
            click OratorCfg "https://github.com/luler/image_classification/blob/master/orator_database.py"
            M1["2022_05_20_202212_create_user_table"]:::backend
            click M1 "https://github.com/luler/image_classification/blob/master/migrations/2022_05_20_202212_create_user_table.py"
            M2["2022_05_20_203637_create_label_table"]:::backend
            click M2 "https://github.com/luler/image_classification/blob/master/migrations/2022_05_20_203637_create_label_table.py"
            M3["2022_05_20_203744_create_image_table"]:::backend
            click M3 "https://github.com/luler/image_classification/blob/master/migrations/2022_05_20_203744_create_image_table.py"
        end
        subgraph "Shared Utilities"
            direction TB
            CommonUtil["tool/common.py"]:::backend
            click CommonUtil "https://github.com/luler/image_classification/blob/master/tool/common.py"
            Validate["tool/validate.py"]:::backend
            click Validate "https://github.com/luler/image_classification/blob/master/tool/validate.py"
            CAS["tool/cas_tool.py"]:::backend
            click CAS "https://github.com/luler/image_classification/blob/master/tool/cas_tool.py"
        end
    end

    %% Storage Layer
    subgraph "Storage"
        direction TB
        DB["Relational Database (MySQL/Postgres)"]:::datastore
        FileStore["Disk Storage"]:::datastore
        subgraph "Static Files"
            direction TB
            Gallery["Gallery Images"]:::datastore
            click Gallery "https://github.com/luler/image_classification/tree/master/static/gallery/"
            PredictIn["Prediction Inputs"]:::datastore
            click PredictIn "https://github.com/luler/image_classification/tree/master/static/predict_images/"
        end
    end

    %% ML Inference Layer
    subgraph "ML Inference Engine (PP-Shitu)" 
        direction TB
        Preprocess["preprocess.py"]:::ml
        click Preprocess "https://github.com/luler/image_classification/blob/master/deploy/python/preprocess.py"
        DetPre["det_preprocess.py"]:::ml
        click DetPre "https://github.com/luler/image_classification/blob/master/deploy/python/det_preprocess.py"
        Postprocess["postprocess.py"]:::ml
        click Postprocess "https://github.com/luler/image_classification/blob/master/deploy/python/postprocess.py"
        Predictor["predictor.py"]:::ml
        click Predictor "https://github.com/luler/image_classification/blob/master/deploy/utils/predictor.py"
        PredictSys["predict_system.py"]:::ml
        click PredictSys "https://github.com/luler/image_classification/blob/master/deploy/python/predict_system.py"
        subgraph "Models"
            direction TB
            Model1["general_PPLCNetV2_base_v1.0"]:::ml
            click Model1 "https://github.com/luler/image_classification/tree/master/deploy/models/general_PPLCNetV2_base_pretrained_v1.0_infer/"
            Model2["picodet_PPLCNet_x2_5_lite_v1.0"]:::ml
            click Model2 "https://github.com/luler/image_classification/tree/master/deploy/models/picodet_PPLCNet_x2_5_mainbody_lite_v1.0_infer/"
        end
        Logger["Logging Utility"]:::ml
        click Logger "https://github.com/luler/image_classification/blob/master/deploy/utils/logger.py"
    end

    %% Containerization
    Dockerfile["Dockerfile"]:::backend
    click Dockerfile "https://github.com/luler/image_classification/tree/master/Dockerfile"
    Compose["docker-compose.yml"]:::backend
    click Compose "https://github.com/luler/image_classification/blob/master/docker-compose.yml"

    %% Flows
    Browser -->|"HTTPS Request"| Nginx
    Nginx -->|"Serves React Bundle"| FE_DIST
    Browser -->|"Loads SPA"| FE_DIST
    Nginx -->|"Proxies /api/*"| APP
    FE_DIST -->|"API Calls"| APP

    APP -->|"Reads/Writes Metadata"| DB
    APP -->|"Stores/Retrieves Images"| FileStore
    APP -->|"Invokes Inference"| Preprocess
    Preprocess --> DetPre
    DetPre --> Predictor
    Predictor --> Postprocess
    Postprocess --> PredictSys
    PredictSys -->|"Loads Model"| Model1
    PredictSys -->|"Loads Model"| Model2
    PredictSys -->|"Returns Predictions"| APP

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef ml fill:#fff3cd,stroke:#856404,color:#856404;
    classDef datastore fill:#f8d7da,stroke:#721c24,color:#721c24;
```
