# adityakamble12/text-based-emotion-detector architecture

> Architecture diagram of the GitHub repository adityakamble12/text-based-emotion-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityakamble12/text-based-emotion-detector
- Repository: https://github.com/adityakamble12/text-based-emotion-detector

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Flask (Python) that provides a UI for users to submit text and returns detected emotions by calling MeaningCloud’s Sentiment Analysis API.
- It is deployed on Vercel and uses static assets (HTML/CSS/JS) plus a small service layer (the `emotion_detection` module).

##### File Structure
- Top-level:
- `app.py` – Flask entry point, route definitions, orchestrates requests.
- `emotion_detection/` – Python package encapsulating the core analysis logic (wrapper around MeaningCloud API).
- `templates/` – Jinja HTML templates (only `index.html`).
- `static/` – Frontend assets (CSS under `/css`, JS under `/js`, images under `/img`).
- `requirements.txt`, `.env` (not checked in), `vercel.json` – deployment/configuration.
- The structure follows a lightweight MVC pattern:
- Controller: Flask routes in `app.py`
- View: Jinja template + static files
- Model/Service: `emotion_detection/emotion_detection.py`

##### Extract Architectural Insights from the README
- Dependencies: Flask, pydash (utility), requests (HTTP calls), python-dotenv (config).
- The app reads an `API_KEY` from `.env` to authenticate with MeaningCloud.
- Hosted on Vercel, so deployment uses `vercel.json`.

##### Main Components & Interactions
1. Client Browser (UI)
2. Static Asset Server (Flask serves CSS/JS/images)
3. Flask App Server
- Route Handler(s) in `app.py`
- Service Layer in `emotion_detection` module
4. Configuration Store (`.env` via python-dotenv)
5. External Emotion Analysis API (MeaningCloud)
1. User types text → submits form in Browser
2. Browser → HTTP POST → Flask App Server
3. Flask Controller → calls Service Layer (`emotion_detection.py`)
4. Service Layer → HTTP request (via `requests`) → MeaningCloud API
5. MeaningCloud API → JSON response → Service Layer
6. Service Layer → processed result → Controller
7. Controller → injects data into `index.html` template or sends JSON → Browser
c. Architectural Patterns & Principles:
- MVC separation (Controller, View, Service/Model)
- Single-Responsibility: `emotion_detection` module purely wraps API logic
- Environment configuration decoupled via python-dotenv
- No persistent database—stateless HTTP + external API
d. Key Technologies & Frameworks:
- Flask (web server, templating)
- Jinja2 (HTML rendering)
- Static files: CSS, JavaScript (optional dynamic behavior in `mywebscript.js`)
- Python libraries: `requests`, `pydash`, `python-dotenv`
- External: MeaningCloud Sentiment Analysis API
- Deployment: Vercel (via `vercel.json`)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Client Browser UI"]:::frontend
        Assets["Static Asset Server"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Controller["Flask Controller (app.py)"]:::backend
        Service["Emotion Service Module"]:::backend
    end

    %% Configuration Store
    Config[("Config Store\n(.env & vercel.json)")]:::config

    %% External Service
    API["MeaningCloud Sentiment Analysis API"]:::external

    %% Data Flow
    Browser -->|"GET static assets"| Assets
    Browser -->|"POST /analyze"| Controller
    Controller -->|"calls Service"| Service
    Service -->|"HTTP request (requests)"| API
    API -->|"JSON response"| Service
    Service -->|"processed result"| Controller
    Controller -->|"render template / JSON"| Browser
    Config --> Controller

    %% Click Events
    click Browser "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/templates/index.html"
    click Browser "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/static/css/styles.css"
    click Browser "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/static/js/mywebscript.js"
    click Browser "https://github.com/adityakamble12/text-based-emotion-detector/tree/main/static/img/"
    click Assets "https://github.com/adityakamble12/text-based-emotion-detector/tree/main/static/"
    click Controller "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/app.py"
    click Service "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/emotion_detection/emotion_detection.py"
    click Service "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/emotion_detection/__init__.py"
    click Config "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/vercel.json"
    click Config "https://github.com/adityakamble12/text-based-emotion-detector/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFD580,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
```
