How insanusmokrassar/ktgbotapi works
Project type and purpose
• Type: Multi-module, Kotlin Multiplatform library (JVM, JS, native)
• Purpose: Provide a strongly-typed, coroutine-based Kotlin interface to Telegram’s Bot API, plus higher-level behavior builders, utilities, and KSP code generation.
Top-level component decomposition
• tgbotapi.core
• tgbotapi.api
• tgbotapi.behaviour_builder
• tgbotapi.behaviour_builder.fsm
• tgbotapi.utils
• tgbotapi.webapps
• tgbotapi.ksp
• Consumer application (example bots)
• External service: Telegram Bot API server
• CI/CD: GitHub Actions / Maven Central / Dokka publishing
Relationships and data flow
a. Core layer (tgbotapi.core)
– Implements HTTP layers via Ktor (RequestExecutor → TelegramBotPipelinesHandler → multipart, download, etc.)
– Defines types/, requests/, updateshandlers/, utils/ in commonMain + platformMain sources.
b. API module (tgbotapi.api)
– Contains IDL-style API definitions (package tgbotapi.api.api) that core & builders implement.
c. Behaviour builders (tgbotapi.behaviour_builder & fsm)
– Layer on core to provide coroutine-based “onCommand”, “waitPhoto” DSL.
– FSM module builds on the base behaviour module.
d. Utilities (tgbotapi.utils)
– Extensions & helpers to simplify filters, flows, JSON formatting, parsing.
– Consumed by behaviour_builder and client code.
e. WebApps module (tgbotapi.webapps)
– Kotlin/JS bindings to Telegram WebApp features (callbacks, UI widgets).
f. KSP plugin (tgbotapi.ksp)
– Compile-time code generation for class casts filler, symbol processor.
g. Consumer bots & examples
– Show sample main() with telegramBot(TOKEN) → uses behaviour_builder.
h. CI/CD & documentation
– GitHub Actions workflows (.github/workflows/*.yml) for testing, publishing to Maven Central, generating docs via Dokka or MkDocs.
Architectural patterns and principles
• Layered architecture:
– Core (foundation)
– API definitions
– DSL / Behaviour (application logic)
– Client code (examples)
• Multiplatform: each module has commonMain, jvmMain, jsMain, native source sets.
• DSL & builder pattern in behaviour modules for event handlers.
• KSP for compile-time metaprogramming.
• CI pipeline for automated testing & publishing.
Recommended elements
• Module names & source‐sets (commonMain, platformMain).
• Ktor HTTP pipeline inside core.
• CI/CD workflows node linking to Gradle build & Maven Central.