# githubak2002/sentiment-analysis-project architecture

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

- Interactive diagram: https://gitdiagram.com/githubak2002/sentiment-analysis-project
- Repository: https://github.com/githubak2002/sentiment-analysis-project

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (App Router) serving both the frontend and backend (API routes).
- The main feature set revolves around emotion analysis of LinkedIn posts (via the Hugging Face API) and visualizing results (bar graphs, etc.).
- There is a Python “py” folder containing notebooks for prototyping sentiment/emotion logic, which informs the Node.js backend or may evolve into a microservice.

##### File structure
- Top-level files: package.json, next.config.mjs, tailwind.config.js show a Next.js + Tailwind CSS stack.
- app/ directory:
- app/page.js, app/layout.js – entrypoints and layout (React Server Components).
- app/about/, app/emotion/, app/social/, app/chetan/ – route-based pages.
- app/api/emotion/route.js and app/api/linkedin/route.js – serverless API endpoints.
- app/components/ – shared server/client components (Header, Home).
- components/ directory: client-only presentation components (Hero, Features, CTA, etc.).
- py/ directory with Jupyter notebooks for sentiment/emotion proof-of-concept.
- No current DB implementation, but README mentions “add to DB and show it on the page.”

##### Key insights from README
- Core flows:
- Landing page (complete)
- Emotion analysis page (bar graph, dummy content)
- LinkedIn post fetching and analysis (latest 5 posts via /api/linkedin, then /api/emotion)
- Future auth and persistence in a database
- External dependency: Hugging Face model “j-hartmann/emotion-english-distilroberta-base” accessed via API key.

##### Main components
a. Client (Browser / Next.js React)
b. Server (Next.js Node.js runtime)
- API Route: /api/linkedin → fetch posts from LinkedIn REST API
- API Route: /api/emotion → call Hugging Face inference API or internal Python service
c. External Services
- LinkedIn REST API
- Hugging Face Inference API (emotion-english-distilroberta-base)
d. (Future) Database (e.g., MongoDB / PostgreSQL)

##### Relationships & dataflows
- Browser → HTTP GET/POST → Next.js frontend pages (React components)
- Frontend → HTTP → /api/linkedin → LinkedIn API → returns JSON posts
- /api/linkedin → Next.js → returns posts JSON to frontend
- Frontend /api calls /api/emotion with text payload → Next.js backend → calls Hugging Face API (or Python service) → returns emotion labels/scores
- (Future) Backend writes results to DB → Frontend reads from DB or fetches aggregated results
- Optionally, a cron job or user action triggers post-analysis persistence

##### Architectural patterns & design principles
- Separation of concerns:
- Presentation layer (components/)
- Domain layer (app/api/)
- Data layer (external APIs, DB)
- Serverless functions pattern via Next.js API routes
- Component-based UI in React with Tailwind CSS styling
- Prototype layer (py/ notebooks) for ML logic, to be refactored or containerized
- Future expansion: authentication layer (OAuth2 with LinkedIn), DB persistence

- Break the system into:
1) Frontend (pages + components)
2) Backend (API routes + server runtime)
3) External services (LinkedIn, Hugging Face)
4) Data store (planned)
5) Prototype/ML service (py notebooks)
- Data flow from client to each service
- Return paths for JSON responses
- Protocols (HTTP, REST) and model endpoints
- Call out future additions: DB, Auth, Python microservice

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Browser)" 
        direction TB
        UI["Next.js App Router<br/>(Next.js 13 + Tailwind CSS)"]:::frontend
        subgraph "Pages" 
            direction TB
            Page["Root Page<br/>app/page.js"]:::frontend
            Layout["Layout<br/>app/layout.js"]:::frontend
            About["About Page<br/>app/about/page.jsx"]:::frontend
            Emotion["Emotion Page<br/>app/emotion/page.jsx"]:::frontend
            EmotionAnalysis["Emotion Analysis Page<br/>app/emotion-analysis/page.jsx"]:::frontend
            Social["Social Page<br/>app/social/page.jsx"]:::frontend
            Chetan["Chetan Page<br/>app/chetan/page.jsx"]:::frontend
        end
        subgraph "Shared Components (Server/Client)" 
            direction TB
            Header["Header Component<br/>app/components/Header.jsx"]:::frontend
            Home["Home Component<br/>app/components/Home.jsx"]:::frontend
        end
        subgraph "Client-Only Components" 
            direction TB
            Hero["Hero<br/>components/Hero.js"]:::frontend
            Features["Features<br/>components/Features.js"]:::frontend
            CTA["CTA<br/>components/CTA.js"]:::frontend
            Footer["Footer<br/>components/Footer.js"]:::frontend
            HowItWorks["How It Works<br/>components/HowItWorks.js"]:::frontend
            Navbar["Navbar<br/>components/Navbar.js"]:::frontend
            Testimonials["Testimonials<br/>components/Testimonials.js"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Next.js Serverless API)" 
        direction TB
        LinkedInAPI["API Route<br/>/api/linkedin<br/>app/api/linkedin/route.js"]:::backend
        EmotionAPI["API Route<br/>/api/emotion<br/>app/api/emotion/route.js"]:::backend
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        LinkedInEXT["LinkedIn REST API"]:::external
        HFEXT["Hugging Face Inference API<br/>j-hartmann/emotion-english-distilroberta-base"]:::external
    end

    %% Data Layer (Future)
    subgraph "Data Layer (Future)" 
        direction TB
        DB["Database<br/>(MongoDB/PostgreSQL)"]:::datastore
        Stories["Data Module<br/>app/data/emotionalStories.js"]:::datastore
    end

    %% Prototype Layer
    subgraph "Prototype Layer (Python)" 
        direction TB
        SentimentNB["Sentiment Notebook<br/>py/Sentiment.ipynb"]:::prototype
        ProgramNB["Program Notebook<br/>py/program.ipynb"]:::prototype
    end

    %% Data Flows
    UI -->|renders| Page
    Page -->|GET posts| LinkedInAPI
    LinkedInAPI -->|HTTP GET| LinkedInEXT
    LinkedInEXT -->|JSON posts| LinkedInAPI
    LinkedInAPI -->|JSON posts| Page

    Page -->|POST text| EmotionAPI
    EmotionAPI -->|HTTP POST| HFEXT
    HFEXT -->|Emotion scores| EmotionAPI
    EmotionAPI -->|JSON scores| Page

    EmotionAPI -->|writes| Stories
    Stories -->|read| Page
    EmotionAPI -->|writes| DB
    DB -->|read| Page

    SentimentNB -.->|prototype logic| EmotionAPI
    ProgramNB -.->|prototype logic| EmotionAPI

    %% Click Events
    click Page "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/page.js"
    click Layout "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/layout.js"
    click About "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/about/page.jsx"
    click Emotion "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/emotion/page.jsx"
    click EmotionAnalysis "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/emotion-analysis/page.jsx"
    click Social "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/social/page.jsx"
    click Chetan "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/chetan/page.jsx"
    click Header "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/components/Header.jsx"
    click Home "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/components/Home.jsx"
    click Hero "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/Hero.js"
    click Features "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/Features.js"
    click CTA "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/CTA.js"
    click Footer "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/Footer.js"
    click HowItWorks "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/HowItWorks.js"
    click Navbar "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/Navbar.js"
    click Testimonials "https://github.com/githubak2002/sentiment-analysis-project/blob/master/components/Testimonials.js"
    click LinkedInAPI "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/api/linkedin/route.js"
    click EmotionAPI "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/api/emotion/route.js"
    click Stories "https://github.com/githubak2002/sentiment-analysis-project/blob/master/app/data/emotionalStories.js"
    click SentimentNB "https://github.com/githubak2002/sentiment-analysis-project/blob/master/py/Sentiment.ipynb"
    click ProgramNB "https://github.com/githubak2002/sentiment-analysis-project/blob/master/py/program.ipynb"

    %% Styles
    classDef frontend fill:#CCE5FF,stroke:#3399FF,color:#000;
    classDef backend fill:#CCFFCC,stroke:#33CC33,color:#000;
    classDef external fill:#EEEEEE,stroke:#888888,color:#000,stroke-dasharray: 5 5;
    classDef datastore fill:#FFE5CC,stroke:#FF9933,color:#000;
    classDef prototype fill:#F0F0F0,stroke:#AAAAAA,color:#000,stroke-dasharray: 2 2;
```
