# tamilselvan-sde/casting-defect-detection- architecture

> Architecture diagram of the GitHub repository tamilselvan-sde/casting-defect-detection-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tamilselvan-sde/casting-defect-detection-
- Repository: https://github.com/tamilselvan-sde/casting-defect-detection-

## Overview

##### Project type and purpose
- This is a machine-learning–powered web application (“Casting Defect Detection”) built with Python and Streamlit.
- Purpose: allow users to upload images of casting components, run a quantized CNN (TensorFlow Lite) model to detect “defective” vs. “non-defective,” and display results in a browser.

##### File-structure overview
- Top-level files:
- app.py             – the Streamlit application entry point (UI + inference logic)
- cnn_model_quantized.tflite – the pre-trained, quantized CNN model file
- requirements.txt   – Python dependencies for app & ML
- vibration_damper_failure_detection.ipynb – a Jupyter notebook for related failure-detection experiments (auxiliary)
- .devcontainer/     – VS Code Dev Container configuration for a reproducible development environment
- No separate “frontend” vs. “backend” repo; it’s a single Python monolith handling both UI and inference.

##### Key components
a. External User & Browser
- The user interacts by visiting the Streamlit URL, uploading images.
b. Streamlit Web UI Layer (app.py)
- Handles HTTP requests, image upload widget, display elements.
c. Inference Engine / Business Logic
- In app.py: loads the TFLite model, preprocesses the image, runs inference, post-processes predictions.
d. Model Artifact Storage
- The cnn_model_quantized.tflite file stored on disk (or bundled in container).
e. Development & Deployment Environment
- VS Code Dev Container (Docker) for local dev; optionally hosted on Streamlit Cloud or another server.
f. (Optional) Experimentation Notebook
- Jupyter notebook used for data exploration & prototyping.

##### Component relationships & data flow
1) User → Browser: open the app URL
2) Browser → Streamlit UI: uploads image
3) UI → Business Logic: passes image to inference module
4) Inference Module → Model File: loads .tflite
5) Model File → Inference Module: returns prediction
6) Inference Module → UI: returns classification & metrics
7) UI → Browser: renders results

##### Architectural patterns & design principles
- Single-process, layered monolith: UI, application logic, and model inference co-located in app.py
- Containerization: Dev Container for consistent environment, matching production
- Separation of concerns: keep preprocessing, inference, and presentation in discrete code blocks

##### Technologies & frameworks
- Streamlit (UI)
- Python (app logic)
- TensorFlow Lite (inference)
- Docker / Dev Container (development environment)
- GitHub (source control)
- (Optional deployment) Streamlit Cloud or any Docker-compatible host

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User & Browser
    User["External User"]:::external
    Browser["Web Browser"]:::external

    %% Frontend Layer
    subgraph Frontend
        UI["Streamlit Web UI"]:::frontend
    end

    %% Backend/Inference Layer
    subgraph Inference
        Engine["Inference Engine / Business Logic"]:::backend
        Model[".tflite Model Artifact"]:::storage
    end

    %% Development Environment
    subgraph "Development & Deployment Environment"
        DevCont["VS Code Dev Container"]:::env
        Req["requirements.txt"]:::env
        Docs["README.md"]:::env
    end

    %% Experimentation
    Notebook["Experimentation Notebook"]:::experiment

    %% Data Flow
    User -->|"visits URL"| Browser
    Browser -->|"uploads image"| UI
    UI -->|"passes image"| Engine
    Engine -->|"loads model"| Model
    Model -->|"returns prediction"| Engine
    Engine -->|"returns result"| UI
    UI -->|"renders results"| Browser

    %% Optional Deployment Annotation
    Cloud["Streamlit Cloud / Docker Host"]:::env
    UI -->|"hosted on"| Cloud

    %% Experimentation Link
    Notebook -.->|"prototyping"| Engine

    %% Click Events
    click UI "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/app.py"
    click Engine "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/app.py"
    click Model "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/cnn_model_quantized.tflite"
    click DevCont "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/.devcontainer/devcontainer.json"
    click Req "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/requirements.txt"
    click Docs "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/README.md"
    click Notebook "https://github.com/tamilselvan-sde/casting-defect-detection-/blob/main/vibration_damper_failure_detection.ipynb"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef storage fill:#FFA500,stroke:#000,stroke-width:1px
    classDef env fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef experiment fill:#F0E68C,stroke:#000,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5
```
