# priyesh-iitb/ai-predictive-maintenance architecture

> Architecture diagram of the GitHub repository priyesh-iitb/ai-predictive-maintenance, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/priyesh-iitb/ai-predictive-maintenance
- Repository: https://github.com/priyesh-iitb/ai-predictive-maintenance

## Overview

##### Project Type & Purpose
- While the README is empty, the file tree indicates that this is a full-stack application with a focus on data/model predictions. It combines API endpoints (found in scripts/api), a dashboard interface (in scripts/dashboard and streamlit_app.py), and Dockerized deployments.
- The “models” folder hints at machine learning or data-driven components, and the existence of a test script (test_predictions.sh) suggests that predictions are a key part of the project’s functionality.

##### Analyzing the File Structure
- Top-Level Files:
- .env.example: Environment variable configuration.
- .gitignore: Standard Git exclusions.
- Dockerfile and Dockerfile.streamlit: Two separate Docker setups, likely one for the API/backend service and one for the Streamlit-based frontend (or dashboard).
- docker-compose.yml: Orchestrates multi-container setup, tying together various services.
- requirements.txt: Python dependencies.
- Main Directories:
- scripts/api: Contains __init__.py, app.py, and middleware.py. This is clearly the backend API component that handles requests, applies middleware logic, and manages prediction endpoints.
- scripts/dashboard: Contains a similar structure with __init__.py and app.py, likely for an interactive dashboard interface possibly for monitoring or interacting with model predictions.
- .streamlit (with a config file): Indicates custom configuration for Streamlit, which implies that a web interface is also built on Streamlit (in addition to the scripts/dashboard interface) or allows local prototyping (via streamlit_app.py).
- models: Reserved for storing machine learning models or related assets.
- Additional Files:
- streamlit_app.py: Acts as the entry-point for a Streamlit application.
- test_predictions.sh: A script that likely runs predictions and tests the endpoints.

a. Main Components to Include:
- Backend API Service:
- “scripts/api” components.
- Middleware functionality and potential endpoints.
- Dashboard Service:
- “scripts/dashboard” and/or the “streamlit_app.py”.
- Role as an interactive interface for end-users.
- Model Repository:
- How these models are accessed or updated by the API.
- Containerization & Deployment:
- Docker: Illustrate both Dockerfiles (one for the API and one specific for Streamlit/dashboard).
- Docker Compose: Show how multiple containers (API, dashboard/Streamlit, etc.) are orchestrated.
- Environment & Configuration:
- .env file for runtime environment variables.
- The .streamlit/config.toml illustrates custom configurations for the Streamlit app.
- Testing:
- Incorporate the role of test_predictions.sh for validating prediction outputs.

b. Relationships & Interactions:
- Requests from the user/interface (dashboard/Streamlit) to the API service.
- Data flow between the API and the model repository.
- The API serving as a central hub that the dashboard interacts with via REST APIs or direct function calls.
- The Docker Compose layer managing the interaction between containers.
- Modularity:
- The API encapsulates business logic and middleware.
- The dashboard handles presentation and user interaction.
- The model storage acts as a shared resource.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: Clearly separate API logic, dashboard interaction, and model handling.
- Containerization: Use Docker for consistent deployment across environments.
- Modularity: Each service (API vs. dashboard) is independently deployable and testable as seen by distinct Dockerfiles and service directories.
- Integration via Docker Compose: This reinforces a microservice-like approach even if the app is monolithic in code.

d. Technologies & Frameworks:
- Python (inferred from requirements.txt and .py files).
- Streamlit for interactive dashboards.
- Docker for containerization and orchestration (via Docker Compose).
- (Potentially) a web framework (such as Flask or FastAPI) in scripts/api/app.py, though specifics aren’t provided—still, highlight that the API likely leverages a Python web framework.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    client("Client/User"):::client

    subgraph "Application Services"
        api("API Service"):::service
        dash("Dashboard Service"):::service
        streamlit("Streamlit App"):::service
    end

    model("Model Repository"):::database
    test("Testing (test_predictions.sh)"):::component

    subgraph "Containerization & Deployment"
        docker_api("Dockerfile"):::container
        docker_streamlit("Dockerfile.streamlit"):::container
        docker_compose("docker-compose.yml"):::container
    end

    subgraph "Environment & Configuration"
        env_example(".env.example"):::config
        streamlit_conf(".streamlit/config.toml"):::config
    end

    %% Relationships
    client -->|"uses"| dash
    client -->|"calls"| api
    api -->|"accesses"| model
    test -->|"validates"| api

    docker_api -->|"builds"| api
    docker_streamlit -->|"builds"| streamlit
    docker_compose -->|"orchestrates"| api
    docker_compose -->|"orchestrates"| dash
    docker_compose -->|"orchestrates"| streamlit

    env_example -->|"configures"| api
    env_example -->|"configures"| dash
    streamlit_conf -->|"configures"| streamlit

    %% Click Events
    click api "https://github.com/priyesh-iitb/ai-predictive-maintenance/tree/main/scripts/api/"
    click dash "https://github.com/priyesh-iitb/ai-predictive-maintenance/tree/main/scripts/dashboard/"
    click streamlit "https://github.com/priyesh-iitb/ai-predictive-maintenance/blob/main/streamlit_app.py"
    click model "https://github.com/priyesh-iitb/ai-predictive-maintenance/tree/main/models/"
    click docker_api "https://github.com/priyesh-iitb/ai-predictive-maintenance/tree/main/Dockerfile"
    click docker_streamlit "https://github.com/priyesh-iitb/ai-predictive-maintenance/blob/main/Dockerfile.streamlit"
    click docker_compose "https://github.com/priyesh-iitb/ai-predictive-maintenance/blob/main/docker-compose.yml"
    click env_example "https://github.com/priyesh-iitb/ai-predictive-maintenance/blob/main/.env.example"
    click streamlit_conf "https://github.com/priyesh-iitb/ai-predictive-maintenance/blob/main/.streamlit/config.toml"
    click test "https://github.com/priyesh-iitb/ai-predictive-maintenance/blob/main/test_predictions.sh"

    %% Styles
    classDef service fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef container fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef database fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef config fill:#D5F5E3,stroke:#1D8348,stroke-width:2px;
    classDef client fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef component fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
```
