# mayuresh-22/engagefy architecture

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

- Interactive diagram: https://gitdiagram.com/mayuresh-22/engagefy
- Repository: https://github.com/mayuresh-22/engagefy

## Overview

##### Project Type and Purpose
- This is a full‑stack web application named “Engagefy” that lets users analyze Instagram engagement metrics.
- It combines a React/Vite‑based frontend, a Node/TypeScript backend (deployed as a Cloudflare Worker via wrangler.toml), Langflow workflows (with custom components), a DataStax Astra DB for storage, and calls out to a third‑party Instagram scraping API plus OpenAI’s GPT for insights.

##### File Structure
- Top‑level directories:
- langflow/… holds custom Langflow components (DBReadComponent, DBWriteComponent, ScrapperComponent)
- server/… is the backend: TypeScript source, a Langflow service wrapper (services/langflow.ts), package.json, wrangler.toml for Cloudflare Workers
- web/… is the client: React + Vite, TypeScript, TailwindCSS, UI components, utilities
- Configuration files: tsconfig.json in both web and server, .env examples, ESLint, PostCSS, Tailwind, Vite config
- Patterns:
- Separation of concerns between UI, API orchestration, workflow management, and storage
- Langflow used as a micro‑orchestration layer

##### Pull Architecture Insights from the README
- The README already outlines a high‑level flow:
User → React Frontend → Langflow Workflow → {Instagram Scraper API, DataStax Astra DB, OpenAI GPT} → Insights → Frontend
- Key tech: React, DataStax Astra DB, Langflow, OpenAI GPT, Third‑party Instagram Scraper API

##### Main Components
a. User Interface
- “User” actor
- “React Frontend” (web/src, Vite)
b. API / Orchestration Layer
- “Server (Cloudflare Worker / Node + Express or native Worker)”
- Internal service “Langflow client” (server/src/services/langflow.ts)
- Custom Langflow components (langflow/custom_components)
c. Data Storage
- “DataStax Astra DB”
d. External Services
- “Instagram Scraper API”
- “OpenAI GPT Model”
e. Workflow Engine
- “Langflow” orchestration environment

##### Relationships & Data Flow
- User → (HTTP/HTTPS) → React Frontend
- React Frontend → (REST/HTTP) → Server API
- Server API → Langflow client triggers a workflow
- Workflow node: ScrapperComponent → calls Instagram Scraper API → returns raw engagement data
- Workflow node: DBWriteComponent → writes raw data to Astra DB
- Workflow node: DBReadComponent → (optional for cached queries) reads from Astra DB
- Workflow node: GPT integration → sends processed data to OpenAI → returns insights
- Final insights return path: Langflow workflow → Server API → Frontend → User

##### Architectural Patterns & Principles
- Clear separation: Presentation (frontend), Business Logic & Orchestration (server + Langflow), Data (DB), External Integrations
- Micro‑orchestration via Langflow: custom components encapsulate 3rd‑party calls and storage operations
- Serverless deployment (Cloudflare Workers) for the API layer

##### Essential Details to Capture
- Custom Langflow components (Scrapper, DBRead, DBWrite) as separate workflow nodes
- The two external service integrations (Instagram Scraper API, OpenAI GPT)
- The role of DataStax Astra DB (write vs. read operations)
- The end‑to‑end flow from user action to insight display

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Actors
    User(("User")):::actor

    %% Frontend Layer
    subgraph "Frontend"
        ReactFrontend["React Frontend"]:::frontend
        Vite["Vite"]:::frontend
        Tailwind["TailwindCSS"]:::frontend
        Main["main.tsx"]:::frontend
        App["App.tsx"]:::frontend
        UI["UI Components"]:::frontend
        Utils["Utils"]:::frontend
    end

    %% Backend and Workflow Layer
    subgraph "Backend/Workflow"
        APIGateway["API Gateway (Cloudflare Worker)"]:::backend
        WorkerConf["wrangler.toml"]:::backend
        LangflowClient["Langflow Client Service"]:::backend
        LangflowEngine["Langflow Engine"]:::backend
        subgraph "Custom Components"
            CustomDir["Langflow Custom Components"]:::backend
            Scraper["ScrapperComponent"]:::backend
            DBWrite["DBWriteComponent"]:::backend
            DBRead["DBReadComponent"]:::backend
        end
        DB[(DataStax Astra DB)]:::db
        InstaAPI(["Instagram Scraper API"]):::external
        GPT(["OpenAI GPT Model"]):::external
    end

    %% Connections
    User -->|"interacts via UI"| ReactFrontend
    ReactFrontend --> Vite
    ReactFrontend --> Tailwind
    ReactFrontend --> Main
    ReactFrontend --> App
    ReactFrontend --> UI
    ReactFrontend --> Utils
    ReactFrontend -->|"POST /analyze"| APIGateway

    APIGateway --> WorkerConf
    APIGateway -->|"trigger workflow"| LangflowClient
    LangflowClient --> LangflowEngine

    LangflowEngine --> Scraper
    LangflowEngine --> DBWrite
    LangflowEngine --> DBRead
    Scraper -->|"GET /scrape"| InstaAPI
    Scraper -->|"RAW DATA"| DBWrite
    DBWrite -->|"write data"| DB
    DBRead -->|"read data"| DB
    LangflowEngine -->|"send prompt"| GPT
    GPT -->|"insights"| LangflowEngine

    LangflowClient -->|"workflow result"| APIGateway
    APIGateway -->|"JSON insights"| ReactFrontend

    %% Click Events
    click ReactFrontend "https://github.com/mayuresh-22/engagefy/tree/main/web/"
    click Main "https://github.com/mayuresh-22/engagefy/blob/main/web/src/main.tsx"
    click App "https://github.com/mayuresh-22/engagefy/blob/main/web/src/App.tsx"
    click UI "https://github.com/mayuresh-22/engagefy/tree/main/web/src/components/ui/"
    click Utils "https://github.com/mayuresh-22/engagefy/blob/main/web/src/lib/utils.tsx"
    click APIGateway "https://github.com/mayuresh-22/engagefy/blob/main/server/src/index.ts"
    click WorkerConf "https://github.com/mayuresh-22/engagefy/blob/main/server/wrangler.toml"
    click LangflowClient "https://github.com/mayuresh-22/engagefy/blob/main/server/src/services/langflow.ts"
    click CustomDir "https://github.com/mayuresh-22/engagefy/tree/main/langflow/custom_components/"
    click Scraper "https://github.com/mayuresh-22/engagefy/blob/main/langflow/custom_components/ScrapperComponent.py"
    click DBWrite "https://github.com/mayuresh-22/engagefy/blob/main/langflow/custom_components/DBWriteComponent.py"
    click DBRead "https://github.com/mayuresh-22/engagefy/blob/main/langflow/custom_components/DBReadComponent.py"

    %% Styles
    classDef actor fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef frontend fill:#cce5ff,stroke:#0066cc,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:1px
    classDef db fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px
    classDef external fill:#e2d4f0,stroke:#6f42c1,stroke-width:1px
```
