# praveen-raj-ragunathan/petpal-ai-pet-buddy architecture

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

- Interactive diagram: https://gitdiagram.com/praveen-raj-ragunathan/petpal-ai-pet-buddy
- Repository: https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy

## Overview

##### Project type and purpose
- From the README and file tree, this is a single-page React web application (“frontend” folder only) called PetPal-AI-Pet-Buddy.
- It delivers an AI-powered virtual pet chat experience entirely client-side (no backend code present).
- It uses OpenChat 3.5 (Mistral) in the browser (likely via WASM or Web Worker), with UI built on React, Vite, TailwindCSS, and shadcn/ui.

##### File structure
- Top level: LICENSE, README.md, and a single “frontend” directory.
- frontend/
- Public & dist folders: static assets, index.html, compiled bundles.
- src/: React code split into pages/, components/, ui/, hooks/, lib/.
- Configuration: vite.config.ts, tailwind.config.ts, tsconfigs, ESLint.
- package.json & lock files: dependencies (React, Vite, OpenChat, Tailwind, shadcn/ui).
- Architectural patterns:
- SPA (Single-Page Application).
- Component-based UI (shadcn/ui, custom components).
- Client-side AI inference engine.

##### Key insights from README
- “No API keys needed” → the AI model runs locally in the browser.
- Core features: pet selection, chat panel, streaming AI responses.

##### Main components
a. Client Browser (User’s device)
– React SPA (App.tsx as root)
– UI components: Dashboard, PetList, ChatPanel, ApiKeyInput (unused), reusable shadcn/ui components
– Hooks: use-mobile, use-toast
b. Static Hosting
– Web server or CDN (e.g., Netlify, Vercel, AWS S3 + CloudFront) serving index.html, JS/CSS bundles, model assets
c. Client-side AI Inference Engine
– OpenChat 3.5 / Mistral WASM or Web Worker module
– Model weights & tokenizer files (loaded from public or CDN)
d. External Services & Libraries
– NPM modules: React, Vite, TailwindCSS, shadcn/ui
– (Optional) Analytics or error-tracking if configured

##### Relationships and data flow
1. User opens URL → browser requests static assets from hosting.
2. Vite-built React app loads, initializes UI.
3. User selects a pet in PetList → App state updates.
4. User types in ChatPanel → SPA calls AI engine API.
5. AI Inference Engine (WASM/Web Worker) loads model weights from hosting → processes user message → streams responses back to ChatPanel.
6. ChatPanel renders the AI’s reply with UI components, triggering toasts via use-toast.

##### Architectural patterns & design principles
- SPA: single entry point (index.html) + client routing (pages/Index.tsx, pages/Dashboard.tsx, pages/NotFound.tsx).
- Componentized UI: reusable primitives in ui/ (accordion, button, dialog, etc.).
- Separation of concerns: UI, business logic (hooks, lib/utils.ts), static assets.
- Client-side compute: model inference isolated in its own module, possibly off-main-thread.

##### Final checklist
- Notes or annotations for key tech (WASM, Web Worker, shadcn/ui).
- Emphasis on the SPA → client-side AI inference loop.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser SPA
    subgraph "Browser / React SPA"
        direction TB
        subgraph "Entry Points"
            direction TB
            Main["main.tsx"]:::frontend
            AppComp["App.tsx"]:::frontend
            IndexHTML["index.html"]:::frontend
        end
        subgraph "Pages"
            direction TB
            Dashboard["Dashboard.tsx"]:::frontend
            Home["Index.tsx"]:::frontend
            NotFound["NotFound.tsx"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            PetList["PetList.tsx"]:::frontend
            ChatPanel["ChatPanel.tsx"]:::frontend
            ApiKeyInput["ApiKeyInput.tsx"]:::frontend
        end
        subgraph "UI Primitives (shadcn/ui)"
            direction TB
            UIPrims["/src/components/ui/"]:::frontend
        end
        subgraph "Hooks"
            direction TB
            MobileHook["use-mobile.tsx"]:::frontend
            ToastHook["use-toast.ts"]:::frontend
        end
        subgraph "AI Inference Engine"
            direction TB
            WasmEngine["WASM AI Engine"]:::ai
            Utils["utils.ts"]:::ai
        end
    end

    %% Hosting and Storage
    StaticHost["Static Hosting / CDN"]:::hosting
    ModelStorage["Model Weights Storage (public/)"]:::hosting

    %% External Libraries
    ReactLib["React"]:::external
    ViteLib["Vite"]:::external
    TailwindLib["TailwindCSS"]:::external

    %% Data Flows
    StaticHost -->|"Fetch index.html"| IndexHTML
    StaticHost -->|"Fetch JS/CSS bundles"| Main
    Main -->|"Initializes"| AppComp
    AppComp -->|"Renders"| Dashboard
    AppComp -->|"Renders"| Home
    AppComp -->|"Renders"| NotFound
    AppComp -->|"Renders"| PetList
    AppComp -->|"Renders"| ChatPanel
    AppComp -->|"Renders"| ApiKeyInput
    AppComp -->|"Uses UI Primitives"| UIPrims
    ChatPanel -->|"calls"| WasmEngine
    WasmEngine -->|"Load model weights"| ModelStorage
    WasmEngine -->|"Stream responses"| ChatPanel
    ChatPanel -->|"Trigger toasts"| ToastHook

    %% Library dependencies (dashed)
    ReactLib -.-> AppComp
    ViteLib -.-> Main
    TailwindLib -.-> UIPrims

    %% Click events
    click Main "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/main.tsx"
    click AppComp "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/App.tsx"
    click IndexHTML "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/index.html"
    click Dashboard "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/pages/Dashboard.tsx"
    click Home "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/pages/Index.tsx"
    click NotFound "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/pages/NotFound.tsx"
    click PetList "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/components/PetList.tsx"
    click ChatPanel "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/components/ChatPanel.tsx"
    click ApiKeyInput "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/components/ApiKeyInput.tsx"
    click UIPrims "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/tree/main/frontend/src/components/ui/"
    click MobileHook "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/hooks/use-mobile.tsx"
    click ToastHook "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/hooks/use-toast.ts"
    click Utils "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/blob/main/frontend/src/lib/utils.ts"
    click StaticHost "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/tree/main/frontend/dist/"
    click ModelStorage "https://github.com/praveen-raj-ragunathan/petpal-ai-pet-buddy/tree/main/frontend/public"

    classDef frontend fill:#D0E8FF,stroke:#0284C7,stroke-width:1px
    classDef ai fill:#DFFFE0,stroke:#22C55E,stroke-width:1px
    classDef hosting fill:#F3F4F6,stroke:#6B7280,stroke-width:1px
    classDef external stroke-dasharray: 3 3,stroke:#9CA3AF,fill:none
```
