# s2-streamstore/s2-sdk-rust architecture

> Architecture diagram of the GitHub repository s2-streamstore/s2-sdk-rust, 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/s2-streamstore/s2-sdk-rust
- Repository: https://github.com/s2-streamstore/s2-sdk-rust

## Overview

##### Main Components

a. Client Layer:
- Center the `Client` struct (from src/client.rs) as the main entry point
- `ClientConfig` component for authentication configuration

b. Service Layer (from src/service/):
- Three main service modules:
- Account Service
- Basin Service
- Stream Service

c. API Layer:
- GRPC interface (indicated by the proto directory)
- Connection to the external S2 API service

d. Core Components:
- Append Session Handler (from src/append_session.rs)
- Batching System (from src/batching.rs)
- Types System (from src/types.rs)

##### Relationship Flows

**[Client Applications] → [SDK Client] → [Service Layer] → [gRPC Interface] → [S2 API Service]**
- ↓
- [Core Components]

##### Detailed Component Relationships

**Client Layer:**
- Authentication Config
- Service Layer Management
- API Coordination

**Service Layer:**
- Account Operations
- Basin Management
- Stream Handling

**Core Components:**
- Append Sessions
- Batch Processing
- Type Definitions

##### Implementation Notes

- Version information and SDK compatibility notes
- Document the authentication flow clearly

##### The integration points with the S2 API service

Remember to include example flows for common operations like:
- Basin creation and management
- Stream operations
- Record appending and retrieval
- Batch processing

This will give developers a clear understanding of both the architecture and the practical usage patterns of the SDK.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client_Apps
        App[Client Applications]:::client
    end

    subgraph SDK_Components
        Client[Client]:::core
        click Client "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/client.rs"
        Config[Client Config]:::config
        
        subgraph Services
            ServiceMgr[Service Manager]:::core
            click ServiceMgr "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/service.rs"
            
            AccountSvc[Account Service]:::service
            click AccountSvc "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/service/account.rs"
            BasinSvc[Basin Service]:::service
            click BasinSvc "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/service/basin.rs"
            StreamSvc[Stream Service]:::service
            click StreamSvc "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/service/stream.rs"
        end
        
        subgraph Core
            AppendSession[Append Session Handler]:::core
            click AppendSession "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/append_session.rs"
            Batching[Batching System]:::core
            click Batching "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/batching.rs"
            Types[Types System]:::core
            click Types "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/types.rs"
        end
    end

    subgraph API_Layer
        GRPC[gRPC Interface]:::api
        click GRPC "https://github.com/s2-streamstore/s2-sdk-rust/tree/main/proto/"
        APIImpl[API Implementation]:::api
        click APIImpl "https://github.com/s2-streamstore/s2-sdk-rust/blob/main/src/api.rs"
    end

    subgraph External
        S2[S2 API Service]:::external
    end

    %% Connections
    App --> Client
    Client --> ServiceMgr
    Client --> Config
    
    ServiceMgr --> AccountSvc
    ServiceMgr --> BasinSvc
    ServiceMgr --> StreamSvc
    
    AccountSvc & BasinSvc & StreamSvc --> GRPC
    GRPC --> APIImpl
    APIImpl --> S2
    
    Client --> AppendSession
    Client --> Batching
    Client --> Types

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#b5d3e7,stroke:#333,stroke-width:2px
    classDef config fill:#ffe4b5,stroke:#333,stroke-width:2px
    classDef service fill:#90ee90,stroke:#333,stroke-width:2px
    classDef api fill:#ffd700,stroke:#333,stroke-width:2px
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Client App]:::client
        L2[Core Component]:::core
        L3[Configuration]:::config
        L4[Service]:::service
        L5[API Layer]:::api
        L6[External Service]:::external
    end
```
