# solendprotocol/suilend-public architecture

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

- Interactive diagram: https://gitdiagram.com/solendprotocol/suilend-public
- Repository: https://github.com/solendprotocol/suilend-public

## Overview

##### Project Type and Purpose
- This is a full-stack DeFi dApp monorepo for the “Suilend” protocol.
- frontend: Next.js/React TypeScript UI for on-chain lending, borrowing, swapping and sends
- sdk: TypeScript client library auto-generated from Move modules, published as @suilend/sdk
- liquidator: Node.js standalone service (bot skeleton) for monitoring/triggering liquidations
- scripts: ad-hoc CSV-processing scripts for airdrop/quest data
- Core use case: UI → SDK → Sui blockchain; off-chain bot → SDK → blockchain + Redis.

##### File-Structure Highlights
- Top level: package.json, bun.lock, eslint, shared configuration.
- frontend/: Next.js app
- src/pages & API routes (serverless edge & client)
- src/components, contexts, hooks, fetchers
- public assets including move_bytecode_template_bg.wasm
- sdk/:
- src/_generated: types & call bindings for Suilend Move modules
- src/api, src/lib, parsers, utils
- published package
- liquidator/:
- src/index.ts & liquidator.ts core logic
- src/swappers/cetus integration
- src/utils: Redis client, constants
- docker-compose.yml to run bot + Redis
- scripts/: small TypeScript scripts for CSV generation & quest logic

##### Architectural Components
A. Frontend (Next.js / React)
- UI components, contexts & hooks
- Uses @suilend/sdk to build transactions & fetch on-chain data
- Serverless API routes (e.g. ip-address-country)
- Fetches from Sui RPC / Indexer endpoints

B. SDK (@suilend/sdk)
- Auto-generated bindings to on-chain Move modules
- Exposes typed classes & functions: markets, obligations, reserves, rate limiter, events
- Underlying HTTP/JSON-RPC client to Sui node

C. Sui Blockchain (External Service)
- Suilend Move program (deployed contracts)
- JSON-RPC node & Indexer for queries

D. Liquidator Bot
- Polls markets via SDK, calculates under-collateralized positions
- Connects to Redis for state/tracking
- Submits liquidation transactions

E. Scripts
- Standalone CLI tasks leveraging SDK or raw CSV processing
- Not part of runtime; for governance/airdrop data preparation

F. Infrastructure
- Redis (for liquidator state)
- Docker-Compose orchestration for liquidator + Redis
- bun/Node.js runtimes

##### Relationships & Data Flows
- Frontend → SDK → Sui JSON-RPC Node (read & write)
- Frontend → API routes → edge functions (geolocation service)
- SDK → Sui blockchain → Move modules
- Liquidator → SDK → Sui blockchain
- Liquidator ↔ Redis (state management)
- Scripts → SDK / filesystem → CSV output

##### Architectural Patterns & Principles
- Separation of concerns: UI vs client library vs bot vs scripts
- Code-gen driven SDK: ensures parity with on-chain types
- Containerization: liquidator + Redis in Docker for easy deployment
- Serverless functions within Next.js for lightweight backend tasks

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "frontend"
        direction TB
        NextUI["Next.js UI"]:::ui
        ServerlessAPI["Serverless API"]:::backend
    end

    %% SDK Layer
    subgraph "sdk"
        direction TB
        SDKGen["_generated bindings"]:::sdk
        SDKLib["@suilend/sdk Library"]:::sdk
    end

    %% Liquidator Service
    subgraph "liquidator"
        direction TB
        Liquidator["Liquidator Bot"]:::service
    end

    %% Scripts
    subgraph "scripts"
        direction TB
        Scripts["CLI Scripts"]:::service
    end

    %% External Services & Blockchain
    SuiRPC["Sui JSON-RPC Node"]:::external
    SuiIndexer["Sui Indexer"]:::external
    MoveProg["Suilend Move Program"]:::blockchain
    Geoloc["GeoIP Service"]:::external
    Redis[(Redis)]:::datastore

    %% Data Flows
    NextUI -->|"uses"| SDKLib
    ServerlessAPI -->|"calls"| Geoloc
    ServerlessAPI -->|"reads/writes"| SuiRPC
    SDKLib -->|"JSON-RPC"| SuiRPC
    SDKLib -->|"queries"| SuiIndexer
    SuiRPC -->|"executes"| MoveProg
    SuiIndexer -->|"indexes"| MoveProg

    Liquidator -->|"uses"| SDKLib
    Liquidator -->|"reads/writes"| Redis
    Redis -->|"state"| Liquidator
    Liquidator -->|"JSON-RPC"| SuiRPC

    Scripts -->|"uses SDK or FS"| SDKLib

    MoveProg -->|"code-gen"| SDKGen
    SDKGen -->|"included in"| SDKLib

    %% Click Events
    click NextUI "https://github.com/solendprotocol/suilend-public/tree/staging/frontend/"
    click ServerlessAPI "https://github.com/solendprotocol/suilend-public/blob/staging/frontend/src/pages/api/ip-address-country.ts"
    click SDKGen "https://github.com/solendprotocol/suilend-public/tree/staging/sdk/src/_generated/"
    click SDKLib "https://github.com/solendprotocol/suilend-public/blob/staging/sdk/src/index.ts"
    click Liquidator "https://github.com/solendprotocol/suilend-public/blob/staging/liquidator/src/index.ts"
    click Redis "https://github.com/solendprotocol/suilend-public/blob/staging/liquidator/docker-compose.yml"
    click Scripts "https://github.com/solendprotocol/suilend-public/blob/staging/scripts/src/index.ts"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef sdk fill:#d4edda,stroke:#155724,color:#155724
    classDef service fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24
    classDef blockchain fill:#d6d8f9,stroke:#1f2e92,color:#1f2e92
    classDef datastore fill:#ffeeba,stroke:#856404,color:#856404
```
