# ducdatit2002/tooth-decay-detection architecture

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

- Interactive diagram: https://gitdiagram.com/ducdatit2002/tooth-decay-detection
- Repository: https://github.com/ducdatit2002/tooth-decay-detection

## Overview

##### Project Type and Purpose
- It is a lightweight full-stack (but largely monolithic) application where the key functionality is image-based tooth decay detection.
- The project uses YOLOv8 (via Ultralytics) to detect tooth decay in images provided by users. The web interface is built with Streamlit, and Pillow is used for image handling.

##### Analyzing the File Structure
- Top-Level Files: The project root contains key files such as app.py (the main entry point for Streamlit), best.pt (the pretrained model file), requirements.txt (dependencies), and readme.MD (.gitignore and .DS_Store for environment control).
- The absence of multiple directories indicates that the core functionality is encapsulated in a small number of files — emphasizing a simple, contained design rather than a heavily modular service-based system.
- Although the README mentions a structure with main.py, in our file tree, app.py is the launching file. This simply reflects a naming inconsistency and should be interpreted as the main entry point for the application.

##### Examining the README Insights
- The README provides a clear walkthrough of operations: uploading or capturing an image, processing it to detect tooth decay using YOLOv8, and then displaying the processed result with highlighted regions.
- It mentions integration with libraries such as Streamlit, YOLOv8 (via Ultralytics), and Pillow, which are the core components assembling the detection pipeline.

a. Main Components:
- User Interface (UI): The Streamlit-based front-end where users upload or capture images.
- Image Processing Module: Responsible for preprocessing or handling input images (using Pillow).
- Detection Engine: The core component where the YOLOv8 model (loaded from best.pt) detects tooth decay.
- External Dependencies/Frameworks: Python runtime, Ultralytics library, and other third-party modules (Streamlit, Pillow).

b. Relationships and Data Interactions:
- The user interacts with the UI, triggering the streamlit application (app.py).
- The UI accepts an image (either uploaded or captured via a camera) and passes it to the image processing module.
- The processed image is then forwarded to the detection engine where the YOLOv8 model (from best.pt) performs inference.
- Dependencies (libraries such as Ultralytics and Pillow) operate within these modules to ensure proper functionality.

c. Architectural Patterns and Design Principles:
- The architecture is monolithic: all components reside in the same application with clear separation of concerns (presentation, processing, detection).
- Emphasis on a pipeline flow: from image acquisition to processing, inference, and result presentation.

d. Relevant Technologies/Frameworks/Libraries:
- Python 3.11 for runtime.
- Streamlit for creating the web-based UI.
- YOLOv8 (via Ultralytics) for object detection.
- Pillow for image processing.
- best.pt as the model container for the object detection logic.

##### Additional Touches
- That while there is no strict microservices separation, the logical segregation (input handling, processing, model inference, and output display) makes the design clear and maintainable.
- Adding a note that for potential future improvements or scaling, components can be separated into more granular services if necessary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Streamlit Frontend (User Interface Layer)"
        UI["User Input (Streamlit)"]:::ui
        RD["Result Rendering"]:::ui
    end

    subgraph "Business Logic / Processing Layer"
        IP["Image Preprocessing (Pillow)"]:::logic
        DE["YOLOv8 Detection Engine"]:::logic
    end

    subgraph "Model Component"
        M["best.pt Model"]:::model
    end

    ED["Python Libraries (Streamlit, Ultralytics, Pillow)"]:::external

    UI -->|"uploads-image"| IP
    IP -->|"processes-image"| DE
    DE -->|"returns-results"| RD
    DE -->|"loads-model"| M
    ED -->|"used-by"| UI
    ED -->|"used-by"| IP
    ED -->|"used-by"| DE

    click UI "https://github.com/ducdatit2002/tooth-decay-detection/blob/main/app.py"
    click IP "https://github.com/ducdatit2002/tooth-decay-detection/blob/main/app.py"
    click DE "https://github.com/ducdatit2002/tooth-decay-detection/blob/main/best.pt"
    click ED "https://github.com/ducdatit2002/tooth-decay-detection/blob/main/requirements.txt"

    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef logic fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#943126,stroke-width:2px;
```
