# huc06/sharkbling architecture

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

- Interactive diagram: https://gitdiagram.com/huc06/sharkbling
- Repository: https://github.com/huc06/sharkbling

## Overview

##### Main components
- Frontend (Client): The client folder contains a React application (TypeScript) built with Vite. It houses the UI in the form of components (common, dashboard, modals, wallet, and UI primitives), pages, contexts, hooks, and library utilities used for blockchain interactions and API calls.
- Backend (Server): The server folder includes an Express-based backend (e.g., index.ts, routes.ts) which exposes API endpoints (e.g., for markets, predictions, social trends, and top predictors) and handles data storage and processing (via storage.ts).
- Smart Contracts (Move): Within the server/move folder, the project defines Move smart contracts (e.g., prediction_market.move) that are deployed to the Sui blockchain.
- Shared Code: The shared folder contains common schemas (schema.ts) that express data definitions used across both client and server to ensure consistency.
- External Integrations: The application also integrates with social media APIs (GitHub, LinkedIn, etc.) and uses blockchain Sui network. Wallet integrations (via SuiWallet in client) create an extra external link to users’ digital wallets.

##### Relationships and interactions
- Shared libraries and schema ensure that data formats are consistent between the client and server.
- The Frontend also directly interacts with external wallet APIs and possibly a Sui client library for blockchain transactions.
- Social media API integrations (with GitHub, LinkedIn, etc.) should be declared as external services that the Backend or even the Frontend can reach out to.

##### Architectural patterns and design principles
- Separation of concerns: There is a clear split between the frontend and backend with a well-defined API layer.
- Modular design: Organize UI components, contexts, and hooks within the frontend; API routes, storage, and configuration in the backend; and decentralized smart contracts in a dedicated folder.
- Decentralization: Smart contracts written in Move and deployed to Sui introduce an additional layer where trustless transactions are confirmed on the blockchain.

##### Additional details to capture
- File structure pointers to indicate that the client code uses modular UI components (UI primitives, modals, dashboards, etc.) and that the server deals with API and blockchain transaction logic.
- Mention that shared schemas ensure data consistency.
- Importance of wallet connectivity (with components like ConnectWalletButton and SuiWalletInfo) as a crucial integration point for user authentication and transactions.

- Divides the system into “Frontend (React/Vite)” and “Backend (Express, Smart Contracts)” components, with a clear “Shared Code” module.
- Captures the modular nature of the frontend (organizing components, contexts, hooks) and the backend (API endpoints, smart contract interactions on Sui).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React/Vite)"
        FE1["React UI"]:::frontend
        FE2["Connect Wallet"]:::frontend
        FE3["Sui Wallet Info"]:::frontend
        FE4["Social API Client"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express)"
        BE1["Express API"]:::backend
        BE1_1["index.ts"]:::backend
        BE1_2["routes.ts"]:::backend
        BE1_3["storage.ts"]:::backend
        BE1_4["vite.ts"]:::backend
    end

    %% Smart Contracts Layer
    subgraph "Smart Contracts (Move)"
        MC1["Move.toml"]:::smart
        MC2["prediction_market.move"]:::smart
    end

    %% Shared Code
    Shared["Shared Code (Schemas)"]:::shared

    %% External Services
    Chain["Blockchain (Sui Network)"]:::external
    Social["Social APIs"]:::external

    %% Data Flow Connections
    FE1 -->|"APIcalls"| BE1
    BE1 -->|"blockchainTx"| MC2
    FE1 -->|"walletTx"| Chain
    FE4 -->|"fetchSocial"| Social
    BE1 -->|"socialData"| Social
    FE1 ---|"dataConsistency"| Shared
    BE1 ---|"dataConsistency"| Shared

    %% Click Events for Frontend
    click FE1 "https://github.com/huc06/sharkbling/tree/main/client/src"
    click FE2 "https://github.com/huc06/sharkbling/blob/main/client/src/components/layout/ConnectWalletButton.tsx"
    click FE3 "https://github.com/huc06/sharkbling/blob/main/client/src/components/wallet/SuiWalletInfo.tsx"
    click FE4 "https://github.com/huc06/sharkbling/blob/main/client/src/lib/socialApi.ts"

    %% Click Events for Backend
    click BE1 "https://github.com/huc06/sharkbling/tree/main/server/"
    click BE1_1 "https://github.com/huc06/sharkbling/blob/main/server/index.ts"
    click BE1_2 "https://github.com/huc06/sharkbling/blob/main/server/routes.ts"
    click BE1_3 "https://github.com/huc06/sharkbling/blob/main/server/storage.ts"
    click BE1_4 "https://github.com/huc06/sharkbling/blob/main/server/vite.ts"

    %% Click Events for Smart Contracts
    click MC1 "https://github.com/huc06/sharkbling/tree/main/server/move/"
    click MC2 "https://github.com/huc06/sharkbling/blob/main/server/move/sources/prediction_market.move"

    %% Click Event for Shared Code
    click Shared "https://github.com/huc06/sharkbling/blob/main/shared/schema.ts"

    %% Styles
    classDef frontend fill:#e1f5fe,stroke:#0277bd,stroke-width:2px;
    classDef backend fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef smart fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef shared fill:#fff9c4,stroke:#f9a825,stroke-width:2px;
    classDef external fill:#f8bbd0,stroke:#c2185b,stroke-width:2px;
```
