# kandasamy21/ppe_compliance architecture

> Architecture diagram of the GitHub repository kandasamy21/ppe_compliance, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kandasamy21/ppe_compliance
- Repository: https://github.com/kandasamy21/ppe_compliance

## Overview

#### Purpose and Entry Points
This repository exposes a FastAPI service for PPE (Personal Protective Equipment) detection on uploaded images using a custom YOLO model. The runtime entry point is `main.py`, launched with `uvicorn main:app --reload`. The public API consists of `GET /` for health checking and `POST /detect` for image inference.

#### HTTP API Layer
`main.py` owns the FastAPI application and request lifecycle. `POST /detect` accepts an image file through multipart form upload, invokes model inference, and returns detection results. This API boundary separates clients from local model-loading and image-processing details.

Grounding:
- `main.py`
- `README.md`

#### Model Inference Boundary
The service depends on a custom-trained PyTorch `.pt` model. Model location is configurable through the `PPE_MODEL_PATH` environment variable; otherwise the application uses a repository-local default path configured in `main.py`. The README describes a YOLOv9 artifact location, while the file tree contains a `yolov5` directory; this naming/path mismatch should be verified before deployment.

Grounding:
- `main.py`
- `yolov5`
- `README.md`

#### Detection Flow
Primary control flow is:
1. Client uploads an image to `POST /detect`.
2. FastAPI receives and validates the multipart file.
3. The server loads or uses the configured YOLO model.
4. Inference identifies PPE-related objects in the image.
5. Detection results are serialized into the HTTP response.

The external boundary is the uploaded image on input and structured detection output on response; model weights are a local deployment dependency rather than an API-managed resource.

Grounding:
- `main.py`
- `README.md`

#### UI Assets
The repository includes static HTML and CSS assets that may support a lightweight browser-facing interface. Their presence does not establish that FastAPI serves them; integration should be confirmed in `main.py`.

Grounding:
- `static/index.html`
- `static/style.css`
- `main.py`

#### Runtime and Dependencies
The system runs on Python with FastAPI and Uvicorn. Inference requires the dependencies declared in `requirements.txt` and a compatible local YOLO/PyTorch model environment. No database, queue, cloud service, or remote inference provider is documented.

Grounding:
- `requirements.txt`
- `main.py`
- `README.md`

#### Supporting Code
`model.py` likely provides a local model-related abstraction, but its role cannot be determined from the supplied tree alone. `Test.py` and `Test_1.py` appear to be ad hoc validation or experiment entry points rather than documented production interfaces.

Grounding:
- `model.py`
- `Test.py`
- `Test_1.py`

Main entry points: [`main.py`](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py) (FastAPI App), [`requirements.txt`](https://github.com/kandasamy21/ppe_compliance/blob/master/requirements.txt) (Python Dependencies), [`yolov5`](https://github.com/kandasamy21/ppe_compliance/tree/master/yolov5) (YOLO Runtime Source), [`model.py`](https://github.com/kandasamy21/ppe_compliance/blob/master/model.py) (Model Abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Python Service"]
  node_fastapi["FastAPI App<br/>HTTP API<br/>[main.py]"]
  node_health["GET /<br/>health endpoint<br/>[main.py]"]
  node_detect["POST /detect<br/>multipart endpoint<br/>[main.py]"]
  node_dependencies["Python Dependencies<br/>runtime dependencies<br/>[requirements.txt]"]
end

subgraph group_model["Local Inference"]
  node_model_loader["Model Loading<br/>inference setup<br/>[main.py]"]
  node_yolo["YOLO Inference<br/>detection engine<br/>[main.py]"]
  node_weights["Custom .pt Weights<br/>local model artifact"]
  node_yolov5["YOLO Runtime Source<br/>model runtime"]
  node_model_module["Model Abstraction<br/>supporting module<br/>[model.py]"]
end

node_client(("API Client<br/>external client"))
node_response["Detection Results<br/>structured response<br/>[main.py]"]
node_static_html["Browser HTML<br/>static asset<br/>[index.html]"]
node_static_css["Browser CSS<br/>static asset<br/>[style.css]"]

node_client -->|"HTTP requests"| node_fastapi
node_fastapi -->|"routes"| node_health
node_fastapi -->|"routes"| node_detect
node_detect -->|"invokes"| node_model_loader
node_model_loader -->|"loads"| node_weights
node_model_loader -->|"provides model"| node_yolo
node_yolov5 -.->|"runtime support"| node_yolo
node_yolo -->|"serializes detections"| node_response
node_response -->|"HTTP response"| node_client
node_dependencies -.->|"provides runtime packages"| node_fastapi
node_model_module -.->|"possible support"| node_model_loader
node_static_html -->|"styles"| node_static_css

click node_fastapi "https://github.com/kandasamy21/ppe_compliance/blob/master/main.py"
click node_health "https://github.com/kandasamy21/ppe_compliance/blob/master/main.py"
click node_detect "https://github.com/kandasamy21/ppe_compliance/blob/master/main.py"
click node_model_loader "https://github.com/kandasamy21/ppe_compliance/blob/master/main.py"
click node_yolo "https://github.com/kandasamy21/ppe_compliance/blob/master/main.py"
click node_yolov5 "https://github.com/kandasamy21/ppe_compliance/tree/master/yolov5"
click node_response "https://github.com/kandasamy21/ppe_compliance/blob/master/main.py"
click node_static_html "https://github.com/kandasamy21/ppe_compliance/blob/master/static/index.html"
click node_static_css "https://github.com/kandasamy21/ppe_compliance/blob/master/static/style.css"
click node_dependencies "https://github.com/kandasamy21/ppe_compliance/blob/master/requirements.txt"
click node_model_module "https://github.com/kandasamy21/ppe_compliance/blob/master/model.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_fastapi,node_health,node_detect,node_dependencies toneBlue
class node_model_loader,node_yolo,node_weights,node_yolov5,node_model_module toneAmber
class node_client,node_response,node_static_html,node_static_css toneNeutral
```

## Components

### Python Service

- [FastAPI App](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py): HTTP API · Provides health and image-detection endpoints. · `main.py`
- [GET /](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py): health endpoint · `main.py`
- [POST /detect](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py): multipart endpoint · Accepts an uploaded image for inference. · `main.py`
- [Python Dependencies](https://github.com/kandasamy21/ppe_compliance/blob/master/requirements.txt): runtime dependencies · Declares FastAPI, Uvicorn, and inference dependencies. · `requirements.txt`

### Local Inference

- [Model Loading](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py): inference setup · Uses PPE_MODEL_PATH or the local default model path. · `main.py`
- [YOLO Inference](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py): detection engine · Identifies PPE-related objects in the uploaded image. · `main.py`
- **Custom .pt Weights**: local model artifact · Deployment-provided PyTorch model weights.
- [YOLO Runtime Source](https://github.com/kandasamy21/ppe_compliance/tree/master/yolov5): model runtime · Repository-local YOLO directory; artifact naming should be verified. · `yolov5`
- [Model Abstraction](https://github.com/kandasamy21/ppe_compliance/blob/master/model.py): supporting module · Its production role is not established. · `model.py`

### Other components

- **API Client**: external client · Uploads PPE images and receives detection output.
- [Detection Results](https://github.com/kandasamy21/ppe_compliance/blob/master/main.py): structured response · `main.py`
- [Browser HTML](https://github.com/kandasamy21/ppe_compliance/blob/master/static/index.html): static asset · May support a lightweight UI; serving integration is unconfirmed. · `static/index.html`
- [Browser CSS](https://github.com/kandasamy21/ppe_compliance/blob/master/static/style.css): static asset · `static/style.css`

## Connections

- API Client → FastAPI App: HTTP requests
- FastAPI App → GET /: routes
- FastAPI App → POST /detect: routes
- POST /detect → Model Loading: invokes
- Model Loading → Custom .pt Weights: loads
- Model Loading → YOLO Inference: provides model
- YOLO Runtime Source → YOLO Inference: runtime support
- YOLO Inference → Detection Results: serializes detections
- Detection Results → API Client: HTTP response
- Python Dependencies → FastAPI App: provides runtime packages
- Model Abstraction → Model Loading: possible support · Role requires confirmation.
- Browser HTML → Browser CSS: styles
