# saumya-bhatt/karya architecture

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

- Interactive diagram: https://gitdiagram.com/saumya-bhatt/karya
- Repository: https://github.com/saumya-bhatt/karya

## Overview

##### Main Components (High-Level Architecture)

a) Client Layer:
- Multiple client SDKs (Java, Python, JavaScript)
- REST API interface

b) Core Services:
- Server (API Gateway)
- Scheduler
- Executor

c) Data Layer:
- Repository (PostgreSQL/Aurora)
- Locks (Redis/ElastiCache)
- Queue (RabbitMQ/SQS)
Use database symbols for these components

##### Component Interactions

- Client → Server: Task submission and management
- Server → Scheduler: Task scheduling and management
- Scheduler → Executor: Task execution delegation
- All components ↔ Data Layer: Data persistence and state management

##### Detailed Component Breakdown

For each major component, create sub-sections showing internal architecture:

a) Server Component:
- API Routers (PlanRouter, UserRouter)
- Service Layer
- Domain Layer
- Data Access Layer

b) Scheduler Component:
- Fetcher Service
- Worker Service
- Task Management
- Metrics Collection

c) Executor Component:
- Task Processor
- Connector Framework
- Hook System
- Action Handlers

##### Data Flow Patterns

Following flows:
- Task Creation Flow
- Task Execution Flow
- Hook Processing Flow
- Chained Plan Flow

##### Scaling and Distribution

How components scale horizontally:
- Load balancing layers
- Queue distribution
- Data replication

##### Integration Points

External integration capabilities:
- Email Connector
- Slack Connector
- REST API Connector
- Kafka Connector
- Custom Connectors

##### Monitoring and Observability

Monitoring components:
- Metrics Collection
- Logging System
- Error Handling

Use these visual elements:
- Clear labels and annotations

Important Considerations:

##### Distributed nature
- Multiple instances of components
- Scalability points
- Load balancing

##### Security boundaries
- Internal vs. external communication
- Authentication/authorization points

##### Fault tolerance
- Redundancy patterns
- Failure handling mechanisms

##### Data consistency
- Transaction boundaries
- Data replication flows

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef client fill:#e1f5fe,stroke:#01579b
    classDef core fill:#fff3e0,stroke:#ff6f00
    classDef data fill:#f3e5f5,stroke:#4a148c
    classDef connector fill:#e8f5e9,stroke:#1b5e20
    classDef config fill:#fbe9e7,stroke:#bf360c

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        SDK["Client SDK"]
        ClientConfig["Client Configuration"]
        REST["REST API Interface"]
    end
    click SDK "https://github.com/Saumya-Bhatt/karya/tree/main/client/src/main/kotlin/karya/client/"
    click ClientConfig "https://github.com/Saumya-Bhatt/karya/blob/main/client/src/main/kotlin/karya/client/configs/KaryaClientConfig.kt"

    %% Core Services
    subgraph CoreServices["Core Services"]
        Server["Server (API Gateway)"]
        Scheduler["Scheduler"]
        Executor["Executor"]
    end
    click Server "https://github.com/Saumya-Bhatt/karya/tree/main/servers/server/src/main/kotlin/karya/servers/server/"
    click Scheduler "https://github.com/Saumya-Bhatt/karya/tree/main/servers/scheduler/src/main/kotlin/karya/servers/scheduler/"
    click Executor "https://github.com/Saumya-Bhatt/karya/tree/main/servers/executor/src/main/kotlin/karya/servers/executor/"

    %% Data Layer
    subgraph DataLayer["Data Layer"]
        DB[(PostgreSQL/Aurora)]
        Redis[(Redis/ElastiCache)]
        Queue[(Message Queue)]
    end
    click DB "https://github.com/Saumya-Bhatt/karya/tree/main/data/psql/src/main/kotlin/karya/data/psql/"
    click Redis "https://github.com/Saumya-Bhatt/karya/tree/main/data/redis/src/main/kotlin/karya/data/redis/"
    click Queue "https://github.com/Saumya-Bhatt/karya/tree/main/data/rabbitmq/src/main/kotlin/karya/data/rabbitmq/"

    %% Connectors
    subgraph Connectors["Connectors"]
        Email["Email Connector"]
        Slack["Slack Connector"]
        RestAPI["REST API Connector"]
        Kafka["Kafka Connector"]
        Chained["Chained Connector"]
    end
    click Email "https://github.com/Saumya-Bhatt/karya/tree/main/connectors/src/main/kotlin/karya/connectors/email/"
    click Slack "https://github.com/Saumya-Bhatt/karya/tree/main/connectors/src/main/kotlin/karya/connectors/slack/"
    click RestAPI "https://github.com/Saumya-Bhatt/karya/tree/main/connectors/src/main/kotlin/karya/connectors/restapi/"
    click Kafka "https://github.com/Saumya-Bhatt/karya/tree/main/connectors/src/main/kotlin/karya/connectors/kafka/"
    click Chained "https://github.com/Saumya-Bhatt/karya/tree/main/connectors/src/main/kotlin/karya/connectors/chained/"

    %% Core Domain
    subgraph CoreDomain["Core Domain"]
        Entities["Entities"]
        Repos["Repositories"]
        QueueIF["Queue Interfaces"]
        LocksIF["Locks Interface"]
    end
    click Entities "https://github.com/Saumya-Bhatt/karya/tree/main/core/src/main/kotlin/karya/core/entities/"
    click Repos "https://github.com/Saumya-Bhatt/karya/tree/main/core/src/main/kotlin/karya/core/repos/"
    click QueueIF "https://github.com/Saumya-Bhatt/karya/tree/main/core/src/main/kotlin/karya/core/queues/"
    click LocksIF "https://github.com/Saumya-Bhatt/karya/tree/main/core/src/main/kotlin/karya/core/locks/"

    %% Configuration
    subgraph Config["Configuration"]
        MainConfig["Main Configs"]
        Migrations["Database Migrations"]
    end
    click MainConfig "https://github.com/Saumya-Bhatt/karya/tree/main/configs/"
    click Migrations "https://github.com/Saumya-Bhatt/karya/tree/main/configs/migrations/"

    %% Relationships
    SDK --> Server
    ClientConfig --> Server
    REST --> Server
    Server --> Scheduler
    Scheduler --> Executor
    Executor --> Connectors
    Server --> DB
    Server --> Redis
    Server --> Queue
    Scheduler --> DB
    Scheduler --> Redis
    Scheduler --> Queue
    Executor --> DB
    Executor --> Redis
    Executor --> Queue
    CoreDomain --> DataLayer

    %% Apply classes
    class SDK,ClientConfig,REST client
    class Server,Scheduler,Executor core
    class DB,Redis,Queue data
    class Email,Slack,RestAPI,Kafka,Chained connector
    class MainConfig,Migrations config
```
