# oriolgalvez/previacare architecture

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

- Interactive diagram: https://gitdiagram.com/oriolgalvez/previacare
- Repository: https://github.com/oriolgalvez/previacare

## Overview

##### Project Type and Purpose
- Monolithic full-stack web application built on Django.
- Provides user authentication and profile management.
- Hosts two prediction services (diabetes risk & heart-disease risk) plus a simple chatbot.
- Renders server-side HTML templates, serves static assets, and exposes form endpoints.

##### Main Components
a. Client (Web Browser)
– Renders HTML/CSS/JS.
– Interacts via HTTP(S) with Django.
b. Django Web Server (Application Tier)
– URL Router & Views (in previacare/previacare/urls.py + each app’s urls.py & views.py).
– Apps:
- users (authentication, profiles, Google OAuth callback)
- diabetes (form → model inference → results)
- heart_disease (same pattern)
- chatbot (REST endpoints or web sockets for chat interaction)
– Templates (templates/…) and Static File Handler (static/css, js, assets).
– Middleware, Settings (previacare/previacare/settings.py).
c. Database (Data Tier)
– Django ORM models (in each app’s models.py, e.g. CustomUser, PredictionResult).
– Migrations folder per app.
– Backed by SQLite/PostgreSQL (configurable in settings).
d. ML Model Components
– Serialized/Pickled models loaded by the diabetes and heart_disease apps.
– Training artifacts maintained in Jupyter notebooks under each app’s model/ or modelo/ folder.
e. External Services & Dependencies
– Google OAuth2 (used in users/templates/users/google_callback.html).
– Python packages (listed in requirements.txt) such as Django, scikit-learn, pandas, etc.

##### Relationships & Data Flow
1. Browser → HTTP Request → Django URL Router
2. Router dispatches to appropriate View in one of the apps
3. View may:
- Render a template (GET dashboard, forms)
- Process form data → call ML inference function → save PredictionResult to DB → render results
- Interact with OAuth service (users app) → update user session
- Forward data to/from chatbot logic
4. View ↔ ORM ↔ Database for CRUD
5. ML inference modules (in-memory loaded models) invoked by views
6. Django static files served (directly or via CDN/web server)

##### Architectural Patterns & Design Principles
- MVC (Django’s MTV) separation: Models (models.py) ↔ Templates (templates/) ↔ Views (views.py)
- Single codebase monolith—no microservices.
- Clear app boundaries: users vs diabetes vs heart_disease vs chatbot
- Reusable components: shared static, shared base.html, common CSS/JS.
- Notebooks are outside runtime path—used for model training only.

##### Essential Elements
- Labels on every component (“Browser,” “Django Router,” “diabetes.views.predict_diabetes,” etc.)
- If space allows, include sample URLs (e.g., “/diabetes/form”, “/users/google/callback”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["Web Browser"]:::browser
        Templates["Templates (HTML)"]:::browser
        Static["Static Assets (CSS/JS/Images)"]:::browser
    end

    %% Application Layer
    subgraph "Application Layer" 
        direction TB
        Router["Django URL Router"]:::apps
        Settings["Settings & Middleware"]:::apps
        subgraph "Users App" 
            direction TB
            UA_Config["apps.py"]:::apps
            UA_Routes["urls.py"]:::apps
            UA_Views["views.py"]:::apps
            UA_Serializers["serializers.py"]:::apps
            UA_Models["models.py"]:::apps
            UA_Migrations["migrations/"]:::apps
            UA_Callback["google_callback.html"]:::browser
        end
        subgraph "Diabetes App"
            direction TB
            D_Config["apps.py"]:::apps
            D_Routes["urls.py"]:::apps
            D_Views["views.py"]:::apps
            D_Models["models.py"]:::apps
            D_Migrations["migrations/"]:::apps
            D_Notebooks["modelo/*.ipynb"]:::ml
        end
        subgraph "Heart Disease App"
            direction TB
            H_Config["apps.py"]:::apps
            H_Routes["urls.py"]:::apps
            H_Views["views.py"]:::apps
            H_Models["models.py"]:::apps
            H_Migrations["migrations/"]:::apps
            H_Notebooks["model/*.ipynb"]:::ml
        end
        subgraph "Chatbot App"
            direction TB
            C_Config["apps.py"]:::apps
            C_Routes["urls.py"]:::apps
            C_Views["views.py"]:::apps
            C_Models["models.py"]:::apps
            C_Migrations["migrations/"]:::apps
        end
        Manage["manage.py"]:::apps
        Requirements["requirements.txt"]:::apps
    end

    %% Data & ML Layer
    subgraph "Data & ML Layer"
        direction TB
        DB["Database (SQLite/PostgreSQL)"]:::db
        ML_Diabetes["Diabetes Model"]:::ml
        ML_Heart["Heart Disease Model"]:::ml
        OAuth["Google OAuth2 Service"]:::external
    end

    %% Connections
    Browser -->|"HTTP request"| Router
    Router -->|"dispatch"| UA_Routes
    Router -->|"dispatch"| D_Routes
    Router -->|"dispatch"| H_Routes
    Router -->|"dispatch"| C_Routes

    Templates -->|renders| Browser
    Static -->|serves| Browser

    Router --> Settings
    UA_Routes --> UA_Views
    UA_Views -->|ORM CRUD| UA_Models
    UA_Views -->|OAuth handshake| OAuth
    UA_Views -->|renders| UA_Callback
    D_Routes --> D_Views
    D_Views -->|inference| ML_Diabetes
    D_Views -->|ORM CRUD| D_Models
    H_Routes --> H_Views
    H_Views -->|inference| ML_Heart
    H_Views -->|ORM CRUD| H_Models
    C_Routes --> C_Views
    C_Views -->|ORM CRUD| C_Models

    UA_Models --> DB
    D_Models --> DB
    H_Models --> DB
    C_Models --> DB

    ML_Diabetes --> D_Views
    ML_Heart --> H_Views

    %% Click Events
    click Templates "https://github.com/oriolgalvez/previacare/tree/main/templates/"
    click Static "https://github.com/oriolgalvez/previacare/tree/main/static/"
    click Router "https://github.com/oriolgalvez/previacare/blob/main/previacare/previacare/urls.py"
    click Settings "https://github.com/oriolgalvez/previacare/blob/main/previacare/previacare/settings.py"

    click UA_Config "https://github.com/oriolgalvez/previacare/blob/main/previacare/users/apps.py"
    click UA_Routes "https://github.com/oriolgalvez/previacare/blob/main/previacare/users/urls.py"
    click UA_Views "https://github.com/oriolgalvez/previacare/blob/main/previacare/users/views.py"
    click UA_Serializers "https://github.com/oriolgalvez/previacare/blob/main/previacare/users/serializers.py"
    click UA_Models "https://github.com/oriolgalvez/previacare/blob/main/previacare/users/models.py"
    click UA_Migrations "https://github.com/oriolgalvez/previacare/tree/main/previacare/users/migrations/"
    click UA_Callback "https://github.com/oriolgalvez/previacare/blob/main/previacare/users/templates/users/google_callback.html"

    click D_Config "https://github.com/oriolgalvez/previacare/blob/main/previacare/diabetes/apps.py"
    click D_Routes "https://github.com/oriolgalvez/previacare/blob/main/previacare/diabetes/urls.py"
    click D_Views "https://github.com/oriolgalvez/previacare/blob/main/previacare/diabetes/views.py"
    click D_Models "https://github.com/oriolgalvez/previacare/blob/main/previacare/diabetes/models.py"
    click D_Migrations "https://github.com/oriolgalvez/previacare/tree/main/previacare/diabetes/migrations/"
    click D_Notebooks "https://github.com/oriolgalvez/previacare/blob/main/previacare/diabetes/modelo/eda_diabetes-2.ipynb"

    click H_Config "https://github.com/oriolgalvez/previacare/blob/main/previacare/heart_disease/apps.py"
    click H_Routes "https://github.com/oriolgalvez/previacare/blob/main/previacare/heart_disease/urls.py"
    click H_Views "https://github.com/oriolgalvez/previacare/blob/main/previacare/heart_disease/views.py"
    click H_Models "https://github.com/oriolgalvez/previacare/blob/main/previacare/heart_disease/models.py"
    click H_Migrations "https://github.com/oriolgalvez/previacare/tree/main/previacare/heart_disease/migrations/"
    click H_Notebooks "https://github.com/oriolgalvez/previacare/blob/main/previacare/heart_disease/model/eda.ipynb"

    click C_Config "https://github.com/oriolgalvez/previacare/blob/main/previacare/chatbot/apps.py"
    click C_Routes "https://github.com/oriolgalvez/previacare/blob/main/previacare/chatbot/urls.py"
    click C_Views "https://github.com/oriolgalvez/previacare/blob/main/previacare/chatbot/views.py"
    click C_Models "https://github.com/oriolgalvez/previacare/blob/main/previacare/chatbot/models.py"
    click C_Migrations "https://github.com/oriolgalvez/previacare/tree/main/previacare/chatbot/migrations/"

    click Manage "https://github.com/oriolgalvez/previacare/blob/main/previacare/manage.py"
    click Requirements "https://github.com/oriolgalvez/previacare/blob/main/requirements.txt"

    %% Styles
    classDef browser fill:#ADD8E6,stroke:#000
    classDef apps fill:#90EE90,stroke:#000
    classDef db fill:#FFA500,stroke:#000,stroke-width:2px
    classDef ml fill:#D8BFD8,stroke:#000
    classDef external fill:#E0E0E0,stroke:#000,stroke-dasharray: 5 5
```
