# monze7/variantwise architecture

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

- Interactive diagram: https://gitdiagram.com/monze7/variantwise
- Repository: https://github.com/monze7/variantwise

## Overview

##### Project type and purpose
- This is a full-stack monorepo for an AI-driven car recommendation system.
- It combines three distinct services:
- A Next.js frontend (`variantwise-landing/`)
- An Express.js backend API (`back/`)
- A Flask-based ML model service (`Model/`)

##### File structure
- Top-level folders:
- `variantwise-landing/` – Next.js UI, pages under `app/`, reusable UI components, custom hooks, context, and API helpers.
- `back/` – Express server, routes for authentication and recommendation proxying, models for MySQL, middlewares, config files.
- `Model/` – Python service, dataset and review corpora, Flask entrypoint (`back.py`), requirements.
- Configuration & deployment artifacts:
- `.env` templates in each service
- `package.json` and lockfiles for JS services
- `requirements.txt` for the Python service
- Next.js config (`next.config.mjs`, Tailwind, PostCSS)
- AWS IAM and Bedrock dependencies in Model

##### README for additional insights
- The README confirms the three-tier architecture, service URLs, ports, and external dependencies:
- MySQL database
- AWS Bedrock AI inference
- Google OAuth (optional)
- It describes startup commands, environment variables, and high-level purpose.

##### Elements
- Labels: “Next.js Frontend”, “Express API”, “Flask Model Service”, “MySQL DB”, “AWS Bedrock”, “Google OAuth”

##### Detailed breakdown of components
- Frontend:
- Pages: Home, Sign-in, Sign-up, Dashboard, Consultant view
- UI components and theme provider
- API client in `lib/api.js` and `utils.js`
- AuthContext for session management
- Backend API:
- `routes/auth.js`: register/sign-in, Google OAuth callbacks
- `routes/response.js`: proxy to model service, returns recommendations
- `models/user.js`: User ORM schema for MySQL
- `middlewares/autho.js`: route protection
- Model Service:
- `back.py`: Flask app exposing endpoints for Q&A and recommendations
- Data assets: `final_dataset.csv`, unzipped car reviews
- Dependencies in `requirements.txt` (Flask, AWS SDK, pandas, etc.)
- Data flow:
1. User logs in → Frontend POST /auth → Backend writes to MySQL
2. User requests recommendation → Frontend GET /response → Backend forwards to Flask
3. Flask preprocesses with pandas, calls AWS Bedrock, returns JSON → Backend returns to Frontend
4. Frontend renders recommendations

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User(("User")):::external

    %% UI Layer
    subgraph "Next.js Frontend (UI Layer)"
        direction TB
        FE[/"Next.js Frontend"/]:::ui
        Home["Home Page"]:::ui
        SignIn["Sign-in Page"]:::ui
        SignUp["Sign-up Page"]:::ui
        Dashboard["Dashboard Page"]:::ui
        Consultant["Consultant View Page"]:::ui
        Layout["Global Layout & Styles"]:::ui
        UIComp["UI Components Library"]:::ui
        Theme["Theme Provider"]:::ui
        AuthCtx["Auth Context Provider"]:::ui
        Hooks["Custom Hooks"]:::ui
        APIOps["API Helpers"]:::ui
        ConfigJS["Next.js & Tailwind Config"]:::ui
    end

    %% Backend API
    subgraph "Express API (Backend)"
        direction TB
        API[/"Express API"/]:::backend
        Entry["Entry Point"]:::backend
        AuthRoutes["Authentication Routes"]:::backend
        RespRoute["Recommendation Proxy Route"]:::backend
        UserModel["User Model"]:::backend
        AuthMid["Auth Middleware"]:::backend
        DBConfig["Database Configuration"]:::backend
        Package["Package Definitions"]:::backend
    end

    %% ML Service
    subgraph "Flask Model Service (ML Layer)"
        direction TB
        ModelSvc[/"Flask Model Service"/]:::ml
        EntryPY["Flask App Entrypoint"]:::ml
        Dataset["Dataset CSV"]:::ml
        Reviews["Review Corpora"]:::ml
        ReqPY["Python Dependencies"]:::ml
    end

    %% Data Stores & External
    MySQL[(MySQL Database)]:::datastore
    Bedrock((AWS Bedrock)):::external
    OAuth((Google OAuth Provider)):::external
    Docs["Project README"]:::external

    %% Connections
    User -->|HTTP/HTTPS| FE
    FE -->|REST API calls| API
    API -->|reads/writes| MySQL
    API -->|proxies inference| ModelSvc
    ModelSvc -->|calls| Bedrock
    API -->|OAuth2 flow| OAuth

    %% Click Events - Frontend
    click FE "https://github.com/monze7/variantwise/tree/main/variantwise-landing/"
    click Home "https://github.com/monze7/variantwise/blob/main/variantwise-landing/app/page.jsx"
    click SignIn "https://github.com/monze7/variantwise/blob/main/variantwise-landing/app/signin/page.jsx"
    click SignUp "https://github.com/monze7/variantwise/blob/main/variantwise-landing/app/signup/page.jsx"
    click Dashboard "https://github.com/monze7/variantwise/blob/main/variantwise-landing/app/dashboard/page.jsx"
    click Consultant "https://github.com/monze7/variantwise/blob/main/variantwise-landing/app/consultant/page.jsx"
    click Layout "https://github.com/monze7/variantwise/blob/main/variantwise-landing/app/layout.jsx"
    click UIComp "https://github.com/monze7/variantwise/tree/main/variantwise-landing/components/"
    click Theme "https://github.com/monze7/variantwise/blob/main/variantwise-landing/components/theme-provider.jsx"
    click AuthCtx "https://github.com/monze7/variantwise/blob/main/variantwise-landing/context/AuthContext.js"
    click Hooks "https://github.com/monze7/variantwise/tree/main/variantwise-landing/hooks/"
    click APIOps "https://github.com/monze7/variantwise/blob/main/variantwise-landing/lib/api.js"
    click APIOps "https://github.com/monze7/variantwise/blob/main/variantwise-landing/lib/utils.js"
    click ConfigJS "https://github.com/monze7/variantwise/blob/main/variantwise-landing/next.config.mjs"
    click ConfigJS "https://github.com/monze7/variantwise/blob/main/variantwise-landing/tailwind.config.js"
    click ConfigJS "https://github.com/monze7/variantwise/blob/main/variantwise-landing/postcss.config.mjs"

    %% Click Events - Backend
    click API "https://github.com/monze7/variantwise/tree/main/back/"
    click Entry "https://github.com/monze7/variantwise/blob/main/back/index.js"
    click AuthRoutes "https://github.com/monze7/variantwise/blob/main/back/routes/auth.js"
    click RespRoute "https://github.com/monze7/variantwise/blob/main/back/routes/response.js"
    click UserModel "https://github.com/monze7/variantwise/blob/main/back/models/user.js"
    click AuthMid "https://github.com/monze7/variantwise/blob/main/back/middlewares/autho.js"
    click DBConfig "https://github.com/monze7/variantwise/blob/main/back/db/config.js"
    click Package "https://github.com/monze7/variantwise/blob/main/back/package.json"
    click Package "https://github.com/monze7/variantwise/blob/main/back/package-lock.json"

    %% Click Events - ML Service
    click ModelSvc "https://github.com/monze7/variantwise/tree/main/Model/"
    click EntryPY "https://github.com/monze7/variantwise/blob/main/Model/back.py"
    click Dataset "https://github.com/monze7/variantwise/blob/main/Model/final_dataset.csv"
    click Reviews "https://github.com/monze7/variantwise/tree/main/Model/reviews/"
    click ReqPY "https://github.com/monze7/variantwise/blob/main/Model/requirements.txt"

    %% Click Event - Docs
    click Docs "https://github.com/monze7/variantwise/blob/main/README.md"

    %% Styles
    classDef ui fill:#aed6f1,stroke:#1f618d,color:#1f618d;
    classDef backend fill:#abebc6,stroke:#1d8348,color:#1d8348;
    classDef ml fill:#d7bde2,stroke:#76448a,color:#76448a;
    classDef datastore fill:#f9e79f,stroke:#b9770e,color:#b9770e;
    classDef external fill:#f5cba7,stroke:#7d6608,color:#7d6608;
```
