# shubham-rasal/hashmind architecture

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

- Interactive diagram: https://gitdiagram.com/shubham-rasal/hashmind
- Repository: https://github.com/shubham-rasal/hashmind

## Overview

##### Project Type & Purpose
- HashMind is a full-stack decentralized application that integrates AI agents, blockchain smart contracts, Web3 authentication, and decentralized messaging.
- Its goal is to let users create and deploy specialized AI agents (for finance-related services) by interacting with a chat interface and integrating various blockchain and messaging components.

##### Key Components
a. Frontend/UI Components:
- Two Next.js-based frontends located under the “dashboard” and “frontend” folders.
- These likely serve different user interfaces (the dashboard for agent management and another client-facing experience for interacting with AI agents).
b. Backend Services:
- The “backend” contains a Node.js/Express-based server for handling API calls, including integration with Lit Protocol for encryption and secure data handling.
- The “message-kit” module is a specialized service packaging XMTP chat functionalities that connect with a Redis database for message logging and management.
c. Smart Contracts/Blockchain Layer:
- The “contracts” directory holds Hardhat configurations, Solidity contracts (including a Galadriel factory contract for agent creation), and deployment scripts. This represents the blockchain layer and smart contract interactions.
d. External/Third-Party Services:
- XMTP Chat Interface for facilitating bot interactions.
- Hedera Consensus Service that provides distributed decision-making for agent operations.
- Web3Auth for user authentication (onboarding via familiar Web2 providers while connecting wallet interactions).
- Lit Protocol for decentralized encryption and fine-grained access control.

##### Relationships & Interactions
- The Frontends (both dashboard and client-side interfaces) interact with:
- The backend server via API calls to handle operations like agent creation, user authentication, and secure data handling.
- External services for real-time messaging (XMTP through message-kit) and user verification.
- The Backend:
- Acts as an orchestrator by taking requests from the UI and communicating with blockchain smart contracts for agent creation and other operations.
- Interfaces with the Lit Protocol for encryption/decryption tasks.
- Smart Contracts:
- Deployed by the contracts directory’s scripts and used by the backend to create and manage “agents” through the Galadriel factory contract.
- Message-Kit:
- Functions as an independent service/module that integrates with XMTP for chat-based agent interactions, supported by Redis for caching or logging.
- External APIs/Third-Party Integrations (XMTP, Hedera, Web3Auth):
- These services are critical for real-time communication, decentralized consensus, and secure user onboarding.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clearly delineate between the presentation layer (frontends), business logic/API layer (backend), blockchain operations (smart contracts), and messaging service (message-kit).
- Integration with External Systems: Show how components interact with third-party services (XMTP, Hedera, Web3Auth, Lit Protocol).

##### Detail Level
- Provide enough detail to capture all core interactions without oversimplification – the goal is to cover data flows and interactions between “Dashboard”, “Frontend”, “Backend”, “Smart Contract Layer”, “Message-Kit”, and various external integrations.
- Don’t shy away from breaking down modules further if needed (for instance, show that the Message-Kit internally interacts with both Redis and XMTP).

## Diagram (Mermaid)

```mermaid
graph TD
    %% UI Layer
    subgraph "UI Layer"
        Dashboard["Dashboard (Next.js UI)"]:::frontend
        Frontend["Frontend (Next.js UI)"]:::frontend
    end

    %% Backend Layer
    subgraph "API Layer"
        Backend["Backend (Express/Node.js API)"]:::backend
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        SmartContracts["Smart Contracts (Galadriel Factory)"]:::blockchain
    end

    %% Messaging Service Layer
    subgraph "Messaging Service"
        MessageKit["Message-Kit (XMTP Integration)"]:::messaging
        Redis["Redis (Message Logging)"]:::database
        Xmtp["XMTP Chat"]:::external
    end

    %% External Services
    subgraph "External Services"
        Hedera["Hedera Consensus Service"]:::external
        Web3Auth["Web3Auth"]:::external
        Lit["Lit Protocol"]:::external
    end

    %% Connections from UI to Backend
    Dashboard -->|"API_calls"| Backend
    Frontend -->|"API_calls"| Backend

    %% Backend interactions
    Backend -->|"Deploys/Operates"| SmartContracts
    Backend -->|"Encryption"| Lit
    Backend -->|"Auth"| Web3Auth
    Backend -->|"Consensus"| Hedera

    %% UI chat interface connection
    Dashboard -.->|"Chat_UI"| MessageKit
    Frontend -.->|"Chat_UI"| MessageKit

    %% Message-Kit integrations
    MessageKit -->|"Uses_XMTP"| Xmtp
    MessageKit -->|"Caches_Messages"| Redis

    %% Click Events
    click Dashboard "https://github.com/shubham-rasal/hashmind/tree/master/dashboard/"
    click Frontend "https://github.com/shubham-rasal/hashmind/tree/master/frontend/"
    click Backend "https://github.com/shubham-rasal/hashmind/blob/master/backend/server.js"
    click SmartContracts "https://github.com/shubham-rasal/hashmind/tree/master/contracts/"
    click MessageKit "https://github.com/shubham-rasal/hashmind/tree/master/message-kit/"

    %% Styles
    classDef frontend fill:#b3e5fc,stroke:#0288d1,stroke-width:2px;
    classDef backend fill:#fce4ec,stroke:#d81b60,stroke-width:2px;
    classDef blockchain fill:#e8f5e9,stroke:#43a047,stroke-width:2px;
    classDef messaging fill:#fff3e0,stroke:#fb8c00,stroke-width:2px;
    classDef external fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;
    classDef database fill:#ffebee,stroke:#c62828,stroke-width:2px;
```
