# tapanhaz/kite-ticker architecture

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

- Interactive diagram: https://gitdiagram.com/tapanhaz/kite-ticker
- Repository: https://github.com/tapanhaz/kite-ticker

## Overview

##### Main Components
- Client Application: This is the user’s code which imports and instantiates the KiteTicker class, provides callback functions (e.g., on_tick, on_message) and manages the event loop.
- KiteTicker Core Module: The heart of the library, implemented in Cython (see kite_ticker.pyx), which manages the websocket connection, partial Cython optimizations, and callback dispatching.
- External Dependencies:
– Asynchronous Event Loop: Depending on the OS, either uvloop (for Linux) or winloop (for Windows) is set as the event loop policy.
– Zerodha Websocket Server: The external service that the KiteTicker connects to (wss://ws.kite.trade).
- Build/Extension Infrastructure: The setup.py and requirements files indicate that the project uses a build process to compile the Cython module. Prebuilt extensions provided in the prebuilt-extensions folder constitute part of this aspect.

##### Relationships and Interactions
- The Client Application calls into the KiteTicker instance, and registers various asynchronous callbacks.
- KiteTicker uses the asynchronous event loop (configured by uvloop or winloop) to drive operations.
- Upon startup, KiteTicker establishes a websocket connection to the Zerodha endpoint and maintains communication. Data flows from the websocket back to KiteTicker, which then dispatches messages to the appropriate callback functions in the client.
- The build process compiles the Cython module via setup.py using requirements-build.txt – ensuring that the KiteTicker component is optimized.

##### Architectural Patterns & Design Principles
- Asynchronous Event-driven Design: Reflects the use of async callbacks and non-blocking I/O.
- Modular Separation: Keeping the KiteTicker module separate from client code, and isolating the build/extension compilation process.
- Callback-based Notification: External events are handled and forwarded via well-defined callback channels (on_tick, on_order_update, etc.).
- Cross-platform Considerations: The design distinguishes between Windows and Linux based on event loop choices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build/Extension Infrastructure
    subgraph "Build/Extension Infrastructure"
        BP1("setup.py"):::build
        RB("requirements-build.txt"):::build
        PE("prebuilt-extensions"):::build
    end

    %% Runtime Components
    subgraph "Runtime Components"
        CA("Client Application"):::internal
        KT("KiteTicker (Cython Module)"):::internal
        EL("Event Loop (uvloop/winloop)"):::external
        ZW("Zerodha Websocket Server"):::external
    end

    %% Connections between Runtime Components
    CA -->|"calls"| KT
    KT -->|"dispatches"| CA
    KT -->|"uses"| EL
    KT -->|"connects_to"| ZW
    ZW -->|"sends_messages"| KT

    %% Build process compiles the module
    BP1 -->|"compiles_module"| KT

    %% Click Events
    click KT "https://github.com/tapanhaz/kite-ticker/blob/main/kite_ticker.pyx"
    click BP1 "https://github.com/tapanhaz/kite-ticker/blob/main/setup.py"
    click RB "https://github.com/tapanhaz/kite-ticker/blob/main/requirements-build.txt"
    click PE "https://github.com/tapanhaz/kite-ticker/tree/main/prebuilt-extensions"

    %% Style definitions
    classDef internal fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef build fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
```
