# sathwikgoundla/textile-inspection architecture

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

- Interactive diagram: https://gitdiagram.com/sathwikgoundla/textile-inspection
- Repository: https://github.com/sathwikgoundla/textile-inspection

## Overview

TextileVision AI is a real-time textile inspection dashboard. The documented workflow captures camera frames, classifies textile versus non-textile, detects and scores defects, records inspections, and streams results to the dashboard. The sampled WebSocket handler shows a scan-triggered analysis and database write, while the sampled main module also contains its own OpenCV analysis; the separate detector and preprocessing modules are documented capabilities, but their integration into that handler is not established by the excerpts. The graph preserves these branches and the stats/logs API; some links reflect README documentation rather than inspected call sites.

Main entry points: [`backend/main.py`](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py) (Live scan handler), [`frontend/index.html`](https://github.com/sathwikgoundla/textile-inspection/blob/main/frontend/index.html) (Dashboard UI), [`backend/utils/camera.py`](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/utils/camera.py) (Camera manager), [`backend/utils/preprocessing.py`](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/utils/preprocessing.py) (Frame preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Image Capture"]
  node_camera_manager["Camera manager<br/>[camera.py]"]
  node_preprocessing["Frame preprocessing<br/>[preprocessing.py]"]
end

subgraph group_inspection["Inspection Engine"]
  node_inline_analysis["OpenCV frame analysis<br/>[main.py]"]
  node_textile_detector["Textile classifier<br/>[detector.py]"]
  node_defect_detector["Defect analysis<br/>[defect_detector.py]"]
  node_result_overlay["Result visualization<br/>[main.py]"]
end

subgraph group_service["API and Persistence"]
  node_websocket["Live scan handler<br/>[main.py]"]
  node_api_routes["HTTP API routes<br/>[main.py]"]
  node_db_session["Database sessions<br/>[db.py]"]
  node_inspection_log["Inspection log model<br/>[models.py]"]
  node_database[("Inspection database")]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_ui["Dashboard UI<br/>[index.html]"]
end

node_operator(("Operator"))
node_camera(("Camera input"))

node_operator -->|"views results"| node_dashboard_ui
node_camera -->|"provides frames"| node_camera_manager
node_camera_manager -.->|"supplies frames"| node_preprocessing
node_preprocessing -->|"prepares frames"| node_textile_detector
node_textile_detector -->|"routes textiles"| node_defect_detector
node_operator -->|"requests scan"| node_websocket
node_websocket -->|"analyzes frame"| node_inline_analysis
node_inline_analysis -->|"creates annotated view"| node_result_overlay
node_websocket -->|"uses session"| node_db_session
node_websocket -->|"creates log"| node_inspection_log
node_websocket -->|"streams results"| node_dashboard_ui
node_api_routes -->|"queries history"| node_inspection_log
node_db_session -->|"connects to"| node_database
node_api_routes -->|"serves interface"| node_dashboard_ui

click node_camera_manager "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/utils/camera.py"
click node_preprocessing "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/utils/preprocessing.py"
click node_websocket "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py"
click node_inline_analysis "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py"
click node_textile_detector "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/models/detector.py"
click node_defect_detector "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/models/defect_detector.py"
click node_result_overlay "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py"
click node_api_routes "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py"
click node_db_session "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/database/db.py"
click node_inspection_log "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/database/models.py"
click node_database "https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/textile_inspection.db"
click node_dashboard_ui "https://github.com/sathwikgoundla/textile-inspection/blob/main/frontend/index.html"

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_camera_manager,node_preprocessing toneBlue
class node_inline_analysis,node_textile_detector,node_defect_detector,node_result_overlay toneAmber
class node_websocket,node_api_routes,node_db_session,node_inspection_log,node_database toneMint
class node_dashboard_ui toneRose
class node_operator,node_camera toneIndigo
```

## Components

### Image Capture

- [Camera manager](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/utils/camera.py): `backend/utils/camera.py`
- [Frame preprocessing](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/utils/preprocessing.py): `backend/utils/preprocessing.py`

### Inspection Engine

- [OpenCV frame analysis](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py): `backend/main.py`
- [Textile classifier](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/models/detector.py): `backend/models/detector.py`
- [Defect analysis](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/models/defect_detector.py): `backend/models/defect_detector.py`
- [Result visualization](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py): `backend/main.py`

### API and Persistence

- [Live scan handler](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py): `backend/main.py`
- [HTTP API routes](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/main.py): `backend/main.py`
- [Database sessions](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/database/db.py): `backend/database/db.py`
- [Inspection log model](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/database/models.py): `backend/database/models.py`
- [Inspection database](https://github.com/sathwikgoundla/textile-inspection/blob/main/backend/textile_inspection.db): `backend/textile_inspection.db`

### Dashboard

- [Dashboard UI](https://github.com/sathwikgoundla/textile-inspection/blob/main/frontend/index.html): `frontend/index.html`

### Other components

- **Operator**
- **Camera input**

## Connections

- Operator → Dashboard UI: views results (evidence: `README.md`)
- Camera input → Camera manager: provides frames (evidence: `README.md`)
- Camera manager → Frame preprocessing: supplies frames
- Frame preprocessing → Textile classifier: prepares frames (evidence: `README.md`)
- Textile classifier → Defect analysis: routes textiles (evidence: `README.md`)
- Operator → Live scan handler: requests scan (evidence: `backend/main.py`)
- Live scan handler → OpenCV frame analysis: analyzes frame (evidence: `backend/main.py`)
- OpenCV frame analysis → Result visualization: creates annotated view (evidence: `backend/main.py`)
- Live scan handler → Database sessions: uses session (evidence: `backend/main.py`)
- Live scan handler → Inspection log model: creates log (evidence: `backend/main.py`)
- Live scan handler → Dashboard UI: streams results (evidence: `README.md`)
- HTTP API routes → Inspection log model: queries history (evidence: `backend/main.py`)
- Database sessions → Inspection database: connects to (evidence: `backend/database/db.py`)
- HTTP API routes → Dashboard UI: serves interface (evidence: `backend/main.py`)
