# yug-sinha/url-copilot architecture

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

- Interactive diagram: https://gitdiagram.com/yug-sinha/url-copilot
- Repository: https://github.com/yug-sinha/url-copilot

## Overview

##### Main Components
- Frontend Component:
- Built with Next.js and styled with Tailwind CSS.
- Contains the React-based chat interface.
- Interacts with backend API endpoints (/extract and /chat).
- Static assets and dynamic pages (files in the “app” directory, public assets, and configuration files like next.config.mjs).

- Backend Component:
- Built with FastAPI and integrates Playwright to scrape and extract text (from both parent pages and child links).
- Exposes API endpoints (/extract and /chat).
- Integrates with an external LLM service (Google Gemini or similar) for generating query responses.
- Contains utility functions (as in utils.py) and the main FastAPI app (in main.py).

- Docker Container:
- Single Dockerfile builds both frontend and backend using a multi‑stage build.
- Represents the unified deployment artifact where both services are served from one container.

- External Dependencies:
- Google Gemini or other LLM API.
- Web resources (target websites for scraping).

##### Relationships and Data Flow
- Users access the frontend over HTTP (for example, via port 80 when deployed in Docker).
- The frontend makes API calls (POST /extract and POST /chat) to the backend within the same container.
- The backend (FastAPI) processes the requests by invoking Playwright to fetch and scrape the website content, then passes the data to the LLM API (Google Gemini) to obtain responses.
- The responses are then funneled back to the frontend which displays them in the chat UI.

##### Highlighted Architectural Patterns and Design Principles
- Separation of Concerns:
- Frontend and backend functionalities are clearly separated into distinct directories and responsibilities.
- API-Driven Communication:
- Clearly defined REST endpoints (POST /extract, POST /chat) for interactions.
- Single Container Deployment:
- Emphasizes ease of deployment and unified process by multi‑stage Docker builds.
- Extensible Scraping and LLM Integration:
- The backend is modular with clear responsibilities (e.g., extracting text, querying LLM, handling utility functions).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Global entities
    U["User"]:::user

    %% Docker Container with contained services and files
    subgraph "Docker Container"
        direction TB
        %% Frontend Component and its files
        FE["Frontend (Next.js + Tailwind CSS)"]:::frontend
        subgraph "Frontend Files"
            direction TB
            FE_App["App Directory"]:::file
            FE_Next["Next Config"]:::file
            FE_Public["Public Assets"]:::file
            FE_Tailwind["Tailwind Config"]:::file
        end

        %% Backend Component and its files
        BE["Backend (FastAPI + Playwright + LLM Integration)"]:::backend
        subgraph "Backend Files"
            direction TB
            BE_Main["Main App"]:::file
            BE_Utils["Utility Utilities"]:::file
        end
    end

    %% External Dependencies
    ELLM["External LLM API (Google Gemini)"]:::external
    PW["Playwright (Web Scraping)"]:::scraping
    TW["Target Website"]:::external

    %% Docker Build Artifact (represents Dockerfile)
    DC_NODE["Docker Container Build"]:::container

    %% Relationships and Data Flow
    U -->|"HTTPRequest"| FE
    FE -->|"POST/extract POST/chat"| BE
    BE -->|"Scrape"| PW
    PW -->|"FetchContent"| TW
    BE -->|"QueryLLM"| ELLM
    ELLM -->|"Response"| BE
    BE -->|"SendResponse"| FE
    FE -->|"DisplayChat"| U

    %% Link Docker Build to contained services
    DC_NODE --- FE
    DC_NODE --- BE

    %% Click Events for Frontend Component files
    click FE_App "https://github.com/yug-sinha/url-copilot/tree/main/frontend/app/"
    click FE_Next "https://github.com/yug-sinha/url-copilot/blob/main/frontend/next.config.mjs"
    click FE_Public "https://github.com/yug-sinha/url-copilot/tree/main/frontend/public"
    click FE_Tailwind "https://github.com/yug-sinha/url-copilot/blob/main/frontend/tailwind.config.js"

    %% Click Events for Backend Component files
    click BE_Main "https://github.com/yug-sinha/url-copilot/blob/main/backend/main.py"
    click BE_Utils "https://github.com/yug-sinha/url-copilot/blob/main/backend/utils.py"

    %% Click Event for Docker Container
    click DC_NODE "https://github.com/yug-sinha/url-copilot/tree/main/Dockerfile"

    %% Styles
    classDef user fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef frontend fill:#e6f7ff,stroke:#0066cc,stroke-width:2px;
    classDef backend fill:#e6ffe6,stroke:#008000,stroke-width:2px;
    classDef container fill:#f0f0f0,stroke:#666,stroke-dasharray:5 5,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#ffa500,stroke-width:2px;
    classDef scraping fill:#fde2e2,stroke:#ff4d4d,stroke-width:2px;
    classDef file fill:#f9f9f9,stroke:#999,stroke-dasharray:2 2,stroke-width:1px;
```
