# drift-labs/keepyrs architecture

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

- Interactive diagram: https://gitdiagram.com/drift-labs/keepyrs
- Repository: https://github.com/drift-labs/keepyrs

## Overview

##### Main Components Identification

The system should be represented with these primary components:
- JIT Maker Service
- Perp Filler Service
- Drift Protocol v2 Interface
- Wallet/Authentication Layer
- Configuration Management

##### Component Details

JIT Maker Service:
- JIT Maker Core (jit_maker.py)
- Utils (utils.py)
- Leverage management system
- Single market constraint

Perp Filler Service:
- Perp Filler Core (perp_filler.py)
- Fill Utils (fill_utils.py)
- Maker Utils (maker_utils.py)
- Node Utils (node_utils.py)

##### Connections and Data Flow

- Bidirectional communication between services and Drift Protocol
- Configuration flow from .env to services
- Wallet authentication flow
- Market data flow
- Order execution paths

##### Technical Details

Annotations for:
- Poetry dependency management
- Environment configuration requirements
- Target leverage constraints
- Market isolation requirements

##### Specific Implementation Notes

Callouts for:
- TARGET_LEVERAGE_PER_ACCOUNT configuration
- Sub-account market limitations
- RPC connection details
- Private key management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        DriftV2[Drift Protocol v2]
        RPC[Blockchain RPC Node]
    end

    subgraph BotServices
        subgraph JITMaker
            JM[JIT Maker Service]:::service
            JMUtils[JIT Utils]:::util
            JMLeverage[Leverage Management]:::util
        end

        subgraph PerpFiller
            PF[Perp Filler Service]:::service
            PFUtils[Service Utils]:::util
            FillUtils[Fill Utils]:::util
            MakerUtils[Maker Utils]:::util
            NodeUtils[Node Utils]:::util
            Constants[Constants]:::util
        end
    end

    subgraph Infrastructure
        Wallet[Wallet Management]:::infra
        Config[Configuration Management]:::infra
        Types[Type Definitions]:::util
        Parser[Parsing Utilities]:::util
        Logger[Logging System]:::util
    end

    %% Connections
    DriftV2 <--> JM
    DriftV2 <--> PF
    RPC --> JM
    RPC --> PF

    JM --> JMUtils
    JM --> JMLeverage
    
    PF --> PFUtils
    PF --> FillUtils
    PF --> MakerUtils
    PF --> NodeUtils
    PF --> Constants

    JM --> Wallet
    PF --> Wallet
    
    JM --> Config
    PF --> Config
    
    JM --> Types
    PF --> Types
    
    JM --> Parser
    PF --> Parser
    
    JM --> Logger
    PF --> Logger

    %% Click Events
    click JM "https://github.com/drift-labs/keepyrs/blob/master/jit_maker/src/jit_maker.py"
    click JMUtils "https://github.com/drift-labs/keepyrs/blob/master/jit_maker/src/utils.py"
    click PF "https://github.com/drift-labs/keepyrs/blob/master/perp_filler/src/perp_filler.py"
    click PFUtils "https://github.com/drift-labs/keepyrs/blob/master/perp_filler/src/utils.py"
    click FillUtils "https://github.com/drift-labs/keepyrs/blob/master/perp_filler/src/fill_utils.py"
    click MakerUtils "https://github.com/drift-labs/keepyrs/blob/master/perp_filler/src/maker_utils.py"
    click NodeUtils "https://github.com/drift-labs/keepyrs/blob/master/perp_filler/src/node_utils.py"
    click Constants "https://github.com/drift-labs/keepyrs/blob/master/perp_filler/src/constants.py"
    click Types "https://github.com/drift-labs/keepyrs/blob/master/keepyr_types.py"
    click Parser "https://github.com/drift-labs/keepyrs/blob/master/keepyr_parse.py"
    click Logger "https://github.com/drift-labs/keepyrs/blob/master/custom_log.py"
    click Config "https://github.com/drift-labs/keepyrs/blob/master/pyproject.toml"

    %% Styles
    classDef service fill:#f9f,stroke:#333,stroke-width:2px
    classDef util fill:#ff9,stroke:#333,stroke-width:1px
    classDef infra fill:#9ff,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        Service[Service]:::service
        Utility[Utility]:::util
        Infrastructure[Infrastructure]:::infra
    end
```
