How lacamposm/mini-proyecto-oic works
• 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.