# expressapp/bot-template architecture

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

- Interactive diagram: https://gitdiagram.com/expressapp/bot-template
- Repository: https://github.com/expressapp/bot-template

## Overview

This repository is a Copier template for building pybotx-based bots, rather than a single bot with a defined business use case. Its main runtime workflow receives BotX command and callback HTTP requests, forwards them to the bot runtime, and returns protocol responses; registered command handlers provide the user-facing behavior. The template also supplies health checks, PostgreSQL record persistence, Redis-backed repositories, logging, and configuration. The README documents these capabilities, but several implementations are unsampled; those branches are included without guessing their internal call paths.

Main entry points: [`app/main.py`](https://github.com/expressapp/bot-template/blob/master/app/main.py) (Application lifecycle), [`app/db/sqlalchemy.py`](https://github.com/expressapp/bot-template/blob/master/app/db/sqlalchemy.py) (Database sessions), [`app/api/endpoints/botx.py`](https://github.com/expressapp/bot-template/blob/master/app/api/endpoints/botx.py) (BotX endpoints), [`app/db/record/repo.py`](https://github.com/expressapp/bot-template/blob/master/app/db/record/repo.py) (Record repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["HTTP entry"]
  node_botx["BotX endpoints<br/>[botx.py]"]
  node_health_endpoint["Health endpoint"]
  node_routers["Router registry<br/>[routers.py]"]
end

subgraph group_bot["Bot runtime"]
  node_bot_runtime["Bot runtime<br/>[bot.py.jinja]"]
  node_common_commands["Common commands<br/>[common.py]"]
  node_bot_middleware["Bot middleware"]
  node_bot_errors["Bot error handlers<br/>[internal_error.py]"]
  node_user_search["BotX user search"]
end

subgraph group_data["Data services"]
  node_record_repo["Record repository<br/>[repo.py]"]
  node_crud["CRUD operations<br/>[crud.py]"]
  node_record_model["Record model<br/>[models.py]"]
  node_record_schema["Record schema<br/>[record.py]"]
  node_postgres[("PostgreSQL")]
  node_redis_repos["Redis repositories<br/>[redis_repo.py]"]
  node_callback_repo["Callback repository"]
  node_redis[("Redis")]
end

subgraph group_platform["Application platform"]
  node_application["Application lifecycle<br/>[main.py]"]
  node_db_sessions["Database sessions<br/>[sqlalchemy.py]"]
  node_settings["Settings<br/>[settings.py]"]
  node_logger["Logging<br/>[logger.py]"]
  node_health_service["Health service<br/>[healthcheck.py]"]
end

node_botx_platform(("BotX platform"))

node_botx_platform -->|"sends requests"| node_botx
node_botx -->|"dispatches commands"| node_bot_runtime
node_botx -->|"delivers callbacks"| node_bot_runtime
node_application -->|"mounts routes"| node_routers
node_routers -->|"registers routes"| node_botx
node_routers -->|"registers routes"| node_health_endpoint
node_bot_runtime -->|"registers handlers"| node_common_commands
node_record_repo -->|"uses CRUD"| node_crud
node_record_repo -->|"uses model"| node_record_model
node_record_repo -->|"creates records"| node_record_schema
node_crud -->|"uses sessions"| node_db_sessions
node_record_model -->|"uses base"| node_db_sessions
node_db_sessions -->|"connects to"| node_postgres
node_application -->|"builds sessions"| node_db_sessions
node_application -->|"configures repository"| node_redis_repos
node_application -->|"starts callback worker"| node_callback_repo
node_redis_repos -.->|"uses Redis"| node_redis
node_callback_repo -.->|"uses Redis"| node_redis
node_db_sessions -->|"reads DSN"| node_settings
node_application -->|"reads configuration"| node_settings

click node_botx "https://github.com/expressapp/bot-template/blob/master/app/api/endpoints/botx.py"
click node_health_endpoint "https://github.com/expressapp/bot-template/blob/master/app/api/endpoints/healthcheck.py.jinja"
click node_routers "https://github.com/expressapp/bot-template/blob/master/app/api/routers.py"
click node_bot_runtime "https://github.com/expressapp/bot-template/blob/master/app/bot/bot.py.jinja"
click node_common_commands "https://github.com/expressapp/bot-template/blob/master/app/bot/commands/common.py"
click node_bot_middleware "https://github.com/expressapp/bot-template/tree/master/app/bot/middlewares"
click node_bot_errors "https://github.com/expressapp/bot-template/blob/master/app/bot/error_handlers/internal_error.py"
click node_user_search "https://github.com/expressapp/bot-template/blob/master/app/services/botx_user_search.py"
click node_record_repo "https://github.com/expressapp/bot-template/blob/master/app/db/record/repo.py"
click node_crud "https://github.com/expressapp/bot-template/blob/master/app/db/crud.py"
click node_record_model "https://github.com/expressapp/bot-template/blob/master/app/db/record/models.py"
click node_record_schema "https://github.com/expressapp/bot-template/blob/master/app/schemas/record.py"
click node_redis_repos "https://github.com/expressapp/bot-template/blob/master/app/caching/redis_repo.py"
click node_callback_repo "https://github.com/expressapp/bot-template/blob/master/app/caching/callback_redis_repo.py"
click node_application "https://github.com/expressapp/bot-template/blob/master/app/main.py"
click node_db_sessions "https://github.com/expressapp/bot-template/blob/master/app/db/sqlalchemy.py"
click node_settings "https://github.com/expressapp/bot-template/blob/master/app/settings.py"
click node_logger "https://github.com/expressapp/bot-template/blob/master/app/logger.py"
click node_health_service "https://github.com/expressapp/bot-template/blob/master/app/services/healthcheck.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_botx,node_health_endpoint,node_routers toneBlue
class node_bot_runtime,node_common_commands,node_bot_middleware,node_bot_errors,node_user_search toneAmber
class node_record_repo,node_crud,node_record_model,node_record_schema,node_postgres,node_redis_repos,node_callback_repo,node_redis toneMint
class node_application,node_db_sessions,node_settings,node_logger,node_health_service toneRose
class node_botx_platform toneIndigo
```

## Components

### HTTP entry

- [BotX endpoints](https://github.com/expressapp/bot-template/blob/master/app/api/endpoints/botx.py): `app/api/endpoints/botx.py`
- [Health endpoint](https://github.com/expressapp/bot-template/blob/master/app/api/endpoints/healthcheck.py.jinja): `app/api/endpoints/healthcheck.py.jinja`
- [Router registry](https://github.com/expressapp/bot-template/blob/master/app/api/routers.py): `app/api/routers.py`

### Bot runtime

- [Bot runtime](https://github.com/expressapp/bot-template/blob/master/app/bot/bot.py.jinja): `app/bot/bot.py.jinja`
- [Common commands](https://github.com/expressapp/bot-template/blob/master/app/bot/commands/common.py): `app/bot/commands/common.py`
- [Bot middleware](https://github.com/expressapp/bot-template/tree/master/app/bot/middlewares): `app/bot/middlewares`
- [Bot error handlers](https://github.com/expressapp/bot-template/blob/master/app/bot/error_handlers/internal_error.py): `app/bot/error_handlers/internal_error.py`
- [BotX user search](https://github.com/expressapp/bot-template/blob/master/app/services/botx_user_search.py): `app/services/botx_user_search.py`

### Data services

- [Record repository](https://github.com/expressapp/bot-template/blob/master/app/db/record/repo.py): `app/db/record/repo.py`
- [CRUD operations](https://github.com/expressapp/bot-template/blob/master/app/db/crud.py): `app/db/crud.py`
- [Record model](https://github.com/expressapp/bot-template/blob/master/app/db/record/models.py): `app/db/record/models.py`
- [Record schema](https://github.com/expressapp/bot-template/blob/master/app/schemas/record.py): `app/schemas/record.py`
- **PostgreSQL**
- [Redis repositories](https://github.com/expressapp/bot-template/blob/master/app/caching/redis_repo.py): `app/caching/redis_repo.py`
- [Callback repository](https://github.com/expressapp/bot-template/blob/master/app/caching/callback_redis_repo.py): `app/caching/callback_redis_repo.py`
- **Redis**

### Application platform

- [Application lifecycle](https://github.com/expressapp/bot-template/blob/master/app/main.py): `app/main.py`
- [Database sessions](https://github.com/expressapp/bot-template/blob/master/app/db/sqlalchemy.py): `app/db/sqlalchemy.py`
- [Settings](https://github.com/expressapp/bot-template/blob/master/app/settings.py): `app/settings.py`
- [Logging](https://github.com/expressapp/bot-template/blob/master/app/logger.py): `app/logger.py`
- [Health service](https://github.com/expressapp/bot-template/blob/master/app/services/healthcheck.py): `app/services/healthcheck.py`

### Other components

- **BotX platform**

## Connections

- BotX platform → BotX endpoints: sends requests (evidence: `README.md`)
- BotX endpoints → Bot runtime: dispatches commands (evidence: `app/api/endpoints/botx.py`)
- BotX endpoints → Bot runtime: delivers callbacks (evidence: `app/api/endpoints/botx.py`)
- Application lifecycle → Router registry: mounts routes (evidence: `app/main.py`)
- Router registry → BotX endpoints: registers routes (evidence: `app/api/routers.py`)
- Router registry → Health endpoint: registers routes (evidence: `app/api/routers.py`)
- Bot runtime → Common commands: registers handlers (evidence: `README.md`)
- Record repository → CRUD operations: uses CRUD (evidence: `app/db/record/repo.py`)
- Record repository → Record model: uses model (evidence: `app/db/record/repo.py`)
- Record repository → Record schema: creates records (evidence: `app/db/record/repo.py`)
- CRUD operations → Database sessions: uses sessions (evidence: `app/db/crud.py`)
- Record model → Database sessions: uses base (evidence: `app/db/record/models.py`)
- Database sessions → PostgreSQL: connects to (evidence: `app/db/sqlalchemy.py`)
- Application lifecycle → Database sessions: builds sessions (evidence: `app/main.py`)
- Application lifecycle → Redis repositories: configures repository (evidence: `app/main.py`)
- Application lifecycle → Callback repository: starts callback worker (evidence: `app/main.py`)
- Redis repositories → Redis: uses Redis
- Callback repository → Redis: uses Redis
- Database sessions → Settings: reads DSN (evidence: `app/db/sqlalchemy.py`)
- Application lifecycle → Settings: reads configuration (evidence: `app/main.py`)
