# yahyamomtaz/ai-image-api architecture

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

- Interactive diagram: https://gitdiagram.com/yahyamomtaz/ai-image-api
- Repository: https://github.com/yahyamomtaz/ai-image-api

## Overview

##### Project Type and Purpose
- The project is a full-stack web application with a focus on applying machine learning models to process images.
- Key features include object detection and image enhancement, along with built-in rate limiting and Docker support for deployment.

##### Main Architectural Components
a. Web Server and Application Layer:
- Main Python application (app.py) as the core web server. This component handles HTTP requests and routes them to the appropriate endpoints.
- API endpoints such as:
- GET / (renders the main page via the templates/index.html file)
- POST /enhance (processes image enhancement)
- POST /detect (processes object detection)
- How the Flask (or similar framework) based server (implied by app.py and templating in the templates directory) ties the overall architecture together.

b. Frontend/UI Component:
- This component is responsible for rendering the user interface in the browser and handling image uploads.

c. Machine Learning Models:
- Create distinct components for the two ML models:
- YOLO Object Detection: The weights stored in the "yolo" directory (e.g., best.pt and yolov5s.pt) and underlying model integration.
- MirNet Image Enhancement: Integration via Hugging Face models as noted in the README.

d. Utility Functions and Helpers:
- Utility or helper module (utils/general.py) that possibly encapsulates common image processing methods or other supportive functions.

e. Deployment and Infrastructure:
- A Docker container component representing containerization (based on Dockerfile, app.yaml, and dockerignore).
- Circleci as a separate CI/CD component showing that there is an integration pipeline (circleci/config.yml).
- Optionally, include an external API endpoint component if the deployed application interfaces with other services or a load balancer.

##### Relationships and Interactions
- Requests from users in the browser (Front-end) go to the Web Server.
- The Web Server then communicates with the ML model components (YOLO and MirNet) for processing images.
- That the web server enforces rate limiting rules on requests to /enhance and /detect endpoints.
- Interactions showing that deployment is managed via Docker, with integration ensured by circleci.

##### Design Principles & Technologies
- Separation of Concerns:
- UI is separated (static files and templates) from back-end processing (app.py, utils).
- Machine learning processing is clearly isolated into separate logical components (the ML models).
- Use of containerization (Docker) to standardize deployment and enable scalability.
- Mention external dependencies such as Python libraries (as denoted in requirements.txt) and potential JavaScript dependencies (package.json in static context).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Layer
    client("Client (Browser)"):::frontend

    %% Backend/API Layer
    server("Web Server (app.py) [Endpoints: GET /, POST /enhance, POST /detect]"):::backend

    templates("Templates (index.html)"):::frontend
    static("Static Files"):::frontend

    %% Machine Learning Models Subgraph
    subgraph "Machine Learning Models"
        yolo("YOLO Object Detection"):::ml
        mirnet("MirNet Image Enhancement"):::ml
    end

    %% Utility Functions
    utils("Utilities (utils/general.py)"):::utility

    %% Deployment/CI/CD Subgraph
    subgraph "Deployment / Containerization"
        dockerfile("Dockerfile"):::deployment
        appyaml("app.yaml"):::deployment
        dockerignore("dockerignore"):::deployment
    end

    circleci("CI/CD (CircleCI)"):::cicd

    %% Connections
    client -->|"requests"| server
    server -->|"renders(/)"| templates
    server -->|"serves"| static
    server -->|"POST_detect"| yolo
    server -->|"POST_enhance"| mirnet
    server -->|"uses"| utils

    %% Deployment connections
    dockerignore --- server
    circleci -->|"triggers"| dockerfile

    %% Click Events
    click server "https://github.com/yahyamomtaz/ai-image-api/blob/main/app.py"
    click templates "https://github.com/yahyamomtaz/ai-image-api/blob/main/templates/index.html"
    click static "https://github.com/yahyamomtaz/ai-image-api/tree/main/static/"
    click yolo "https://github.com/yahyamomtaz/ai-image-api/tree/main/yolo/"
    click utils "https://github.com/yahyamomtaz/ai-image-api/blob/main/utils/general.py"
    click dockerfile "https://github.com/yahyamomtaz/ai-image-api/tree/main/Dockerfile"
    click appyaml "https://github.com/yahyamomtaz/ai-image-api/blob/main/app.yaml"
    click dockerignore "https://github.com/yahyamomtaz/ai-image-api/tree/main/dockerignore"
    click circleci "https://github.com/yahyamomtaz/ai-image-api/blob/main/circleci/config.yml"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef ml fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef utility fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
    classDef deployment fill:#FAD7A0,stroke:#F39C12,stroke-width:2px;
    classDef cicd fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
