# christianarroyoauz/predict-rental-prices-ecuador architecture

> Architecture diagram of the GitHub repository christianarroyoauz/predict-rental-prices-ecuador, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/christianarroyoauz/predict-rental-prices-ecuador
- Repository: https://github.com/christianarroyoauz/predict-rental-prices-ecuador

## Overview

1. **Repository purpose**
   - This is a small ML inference service, not a full CRUD application.
   - The production surface is a **FastAPI REST API** that predicts monthly rental prices for properties in Ecuador from a handful of structured inputs.

2. **Main runtime boundary**
   - The live serving layer is in the **`api/`** package.
   - The rest of the repository is supporting offline work: model training, data exploration, artifact generation, and deployment configuration.
   - For an architecture diagram, treat **`api/` as the online path** and **`notebooks/`, `src/`, `data/`, `models/` as the offline ML pipeline/assets**.

3. **API layer**
   - `api/main.py` is the entrypoint for the HTTP service.
   - `api/schemas.py` defines the request/response contracts used by FastAPI/Pydantic.
   - The API exposes at least:
     - `GET /health` for liveness/model status
     - `POST /predict` for inference
   - The `/health` endpoint also reports library versions, which indicates the service is used to confirm the runtime environment as well as readiness.

4. **Inference flow**
   - A client sends JSON with `provincia`, `lugar`, `num_dormitorios`, `num_banos`, `area`, and `num_garages`.
   - FastAPI validates the payload via Pydantic schemas.
   - The request is passed to the model loading/prediction code in `src/model.py` and helper utilities in `src/utils.py`.
   - The response returns a single numeric prediction, likely in USD.

5. **Model and artifact layer**
   - The deployed model is stored as a serialized artifact in `models/rental_price_model.pkl`.
   - Additional artifacts exist in `models/mejor_modelo.pkl` and `models/model_artifacts.pkl`, suggesting the training pipeline produced multiple saved outputs or a best-model snapshot.
   - The application reads the model path from configuration; the README explicitly mentions `MODEL_PATH=./models/rental_price_model.pkl`.

6. **Preprocessing / feature engineering**
   - `src/data_processing.py` likely contains the transformation logic for cleaning, encoding, and shaping inputs before prediction.
   - Because the model is a Random Forest pipeline per the README, preprocessing is probably bundled into the serialized pipeline or mirrored in the `src/` helpers.
   - This is an important boundary: **raw API inputs are not fed directly to the estimator**; they are normalized into the exact feature structure expected by the saved model.

7. **Training and analysis workflow**
   - `notebooks/01_eda.ipynb` and `notebooks/02_modeling.ipynb` document the offline ML lifecycle: exploration, feature analysis, training, and artifact creation.
   - The root notebooks `Prueba_Funcionamiento_Local.ipynb` and `Pruebas_Funcionamiento_API.ipynb` appear to be validation/demo notebooks for local and API testing.
   - `data/real_state_ecuador_dataset.csv` is the training dataset source used offline, not part of the inference request path.

8. **Shared library code**
   - `src/` is the reusable ML support layer imported by the API and likely by notebooks during experimentation.
   - `src/model.py` is the most important internal abstraction for loading the persisted model and producing predictions.
   - `src/utils.py` likely holds common helpers such as path resolution, serialization, or feature preparation.
   - This separation suggests a clean divide between **application entrypoint (`api/`)** and **ML utility code (`src/`)**.

9. **Deployment architecture**
   - The service is designed to run in containers: there is a `Dockerfile.frontend`, a second `dockerfile`, and `docker-compose.yaml`.
   - `render.yaml` and the README’s Railway references show cloud deployment is managed through platform config rather than custom infrastructure code.
   - `runtime.txt` and `requirements.txt` pin the Python environment and dependencies for reproducible deployment.

10. **External/runtime characteristics**
   - The stack is Python 3.11 with FastAPI/Uvicorn/Pydantic on the serving side, and scikit-learn/pandas/numpy/joblib on the ML side.
   - The application is stateless at request time: the model is loaded from disk and predictions are computed in-process.
   - There is no database, message queue, or object storage in the current architecture.

11. **Operational behavior**
   - Startup behavior likely includes loading the serialized model and exposing the API once the model is available.
   - If the model is missing or fails to load, `/health` reports that state through `model_loaded`.
   - This makes model availability the key operational dependency for the service.

12. **What to draw in an architecture diagram**
   - Show four main blocks:
     - **Client/UI/CLI** sending JSON requests
     - **FastAPI service (`api/`)** handling validation and routing
     - **ML inference layer (`src/` + `models/*.pkl`)** performing preprocessing and prediction
     - **Offline training assets (`notebooks/`, `data/`)** producing the serialized model
   - Connect deployment config (`Dockerfile`, `docker-compose.yaml`, `render.yaml`, Railway) around the API service as the execution environment.

Main entry points: [`api/main.py`](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/api/main.py) (API entrypoint), [`src/model.py`](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/model.py) (Model loader), [`notebooks/02_modeling.ipynb`](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/notebooks/02_modeling.ipynb) (Modeling notebook), [`requirements.txt`](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/requirements.txt) (Dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_online["Online serving"]
  node_client(("Client<br/>requester"))
  node_api_main["API entrypoint<br/>FastAPI app<br/>[main.py]"]
  node_api_schemas["Schemas<br/>Pydantic contracts<br/>[schemas.py]"]
  node_health_route["Health check<br/>endpoint"]
  node_predict_route["Predict route<br/>endpoint"]
  node_model_loader["Model loader<br/>inference core<br/>[model.py]"]
  node_data_processing["Preprocessing<br/>feature prep<br/>[data_processing.py]"]
  node_utils["Helpers<br/>shared utils<br/>[utils.py]"]
  node_artifact_model[("Rental model<br/>pickle artifact")]
end

subgraph group_offline["Offline ML lifecycle"]
  node_artifact_best[("Best model<br/>pickle artifact<br/>[mejor_modelo.pkl]")]
  node_artifact_bundle[("Artifact bundle<br/>pickle artifact")]
  node_dataset[("Dataset<br/>training data")]
  node_eda_notebook["EDA notebook<br/>analysis notebook<br/>[01_eda.ipynb]"]
  node_modeling_notebook["Modeling notebook<br/>training notebook<br/>[02_modeling.ipynb]"]
  node_local_demo["Local demo<br/>validation notebook"]
  node_api_demo["API demo<br/>validation notebook"]
end

subgraph group_deploy["Deployment"]
  node_dockerfiles["Containers<br/>runtime config"]
  node_compose["Compose<br/>runtime config"]
  node_platform["Platform config<br/>deploy config<br/>[render.yaml]"]
  node_runtime["Python env<br/>runtime pinning<br/>[runtime.txt]"]
  node_requirements["Dependencies<br/>package lock<br/>[requirements.txt]"]
end

node_client -->|"HTTP requests"| node_api_main
node_api_main -->|"validates with"| node_api_schemas
node_api_main -->|"serves"| node_health_route
node_api_main -->|"serves"| node_predict_route
node_predict_route -->|"parses input"| node_api_schemas
node_predict_route -->|"preprocesses"| node_data_processing
node_predict_route -->|"predicts via"| node_model_loader
node_health_route -->|"checks model"| node_model_loader
node_health_route -->|"reports versions"| node_utils
node_model_loader -->|"loads"| node_artifact_model
node_model_loader -.->|"may use"| node_artifact_bundle
node_data_processing -->|"uses"| node_utils
node_modeling_notebook -->|"trains on"| node_dataset
node_eda_notebook -->|"explores"| node_dataset
node_modeling_notebook -->|"produces"| node_artifact_model
node_modeling_notebook -->|"produces"| node_artifact_best
node_modeling_notebook -->|"produces"| node_artifact_bundle
node_local_demo -.->|"tests"| node_api_main
node_api_demo -.->|"tests"| node_api_main
node_dockerfiles -->|"runs"| node_api_main
node_compose -->|"orchestrates"| node_dockerfiles
node_platform -->|"deploys"| node_dockerfiles
node_runtime -->|"pins"| node_requirements
node_requirements -->|"supports"| node_api_main
node_requirements -->|"supports"| node_model_loader

click node_api_main "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/api/main.py"
click node_api_schemas "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/api/schemas.py"
click node_model_loader "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/model.py"
click node_data_processing "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/data_processing.py"
click node_utils "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/utils.py"
click node_artifact_model "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/models/rental_price_model.pkl"
click node_artifact_best "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/models/mejor_modelo.pkl"
click node_artifact_bundle "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/models/model_artifacts.pkl"
click node_dataset "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/data/real_state_ecuador_dataset.csv"
click node_eda_notebook "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/notebooks/01_eda.ipynb"
click node_modeling_notebook "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/notebooks/02_modeling.ipynb"
click node_local_demo "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/Prueba_Funcionamiento_Local.ipynb"
click node_api_demo "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/Pruebas_Funcionamiento_API.ipynb"
click node_compose "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/docker-compose.yaml"
click node_platform "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/render.yaml"
click node_runtime "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/runtime.txt"
click node_requirements "https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/requirements.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_api_main,node_api_schemas,node_health_route,node_predict_route,node_model_loader,node_data_processing,node_utils,node_artifact_model toneBlue
class node_artifact_best,node_artifact_bundle,node_dataset,node_eda_notebook,node_modeling_notebook,node_local_demo,node_api_demo toneAmber
class node_dockerfiles,node_compose,node_platform,node_runtime,node_requirements toneMint
```

## Components

### Online serving

Live FastAPI inference path

- **Client**: requester · Sends structured JSON for health checks and rent predictions
- [API entrypoint](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/api/main.py): FastAPI app · Starts the HTTP service and registers routes · `api/main.py`
- [Schemas](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/api/schemas.py): Pydantic contracts · Validates prediction input and shapes responses · `api/schemas.py`
- **Health check**: endpoint · Reports liveness, model status, and runtime versions
- **Predict route**: endpoint · Accepts property features and returns a rent estimate
- [Model loader](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/model.py): inference core · Loads the serialized model and runs predictions · `src/model.py`
- [Preprocessing](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/data_processing.py): feature prep · Normalizes and transforms raw inputs into model-ready features · `src/data_processing.py`
- [Helpers](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/src/utils.py): shared utils · Common support code for pathing, serialization, and feature helpers · `src/utils.py`
- [Rental model](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/models/rental_price_model.pkl): pickle artifact · Primary persisted model used by the API · `models/rental_price_model.pkl`

### Offline ML lifecycle

Training, exploration, and artifact generation

- [Best model](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/models/mejor_modelo.pkl): pickle artifact · Alternative or best-snapshot model artifact · `models/mejor_modelo.pkl`
- [Artifact bundle](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/models/model_artifacts.pkl): pickle artifact · Saved training outputs and supporting metadata · `models/model_artifacts.pkl`
- [Dataset](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/data/real_state_ecuador_dataset.csv): training data · Offline source dataset for exploration and model fitting · `data/real_state_ecuador_dataset.csv`
- [EDA notebook](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/notebooks/01_eda.ipynb): analysis notebook · Explores the rental data and feature distributions · `notebooks/01_eda.ipynb`
- [Modeling notebook](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/notebooks/02_modeling.ipynb): training notebook · Trains and evaluates the model, producing artifacts · `notebooks/02_modeling.ipynb`
- [Local demo](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/Prueba_Funcionamiento_Local.ipynb): validation notebook · Checks the service and model behavior locally · `Prueba_Funcionamiento_Local.ipynb`
- [API demo](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/Pruebas_Funcionamiento_API.ipynb): validation notebook · Exercises the HTTP prediction flow end to end · `Pruebas_Funcionamiento_API.ipynb`

### Deployment

Container and platform configuration

- **Containers**: runtime config · Container build definitions for running the service
- [Compose](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/docker-compose.yaml): runtime config · Local multi-container orchestration for development · `docker-compose.yaml`
- [Platform config](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/render.yaml): deploy config · Deployment settings for hosted runtime platforms · `render.yaml`
- [Python env](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/runtime.txt): runtime pinning · Pins Python version and dependencies for reproducible deploys · `runtime.txt`
- [Dependencies](https://github.com/christianarroyoauz/predict-rental-prices-ecuador/blob/main/requirements.txt): package lock · Python libraries used by the API and ML stack · `requirements.txt`

## Connections

- Client → API entrypoint: HTTP requests · External caller sends health and prediction requests
- API entrypoint → Schemas: validates with · FastAPI uses schemas for request and response contracts
- API entrypoint → Health check: serves · Exposes liveness and model status endpoint
- API entrypoint → Predict route: serves · Exposes prediction endpoint
- Predict route → Schemas: parses input · Structured request payload is validated before inference
- Predict route → Preprocessing: preprocesses · Raw feature values are shaped into model-ready inputs
- Predict route → Model loader: predicts via · Prediction route delegates to model loading and inference code
- Health check → Model loader: checks model · Health response includes model_loaded state
- Health check → Helpers: reports versions · Runtime/library metadata is assembled for readiness checks
- Model loader → Rental model: loads · Primary serialized model artifact is read from disk
- Model loader → Artifact bundle: may use · Loader can rely on saved metadata or auxiliary artifacts
- Preprocessing → Helpers: uses · Shares helper functions and path/feature utilities
- Modeling notebook → Dataset: trains on · Offline training uses the CSV dataset
- EDA notebook → Dataset: explores · EDA notebook analyzes the same training data
- Modeling notebook → Rental model: produces · Training pipeline exports the deployed model artifact
- Modeling notebook → Best model: produces · May also export best-snapshot model artifacts
- Modeling notebook → Artifact bundle: produces · Stores training outputs and supporting artifacts
- Local demo → API entrypoint: tests · Notebook exercises the local service runtime
- API demo → API entrypoint: tests · Notebook exercises the HTTP prediction flow
- Containers → API entrypoint: runs · Container images package the FastAPI application
- Compose → Containers: orchestrates · Compose coordinates local container execution
- Platform config → Containers: deploys · Platform config references containerized runtime
- Python env → Dependencies: pins · Environment version works with declared dependencies
- Dependencies → API entrypoint: supports · API depends on FastAPI, Uvicorn, and Pydantic stack
- Dependencies → Model loader: supports · Inference layer depends on scikit-learn and joblib stack
