# sahilbehl2003/healthcare_e_vault architecture

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

- Interactive diagram: https://gitdiagram.com/sahilbehl2003/healthcare_e_vault
- Repository: https://github.com/sahilbehl2003/healthcare_e_vault

## Overview

##### Project Type and Purpose
- This is a full-stack DApp (decentralized application) with:
- A React-based web client
- A Python-based AI/QA chatbot backend
- A Solidity smart contract running on a local Ethereum network (Hardhat)
- Purpose:
- Allow users to upload, remove, and share file references on-chain
- Provide an AI assistant for searching/qa’ing medical documents

##### Main Components
A. Frontend (client/)
- React SPA (App.js, components/…)
- Ethers.js + MetaMask integration for on-chain calls
- HTTP calls to Python AI backend (e.g., for vector searches)

B. Backend & AI (chatbot/)
- ingest.py: PDF ingestion & embedding creation
- model.py: Query interface for FAISS vectorstore
- FAISS DB (vectorstore/db_faiss/index.faiss & index.pkl)

C. Smart Contract (contracts/, scripts/, test/)
- Solidity contract “Upload.sol” (in contracts/)
- Hardhat config & scripts (hardhat.config.js, scripts/deploy.js)
- Local Ethereum node via `npx hardhat node`
- Tests (test/UploadTest.js)

##### Relationships & Data Flows
1. User interacts with React UI
– FileUpload component → optional off-chain storage (e.g., IPFS)
– Calls `uploadInstance.add(...)` via Ethers.js → Smart Contract on Hardhat network
2. Smart Contract stores IPFS URIs in user-scoped lists, manages access control
– add(), removeFile(), allow(), disallow(), display()
– Data remains on-chain; URIs point to off-chain content
3. React UI queries contract for file list → renders in Display component
4. AI Query Flow
– User enters question in AI component → HTTP POST to Python service
– Python service loads FAISS index & embeddings → returns best matches
– React UI displays AI/QA results
5. Deployment Flow
– scripts/deploy.js → deploys Upload.sol → returns contract address → injected into React env

##### Architectural Patterns & Design Principles
- Separation of Concerns
– UI Layer (React)
– Business Logic (Python AI + Solidity contract)
– Data Persistence
- On-chain (Smart Contract)
- Off-chain (FAISS vectorstore, IPFS)
- Modular components
– React components folder
– Python modules for ingest & model
– Hardhat scripts/tests separated
- API abstraction
– Ethers.js abstracts contract calls
– Potential REST API for Python AI

##### Essential Elements
- Clear labels for each component & folder
- Notes on data formats (e.g., IPFS URI, JSON, embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    User["User"] 

    %% Frontend Subsystem
    subgraph "Frontend (client/)"
        direction TB
        ReactApp["React App\n(App.js)"]:::frontend
        FileUpload["FileUpload"]:::frontend
        Display["Display"]:::frontend
        AIComponent["AI"]:::frontend
        Ocr["Ocr"]:::frontend
        SearchFormdb["SearchFormdb"]:::frontend
        Login["Login"]:::frontend
        Modal["Modal"]:::frontend
        AppModal["AppModal"]:::frontend
        subgraph "Static Assets"
            direction TB
            IndexHTML["index.html"]:::frontend
            ManifestJSON["manifest.json"]:::frontend
        end
    end

    %% Backend & AI Subsystem
    subgraph "Backend & AI (chatbot/)"
        direction TB
        Ingest["ingest.py"]:::backend
        Model["model.py"]:::backend
        Requirements["requirements.txt"]:::backend
        AIService["FastAPI/Flask Service"]:::backend
        subgraph "FAISS Vectorstore (Off-chain)"
            direction TB
            IndexFAISS["index.faiss"]:::storage
            IndexPKL["index.pkl"]:::storage
        end
    end

    %% Blockchain Subsystem
    subgraph "Blockchain"
        direction TB
        HardhatNode["Hardhat Node\n(local Ethereum)"]:::blockchain
        UploadContract["Upload.sol"]:::blockchain
        DeployScript["deploy.js"]:::blockchain
        TestSuite["UploadTest.js"]:::blockchain
    end

    %% Data Flows
    User -->|"interacts"| ReactApp
    ReactApp -->|"Ethers.js JSON-RPC\nvia MetaMask"| HardhatNode
    ReactApp -->|"calls add(), removeFile(), display()"| UploadContract
    ReactApp -->|"HTTP POST JSON"| AIService
    ReactApp -->|"upload to IPFS"| IPFS["IPFS"]:::storage
    IPFS -->|"returns URI"| ReactApp
    AIService -->|"loads embeddings"| IndexFAISS
    AIService -->|"loads embeddings"| IndexPKL
    AIService -->|"returns QA results"| ReactApp
    DeployScript -->|"deploys contract"| UploadContract
    DeployScript -->|"runs on"| HardhatNode
    TestSuite -->|"tests contract"| UploadContract

    %% Relationships
    HardhatNode -->|"JSON-RPC responses"| ReactApp

    %% Click Events - Frontend
    click ReactApp "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/App.js"
    click FileUpload "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/FileUpload.js"
    click Display "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/Display.js"
    click AIComponent "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/AI.js"
    click Ocr "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/Ocr.js"
    click SearchFormdb "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/SearchFormdb.js"
    click Login "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/Login.js"
    click Modal "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/Modal.js"
    click AppModal "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/src/components/AppModal.jsx"
    click IndexHTML "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/public/index.html"
    click ManifestJSON "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/client/public/manifest.json"

    %% Click Events - Backend & AI
    click Ingest "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/chatbot/ingest.py"
    click Model "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/chatbot/model.py"
    click Requirements "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/chatbot/requirements.txt"
    click IndexFAISS "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/chatbot/vectorstore/db_faiss/index.faiss"
    click IndexPKL "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/chatbot/vectorstore/db_faiss/index.pkl"

    %% Click Events - Smart Contract
    click UploadContract "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/contracts/Upload.sol"
    click DeployScript "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/scripts/deploy.js"
    click TestSuite "https://github.com/sahilbehl2003/healthcare_e_vault/blob/main/test/UploadTest.js"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef blockchain fill:#FFFF99,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
```
