# zeroam/kispy architecture

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

- Interactive diagram: https://gitdiagram.com/zeroam/kispy
- Repository: https://github.com/zeroam/kispy

## Overview

##### Main Components

a) Client Layer:
- It to `KisAuth` component for authentication handling
- Rate limiter component (from rate_limit.py)

- Domestic Stock Services
- Overseas Stock Services

c) Core Infrastructure:
- Authentication System
- Rate Limiting System
- Error Handling System

##### Detailed Component Breakdown

a) For Each Stock Service Domain (Domestic/Overseas):
- Account Management
- Order Processing
- Quote/Price Information
- Real-time Data Handling

b) Shared Components:
- Models Layer
- Response Handlers
- Utility Functions

**[Client Applications]**
- ↓
- [KisClient]
- ↓
**[Authentication Layer] ← → [Rate Limiter]**
- ↓
**┌─────────┴─────────┐**

**[Domestic Stock]  [Overseas Stock]**

- → Account        ├→ Account
- → Order          ├→ Order
- → Quote          ├→ Quote
- → Realtime       ├→ Realtime
- → Analysis       └→ Market Data

##### Important Elements to Highlight

a) Data Flow:
- How requests flow from client through authentication
- Rate limiting checks
- Error handling paths

b) Key Interactions:
- Token refresh flows
- Real-time data streams
- API call patterns

##### Technical Details

- Rate limit annotation (19 calls/second)
- Authentication token management
- Error code handling
- Model transformations

##### Implementation Notes

- Clear separation between domestic and overseas stock operations
- Centralized authentication and rate limiting
- Model-driven design pattern
- Error handling and response processing

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef client fill:#2196F3,stroke:#1565C0,color:white
    classDef auth fill:#4CAF50,stroke:#2E7D32,color:white
    classDef service fill:#FF9800,stroke:#EF6C00,color:white
    classDef model fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef util fill:#757575,stroke:#424242,color:white
    classDef error fill:#F44336,stroke:#C62828,color:white

    %% Client Applications Entry Point
    ClientApps["Client Applications"]
    KisClient["KIS Client"]:::client
    click KisClient "https://github.com/zeroam/kispy/blob/main/kispy/client.py"

    %% Core Infrastructure
    AuthSystem["Authentication System"]:::auth
    RateLimiter["Rate Limiter"]:::util
    ErrorHandler["Error Handler"]:::error
    click AuthSystem "https://github.com/zeroam/kispy/blob/main/kispy/auth.py"
    click RateLimiter "https://github.com/zeroam/kispy/blob/main/kispy/rate_limit.py"
    click ErrorHandler "https://github.com/zeroam/kispy/blob/main/kispy/err_codes.py"

    %% Models Layer
    subgraph Models
        BaseModels["Base Models"]:::model
        AccountModels["Account Models"]:::model
        MarketModels["Market Models"]:::model
    end
    click BaseModels "https://github.com/zeroam/kispy/blob/main/kispy/models/base.py"
    click AccountModels "https://github.com/zeroam/kispy/blob/main/kispy/models/account.py"
    click MarketModels "https://github.com/zeroam/kispy/blob/main/kispy/models/market.py"

    %% Shared Components
    ResponseHandler["Response Handler"]:::util
    Utils["Utilities"]:::util
    Constants["Constants"]:::util
    BaseClasses["Base Classes"]:::util
    click ResponseHandler "https://github.com/zeroam/kispy/blob/main/kispy/responses.py"
    click Utils "https://github.com/zeroam/kispy/blob/main/kispy/utils.py"
    click Constants "https://github.com/zeroam/kispy/blob/main/kispy/constants.py"
    click BaseClasses "https://github.com/zeroam/kispy/blob/main/kispy/base.py"

    %% Stock Services
    subgraph DomesticStock["Domestic Stock Services"]
        DAccount["Account Management"]:::service
        DOrder["Order Processing"]:::service
        DQuote["Quote Information"]:::service
        DRealtime["Real-time Data"]:::service
        DAnalysis["Analysis"]:::service
    end
    click DomesticStock "https://github.com/zeroam/kispy/tree/main/kispy/domestic_stock"
    click DAccount "https://github.com/zeroam/kispy/blob/main/kispy/domestic_stock/account.py"
    click DOrder "https://github.com/zeroam/kispy/blob/main/kispy/domestic_stock/order.py"
    click DQuote "https://github.com/zeroam/kispy/blob/main/kispy/domestic_stock/quote.py"
    click DRealtime "https://github.com/zeroam/kispy/blob/main/kispy/domestic_stock/realtime.py"
    click DAnalysis "https://github.com/zeroam/kispy/blob/main/kispy/domestic_stock/analysis.py"

    subgraph OverseasStock["Overseas Stock Services"]
        OAccount["Account Management"]:::service
        OOrder["Order Processing"]:::service
        OQuote["Quote Information"]:::service
        ORealtime["Real-time Data"]:::service
    end
    click OverseasStock "https://github.com/zeroam/kispy/tree/main/kispy/overseas_stock"
    click OAccount "https://github.com/zeroam/kispy/blob/main/kispy/overseas_stock/account.py"
    click OOrder "https://github.com/zeroam/kispy/blob/main/kispy/overseas_stock/order.py"
    click OQuote "https://github.com/zeroam/kispy/blob/main/kispy/overseas_stock/quote.py"
    click ORealtime "https://github.com/zeroam/kispy/blob/main/kispy/overseas_stock/realtime.py"

    %% Connections
    ClientApps --> KisClient
    KisClient --> AuthSystem
    KisClient --> RateLimiter
    KisClient --> ErrorHandler
    
    AuthSystem --> DomesticStock
    AuthSystem --> OverseasStock
    
    DomesticStock --> ResponseHandler
    OverseasStock --> ResponseHandler
    
    ResponseHandler --> Models
    
    %% Legend
    subgraph Legend
        L1["Client Components"]:::client
        L2["Authentication"]:::auth
        L3["Services"]:::service
        L4["Models"]:::model
        L5["Utilities"]:::util
        L6["Error Handling"]:::error
    end
```
