Telegram-first ordering system for a bakery. Shops and bakers place orders to the workshop, bakers manage production and ingredient calculations, and admins manage users and the iiko ERP sync.
Two surfaces — a Telegram bot and a Telegram Mini App / web frontend — talk to the same backend.
Modular monolith with clean architecture and dependency inversion. Each service lives under internal/services/<svc>/ with strict layering:
delivery (infra/http, inbound/bot) ─┐
infra/repo (adapters) ─┤──► usecase (ports + service) ──► domain
composition (app/, deps) ─┘
Stack
| Layer | Technology |
|---|---|
| Language | Go 1.26 |
| Database | SQLite (one file, modernc.org/sqlite), queries generated by sqlc |
| Events | Transactional outbox, delivered to the bot in-process |
| Frontend | Go html/template + HTMX 2.0.4 + plain CSS/JavaScript |
One binary — cmd/bakery runs, in one process: the HTML/HTMX web UI and
Telegram Mini App (the only listener), the JSON API (called in-process, not
exposed), the Telegram bot, iiko sync, order cleanup and the outbox relay. It
applies DB migrations on startup.
cmd/
bakery/ the application: web UI + API + bot + background jobs
internal/
config/ env config + dotenv loader
deps/ composition root (InfraDeps + AppDeps)
pkg/ shared packages (authtoken, dbmigrate, enum, helpers, sharedkernel)
inbound/
api/ API handler + middleware (recover, logger)
api/httpx/ shared HTTP primitives, auth middlewares
bot/ Telegram handlers, sessions, notifications
outbound/
db/ SQLite open + sqlc generated code
iiko/ iiko ERP REST client
services/
order/ order domain, use cases, HTTP handlers, outbox relay
monitor/ ingredient calculation (pure domain math)
auth/ login, password, token, RBAC
admin/ user management (orchestrates auth + department)
department/ department CRUD
techcard/ iiko tech-card graph (used by monitor + bot)
sync/ background iiko → DB sync
pkg/
logger/ structured slog logger
migrations/ goose-style SQL migrations
queries/ sqlc SQL source files
templates/ seed data (dish catalog)
Dockerfile, railway.json the deployable image and its Railway config
frontend/ Go HTML/HTMX Mini App (frontend.NewHandler)
internal/application/ CQRS Queries/Commands and ports
internal/backend/ typed API adapter (in-process transport)
internal/web/ handlers, templates, CSS and JavaScript
- Go 1.26+
- sqlc (for SQL codegen)
- golangci-lint (for linting)
Copy .env.example to .env and fill in the values:
cp .env.example .envKey variables:
| Variable | Description |
|---|---|
BOT_ENV |
test or prod |
TEST_BOT_TOKEN / PROD_BOT_TOKEN |
Telegram bot token |
MINI_APP_URL |
Public HTTPS URL of the deployed app |
TELEGRAM_WORKSHOP_CHAT_ID |
Workshop group chat for order notifications |
SQLITE_PATH |
SQLite database file (default data/bakery.db) |
IIKO_HOST / IIKO_LOGIN / IIKO_PASSWORD |
iiko ERP credentials |
ADMIN_USERNAME / ADMIN_PASSWORD |
Initial admin user (created on startup) |
docker compose upgo run ./cmd/bakery # http://localhost:8080make build # go build ./...
make vet # go vet ./...
make test # go test ./...
make lint # golangci-lint run ./...
make sqlc # sqlc generate (run after editing queries/)After editing queries/*.sql, regenerate the sqlc code before building:
make sqlc && make buildgo test ./frontend/...
go vet ./frontend/...The API authenticates via the Authorization header:
tma <initData>— Telegram Mini App: HMAC-validated initData resolved bytelegram_idBearer <token>— Plain web: session token fromPOST /login(username + password)
The frontend BFF exchanges either credential for an HttpOnly,
SameSite=Lax cookie. Browsers submit HTML forms to the BFF; only the BFF
calls the JSON API, inside the process.
- Order service records domain events (
order.created,order.updated, …) and stores them in theorder_outboxtable in the same transaction - The outbox relay hands them to the bot in-process, in order
- The bot notifies the order creator, all bakers, and the workshop group chat
One image from the root Dockerfile; Railway config in railway.json. The app
applies DB migrations automatically on startup. See
docs/deployment.md.