# j43fura/text-sentiment-analysis architecture

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

- Interactive diagram: https://gitdiagram.com/j43fura/text-sentiment-analysis
- Repository: https://github.com/j43fura/text-sentiment-analysis

## Overview

##### Project Type & Purpose
- This is a lightweight full-stack web application built on FastAPI.

##### File Structure
- Top-level files: README, requirements.txt, .gitignore, .gitattributes.
- src/
- main.py – FastAPI application entrypoint.
- sentiment_analysis.py – encapsulates sentiment logic (TextBlob, VADER usage).
- templates/index.html – Jinja2 template for rendering results.

##### Key Insights from README
- Frameworks & Tools: FastAPI (with Uvicorn), Jinja2, simplecss for styling.
- Models: TextBlob, VADER (externally maintained Python libraries, plus TextBlob corpora).
- Execution: served via Uvicorn at HTTP endpoints, renders HTML form + results.

##### Main Components & Their Interactions
a. Client Browser (Front-end)
- Displays index.html (form + empty result area).
- Sends HTTP POST (or GET) with user text to the FastAPI endpoint.
b. Web Server & API Layer
- Uvicorn running FastAPI (main.py)
- Routes: e.g., “/” serving index.html, “/analyze” handling form submissions.
c. Template Engine
- Jinja2 integrates with FastAPI to render dynamic HTML based on analysis.
d. Sentiment Analysis Module
- sentiment_analysis.py exposes functions that:
- Invoke TextBlob for polarity/subjectivity.
- Invoke VADER for sentiment scoring.
- Classify tokens into one of five categories.
e. External Dependencies & Data
- TextBlob corpora (downloaded at setup).
- VADER lexicon.
- simplecss static style sheet.

##### Architectural Patterns & Principles
- Separation of concerns:
- Presentation (templates + static CSS) vs. business logic (analysis module) vs. API layer.
- Modular design: sentiment logic is isolated for easy extension (e.g., adding new models).
- Request-response pattern over HTTP.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Front-end Client
    Browser["Browser"]:::frontend
    %% API/Web Server Layer
    Uvicorn["Uvicorn / FastAPI"]:::api
    %% Template Engine
    Template["Jinja2 Template"]:::api
    %% Business Logic
    Sentiment["Sentiment Analysis Module"]:::logic
    %% External Dependencies & Data
    External["External Dependencies\n(TextBlob, VADER, simplecss)"]:::external

    %% Data Flow
    Browser -->|"GET index.html"| Uvicorn
    Uvicorn -->|"render index.html"| Template
    Template -->|"HTML response"| Browser

    Browser -->|"POST text"| Uvicorn
    Uvicorn -->|"invoke analyze()"| Sentiment
    Sentiment -->|"use corpora & lexicon"| External
    Sentiment -->|"analysis results"| Template

    %% Click Events
    click Browser "https://github.com/j43fura/text-sentiment-analysis/blob/main/src/templates/index.html"
    click Uvicorn "https://github.com/j43fura/text-sentiment-analysis/blob/main/src/main.py"
    click Template "https://github.com/j43fura/text-sentiment-analysis/blob/main/src/templates/index.html"
    click Sentiment "https://github.com/j43fura/text-sentiment-analysis/blob/main/src/sentiment_analysis.py"
    click External "https://github.com/j43fura/text-sentiment-analysis/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#D4E6F1,stroke:#1B4F72,color:#1B4F72,stroke-width:2px;
    classDef api fill:#D5F5E3,stroke:#196F3D,color:#196F3D,stroke-width:2px;
    classDef logic fill:#FCF3CF,stroke:#B7950B,color:#6E2C00,stroke-width:2px;
    classDef external fill:#EBEDEF,stroke:#707B7C,color:#212F3C,stroke-width:2px;
```
