# etherspot/arka architecture

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

- Interactive diagram: https://gitdiagram.com/etherspot/arka
- Repository: https://github.com/etherspot/arka

## Overview

##### Main Components Identification

The system consists of three major components:
- Admin Frontend (React-based dashboard)
- User Frontend (React-based interface)
- Backend Service (Node.js with PostgreSQL)
- Indexer Service (for blockchain data)

##### Key Architectural Elements

a) Frontend Layer:
- Admin Dashboard (port 3002)
- API Key Management
- Network Configuration
- ERC20 Paymaster Management
- System Configuration

- User Frontend (port 3000)
- Transaction Sponsorship Interface
- Wallet Connection
- Transaction Management

b) Backend Layer (port 5050):
- API Services
- Paymaster Routes
- Admin Routes
- Whitelist Routes
- Sponsorship Policy Routes
- Deposit Routes
- Database Integration
- Blockchain Integration
- Indexer Service

c) Data Layer:
- PostgreSQL Database
- API Keys
- Arka Configuration
- Sponsorship Policies
- Whitelists
- Contract Whitelists

d) Blockchain Integration:
- Smart Contracts
- ERC20 Paymaster
- Verifying Paymaster
- Multi-token Paymaster
- Oracle Integration
- Chainlink
- Pyth
- Orochi

**[User/Admin Browsers] → [Load Balancer/Reverse Proxy]**
- ↓
**[Frontend Layer] → [Admin Frontend (3002)]**
- → [User Frontend (3000)]
- ↓
**[Backend Layer (5050)] → [API Services]**
- → [Business Logic]
- → [Blockchain Services]
- ↓
**[Data Layer] → [PostgreSQL]**
- → [Indexer Service]
- ↓
**[Blockchain Layer] → [Smart Contracts]**
- → [Oracles]

##### Important Flows to Highlight
- User Transaction Flow:
- Transaction Request → Frontend → Backend → Smart Contract
- Sponsorship Verification Flow
- Payment Processing Flow

- Admin Management Flow:
- Configuration Management
- API Key Management
- Network Management

##### Additional Elements
- Security Layer (HMAC authentication)
- Cron Jobs for Price Updates
- Webhook Integration
- Docker Container Boundaries
- Network Isolation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Layer"
        Browser["Web Browser"]
        AdminBrowser["Admin Browser"]
    end

    subgraph "Frontend Layer"
        UserFE["User Frontend (3000)"]:::frontend
        AdminFE["Admin Dashboard (3002)"]:::frontend
        Dashboard["Dashboard"]:::frontend
        ApiKeys["API Key Management"]:::frontend
        NetworkConfig["Network Configuration"]:::frontend
        TxManagement["Transaction Management"]:::frontend
    end

    subgraph "Backend Layer"
        API["API Services (5050)"]:::backend
        PaymasterImpl["Paymaster Implementation"]:::backend
        IndexerSvc["Indexer Service"]:::backend
        Repository["Repository Layer"]:::backend
    end

    subgraph "Data Layer"
        DB[(PostgreSQL)]:::database
        Models["Database Models"]:::database
        Migrations["Database Migrations"]:::database
    end

    subgraph "Blockchain Layer"
        SmartContracts["Smart Contracts"]:::blockchain
        Oracles["Oracle Services"]:::blockchain
        ChainLink["Chainlink Oracle"]:::blockchain
        Pyth["Pyth Oracle"]:::blockchain
        Orochi["Orochi Oracle"]:::blockchain
    end

    Browser --> UserFE
    AdminBrowser --> AdminFE
    UserFE --> API
    AdminFE --> API
    AdminFE --> Dashboard
    AdminFE --> ApiKeys
    AdminFE --> NetworkConfig
    UserFE --> TxManagement

    API --> PaymasterImpl
    API --> Repository
    PaymasterImpl --> SmartContracts
    IndexerSvc --> SmartContracts
    Repository --> DB
    DB --> Models
    DB --> Migrations

    SmartContracts --> Oracles
    Oracles --> ChainLink
    Oracles --> Pyth
    Oracles --> Orochi

    %% Click Events
    click UserFE "https://github.com/etherspot/arka/tree/master/frontend"
    click AdminFE "https://github.com/etherspot/arka/tree/master/admin_frontend"
    click Dashboard "https://github.com/etherspot/arka/blob/master/admin_frontend/src/components/Dashboard.jsx"
    click ApiKeys "https://github.com/etherspot/arka/blob/master/admin_frontend/src/components/ApiKeys.jsx"
    click NetworkConfig "https://github.com/etherspot/arka/blob/master/admin_frontend/src/modals/AddSupportedNetworksModal.jsx"
    click TxManagement "https://github.com/etherspot/arka/blob/master/frontend/src/components/TransactionSentToast.jsx"
    click API "https://github.com/etherspot/arka/tree/master/backend/src/routes"
    click PaymasterImpl "https://github.com/etherspot/arka/tree/master/backend/src/paymaster"
    click IndexerSvc "https://github.com/etherspot/arka/blob/master/backend/indexer/src/index.ts"
    click Models "https://github.com/etherspot/arka/tree/master/backend/src/models"
    click Migrations "https://github.com/etherspot/arka/tree/master/backend/migrations"
    click Repository "https://github.com/etherspot/arka/tree/master/backend/src/repository"
    click ChainLink "https://github.com/etherspot/arka/blob/master/backend/src/abi/ChainlinkOracleAbi.ts"
    click Pyth "https://github.com/etherspot/arka/blob/master/backend/src/abi/PythOracleAbi.ts"
    click Orochi "https://github.com/etherspot/arka/blob/master/backend/src/abi/OrochiOracleAbi.ts"

    %% Styling
    classDef frontend fill:#2374ab
    classDef backend fill:#2a9d8f
    classDef database fill:#e9c46a
    classDef blockchain fill:#8338ec
    classDef external fill:#grey

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Database["Database Component"]:::database
        Blockchain["Blockchain Component"]:::blockchain
    end
```
