# dileep-sai-paila/kc_detector architecture

> Architecture diagram of the GitHub repository dileep-sai-paila/kc_detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dileep-sai-paila/kc_detector
- Repository: https://github.com/dileep-sai-paila/kc_detector

## Overview

##### Main Components
- Frontend:
- Represents the mobile or desktop user interface built with Flet.
- Key parts include the file picker, progress bar, result display panel, and demo button.
- Backend:
- A Flask API service handling image upload, processing, and ML predictions.
- Core endpoints include /predict (image analysis and prediction) and /greet (simple health-check endpoint).
- Machine Learning Models:
- ML assets stored in the backend’s static/assets directory:
▸ Random Forest model (RF_model.pkl) for creatinine prediction.
▸ Feature Extractor model (feature_extractor_model.h5) to process input images.
▸ Label Encoder (label_encoder.pkl) for mapping model outputs.
- Data & Static Assets:
- Frontend static assets (e.g., demo_data.json) as well as backend assets used during processing.
- Image Processing Pipeline:

##### Relationships and Interactions
- The Frontend captures an image (or takes the demo data) and sends it via an API call (using /predict) to the Backend.
- The Backend processes the image using image processing routines and then passes extracted features to the ML models.
- ML models (feature extractor followed by the Random Forest predictor) generate the creatinine level prediction, which is then returned (along with similarity metrics) to the Frontend.
- Additionally, the /greet endpoint demonstrates a direct communication check.

##### Architectural Patterns and Design Principles
- Separation of Concerns (Frontend for UI/UX; Backend for processing and predictions).
- Modular Design: Isolate image processing, ML prediction, and API routing in the backend.
- Clear API boundary: Defined endpoints ensure a well-structured communication channel.
- Use of pre-trained models emphasizes the reuse of existing components and supports maintainability.

##### Relevant Technologies and Frameworks
- Backend: Python Flask is used to set up the API, handling request routing, image processing, and ML inference.
- Frontend: Flet UI framework to build a responsive modern interface.
- Machine Learning: Models implemented using Python (likely with libraries such as scikit-learn, TensorFlow/Keras for the feature extractor, etc.).

- Flow within the backend. For example:
- “Image Preprocessing → Feature Extraction → Prediction” as a step-by-step process within the Backend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        FUI["Frontend UI (Flet)"]:::frontend
        Demo["Demo Data"]:::frontend
    end

    subgraph "Backend"
        APIPredict["API /predict"]:::backend
        APIGreet["API /greet"]:::backend
        subgraph "Image Processing Pipeline"
            IMP["Image Preprocessing"]:::process
            FE["Feature Extraction"]:::process
            Pred["Prediction"]:::process
            Resp["Response Preparation"]:::process
        end
    end

    subgraph "ML Models"
        MLRF["Random Forest Model"]:::ml
        MLFE["Feature Extractor Model"]:::ml
        MLE["Label Encoder"]:::ml
    end

    FUI -->|"sends_image"| APIPredict
    FUI -->|"health-check"| APIGreet
    Demo -->|"provides_sample"| FUI
    APIPredict -->|"processes"| IMP
    IMP --> FE
    FE --> Pred
    Pred --> Resp
    Resp -->|"returns_results"| FUI
    FE -->|"uses"| MLFE
    Pred -->|"uses"| MLRF
    Pred -->|"uses"| MLE

    click FUI "https://github.com/dileep-sai-paila/kc_detector/blob/main/frontend/main.py"
    click Demo "https://github.com/dileep-sai-paila/kc_detector/blob/main/frontend/assets/demo_data.json"
    click APIPredict "https://github.com/dileep-sai-paila/kc_detector/blob/main/backend/main.py"
    click IMP "https://github.com/dileep-sai-paila/kc_detector/blob/main/backend/main.py"
    click MLRF "https://github.com/dileep-sai-paila/kc_detector/tree/main/backend/static/assets/"
    click MLFE "https://github.com/dileep-sai-paila/kc_detector/tree/main/backend/static/assets/"
    click MLE "https://github.com/dileep-sai-paila/kc_detector/tree/main/backend/static/assets/"

    classDef frontend fill:#B3CDE0,stroke:#0277BD,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef process fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef ml fill:#FFCCBC,stroke:#D84315,stroke-width:2px;
```
