Skip to content
Nap20192Public

About

Bakery ordering and production management with Telegram, a web app, and iiko integration.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

551 Commits

Folders and files

Repository files navigation

Bakery

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.


Architecture

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.


Directory layout

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

Getting started

Prerequisites

Configuration

Copy .env.example to .env and fill in the values:

cp .env.example .env

Key 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)

Run with Docker Compose

docker compose up

Run locally

go run ./cmd/bakery          # http://localhost:8080

Development

make 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 build

Frontend

go test ./frontend/...
go vet ./frontend/...

Authentication

The API authenticates via the Authorization header:

  • tma <initData> — Telegram Mini App: HMAC-validated initData resolved by telegram_id
  • Bearer <token> — Plain web: session token from POST /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.


Events

  1. Order service records domain events (order.created, order.updated, …) and stores them in the order_outbox table in the same transaction
  2. The outbox relay hands them to the bot in-process, in order
  3. The bot notifies the order creator, all bakers, and the workshop group chat

Deploy

One image from the root Dockerfile; Railway config in railway.json. The app applies DB migrations automatically on startup. See docs/deployment.md.

About

Bakery ordering and production management with Telegram, a web app, and iiko integration.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages