# abdullahlali/sugarsage architecture

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

- Interactive diagram: https://gitdiagram.com/abdullahlali/sugarsage
- Repository: https://github.com/abdullahlali/sugarsage

## Overview

##### Project Type and Purpose
- SugarSage is clearly a full-stack web application that integrates machine learning (for diabetes prediction) and natural language processing (for the chatbot).
- The backend is built with Flask (Python) and leverages Scikit-Learn, Pandas, and NLP libraries (including NLTK), while the frontend uses Tailwind CSS and JavaScript.
- Key functionalities include RESTful API interactions between the frontend and backend, real-time model predictions (via a regression model) and a chatbot powered by TF-IDF vectorization with SVM classification.

##### Analyzing the File Structure
- The top-level directories and files indicate separation of concerns:
- The “app” directory hosts the back-end application code (app.py), machine learning models (model.pkl, vectorizer.pkl, xtrainvectors.pkl), dataset files (cleaned_diabetes_dataset.csv, dataset.pkl), and supporting scripts (makeDataset.py, saveModel.py, download_nltk_data.py). It also contains NLTK data necessary for NLP functionality.
- The “assets” and “index.html” together with “script.js” indicate the front-end components, providing the user interface.
- The “tests” directory (with Selenium tests) and “.github/workflows” (for CI tests like selenium-tests.yml) show that testing and continuous integration processes are incorporated.
- Configuration and deployment files like “Procfile” indicate deployment on Heroku.

##### Key Architectural Components
- Frontend: Includes static files (index.html, script.js, assets) styled with Tailwind CSS. This layer deals with user interactions and presents a responsive UI.
- Backend API: The Flask application (app/app.py) acts as the server that handles RESTful API endpoints. It bridges requests from the frontend to the business logic.
- Machine Learning & NLP Components:
- Model Components: The diabetes prediction model (model.pkl, vectorizer.pkl, xtrainvectors.pkl, dataset files) and supporting scripts (makeDataset.py, saveModel.py) handle data preparation and predictions.
- Chatbot Component: Utilizes TF-IDF and SVM (as described in the README) along with NLTK resources for natural language processing (data stored in app/nltk_data).
- Deployment & CI/CD: The “Procfile” and GitHub workflows indicate automated deployment (Heroku) and testing routines (Selenium testing).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/UI Layer
    subgraph "Client/UI Layer"
      FE["Frontend (HTML/JS/Tailwind)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
      API["Flask API Server"]:::backend
    end

    %% Machine Learning Services
    subgraph "Machine Learning Services"
      DP["Diabetes Prediction Service"]:::ml
      CHAT["AI Chatbot Service"]:::ml
    end

    %% Local File Storage
    subgraph "Local File Storage"
      STORAGE["Data & Model Storage"]:::storage
    end

    %% Infrastructure
    subgraph "Infrastructure"
      DEPLOY["Deployment (Heroku)"]:::deploy
      CI["CI/CD & Testing"]:::ci
    end

    %% Relationships
    FE -->|"HTTP_request"| API
    API -->|"predicts"| DP
    API -->|"chat_requests"| CHAT
    DP -->|"reads_writes"| STORAGE
    CHAT -->|"accesses"| STORAGE
    API -->|"deployed_on"| DEPLOY
    API -->|"tested_by"| CI
    DP -->|"tested_by"| CI
    CHAT -->|"tested_by"| CI

    %% Click Events for Frontend Components
    click FE "https://github.com/abdullahlali/sugarsage/blob/main/index.html"
    click FE "https://github.com/abdullahlali/sugarsage/blob/main/script.js"
    click FE "https://github.com/abdullahlali/sugarsage/tree/main/assets/"

    %% Click Event for Backend API Server
    click API "https://github.com/abdullahlali/sugarsage/blob/main/app/app.py"

    %% Click Events for Diabetes Prediction Service Components
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/model.pkl"
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/vectorizer.pkl"
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/xtrainvectors.pkl"
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/cleaned_diabetes_dataset.csv"
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/dataset.pkl"
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/makeDataset.py"
    click DP "https://github.com/abdullahlali/sugarsage/blob/main/app/saveModel.py"

    %% Click Events for AI Chatbot Service Components
    click CHAT "https://github.com/abdullahlali/sugarsage/blob/main/app/download_nltk_data.py"
    click CHAT "https://github.com/abdullahlali/sugarsage/tree/main/app/nltk_data/"

    %% Click Event for Deployment Configuration
    click DEPLOY "https://github.com/abdullahlali/sugarsage/tree/main/app/Procfile"

    %% Click Events for CI/CD & Testing Components
    click CI "https://github.com/abdullahlali/sugarsage/blob/main/.github/workflows/selenium-tests.yml"
    click CI "https://github.com/abdullahlali/sugarsage/tree/main/tests/"

    %% Styles
    classDef frontend fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef ml fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef deploy fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef ci fill:#ccffff,stroke:#333,stroke-width:2px;
```
