# jsm1306/trendtakeaway architecture

> Architecture diagram of the GitHub repository jsm1306/trendtakeaway, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jsm1306/trendtakeaway
- Repository: https://github.com/jsm1306/trendtakeaway

## Overview

##### Project type and purpose
- TrendTakeaway is a full-stack MERN (MongoDB, Express, React, Node.js) product comparison and analysis platform.
- It ingests real-time e-commerce data by scraping external sites (Amazon, Bajaj) with Puppeteer, performs optional sentiment analysis and summarization, and serves a React/Vite frontend with secured Auth0-based authentication.

##### File structure
- Top level: a monorepo with two main folders: “backend” (Node/Express API) and “frontend” (React/Vite SPA).
- Backend follows an MVC-style layout:
- config (db connection),
- models (Mongoose schemas),
- controllers (business logic per resource),
- routes (Express endpoints),
- utils (authentication middleware, scraping, review cleaning, summarization, sentiment).
- Frontend: a Vite+React TypeScript app
- src/components and ui subfolder for reusable UI pieces (TailwindCSS + Framer Motion),
- src/pages for routes,
- src/context for Auth0 context provider,
- src/hooks for helpers,
- dist/public for static assets.
- Configuration files: tailwind.config.js, vite.config.ts, tsconfig.json, eslint.config.js.

##### Key insights from the README
- Web scraping with Puppeteer for real-time price/features
- Data visualization with Recharts
- Secure login via Auth0 + JWT
- Deployed on Render: static site for frontend, separate web service for backend
- MongoDB Atlas database

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        StaticHost["Static Hosting"]:::frontend
        ReactSPA["React SPA"]:::frontend
        subgraph "Configs"
            direction TB
            TailwindCFG["tailwind.config.js"]:::frontend
            ViteCFG["vite.config.ts"]:::frontend
            TSConfig["tsconfig.json"]:::frontend
        end
        AuthContext["AuthContext"]:::frontend
        Pages["Pages"]:::frontend
        Components["UI Components"]:::frontend
        Hooks["Hooks"]:::frontend
        UtilsFE["Utils"]:::frontend

        StaticHost --> ReactSPA
        ReactSPA --> Pages
        ReactSPA --> Components
        ReactSPA --> AuthContext
        ReactSPA --> Hooks
        ReactSPA --> UtilsFE
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Server["Express Server"]:::backend
        ConfigDB["DB Config"]:::backend
        subgraph "API Layer"
            direction TB
            Routes["Routes"]:::backend
            Controllers["Controllers"]:::backend
        end
        subgraph "Business Logic & Utilities"
            direction TB
            AuthMW["Auth Middleware"]:::util
            ScraperAmazon["Amazon Scraper"]:::util
            ScraperBajaj["Bajaj Scraper"]:::util
            CleanReviews["Review Cleaning"]:::util
            Sentiment["Sentiment Analysis"]:::util
            Summarizer["Review Summarization"]:::util
        end
        subgraph "Data Layer"
            direction TB
            Models["Mongoose Models"]:::backend
            DB["MongoDB Atlas"]:::database
        end

        Server --> ConfigDB
        Server --> Routes
        Routes --> Controllers
        Controllers --> Models
        Controllers --> AuthMW
        Controllers --> ScraperAmazon
        Controllers --> ScraperBajaj
        Controllers --> CleanReviews
        Controllers --> Sentiment
        Controllers --> Summarizer
        Models --> DB
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Auth0["Auth0 Service"]:::external
        Amazon["Amazon"]:::external
        Bajaj["Bajaj"]:::external
    end

    %% Data Flows
    ReactSPA -->|"API Calls (JWT)"| Server
    ReactSPA -->|"Login Redirect"| Auth0
    Server -->|"Validate JWT"| Auth0
    ScraperAmazon -->|"Scrape Data"| Amazon
    ScraperBajaj -->|"Scrape Data"| Bajaj
    Server -->|"Responses"| ReactSPA

    %% Click Events
    click StaticHost "https://github.com/jsm1306/trendtakeaway/tree/main/frontend/dist/"
    click ReactSPA "https://github.com/jsm1306/trendtakeaway/tree/main/frontend/src/"
    click TailwindCFG "https://github.com/jsm1306/trendtakeaway/blob/main/frontend/tailwind.config.js"
    click ViteCFG "https://github.com/jsm1306/trendtakeaway/blob/main/frontend/vite.config.ts"
    click TSConfig "https://github.com/jsm1306/trendtakeaway/blob/main/frontend/tsconfig.json"
    click AuthContext "https://github.com/jsm1306/trendtakeaway/blob/main/frontend/src/context/AuthContext.jsx"
    click Pages "https://github.com/jsm1306/trendtakeaway/tree/main/frontend/src/pages/"
    click Components "https://github.com/jsm1306/trendtakeaway/tree/main/frontend/src/components/ui/"
    click Hooks "https://github.com/jsm1306/trendtakeaway/blob/main/frontend/src/hooks/use-outside-click.tsx"
    click UtilsFE "https://github.com/jsm1306/trendtakeaway/blob/main/frontend/src/lib/utils.ts"

    click Server "https://github.com/jsm1306/trendtakeaway/blob/main/backend/server.js"
    click ConfigDB "https://github.com/jsm1306/trendtakeaway/blob/main/backend/config/db.js"
    click Routes "https://github.com/jsm1306/trendtakeaway/tree/main/backend/routes/"
    click Controllers "https://github.com/jsm1306/trendtakeaway/tree/main/backend/controllers/"
    click Models "https://github.com/jsm1306/trendtakeaway/tree/main/backend/models/"
    click AuthMW "https://github.com/jsm1306/trendtakeaway/blob/main/backend/utils/authMiddleware.js"
    click ScraperAmazon "https://github.com/jsm1306/trendtakeaway/blob/main/backend/utils/scrapeProductsAmazon.js"
    click ScraperBajaj "https://github.com/jsm1306/trendtakeaway/blob/main/backend/utils/scrapeProductsBajaj.js"
    click CleanReviews "https://github.com/jsm1306/trendtakeaway/blob/main/backend/utils/cleanReviews.js"
    click Sentiment "https://github.com/jsm1306/trendtakeaway/blob/main/backend/utils/sentimenttest.js"
    click Summarizer "https://github.com/jsm1306/trendtakeaway/blob/main/backend/utils/summarizeReviews.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#000;
    classDef backend fill:#E8F5E9,stroke:#2E7D32,color:#000;
    classDef util fill:#ECEFF1,stroke:#546E7A,color:#000;
    classDef database fill:#F3E5F5,stroke:#6A1B9A,color:#000;
    classDef external fill:#FFF3E0,stroke:#EF6C00,color:#000;
```
