# atharshafi/sentiment-analysis-api architecture

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

- Interactive diagram: https://gitdiagram.com/atharshafi/sentiment-analysis-api
- Repository: https://github.com/atharshafi/sentiment-analysis-api

## Overview

This is a stateless, full-stack sentiment analysis application. A user enters text in the React interface, which sends it to FastAPI; the API validates the request, selects an available engine, and returns sentiment, confidence, engine, and inference time for display. Engine selection is configured at startup: DistilBERT is intended for local learning, while VADER is the lightweight hosted default, with fallback to VADER if DistilBERT fails to load. The interface also keeps a short in-memory history. The README documents health and root endpoints and a standalone DistilBERT learning script; some backend wiring is omitted from the sampled excerpts, so uncertain calls are not shown.

Main entry points: [`backend/app.py`](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py) (FastAPI app), [`frontend/src/components/SentimentAnalyzer.jsx`](https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/components/SentimentAnalyzer.jsx) (Analyzer UI), [`frontend/src/main.jsx`](https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/main.jsx) (React entry), [`frontend/src/App.jsx`](https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/App.jsx) (App shell)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web interface"]
  node_main["React entry<br/>[main.jsx]"]
  node_app["App shell<br/>[App.jsx]"]
  node_analyzer["Analyzer UI"]
end

subgraph group_api["HTTP API"]
  node_fastapi["FastAPI app<br/>[app.py]"]
  node_startup["Engine startup<br/>[app.py]"]
  node_analyze_route["Analyze endpoint<br/>[app.py]"]
  node_health_route["Health endpoint<br/>[app.py]"]
end

subgraph group_engines["Sentiment engines"]
  node_distilbert["DistilBERT inference<br/>[app.py]"]
  node_vader["VADER analysis<br/>[app.py]"]
end

subgraph group_learning["Learning script"]
  node_local_script["Local inference demo"]
end

node_user(("User"))
node_browser(("Browser"))
node_hf_model["Model hosting"]

node_user -->|"enters text"| node_browser
node_browser -->|"loads interface"| node_main
node_main -->|"renders"| node_app
node_app -->|"renders"| node_analyzer
node_analyzer -->|"sends analysis"| node_fastapi
node_fastapi -->|"starts with"| node_startup
node_startup -->|"loads if selected"| node_distilbert
node_startup -->|"loads by default"| node_vader
node_startup -.->|"falls back to"| node_vader
node_distilbert -.->|"downloads model"| node_hf_model
node_fastapi -->|"routes request"| node_analyze_route
node_analyze_route -->|"runs if selected"| node_distilbert
node_analyze_route -->|"runs otherwise"| node_vader
node_analyze_route -->|"returns result"| node_analyzer
node_fastapi -->|"routes health check"| node_health_route
node_user -.->|"runs learning demo"| node_local_script
node_local_script -.->|"loads model"| node_hf_model

click node_main "https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/App.jsx"
click node_analyzer "https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/components/SentimentAnalyzer.jsx"
click node_fastapi "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py"
click node_startup "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py"
click node_analyze_route "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py"
click node_health_route "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py"
click node_distilbert "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py"
click node_vader "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py"
click node_local_script "https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/sentiment_analysis_local_v2.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app,node_analyzer,node_user,node_browser toneBlue
class node_fastapi,node_startup,node_analyze_route,node_health_route toneAmber
class node_distilbert,node_vader toneMint
class node_local_script toneRose
class node_hf_model toneIndigo
```

## Components

### Web interface

- [React entry](https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`
- [App shell](https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Analyzer UI](https://github.com/atharshafi/sentiment-analysis-api/blob/main/frontend/src/components/SentimentAnalyzer.jsx): `frontend/src/components/SentimentAnalyzer.jsx`

### HTTP API

- [FastAPI app](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py): `backend/app.py`
- [Engine startup](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py): `backend/app.py`
- [Analyze endpoint](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py): `backend/app.py`
- [Health endpoint](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py): `backend/app.py`

### Sentiment engines

- [DistilBERT inference](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py): `backend/app.py`
- [VADER analysis](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/app.py): `backend/app.py`

### Learning script

- [Local inference demo](https://github.com/atharshafi/sentiment-analysis-api/blob/main/backend/sentiment_analysis_local_v2.py): `backend/sentiment_analysis_local_v2.py`

### Other components

- **User**
- **Browser**
- **Model hosting**

## Connections

- User → Browser: enters text
- Browser → React entry: loads interface
- React entry → App shell: renders
- App shell → Analyzer UI: renders
- Analyzer UI → FastAPI app: sends analysis
- FastAPI app → Engine startup: starts with
- Engine startup → DistilBERT inference: loads if selected
- Engine startup → VADER analysis: loads by default
- Engine startup → VADER analysis: falls back to
- DistilBERT inference → Model hosting: downloads model
- FastAPI app → Analyze endpoint: routes request
- Analyze endpoint → DistilBERT inference: runs if selected
- Analyze endpoint → VADER analysis: runs otherwise
- Analyze endpoint → Analyzer UI: returns result
- FastAPI app → Health endpoint: routes health check
- User → Local inference demo: runs learning demo
- Local inference demo → Model hosting: loads model
