How githubak2002/sentiment-analysis-project works
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