# lovish888/care-ai architecture

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

- Interactive diagram: https://gitdiagram.com/lovish888/care-ai
- Repository: https://github.com/lovish888/care-ai

## Overview

##### Main Components
- Frontend: This side (located in the “frontend” directory) is built with TypeScript and Vite, and it includes several React components (e.g., ChatFeedback, ChatHistory, LandingPage, Layout, MainMenu, and SupportChat) that provide the user interface.
- Backend: Found in the “backend” directory, the backend is implemented in TypeScript with entry points like “index.ts” and “socket.ts”. It hosts the core functionalities of the server.
- Agents Modules: Under “backend/src/agents” you have various agent implementations (coinbaseAgentKit, ecommerceAgent, ecommercePrompt, foodDeliveryagent, and foodDeliveryPrompt) that encapsulate domain-specific logic.
- Blockchain Module: Within “backend/src/blockchain” there’s at least one module (chatLogger.ts) intended to handle blockchain interactions or logging, possibly for ensuring message integrity or persistent audit logs.
- Storage Module: The “backend/src/storage” directory contains modules like “zeroGStorage.ts” which likely handles data persistence or caching.
- Types and Configurations: The “backend/src/types” directory and various configuration files (tsconfig.json, environment examples) provide the supporting infrastructure to ensure type safety and proper environment-specific configurations.

##### Relationships and Interactions
- Client-Server Communication: The frontend interacts with the backend via HTTP requests and likely through WebSockets (given the presence of “socket.ts” in the backend) for real-time chat updates.
- Agent Interaction: The backend routes specific tasks to agent modules to process different kinds of requests (e.g., ecommerce, food delivery, Coinbase integrations). Each agent is a self-contained component offering specialized functions.
- Logging and Storage: The backend integrates with a blockchain-logging mechanism (chatLogger.ts) to record interactions, and a storage module (zeroGStorage.ts) to persist or retrieve relevant data.
- Data Flow: User actions on the frontend trigger events or HTTP calls to the backend. The backend then directs these requests to the appropriate agent module, which may then interact with external services, update the blockchain log, or access persistent storage.

##### Architectural Patterns and Key Design Principles
- Separation of Concerns: The project is clearly divided between frontend (presentation layer) and backend (business logic), with additional modularization of the agents.
- Real-time Communication: The presence of a dedicated socket module suggests real-time events and data synchronization between the client and server.
- Modular Agent Design: Each agent encapsulates its domain logic making the system highly extensible and maintainable.
- Configuration Management: The use of environment variables (via .env files) and clear directory separation emphasizes ease of configuration for different deployment environments.

- Layout:
- API Server / Entry Points (index.ts, socket.ts).
- Blockchain Logger Module.
- Storage Module.
- Flow:
- User inputs on frontend -> API/Socket communication -> routed to appropriate Agents.
- Agent results -> update logs via Blockchain module.
- Data persistence queries directed to Storage module.
- Annotation:

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Subgraph
    subgraph "Frontend (React/Vite)"
        FERoot["Frontend Application"]:::frontend
        FE1["ChatFeedback Component"]:::frontend
        FE2["ChatHistory Component"]:::frontend
        FE3["LandingPage Component"]:::frontend
        FE4["Layout Component"]:::frontend
        FE5["MainMenu Component"]:::frontend
        FE6["SupportChat Component"]:::frontend
        FERoot --- FE1
        FERoot --- FE2
        FERoot --- FE3
        FERoot --- FE4
        FERoot --- FE5
        FERoot --- FE6
    end

    %% Backend Subgraph
    subgraph "Backend API Server"
        %% API Entry Points
        subgraph "API Entry Points"
            BE1["index.ts"]:::backend
            BE2["socket.ts"]:::backend
        end

        %% Agents Modules
        subgraph "Agents Modules"
            A1["coinbaseAgentKit.ts"]:::agent
            A2["ecommerceAgent.ts"]:::agent
            A3["ecommercePrompt.ts"]:::agent
            A4["foodDeliveryagent.ts"]:::agent
            A5["foodDeliveryPrompt.ts"]:::agent
        end

        %% Blockchain Logger Module
        subgraph "Blockchain Logger Module"
            BL1["chatLogger.ts"]:::blockchain
        end

        %% Storage Module
        subgraph "Storage Module"
            ST1["zeroGStorage.ts"]:::storage
        end

        %% Types & Configurations
        subgraph "Types & Configurations"
            TC1["Backend Types"]:::config
            TC2["backend/tsconfig.json"]:::config
            TC3["frontend/tsconfig.json"]:::config
            TC4["frontend/tsconfig.app.json"]:::config
            TC5["frontend/tsconfig.node.json"]:::config
            TC6["backend/.env.example"]:::config
            TC7["frontend/.env.example"]:::config
        end
    end

    %% Frontend to Backend Connections
    FERoot -->|"API_Request"| BE1
    FERoot -->|"Real-time_Event"| BE2

    %% Backend Internal Connections
    BE1 -->|"Agent_Call"| A1
    BE1 -->|"Agent_Call"| A2
    BE1 -->|"Agent_Call"| A3
    BE1 -->|"Agent_Call"| A4
    BE1 -->|"Agent_Call"| A5
    BE1 -->|"Logging"| BL1
    BE1 -->|"Data_Persistence"| ST1

    %% Click Events for Frontend Components
    click FERoot "https://github.com/lovish888/care-ai/tree/main/frontend/"
    click FE1 "https://github.com/lovish888/care-ai/blob/main/frontend/src/components/ChatFeedback.tsx"
    click FE2 "https://github.com/lovish888/care-ai/blob/main/frontend/src/components/ChatHistory.tsx"
    click FE3 "https://github.com/lovish888/care-ai/blob/main/frontend/src/components/LandingPage.tsx"
    click FE4 "https://github.com/lovish888/care-ai/blob/main/frontend/src/components/Layout.tsx"
    click FE5 "https://github.com/lovish888/care-ai/blob/main/frontend/src/components/MainMenu.tsx"
    click FE6 "https://github.com/lovish888/care-ai/blob/main/frontend/src/components/SupportChat.tsx"

    %% Click Events for Backend API Entry Points
    click BE1 "https://github.com/lovish888/care-ai/blob/main/backend/src/index.ts"
    click BE2 "https://github.com/lovish888/care-ai/blob/main/backend/src/socket.ts"

    %% Click Events for Agents Modules
    click A1 "https://github.com/lovish888/care-ai/blob/main/backend/src/agents/coinbaseAgentKit.ts"
    click A2 "https://github.com/lovish888/care-ai/blob/main/backend/src/agents/ecommerceAgent.ts"
    click A3 "https://github.com/lovish888/care-ai/blob/main/backend/src/agents/ecommercePrompt.ts"
    click A4 "https://github.com/lovish888/care-ai/blob/main/backend/src/agents/foodDeliveryagent.ts"
    click A5 "https://github.com/lovish888/care-ai/blob/main/backend/src/agents/foodDeliveryPrompt.ts"

    %% Click Event for Blockchain Logger Module
    click BL1 "https://github.com/lovish888/care-ai/blob/main/backend/src/blockchain/chatLogger.ts"

    %% Click Event for Storage Module
    click ST1 "https://github.com/lovish888/care-ai/blob/main/backend/src/storage/zeroGStorage.ts"

    %% Click Events for Types & Configurations
    click TC1 "https://github.com/lovish888/care-ai/tree/main/backend/src/types/"
    click TC2 "https://github.com/lovish888/care-ai/blob/main/backend/tsconfig.json"
    click TC3 "https://github.com/lovish888/care-ai/blob/main/frontend/tsconfig.json"
    click TC4 "https://github.com/lovish888/care-ai/blob/main/frontend/tsconfig.app.json"
    click TC5 "https://github.com/lovish888/care-ai/blob/main/frontend/tsconfig.node.json"
    click TC6 "https://github.com/lovish888/care-ai/blob/main/backend/.env.example"
    click TC7 "https://github.com/lovish888/care-ai/blob/main/frontend/.env.example"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
    classDef agent fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef blockchain fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef storage fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef config fill:#F2F3F4,stroke:#7F8C8D,stroke-width:2px;
```
