# cleyfe/chaincare architecture

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

- Interactive diagram: https://gitdiagram.com/cleyfe/chaincare
- Repository: https://github.com/cleyfe/chaincare

## Overview

##### Main System Components

A. Client Layer (Frontend)
- React/TypeScript frontend with components:
- Core Pages (Dashboard, Vault, Projects, Achievements)
- UI Components Library
- Web3 Integration Components
- State Management & Hooks

B. Server Layer (Backend)
- Node.js server with:
- Authentication Service
- API Routes
- Vite Development Server

C. Database Layer
- PostgreSQL Database with Drizzle ORM
- Key Tables Structure:
- Users & Authentication
- Vault Deposits
- Projects & Distributions
- Rewards & Achievements

D. Blockchain Layer
- Base Network Integration
- Smart Contracts for Vaults
- Dynamic.xyz Authentication
- Ethers.js Integration

##### Component Relationships

Key relationships to highlight:
- Frontend → Backend API calls
- Backend → Database queries
- Frontend → Blockchain interactions
- Authentication flow between Dynamic.xyz, frontend, and backend

##### Specific Implementation Details

Frontend Section:
**┌─ Client Layer ─────────────────┐**
- Pages                       │
- Dashboard               │
- Vault                   │
- Projects               │
- Components                  │
- UI Library             │
- Custom Components      │
- Hooks & Utils              │
- ┘

Backend Section:
**┌─ Server Layer ────────────────┐**
- Authentication            │
- API Routes               │
- Vite Server             │
- ┘

##### External Integrations

External service integrations:
- Dynamic.xyz Authentication
- Base Network
- PostgreSQL Database

##### Data Flow Patterns

Data flows:
- User authentication process
- Vault deposit/withdrawal flow
- Impact tracking metrics
- Achievement unlocking process

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Pages["Pages"]
        click Pages "https://github.com/cleyfe/chaincare/tree/main/client/src/pages/"
        Pages --> Dashboard["Dashboard"]
        click Dashboard "https://github.com/cleyfe/chaincare/blob/main/client/src/pages/Dashboard.tsx"
        Pages --> Vault["Vault"]
        click Vault "https://github.com/cleyfe/chaincare/blob/main/client/src/pages/Vault.tsx"
        Pages --> Projects["Projects"]
        click Projects "https://github.com/cleyfe/chaincare/blob/main/client/src/pages/Projects.tsx"
        Pages --> Achievements["Achievements"]
        click Achievements "https://github.com/cleyfe/chaincare/blob/main/client/src/pages/Achievements.tsx"
        
        Components["UI Components"]
        click Components "https://github.com/cleyfe/chaincare/tree/main/client/src/components/ui/"
        Components --> Layout["Core Layout"]
        click Layout "https://github.com/cleyfe/chaincare/blob/main/client/src/components/Layout.tsx"
        Components --> RewardsCard["Rewards System"]
        click RewardsCard "https://github.com/cleyfe/chaincare/blob/main/client/src/components/RewardsCard.tsx"
        Components --> Stats["Statistics"]
        click Stats "https://github.com/cleyfe/chaincare/blob/main/client/src/components/Stats.tsx"
        Components --> DepositModal["Vault Interface"]
        click DepositModal "https://github.com/cleyfe/chaincare/blob/main/client/src/components/ui/deposit-modal.tsx"
        Components --> AchievementBadge["Achievement Badge"]
        click AchievementBadge "https://github.com/cleyfe/chaincare/blob/main/client/src/components/ui/achievement-badge.tsx"
        Components --> ShareButton["Social Sharing"]
        click ShareButton "https://github.com/cleyfe/chaincare/blob/main/client/src/components/ui/share-button.tsx"
        
        Web3["Web3 Integration"]
        click Web3 "https://github.com/cleyfe/chaincare/blob/main/client/src/lib/web3.ts"
        Web3 --> Execution["Execution Logic"]
        click Execution "https://github.com/cleyfe/chaincare/blob/main/client/src/lib/execution.ts"
        
        StateHooks["State & Hooks"]
        StateHooks --> UserState["User State"]
        click UserState "https://github.com/cleyfe/chaincare/blob/main/client/src/hooks/use-user.ts"
        StateHooks --> MobileDetect["Mobile Detection"]
        click MobileDetect "https://github.com/cleyfe/chaincare/blob/main/client/src/hooks/use-mobile.tsx"
        StateHooks --> Toast["Toast Notifications"]
        click Toast "https://github.com/cleyfe/chaincare/blob/main/client/src/hooks/use-toast.ts"
    end
    
    subgraph Server
        Auth["Authentication Service"]
        click Auth "https://github.com/cleyfe/chaincare/blob/main/server/auth.ts"
        APIRoutes["API Routes"]
        click APIRoutes "https://github.com/cleyfe/chaincare/blob/main/server/routes.ts"
        ViteServer["Vite Server"]
        click ViteServer "https://github.com/cleyfe/chaincare/blob/main/server/vite.ts"
    end
    
    subgraph Database
        DB["PostgreSQL + Drizzle ORM"]
        click DB "https://github.com/cleyfe/chaincare/blob/main/db/index.ts"
        Schema["Database Schema"]
        click Schema "https://github.com/cleyfe/chaincare/blob/main/db/schema.ts"
        OrmConfig["ORM Configuration"]
        click OrmConfig "https://github.com/cleyfe/chaincare/blob/main/drizzle.config.ts"
    end
    
    subgraph Blockchain
        BaseNetwork["Base Network"]
        SmartContracts["Vault Smart Contracts"]
        DynamicAuth["Dynamic.xyz Auth"]
        EthersJS["Ethers.js"]
    end
    
    %% Relationships
    Pages --> Components
    Pages --> Web3
    Pages --> StateHooks
    Components --> Web3
    Web3 --> Blockchain
    Auth --> DynamicAuth
    APIRoutes --> DB
    Pages --> APIRoutes
    
    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef blockchain fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    
    class Pages,Components,Web3,StateHooks frontend
    class Auth,APIRoutes,ViteServer backend
    class DB,Schema,OrmConfig database
    class BaseNetwork,SmartContracts,EthersJS blockchain
    class DynamicAuth external
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Service"]:::backend
        DatabaseComp["Database Component"]:::database
        BlockchainComp["Blockchain Component"]:::blockchain
        ExternalService["External Service"]:::external
    end
```
