# Architecture

go-bot keeps each chat platform in its own package under `core/`; the only thing they share is the reply convention.

## System overview

```mermaid
flowchart LR
  App[Your application] -->|New / Reply / Start| TG[core/telegram]
  App -->|New / Reply / Start| DC[core/discord]
  App -->|New / Reply / Start| LN[core/line]
  TG -->|long polling, outbound| TGA[Telegram Bot API]
  DC -->|WebSocket gateway + REST, outbound| DGA[Discord API]
  LNA[LINE Messaging API] -->|HTTPS webhook, inbound| LN
  LN -->|reply / push| LNA
```

## Layers

| Layer | Packages | Responsibility |
|---|---|---|
| Application | your code | Registers one `ReplyHandler` per bot, calls `Send*` methods |
| Platform adapter | `core/telegram`, `core/discord`, `core/line` | Transport lifecycle, event dispatch into `Input`, sending, media download, interactive state |
| Platform SDK | `go-telegram/bot` v1.20.0, `bwmarrin/discordgo` v0.29.0, `line-bot-sdk-go/v8/linebot` v8.18.0 | Wire protocol; still reachable through `Input.Raw` |
| Shared utility | `github.com/pardnchiu/go-pkg/utils` | UUIDs for saved filenames and Discord component IDs |

Single-platform Go libraries such as `go-telegram-bot-api/telegram-bot-api` and `tucnak/telebot` (Telegram), `bwmarrin/discordgo` (Discord), and `line/line-bot-sdk-go` (LINE) each cover one platform's API. go-bot builds on `go-telegram/bot`, `discordgo`, and `line-bot-sdk-go`, and runs a Telegram bot, a Discord bot, and a LINE bot under the same `New` / `Reply` / `Start` / `Close` lifecycle; the raw SDK event of each incoming message stays available in `Input.Raw`.

## Cross-cutting rules

| Rule | Effect |
|---|---|
| No shared `internal` package | Each package declares its own `Input`, `ReplyHandler`, `Status`; identifiers differ (`int64` chat IDs on Telegram, string snowflakes on Discord, source IDs on LINE) |
| One handler, synchronous | `Reply(handler)` replaces any previous handler; a non-empty return is sent back automatically |
| `context.Context` on every network call | Every `Send*`, `Delete`, `Save`, and status call accepts `ctx` |
| `Close` instead of `Stop` | Matches `io.Closer`; safe to call more than once |
| Platform-native interactions | Telegram uses inline keyboards and ForceReply, Discord uses components and modals, LINE has none |

## Related pages

- [Bot Lifecycle](/core-concepts)
- [Reply Handler](/reply-handler)
- [API Reference](/api-reference)
- Full module diagrams: [doc/architecture.md](https://github.com/pardnchiu/go-bot/blob/master/doc/architecture.md)
