# dhanush-r-git/mh-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/dhanush-r-git/mh-analysis
- Repository: https://github.com/dhanush-r-git/mh-analysis

## Overview

##### Project type and purpose
- Maṉa is a full-stack web application for mental‐health analysis via social media.
- It ingests user comments or API-fetched posts, runs sentiment analysis (MHRoberta/RoBERTa), then branches into two chat modes:
- MaṉaNow (DeepSeek-R1) for in-depth assessments and report generation

##### File structure
- Top level: README, requirement.txt, research notebooks, mental_health_docs (static docs)
- static/assets: front-end static files (CSS/JS/images)
- webapp_setup/
- templates/: Jinja2 HTML views (Landing, Overview, MaṉaChat, MaṉaNow, etc.)
- *.py modules:
– chatbot.py: entry point / FastAPI or Flask server
– Manachat.py: orchestrates MaṉaChat mode
– Mananow.py: orchestrates MaṉaNow mode
– web_scrapper.py: collects comments via social-media APIs
– error_logger.py: logs errors/reports
- No explicit database folder, so reports may be written to files or external store

##### README for insights
- Confirms FastAPI-powered chatbot backend
- Uses Hugging Face Inference API or local fallback models

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["User Browser"]:::frontend
        Templates["Jinja2 Templates"]:::frontend
        StaticAssets["Static Assets (CSS/JS/Images)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        Chatbot["Web Server\n(chatbot.py)"]:::backend
        WebScraper["Web Scraper Service\n(web_scrapper.py)"]:::service
        Sentiment["Sentiment Analysis Service\n(MHRoberta)"]:::service
        ManaChat["MaṉaChat Service\n(Manachat.py)"]:::service
        ManaNow["MaṉaNow Service\n(Mananow.py)"]:::service
        ErrorLogger["Error Logger\n(error_logger.py)"]:::service
    end

    %% ML Inference Layer
    subgraph "ML Inference Layer"
        HFAPI["Hugging Face Inference API"]:::external
        LocalModels["Local Models\n(Llama-3.2, DeepSeek-R1)"]:::external
    end

    %% External Services
    subgraph "External Services"
        SocialAPI["Social Media APIs"]:::external
    end

    %% Storage
    subgraph "Storage"
        Logs["Logs/Reports\n(Flat Files or DB)"]:::storage
    end

    %% Offline Resources
    subgraph "Offline Resources"
        Research["Research Notebooks"]:::resource
        KB["Mental Health Docs"]:::resource
        Req["Requirement Specification\n(requirement.txt)"]:::resource
        Readme["Project Overview\n(README.md)"]:::resource
    end

    %% Data Flows
    Browser -->|"HTTP Request\n(GET landing, POST analyze)"| Chatbot
    Chatbot -->|"fetch comments"| WebScraper
    WebScraper -->|"API calls"| SocialAPI
    SocialAPI --> WebScraper
    WebScraper --> Chatbot

    Chatbot -->|"POST /analyze\nsentiment analysis"| Sentiment
    Sentiment -->|"Positive"| ManaChat
    Sentiment -->|"Negative"| ManaNow

    ManaChat -->|"inference call"| HFAPI
    ManaChat -->|"local fallback"| LocalModels
    ManaChat -->|"response"| Chatbot

    ManaNow -->|"inference call"| HFAPI
    ManaNow -->|"local fallback"| LocalModels
    ManaNow -->|"generate report"| Chatbot

    Chatbot -->|"render response"| Browser

    %% Error Logging
    Chatbot -->|errors| ErrorLogger
    WebScraper -->|errors| ErrorLogger
    Sentiment -->|errors| ErrorLogger
    ManaChat -->|errors| ErrorLogger
    ManaNow -->|errors| ErrorLogger

    ErrorLogger --> Logs

    %% Click Events
    click Templates "https://github.com/dhanush-r-git/mh-analysis/tree/main/webapp_setup/templates"
    click StaticAssets "https://github.com/dhanush-r-git/mh-analysis/tree/main/static/assets"
    click Chatbot "https://github.com/dhanush-r-git/mh-analysis/blob/main/webapp_setup/chatbot.py"
    click WebScraper "https://github.com/dhanush-r-git/mh-analysis/blob/main/webapp_setup/web_scrapper.py"
    click ManaChat "https://github.com/dhanush-r-git/mh-analysis/blob/main/webapp_setup/Manachat.py"
    click ManaNow "https://github.com/dhanush-r-git/mh-analysis/blob/main/webapp_setup/Mananow.py"
    click ErrorLogger "https://github.com/dhanush-r-git/mh-analysis/blob/main/webapp_setup/error_logger.py"
    click Research "https://github.com/dhanush-r-git/mh-analysis/tree/main/Research"
    click KB "https://github.com/dhanush-r-git/mh-analysis/tree/main/mental_health_docs"
    click Req "https://github.com/dhanush-r-git/mh-analysis/blob/main/requirement.txt"
    click Readme "https://github.com/dhanush-r-git/mh-analysis/blob/main/README.md"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef backend fill:#FFF3E0,stroke:#E65100,color:#E65100;
    classDef service fill:#FFFDE7,stroke:#F9A825,color:#F9A825;
    classDef external fill:#ECEFF1,stroke:#455A64,color:#455A64;
    classDef storage fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef resource fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A;
```
