# jonasluis/intuitive-care architecture

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

- Interactive diagram: https://gitdiagram.com/jonasluis/intuitive-care
- Repository: https://github.com/jonasluis/intuitive-care

## Overview

- Data Collection Module:
- Web Scraping (backend/scraper.py): Automates the collection of PDF links from the ANS website.
- Downloaders (backend/downloader.py and backend/ftp_downloader.py): Responsible for downloading PDFs and data files via FTP.
- Data Processing Module:
- Data Transformation (backend/data_transformer.py): Handles processing, cleaning, and converting data (e.g., PDF to CSV) after collection.
- Compression (backend/compressor.py): Compresses files after processing.
- CSV Checks (backend/check_csv.py): Validates or checks CSV integrity.
- Database Operations Module:
- Scripts (backend/database/): SQL files (create_tables.sql and import_and_analyze.sql) for initializing the MySQL database schema and managing data analysis.
- API Module:
- API Endpoints (backend/api.py): Implements RESTful endpoints using FastAPI.
- API Runner (backend/run_api.py): Script to start the FastAPI server.
- Main Orchestrator (backend/main.py): Coordinates the data collection and transformation processes through command-line arguments that trigger specific routines.
- Frontend Module:
- User Interface (frontend/index.html and frontend/src/App.vue): Main view layer in Vue.js to present search and data views.
- Entry Point (frontend/src/main.js): Initializes the Vue application.
- Service Layer (frontend/src/services/operadoraService.js): Handles client-side API requests using Axios.
- External Systems:
- MySQL Database: Holds the transformed data for operations and analytics.
- External Data Sources: ANS website and FTP endpoints for obtaining data.
- Postman Collection: Documentation for API endpoints.

##### Interactions and Relationships
- Data Flow:
- The API layer (FastAPI) then interacts with the database to serve data requests.
- The frontend Vue.js application communicates with the API endpoints (via Axios calls) to fetch and display data.
- Dependencies:
- The orchestration (backend/main.py) relies on separate modules (scraper, downloader, transformer) that eventually supply data into the database.
- The API (backend/api.py) acts as a middleware, providing RESTful endpoints to the Vue.js frontend.
- Configuration settings in config.py ensure that environmental parameters (like external URLs and API endpoints) are correctly injected into the system.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clearly separate data collection, processing, and presentation layers.
- Modular Decomposition: Each Python script and package in the backend encapsulates specific functionalities (scraping, downloading, transformation, etc.).
- API-Driven Design: Communication between the frontend (Vue.js) and backend (FastAPI) is through well-defined RESTful APIs.
- Separation of Concerns: Different components (data manipulation vs. user interface) are isolated to simplify maintenance and updates.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    subgraph "External Systems"
        ANS["ANS Website"]:::external
        FTP["FTP Endpoints"]:::external
        MySQL[/"MySQL Database"/]:::database
        Postman["Postman API Collection"]:::external
    end

    %% Data Collection Module
    subgraph "Data Collection Module"
        WS["Web Scraper"]:::backend
        PD["PDF Downloader"]:::backend
        FD["FTP Downloader"]:::backend
    end

    %% Data Processing Module
    subgraph "Data Processing Module"
        DT["Data Transformer"]:::backend
        CP["Compressor"]:::backend
        CC["CSV Checker"]:::backend
    end

    %% Database Operations Module
    subgraph "Database Operations Module"
        DS["Database Scripts"]:::backend
    end

    %% API Module
    subgraph "API Module"
        APIE["API Endpoints"]:::backend
        APIR["API Runner"]:::backend
        MO["Main Orchestrator"]:::backend
        CFG["Configuration Settings"]:::backend
    end

    %% Frontend Module
    subgraph "Frontend Module"
        UI["Main User Interface"]:::frontend
        VA["Vue App Component"]:::frontend
        VM["Vue Application Entry Point"]:::frontend
        AS["Service Layer for API Calls"]:::frontend
    end

    %% Data Flow Connections (vertical layout)
    ANS -->|"provides"| WS
    FTP -->|"provides"| FD

    WS -->|"sends data"| DT
    FD -->|"sends data"| DT
    PD -->|"alternative fetch"| WS

    DT -->|"transforms"| CP
    CP -->|"compresses data"| CC
    CC -->|"loads"| DS

    DS -->|"populates"| MySQL

    MySQL -->|"queried by"| APIE
    APIR -->|"initiates"| MO
    CFG -.-> APIR

    APIE -->|"serves data"| VA
    VA -->|"renders view"| VM
    AS -->|"calls"| APIE
    UI --> VA

    MO -->|"orchestrates"| WS
    MO -->|"orchestrates"| FD
    MO -->|"orchestrates"| DT

    %% Styling classes
    classDef backend fill:#e0f7fa,stroke:#006064,stroke-width:2px;
    classDef frontend fill:#f1f8e9,stroke:#33691e,stroke-width:2px;
    classDef external fill:#ffebee,stroke:#c62828,stroke-width:2px;
    classDef database fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px;

    %% Click Events
    click WS "https://github.com/jonasluis/intuitive-care/blob/main/backend/scraper.py"
    click PD "https://github.com/jonasluis/intuitive-care/blob/main/backend/downloader.py"
    click FD "https://github.com/jonasluis/intuitive-care/blob/main/backend/ftp_downloader.py"
    click DT "https://github.com/jonasluis/intuitive-care/blob/main/backend/data_transformer.py"
    click CP "https://github.com/jonasluis/intuitive-care/blob/main/backend/compressor.py"
    click CC "https://github.com/jonasluis/intuitive-care/blob/main/backend/check_csv.py"
    click DS "https://github.com/jonasluis/intuitive-care/tree/main/backend/database/"
    click APIE "https://github.com/jonasluis/intuitive-care/blob/main/backend/api.py"
    click APIR "https://github.com/jonasluis/intuitive-care/blob/main/backend/run_api.py"
    click MO "https://github.com/jonasluis/intuitive-care/blob/main/backend/main.py"
    click CFG "https://github.com/jonasluis/intuitive-care/blob/main/backend/config.py"
    click UI "https://github.com/jonasluis/intuitive-care/blob/main/frontend/index.html"
    click VA "https://github.com/jonasluis/intuitive-care/blob/main/frontend/src/App.vue"
    click VM "https://github.com/jonasluis/intuitive-care/blob/main/frontend/src/main.js"
    click AS "https://github.com/jonasluis/intuitive-care/blob/main/frontend/src/services/operadoraService.js"
```
