# alnyz/asyncline architecture

> Architecture diagram of the GitHub repository alnyz/asyncline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alnyz/asyncline
- Repository: https://github.com/alnyz/asyncline

## Overview

1. **What this repository is**
   - `AsyncLine` is an **async Python client library for the LINE messaging platform**.
   - It is not an app server; it is a reusable SDK that connects user code to LINE’s backend APIs and event stream.

2. **Top-level architecture**
   - The public package is `AsyncLine/`.
   - The central runtime object is the **client** exposed from `main.py` and imported as `Client` in the README.
   - User code typically creates a client, logs in, registers async handlers, then starts the polling/stream loop.

3. **Authentication and session management**
   - `auth.py`, `connections.py`, and `config.py` form the login/session boundary.
   - The library supports multiple login paths mentioned in the README: token, email/password, QR login, and saved session/cert-based reuse.
   - This layer is responsible for establishing and persisting the client identity used by downstream API calls.

4. **Network and transport layer**
   - `http_client.py` is the general HTTP transport wrapper.
   - `lib/Gen/` contains generated service bindings and type definitions, which indicate the library talks to LINE services through generated RPC/Thrift-style clients rather than handwritten request objects.
   - `proto.py` likely contains serialization or protocol helpers used by the transport and service layers.

5. **Service-oriented feature modules**
   - The package is split into domain clients that map to LINE product areas:
     - `talk.py` for messaging/chat actions
     - `buddy.py` for contacts/buddy operations
     - `timeline.py` for social/timeline features
     - `channel.py` for channel-related APIs
     - `call.py` for call/voice features
     - `shop.py` for store/shop-related data
     - `liff.py` for LIFF integration
   - These modules are thin feature boundaries on top of the shared auth/network stack.

6. **Event ingestion and bot loop**
   - `poll.py` and `handler.py` are the event-processing core.
   - The README’s `cli.poll.streams()` and `@cli.hooks(...)` pattern shows the runtime is built around:
     - consuming incoming events from LINE
     - matching them through filters
     - dispatching them to async callback handlers
   - `filters.py` provides event predicates such as command matching.

7. **Callback-driven application model**
   - User bots are assembled by registering handlers against event types.
   - The examples directory demonstrates common bot shapes:
     - simple echo bot
     - conversation bot
     - content mutation/send examples
     - a plugin-based bot layout
   - This makes the library feel like an event-driven framework layered on top of the LINE client.

8. **Models and shared domain objects**
   - `models.py` holds shared data structures used across service modules and handlers.
   - `lib/Gen/ttypes.py` and `lib/Gen/liff/ttypes.py` contain generated request/response/data types, which are part of the contract between the client and LINE’s APIs.
   - This separation keeps transport payloads distinct from higher-level client logic.

9. **Security and message handling**
   - `e2ee.py` suggests optional end-to-end encryption support for message content.
   - `log.py` centralizes logging.
   - `buddy.py`, `talk.py`, and `poll.py` likely rely on these lower-level utilities when processing inbound/outbound message payloads.

10. **LIFF and generated API surface**
   - `liff.py` plus `lib/Gen/liff/` provide a separate integration path for LINE Front-end Framework endpoints.
   - The presence of generated constants and service classes in `lib/Gen/f_LineService.py` and `lib/Gen/liff/f_LiffService.py` indicates two backend API surfaces are supported: core LINE services and LIFF services.

11. **Repository usage boundary**
   - `examples/` is the main consumer-facing boundary of the repo.
   - `setup.py`, `requirements.txt`, `setup.cfg`, and `.travis.yml` indicate standard Python packaging and CI, but they do not change the runtime architecture.
   - The library targets Python 3.6/3.7 and relies heavily on `async/await`.

12. **How data flows through the system**
   - Outbound path: user code -> `Client` -> auth/session -> feature module (`talk`, `timeline`, etc.) -> HTTP/RPC transport -> LINE backend.
   - Inbound path: LINE backend -> poll/stream connection -> handler/filter pipeline -> user async callback -> optional outbound response through the same client.
   - The main architectural boundary is therefore between **user bot logic** and **LINE service access**, with the client package mediating both directions.

Main entry points: [`AsyncLine/main.py`](https://github.com/alnyz/asyncline/blob/master/AsyncLine/main.py) (Client), [`AsyncLine/http_client.py`](https://github.com/alnyz/asyncline/blob/master/AsyncLine/http_client.py) (HTTP), [`AsyncLine/talk.py`](https://github.com/alnyz/asyncline/blob/master/AsyncLine/talk.py) (Talk), [`AsyncLine/handler.py`](https://github.com/alnyz/asyncline/blob/master/AsyncLine/handler.py) (Handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pkg["AsyncLine"]
  node_client["Client<br/>[main.py]"]
  node_auth["Auth<br/>[auth.py]"]
  node_connections["Conn<br/>session transport<br/>[connections.py]"]
  node_config["Config<br/>[config.py]"]
  node_http_client["HTTP<br/>transport<br/>[http_client.py]"]
  node_proto["Proto<br/>[proto.py]"]
  node_models["Models<br/>shared domain types<br/>[models.py]"]
  node_poll["Poll<br/>event stream<br/>[poll.py]"]
  node_handler["Handler<br/>dispatch pipeline<br/>[handler.py]"]
  node_filters["Filters<br/>predicates<br/>[filters.py]"]
  node_talk["Talk<br/>messaging api<br/>[talk.py]"]
  node_buddy["Buddy<br/>contacts api<br/>[buddy.py]"]
  node_timeline["Timeline<br/>social api<br/>[timeline.py]"]
  node_channel["Channel<br/>[channel.py]"]
  node_call["Call<br/>voice api<br/>[call.py]"]
  node_shop["Shop<br/>commerce api<br/>[shop.py]"]
  node_liff["LIFF<br/>[liff.py]"]
  node_e2ee{{"E2EE<br/>security<br/>[e2ee.py]"}}
  node_log["Log<br/>[log.py]"]
end

subgraph group_gen["Generated API"]
  node_line_gen["LINE Gen<br/>generated service bindings<br/>[f_LineService.py]"]
  node_line_types["LINE Types<br/>generated types<br/>[ttypes.py]"]
  node_liff_gen["LIFF Gen<br/>generated service bindings<br/>[f_LiffService.py]"]
  node_liff_types["LIFF Types<br/>generated types<br/>[ttypes.py]"]
end

subgraph group_examples["Examples"]
  node_echo_ex["Echo<br/>example bot<br/>[echo.py]"]
  node_conv_ex["Chat bot<br/>example bot<br/>[conversation.py]"]
  node_send_ex["Send content<br/>example bot<br/>[send_content.py]"]
  node_change_ex["Change content<br/>example bot<br/>[change_content.py]"]
  node_plugin_ex["Plugins<br/>example app<br/>[bot.py]"]
end

node_client -->|"login"| node_auth
node_client -->|"reuse"| node_connections
node_client -->|"configure"| node_config
node_client -->|"stream"| node_poll
node_client -->|"messages"| node_talk
node_client -->|"contacts"| node_buddy
node_client -->|"timeline"| node_timeline
node_client -->|"channels"| node_channel
node_client -->|"calls"| node_call
node_client -->|"shop"| node_shop
node_client -->|"liff"| node_liff
node_talk -->|"transport"| node_http_client
node_buddy -->|"transport"| node_http_client
node_timeline -->|"transport"| node_http_client
node_channel -->|"transport"| node_http_client
node_call -->|"transport"| node_http_client
node_shop -->|"transport"| node_http_client
node_liff -->|"transport"| node_http_client
node_http_client -->|"encode"| node_proto
node_talk -->|"rpc"| node_line_gen
node_talk -->|"types"| node_line_types
node_liff -->|"rpc"| node_liff_gen
node_liff -->|"types"| node_liff_types
node_poll -->|"dispatch"| node_handler
node_handler -->|"match"| node_filters
node_handler -->|"events"| node_models
node_poll -->|"decrypt"| node_e2ee
node_client -->|"log"| node_log
node_echo_ex -->|"uses"| node_client
node_conv_ex -->|"hooks"| node_handler
node_send_ex -->|"send"| node_talk
node_change_ex -->|"mutate"| node_talk
node_plugin_ex -->|"plugins"| node_handler

click node_client "https://github.com/alnyz/asyncline/blob/master/AsyncLine/main.py"
click node_auth "https://github.com/alnyz/asyncline/blob/master/AsyncLine/auth.py"
click node_connections "https://github.com/alnyz/asyncline/blob/master/AsyncLine/connections.py"
click node_config "https://github.com/alnyz/asyncline/blob/master/AsyncLine/config.py"
click node_http_client "https://github.com/alnyz/asyncline/blob/master/AsyncLine/http_client.py"
click node_proto "https://github.com/alnyz/asyncline/blob/master/AsyncLine/proto.py"
click node_models "https://github.com/alnyz/asyncline/blob/master/AsyncLine/models.py"
click node_poll "https://github.com/alnyz/asyncline/blob/master/AsyncLine/poll.py"
click node_handler "https://github.com/alnyz/asyncline/blob/master/AsyncLine/handler.py"
click node_filters "https://github.com/alnyz/asyncline/blob/master/AsyncLine/filters.py"
click node_talk "https://github.com/alnyz/asyncline/blob/master/AsyncLine/talk.py"
click node_buddy "https://github.com/alnyz/asyncline/blob/master/AsyncLine/buddy.py"
click node_timeline "https://github.com/alnyz/asyncline/blob/master/AsyncLine/timeline.py"
click node_channel "https://github.com/alnyz/asyncline/blob/master/AsyncLine/channel.py"
click node_call "https://github.com/alnyz/asyncline/blob/master/AsyncLine/call.py"
click node_shop "https://github.com/alnyz/asyncline/blob/master/AsyncLine/shop.py"
click node_liff "https://github.com/alnyz/asyncline/blob/master/AsyncLine/liff.py"
click node_e2ee "https://github.com/alnyz/asyncline/blob/master/AsyncLine/e2ee.py"
click node_log "https://github.com/alnyz/asyncline/blob/master/AsyncLine/log.py"
click node_line_gen "https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/f_LineService.py"
click node_line_types "https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/ttypes.py"
click node_liff_gen "https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/liff/f_LiffService.py"
click node_liff_types "https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/liff/ttypes.py"
click node_echo_ex "https://github.com/alnyz/asyncline/blob/master/examples/echo.py"
click node_conv_ex "https://github.com/alnyz/asyncline/blob/master/examples/conversation.py"
click node_send_ex "https://github.com/alnyz/asyncline/blob/master/examples/send_content.py"
click node_change_ex "https://github.com/alnyz/asyncline/blob/master/examples/change_content.py"
click node_plugin_ex "https://github.com/alnyz/asyncline/blob/master/examples/plugins_example/bot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_auth,node_connections,node_config,node_http_client,node_proto,node_models,node_poll,node_handler,node_filters,node_talk,node_buddy,node_timeline,node_channel,node_call,node_shop,node_liff,node_e2ee,node_log toneBlue
class node_line_gen,node_line_types,node_liff_gen,node_liff_types toneAmber
class node_echo_ex,node_conv_ex,node_send_ex,node_change_ex,node_plugin_ex toneMint
```

## Components

### AsyncLine

Core client library package

- [Client](https://github.com/alnyz/asyncline/blob/master/AsyncLine/main.py): runtime client · Primary async LINE client used by user code · `AsyncLine/main.py`
- [Auth](https://github.com/alnyz/asyncline/blob/master/AsyncLine/auth.py): session auth · Login and identity/session setup · `AsyncLine/auth.py`
- [Conn](https://github.com/alnyz/asyncline/blob/master/AsyncLine/connections.py): session transport · Connection/session reuse and login path support · `AsyncLine/connections.py`
- [Config](https://github.com/alnyz/asyncline/blob/master/AsyncLine/config.py): runtime config · Client configuration and runtime options · `AsyncLine/config.py`
- [HTTP](https://github.com/alnyz/asyncline/blob/master/AsyncLine/http_client.py): transport · Shared HTTP transport wrapper · `AsyncLine/http_client.py`
- [Proto](https://github.com/alnyz/asyncline/blob/master/AsyncLine/proto.py): protocol helpers · Serialization and protocol utilities · `AsyncLine/proto.py`
- [Models](https://github.com/alnyz/asyncline/blob/master/AsyncLine/models.py): shared domain types · Common data structures used across modules · `AsyncLine/models.py`
- [Poll](https://github.com/alnyz/asyncline/blob/master/AsyncLine/poll.py): event stream · Incoming event ingestion and polling loop · `AsyncLine/poll.py`
- [Handler](https://github.com/alnyz/asyncline/blob/master/AsyncLine/handler.py): dispatch pipeline · Routes events to async callbacks · `AsyncLine/handler.py`
- [Filters](https://github.com/alnyz/asyncline/blob/master/AsyncLine/filters.py): predicates · Event matching and command predicates · `AsyncLine/filters.py`
- [Talk](https://github.com/alnyz/asyncline/blob/master/AsyncLine/talk.py): messaging api · Messaging and chat operations · `AsyncLine/talk.py`
- [Buddy](https://github.com/alnyz/asyncline/blob/master/AsyncLine/buddy.py): contacts api · Buddy and contact operations · `AsyncLine/buddy.py`
- [Timeline](https://github.com/alnyz/asyncline/blob/master/AsyncLine/timeline.py): social api · Timeline and social feature operations · `AsyncLine/timeline.py`
- [Channel](https://github.com/alnyz/asyncline/blob/master/AsyncLine/channel.py): channel api · Channel-related operations · `AsyncLine/channel.py`
- [Call](https://github.com/alnyz/asyncline/blob/master/AsyncLine/call.py): voice api · Calling and voice-related operations · `AsyncLine/call.py`
- [Shop](https://github.com/alnyz/asyncline/blob/master/AsyncLine/shop.py): commerce api · Store and shop-related operations · `AsyncLine/shop.py`
- [LIFF](https://github.com/alnyz/asyncline/blob/master/AsyncLine/liff.py): liff client · LIFF integration surface · `AsyncLine/liff.py`
- [E2EE](https://github.com/alnyz/asyncline/blob/master/AsyncLine/e2ee.py): security · Optional end-to-end encryption support · `AsyncLine/e2ee.py`
- [Log](https://github.com/alnyz/asyncline/blob/master/AsyncLine/log.py): logging · Central logging helpers · `AsyncLine/log.py`

### Generated API

Auto-generated LINE and LIFF service bindings

- [LINE Gen](https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/f_LineService.py): generated service bindings · Generated core LINE service definitions · `AsyncLine/lib/Gen/f_LineService.py`
- [LINE Types](https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/ttypes.py): generated types · Generated core API request and response types · `AsyncLine/lib/Gen/ttypes.py`
- [LIFF Gen](https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/liff/f_LiffService.py): generated service bindings · Generated LIFF service definitions · `AsyncLine/lib/Gen/liff/f_LiffService.py`
- [LIFF Types](https://github.com/alnyz/asyncline/blob/master/AsyncLine/lib/Gen/liff/ttypes.py): generated types · Generated LIFF API request and response types · `AsyncLine/lib/Gen/liff/ttypes.py`

### Examples

Consumer-facing bot and usage patterns

- [Echo](https://github.com/alnyz/asyncline/blob/master/examples/echo.py): example bot · Simple message echo example · `examples/echo.py`
- [Chat bot](https://github.com/alnyz/asyncline/blob/master/examples/conversation.py): example bot · Conversation example · `examples/conversation.py`
- [Send content](https://github.com/alnyz/asyncline/blob/master/examples/send_content.py): example bot · Content sending example · `examples/send_content.py`
- [Change content](https://github.com/alnyz/asyncline/blob/master/examples/change_content.py): example bot · Content mutation example · `examples/change_content.py`
- [Plugins](https://github.com/alnyz/asyncline/blob/master/examples/plugins_example/bot.py): example app · Plugin-based bot layout · `examples/plugins_example/bot.py`

## Connections

- Client → Auth: login · Establishes client identity
- Client → Conn: reuse · Manages session and connection reuse
- Client → Config: configure · Reads runtime settings
- Client → Poll: stream · Starts event polling or streaming
- Client → Talk: messages · Routes messaging actions
- Client → Buddy: contacts · Routes buddy operations
- Client → Timeline: timeline · Routes timeline operations
- Client → Channel: channels · Routes channel operations
- Client → Call: calls · Routes call operations
- Client → Shop: shop · Routes commerce operations
- Client → LIFF: liff · Routes LIFF operations
- Talk → HTTP: transport · Uses shared HTTP transport
- Buddy → HTTP: transport · Uses shared HTTP transport
- Timeline → HTTP: transport · Uses shared HTTP transport
- Channel → HTTP: transport · Uses shared HTTP transport
- Call → HTTP: transport · Uses shared HTTP transport
- Shop → HTTP: transport · Uses shared HTTP transport
- LIFF → HTTP: transport · Uses shared HTTP transport
- HTTP → Proto: encode · Applies protocol helpers
- Talk → LINE Gen: rpc · Calls generated core LINE service
- Talk → LINE Types: types · Uses generated core API types
- LIFF → LIFF Gen: rpc · Calls generated LIFF service
- LIFF → LIFF Types: types · Uses generated LIFF API types
- Poll → Handler: dispatch · Hands incoming events to callbacks
- Handler → Filters: match · Selects callbacks by predicates
- Handler → Models: events · Consumes shared domain objects
- Poll → E2EE: decrypt · May decrypt protected message content
- Client → Log: log · Uses centralized logging
- Echo → Client: uses · Example client entry point
- Chat bot → Handler: hooks · Registers event callbacks
- Send content → Talk: send · Demonstrates outbound messaging
- Change content → Talk: mutate · Demonstrates content changes via messaging APIs
- Plugins → Handler: plugins · Shows plugin-based event dispatch
