# chryssaaliferi/rudder-sdk-kotlin architecture

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

- Interactive diagram: https://gitdiagram.com/chryssaaliferi/rudder-sdk-kotlin
- Repository: https://github.com/chryssaaliferi/rudder-sdk-kotlin

## Overview

##### Project Type and Purpose
- This is a multi-module SDK aimed at enabling event tracking and user analytics from Android and Kotlin JVM applications.
- The SDK provides core functionality (in the “core” module) that is extended by platform-specific implementations (e.g., the “android” module for Android applications and “kotlin-jvm-app” for JVM use cases).
- Sample applications (“app” and “kotlin-jvm-app”) illustrate how to integrate the SDK into client projects.

##### Main Components
- Platform-Specific SDK Modules:
- Android SDK Module: Contains packages for Android-specific initialization, configuration, lifecycle management, and various plugins (analytics, logging, plugins for deeplinks, screen recording, session tracking, etc.).
- Kotlin JVM SDK (and associated sample): Focused on non-Android environments that use the core functionalities provided by the SDK.
- Core SDK Module:
- The “core” module centralizes core logic like event modeling, network communications (HTTP client, error handling), storage (event batching, key-value storage), policies (flush policies), and plugin management. It provides the base interfaces and utility functions used by the platform-specific modules.
- Sample Applications:
- The “app” directory contains an Android sample application that demonstrates SDK initialization (e.g., Analytics, Configuration) and usage (identify, track, etc.).
- The “kotlin-jvm-app” directory includes a sample JVM application, showing how to integrate and initialize the SDK on a JVM environment.
- Test Suites and Build Infrastructure:
- Each module (android, core, etc.) includes extensive test directories that validate functionality of plugins, network modules, storage utilities, and more.
- Build configuration files (e.g., Gradle scripts, settings file) ensure that dependencies and module interactions are properly configured.

##### Relationships and Interactions
- The Sample Applications depend on the Android/Kotlin-JVM SDK modules for initializing analytics, capturing user events (track, identify), and using plugins.
- The Android module interacts with the core module to leverage shared utilities such as networking, storage, and event queuing.
- The plugin system (present in both android and core) lets you extend and modify the default behavior of analytics (e.g., screen info, device info, lifecycle events).
- Testing modules validate the implementations of each component, ensuring that the core services as well as platform-specific plugins work correctly.
- Build scripts and GitHub workflows (e.g., lint.yml) indicate the CI/CD and quality control process.

##### Architectural Patterns and Design Principles
- Modular Architecture: The separation between core, android, and JVM modules promotes reusability and separation of concerns.
- Plugin Pattern: The design utilizes plugins for various analytics aspects (e.g., lifecycle management plugins, custom plugins in the sample app), allowing for extensibility.
- Separation of Concerns: Distinct layers for event data models, network communication, storage management, and user identification enable maintainable code.
- Test-Driven Development (TDD): The extensive test folders indicate an emphasis on unit testing and integration testing of each component.

##### Elements
- Android SDK, Kotlin JVM SDK, Core SDK, Sample Application (App), Test Suites, CI/CD Infrastructure.
- Where typical SDK calls (like initialize, track, identify) occur and how they propagate through the system.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Sample Applications
    subgraph "Sample Applications"
        A1("Android Sample App"):::sample
        A2("Kotlin JVM Sample App"):::sample
    end

    %% Platform Specific SDK Modules
    subgraph "Platform SDK Modules"
        B1("Android SDK Module"):::sdk
        B2("Kotlin JVM SDK Module"):::sdk
    end

    %% Core SDK and its Subcomponents
    subgraph "Core SDK Module"
        C1("Core SDK Module"):::core
        C2("Network & Storage Manager"):::core
        C3("Plugin System (Core)"):::plugin
    end

    %% Android Plugin System (specific to Android SDK)
    F("Plugin System (Android)"):::plugin

    %% Testing Suites
    subgraph "Testing Suites"
        T1("Android Tests"):::test
        T2("Core Tests"):::test
    end

    %% Build & CI/CD
    subgraph "Build & CI/CD"
        BS("Build Scripts"):::ci
        CI("CI/CD"):::ci
    end

    %% External Services
    EX("External Analytics Services"):::external

    %% Relationships between components
    A1 -- "initializes" --> B1
    A2 -- "initializes" --> B2

    B1 -- "calls_core" --> C1
    B2 -- "calls_core" --> C1

    B1 -- "registers" --> F

    C1 -- "manages" --> C3
    C1 -- "handles" --> C2
    C2 -- "sends_events" --> EX

    T1 -- "tests" --> B1
    T2 -- "tests" --> C1

    BS -- "builds" --> B1
    BS -- "builds" --> C1

    CI -- "orchestrates" --> BS
    CI -- "triggers" --> T1
    CI -- "triggers" --> T2

    %% Click Events
    click B1 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/android/src/main/kotlin/com/rudderstack/sdk/kotlin/android"
    click B2 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/blob/main/kotlin-jvm-app/src/main/java/com/rudderstack/android/kotlin_jvm_app/main.kt"
    click C1 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/core/src/main/kotlin/com/rudderstack/sdk/kotlin/core"
    click A1 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/app/src/main/java/com/rudderstack/sampleapp"
    click F "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/android/src/main/kotlin/com/rudderstack/sdk/kotlin/android/plugins"
    click C3 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/core/src/main/kotlin/com/rudderstack/sdk/kotlin/core/plugins"
    click T1 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/android/src/test/kotlin/com/rudderstack/sdk/kotlin/android"
    click T2 "https://github.com/chryssaaliferi/rudder-sdk-kotlin/tree/main/core/src/test/kotlin/com/rudderstack/sdk/kotlin/core"
    click BS "https://github.com/chryssaaliferi/rudder-sdk-kotlin/blob/main/build.gradle.kts"
    click CI "https://github.com/chryssaaliferi/rudder-sdk-kotlin/blob/main/.github/workflows/lint.yml"

    %% Styles
    classDef sample fill:#f4cccc,stroke:#333,stroke-width:1px;
    classDef sdk fill:#c9daf8,stroke:#333,stroke-width:1px;
    classDef core fill:#ffeb9c,stroke:#333,stroke-width:1px;
    classDef plugin fill:#d9ead3,stroke:#333,stroke-width:1px;
    classDef test fill:#ead1dc,stroke:#333,stroke-width:1px;
    classDef ci fill:#d0e0e3,stroke:#333,stroke-width:1px;
    classDef external fill:#d5a6bd,stroke:#333,stroke-width:1px;
```
