# coip/rebus architecture

> Architecture diagram of the GitHub repository coip/rebus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coip/rebus
- Repository: https://github.com/coip/rebus

## Overview

##### Project Type Analysis
This is a specialized financial trading API client library that interfaces with Interactive Brokers' Trader Workstation. The project structure suggests it's a standalone library package with clear separation of concerns.

##### Main Components

a. Core Components:
- Client Interface Layer
- Connection Management
- Message Processing (Decoder)
- Domain-Specific Components:
- Order Management
- Contract Management
- Execution Handling
- Scanner Services
- Error Handling

b. External Systems:
- Interactive Brokers TWS
- Client Applications (consumers of this library)

##### Middle Layer (Core Library Components)
- Client Component (client.go)
- Connection Manager (connection.go)
- Message Decoder (decoder.go)
- Domain Services:
- Order Service (order.go)
- Contract Service (contract.go)
- Execution Service (execution.go)
- Scanner Service (scanner.go)
- Infrastructure components (connection, decoder) - Use green
- Business domain components (order, contract, execution) - Use yellow
- Utility components (utils.go) - Use gray

##### Connections and Data Flow
- Client Applications ↔ Client Component
- Client Component ↔ Connection Manager
- Connection Manager ↔ TWS

##### Additional Elements
- Version information and key dependencies
- Notes about important interfaces and protocols

Key Considerations:

##### Following aspects
- The connection management layer that handles TWS communication
- The decoder component that processes TWS messages
- The separation between infrastructure and domain components
- Error handling flow across components

##### Technical details
- TCP/IP connection to TWS
- Message encoding/decoding flow
- Event handling patterns
- Error propagation paths

##### Clear boundaries between
- Library internals
- External interfaces
- Communication protocols

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef external fill:#B3D9FF,stroke:#333,stroke-width:2px
    classDef core fill:#A0D8B3,stroke:#333,stroke-width:2px
    classDef domain fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef infrastructure fill:#98FB98,stroke:#333,stroke-width:2px
    classDef utility fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% External Systems
    ClientApps["Client Applications"]:::external
    TWS["Interactive Brokers TWS"]:::external

    %% Main Container
    subgraph IBService["IB Service Library"]
        %% Core Components
        Client["Client Interface"]:::core
        click Client "https://github.com/coip/rebus/blob/master/ibsvc/client.go"
        
        Wrapper["Wrapper Interface"]:::core
        click Wrapper "https://github.com/coip/rebus/blob/master/ibsvc/wrapper.go"
        
        ConnMgr["Connection Manager"]:::infrastructure
        click ConnMgr "https://github.com/coip/rebus/blob/master/ibsvc/connection.go"
        
        Decoder["Message Decoder"]:::infrastructure
        click Decoder "https://github.com/coip/rebus/blob/master/ibsvc/decoder.go"

        %% Domain Components
        subgraph DomainServices["Domain Services"]
            OrderMgmt["Order Management"]:::domain
            click OrderMgmt "https://github.com/coip/rebus/blob/master/ibsvc/order.go"
            
            OrderCond["Order Conditions"]:::domain
            click OrderCond "https://github.com/coip/rebus/blob/master/ibsvc/orderCondition.go"
            
            ContractMgmt["Contract Management"]:::domain
            click ContractMgmt "https://github.com/coip/rebus/blob/master/ibsvc/contract.go"
            
            ExecHandler["Execution Handler"]:::domain
            click ExecHandler "https://github.com/coip/rebus/blob/master/ibsvc/execution.go"
            
            Scanner["Scanner Service"]:::domain
            click Scanner "https://github.com/coip/rebus/blob/master/ibsvc/scanner.go"
        end

        %% Utility Components
        subgraph Utils["Utility Components"]
            ErrorHandler["Error Handler"]:::utility
            click ErrorHandler "https://github.com/coip/rebus/blob/master/ibsvc/errors.go"
            
            Common["Common Components"]:::utility
            click Common "https://github.com/coip/rebus/blob/master/ibsvc/common.go"
            
            Constants["Constants"]:::utility
            click Constants "https://github.com/coip/rebus/blob/master/ibsvc/const.go"
            
            Utilities["Utilities"]:::utility
            click Utilities "https://github.com/coip/rebus/blob/master/ibsvc/utils.go"
        end
    end

    %% Relationships
    ClientApps <--> Client
    Client <--> Wrapper
    Wrapper <--> ConnMgr
    ConnMgr <--> TWS
    ConnMgr <--> Decoder
    
    %% Domain Service Relationships
    Wrapper --> OrderMgmt
    Wrapper --> ContractMgmt
    Wrapper --> ExecHandler
    Wrapper --> Scanner
    OrderMgmt --> OrderCond
    
    %% Utility Relationships
    ErrorHandler -.-> Client
    Common -.-> DomainServices
    Constants -.-> DomainServices
    Utilities -.-> DomainServices

    %% Legend
    subgraph Legend
        E["External Systems"]:::external
        C["Core Components"]:::core
        D["Domain Components"]:::domain
        I["Infrastructure Components"]:::infrastructure
        U["Utility Components"]:::utility
    end
```
