# lacamposm/mini-proyecto-oic architecture

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

- Interactive diagram: https://gitdiagram.com/lacamposm/mini-proyecto-oic
- Repository: https://github.com/lacamposm/mini-proyecto-oic

## Overview

- A machine learning model (regression model) with training routines and utilities (found under the “model” directory).
- A RESTful API server built with FastAPI (in the “oic_model_server” directory) for making predictions, managing users, and handling data-related operations.
- A front-end application developed with Streamlit (in the “streamlit_app” directory) that provides a graphical UI for users to interact with the model.
- Supporting artifacts (data files, input schemas, trained model pickle, etc.) used during both training and prediction.
- A PostgreSQL database that is set up and connected via Docker Compose (as specified in the README and docker-compose.yml).
- Docker and docker-compose orchestration to containerize and unify these services for ease of deployment.

##### Main Components
a. Model Training & Artifacts:
– “model” component containing the regression model, training scripts (run_training.py), and utility functions.
– “artifacts” directory holding the CSV dataset, input schema, and pickled model.
b. API Backend:
– “oic_model_server” that provides FastAPI endpoints. Divide it further as:
- API Routes: “api/routes” with endpoints like “predict.py” and “user.py”.
- Core Services: “core” (configuration and database connection) and “services” (predict_service, raw_data_service, user_service).
- Models: “models” directory encapsulating prediction, raw_data, and user data models.
– Main application entry point (main.py) for the server.
c. Frontend Interface:
– Streamlit-based UI in the “streamlit_app” directory (includes main app.py and component modules like prediction, history, and user management).
d. Database:
– PostgreSQL service (configured/mentioned in docker-compose.yml) that the API backend communicates with.
e. Containerization & Orchestration:
– Dockerfile and docker-compose.yml orchestrate the different services.
– Additional support for a development mode with live volume mounts and even a VS Code-Server IDE container.

##### Relationships and Interactions
a. The Frontend (Streamlit UI) interacts with the API Backend via HTTP requests (e.g., to the /predict endpoint).
b. The API Backend uses the “model” component to load the trained regression model and performs predictions.
c. The API Backend communicates with the PostgreSQL database for persisting or retrieving user data and prediction records.
d. Docker Compose defines how these services are brought up together (each running as separate containers) and sets up port mappings (FastAPI on 8000, Streamlit on 8501, database on 5433, and code-server on 8080).

##### Architectural Patterns & Design Principles
a. Modularization: Each component (model, API, UI) lives in its own directory, promoting separation of concerns.
b. Layered Architecture: The API backend is separated logically into routes (controllers), services (business logic), and models.
c. Containerization: Using Docker for encapsulation and ease of deployment across environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Docker & Orchestration Layer
    subgraph "Docker & Orchestration"
        D1["Dockerfile"]:::orchestration
        D2["docker-compose.yml"]:::orchestration
    end

    %% Model Training & Artifacts Branch
    subgraph "Model Training & Artifacts"
        M1["Model (Regression Model, Training Scripts)"]:::model
        M2["Artifacts (CSV, Input Schema, Pickled Model)"]:::artifact
    end

    %% API Backend Branch
    subgraph "API Backend"
        A1["Main Application (oic_model_server/main.py)"]:::api
        subgraph "API Routes"
            A2["Routes (oic_model_server/api/routes)"]:::apiRoutes
        end
        subgraph "Core & Config"
            A3["Core Services & Config (oic_model_server/core)"]:::core
        end
        subgraph "Business Services"
            A4["Services (oic_model_server/services)"]:::services
        end
        subgraph "Data Models"
            A5["Data Models (oic_model_server/models)"]:::models
        end
    end

    %% Frontend Interface Branch
    subgraph "Frontend Interface"
        F1["Streamlit App (streamlit_app)"]:::frontend
    end

    %% PostgreSQL Database Node
    DB["PostgreSQL Database"]:::database

    %% Connections: Orchestration to components
    D2 -->|"orchestrates"| A1
    D2 -->|"orchestrates"| F1
    D2 -->|"orchestrates"| DB

    %% Frontend to API communication
    F1 -->|"HTTP_Request"| A1

    %% API Backend interactions
    A1 -->|"Prediction_Call"| M1
    A1 -->|"DB_Query"| DB

    %% Styles
    classDef orchestration fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef model fill:#A1C6EA,stroke:#333,stroke-width:2px;
    classDef artifact fill:#BEE3DB,stroke:#333,stroke-width:2px;
    classDef api fill:#F7C59F,stroke:#333,stroke-width:2px;
    classDef apiRoutes fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef core fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef services fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef models fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef frontend fill:#C3FDB8,stroke:#333,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click M1 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/model/"
    click M2 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/artifacts/"
    click A1 "https://github.com/lacamposm/mini-proyecto-oic/blob/main/oic_model_server/main.py"
    click A2 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/oic_model_server/api/routes/"
    click A3 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/oic_model_server/core/"
    click A4 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/oic_model_server/services/"
    click A5 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/oic_model_server/models/"
    click F1 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/streamlit_app/"
    click D2 "https://github.com/lacamposm/mini-proyecto-oic/blob/main/docker-compose.yml"
    click D1 "https://github.com/lacamposm/mini-proyecto-oic/tree/main/Dockerfile"
```
