# vgamboa-sys/modelo_ia_proyecto_mineria architecture

> Architecture diagram of the GitHub repository vgamboa-sys/modelo_ia_proyecto_mineria, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vgamboa-sys/modelo_ia_proyecto_mineria
- Repository: https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria

## Overview

##### Project Type and Purpose
- SafeMine AI is a full-stack, alert-generation application for mining safety.
- Backend (Python/FastAPI) ingests weather data, enriches it with Google Gemini AI, and persists alert records in a local SQLite database.
- Frontend (React + Vite) presents a dashboard of preventive daily safety alerts to end users.

##### File Structure Analysis
- Top-level:
- backend/ – the Python API service
- frontend/ – the React SPA
- README.md, requirements.txt for global context
- backend/app/:
- main.py – FastAPI app entry point
- routers/ – API endpoints (weather fetch, AI integration)
- database/db.py – DB connection layer (SQLite)
- schemas/ – Pydantic models for request/response
- .env – config for external API keys
- frontend/:
- src/ – React components (Dashboard, AlertCard, Filter, Header)
- index.html, vite.config.js – SPA hosting/config
- package.json – Node dependencies and scripts

##### README Insights
- Clearly defines the two main modules and tech stack:
- Frontend: React + Vite
- Backend: FastAPI + Python 3.13.5 + SQLite
- External services: OpenWeatherMap, Google Gemini

a. Main Components
1. User’s Browser / React SPA
2. FastAPI Backend Service
3. SQLite Database (local file)
4. External Weather API (OpenWeatherMap)
5. External AI Service (Google Gemini)
b. Relationships and Data Flows
- Backend → OpenWeatherMap API (fetch raw weather JSON)
- Backend → Google Gemini API (send weather data, receive analysis)
- Backend → SQLite (read/write alert records)
- Backend → Browser (response with processed alert payload)
c. Architectural Patterns
- Monolithic API with clear separation of routers (controllers), schemas (models), and database layer.
- SPA-API pattern: decoupled frontend and backend communicating via REST.
d. Key Technologies
- React + Vite (frontend build & dev server)
- FastAPI + Uvicorn (backend HTTP server)
- Pydantic schemas for data validation
- SQLite via SQLAlchemy or native driver
- OpenWeatherMap & Google Gemini external REST APIs

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Presentation Tier"
        direction TB
        Browser["React Frontend"]:::internal
        Dashboard["Dashboard UI Component"]:::internal
        AlertCard["Alert Card UI Component"]:::internal
        Filter["Filter UI Component"]:::internal
        Header["Header UI Component"]:::internal
    end

    %% Backend Layer
    subgraph "Application Tier"
        direction TB
        Backend["FastAPI Backend Service"]:::internal
        subgraph "API Routers"
            direction TB
            DataWeather["Weather Data Router"]:::internal
            AIIntegration["AI Integration Router"]:::internal
        end
        subgraph "Data Layer"
            direction TB
            DBLayer["SQLite Database Layer"]:::db
            Schemas["Pydantic Schemas"]:::internal
        end
        Config["External API Keys Configuration"]:::internal
        ReqTxt["Backend Python Dependencies"]:::internal
    end

    %% External Services
    subgraph "External Services"
        direction TB
        WeatherAPI["OpenWeatherMap API"]:::external
        GeminiAI["Google Gemini AI"]:::external
    end

    %% Connections
    Browser -->|"HTTP GET /api/alertas/actual"| Backend
    Backend -->|"fetch weather data"| DataWeather
    DataWeather --> WeatherAPI
    Backend -->|"call AI analysis"| AIIntegration
    AIIntegration --> GeminiAI
    Backend -->|"read/write alerts"| DBLayer
    Backend -->|"validate payload"| Schemas
    Config --- Backend
    ReqTxt --- Backend

    Browser --> Dashboard
    Dashboard --> AlertCard
    Dashboard --> Filter
    Dashboard --> Header

    %% Styles
    classDef internal fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px
    classDef db fill:#FFE4B5,stroke:#000,stroke-width:1px

    %% Click Events
    click Browser "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/tree/main/frontend/"
    click Browser "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/index.html"
    click Browser "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/src/main.jsx"
    click Browser "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/vite.config.js"
    click Dashboard "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/src/components/Dashboard.jsx"
    click AlertCard "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/src/components/AlertCard.jsx"
    click Filter "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/src/components/Filter.jsx"
    click Header "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/frontend/src/components/Header.jsx"
    click Backend "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/main.py"
    click DataWeather "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/routers/data_weather.py"
    click AIIntegration "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/routers/cnx_IA.py"
    click DBLayer "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/database/db.py"
    click Schemas "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/schemas/weather.py"
    click Config "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/.env"
    click ReqTxt "https://github.com/vgamboa-sys/modelo_ia_proyecto_mineria/blob/main/backend/app/requirements.txt"
```
