# wolefabikun/green-thumb-drive architecture

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

- Interactive diagram: https://gitdiagram.com/wolefabikun/green-thumb-drive
- Repository: https://github.com/wolefabikun/green-thumb-drive

## Overview

##### Project type and purpose
- This is a full-stack web application (“Green Thumb Guide”) that provides personalized plant care advice and retrieves video content via a Retrieval-Augmented Generation (RAG) pipeline.
- Frontend: Next.js + TypeScript (“client” folder)
- Backend: Flask API (“server/app.py”)
- Data/Services: VideoDB (vector store), VideoDBRetriever, LlamaIndex, OpenAI API

##### File structure
- Top-level:
- client/ – Next.js app
– src/app – Next.js App Router (layout.tsx, page.tsx)
– src/components – React UI components (AvatarPlant, Chat, Loader, etc.)
– src/lib/utils.ts – helper functions
– public/ – static assets
– next.config.mjs, tsconfig.json, bun.lockb, package.json, tailwind.config.ts
- server/ – Flask backend
– app.py – main Flask routes and RAG pipeline orchestration
– requirements.txt – Python dependencies (Flask, LlamaIndex, VideoDBRetriever)
- No separate infra as Terraform; environment configured via `.env`

##### Key insights from README
- Uses a RAG pipeline: user query → backend invokes VideoDBRetriever + LlamaIndex → optionally calls OpenAI to generate or refine answers
- VideoDB is both the primary database (vector store) and content source
- The frontend communicates with the Flask backend over HTTP

##### Main components & relationships
a. Frontend (Next.js)
- UI: React components render chat, video cards, plant advice
- Fetch layer: calls Flask backend endpoints (e.g., `POST /api/query`)
b. Backend API (Flask)
- Receives queries, maintains session state if needed
- Instantiates RAG pipeline:
- VideoDBRetriever – semantic video search
- LlamaIndex – organizes retrieved chunks + query understanding
- OpenAI API – optional generation/refinement
- Returns JSON payload with text answer + video recommendations
c. VideoDB (Vector Store)
- Stores video embeddings and metadata
- Queried by VideoDBRetriever using user query embeddings
d. External Services
- OpenAI API – text generation/completion
- VideoDB API – initial indexing and embedding creation

##### Architectural patterns & design principles
- Separation of concerns: frontend-only UI/rendering vs. backend orchestration
- RAG pipeline pattern: retrieval (VideoDBRetriever) → augmentation (LlamaIndex) → generation (OpenAI)
- Modular code organization: React UI in reusable components, backend logic in a single Flask app (could evolve into microservices)
- Environment-based configuration via `.env` for API keys

## Diagram (Mermaid)

```mermaid
graph TB
    %% User Layer
    User["User"]:::user
    Browser["Browser"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        NextApp["Next.js App"]:::frontend
        UIComponents["UI Components"]:::frontend
        DataFetcher["Data Fetcher (utils.ts)"]:::frontend
    end

    %% Backend & Services Layer
    subgraph "Backend & Services Layer"
        direction TB
        FlaskAPI["Flask API"]:::backend
        Requirements["requirements.txt"]:::backend
        subgraph "RAG Pipeline"
            direction TB
            VDBRetriever["VideoDBRetriever"]:::backend
            LlamaIndex["LlamaIndex"]:::backend
            OpenAIClient["OpenAI API Client"]:::external
        end
    end

    %% Datastore and External Services
    VideoDB["VideoDB (Vector Store)"]:::datastore
    VideoDBAPI["VideoDB API"]:::external

    %% Connections
    User --> Browser
    Browser --> UIComponents
    UIComponents --> NextApp
    NextApp -->|"HTTP POST /api/query"| FlaskAPI
    FlaskAPI --> VDBRetriever
    VDBRetriever -->|"query embeddings"| VideoDB
    FlaskAPI --> LlamaIndex
    FlaskAPI -->|"async call"| OpenAIClient
    OpenAIClient -->|"response"| FlaskAPI
    FlaskAPI -->|"JSON response"| NextApp

    %% Click Events
    click NextApp "https://github.com/wolefabikun/green-thumb-drive/tree/main/client/src/app"
    click UIComponents "https://github.com/wolefabikun/green-thumb-drive/tree/main/client/src/components"
    click DataFetcher "https://github.com/wolefabikun/green-thumb-drive/blob/main/client/src/lib/utils.ts"
    click FlaskAPI "https://github.com/wolefabikun/green-thumb-drive/blob/main/server/app.py"
    click Requirements "https://github.com/wolefabikun/green-thumb-drive/blob/main/server/requirements.txt"
    click VDBRetriever "https://github.com/wolefabikun/green-thumb-drive/blob/main/server/app.py"
    click LlamaIndex "https://github.com/wolefabikun/green-thumb-drive/blob/main/server/app.py"
    click OpenAIClient "https://github.com/wolefabikun/green-thumb-drive/blob/main/server/app.py"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#DFFFE0,stroke:#2c662d,color:#2c662d
    classDef datastore fill:#FFE0B2,stroke:#e65100,color:#e65100
    classDef external fill:#E0E0E0,stroke:#616161,color:#424242
    classDef user fill:#F0F0F0,stroke:#888,color:#444
```
