RozMakc
Back to work
In developmentEngineering demo

Case study 04

Telegram Commercea store that lives inside Telegram

A catalog, cart, checkout, order history and admin dashboard for a Telegram Mini App. Prices, stock and permissions are always checked on a FastAPI backend; the Mini App renders what the server returns.

Role
Personal project, built end-to-end
Status
Mini App and bot ready · live bot pending credentials

Stack

  • Next.js
  • React
  • TypeScript
  • FastAPI
  • Python
  • PostgreSQL
  • SQLAlchemy 2
  • aiogram
  • Telegram Web Apps

The browser demo runs in an isolated sandbox and is never treated as a verified Telegram identity. Use Demo Mode to explore orders and reset state. A live bot link is shown only after a bot username and HTTPS Mini App URL are configured.

storefront-preview
Catalog2

Pulse Headphones

Slate Stand

Aurora Lamp

Catalog artwork used by the demo storefront

Product experience

Screens captured from the demo

Real screenshots of the running Mini App and admin dashboard with seeded demo data, not mockups. Open an image to enlarge it.

Click an image to enlarge

Overview

One product flow across bot, Mini App and API

Telegram Commerce is a separate engineering demo, not a feature of MiniBooking. The Mini App handles discovery and checkout; the aiogram bot opens the app, lists orders and profile data, and delivers order notifications from the outbox.

The backend is the only authority for pricing, stock, carts, orders and admin rights. The frontend keeps no trusted business state: it sends product IDs and quantities, then displays the recalculated cart returned by the server.

  • Catalog, categories, product details and server-side search
  • Cart synchronized with the backend on every change
  • Checkout that creates a pending order without a payment provider
  • Order history and a session-scoped profile
  • Admin dashboard for orders, statuses and products

Mini App

Seven screens, one server contract

Each screen is a route in the same Next.js app. Data comes from the commerce API; nothing is hard-coded in the client.

  1. 01

    Home / Catalog

    Server-side search, category filters, sorting and pagination over the seeded catalog.

  2. 02

    Categories

    Category cards with live product counts and artwork stored in the repository.

  3. 03

    Product details

    Price, availability, quantity selection and add-to-cart against the real product record.

  4. 04

    Cart

    Every quantity change is persisted through the API; unavailable lines block checkout.

  5. 05

    Checkout

    Name, phone and comment. The order is created as pending with an idempotency key.

  6. 06

    My orders

    Order list scoped to the current user, with a detail view and status timeline.

  7. 07

    Profile

    Verified Telegram identity or an explicitly labelled browser sandbox, plus demo reset.

Architecture

A modular monolith with a clear trust boundary

The Mini App and the portfolio site share one Next.js deployment. FastAPI owns authentication, business rules and persistence; PostgreSQL stores users, carts, orders and stock.

Telegram Mini App

Next.js · Web Apps SDK

Telegram bot

aiogram 3 · commands

HTTPS

Web deployment

Next.js · same-origin API

same-origin /api rewrite

Commerce API

FastAPI · sessions · validation

SQL · transactions

PostgreSQL

users · carts · orders · stock

queued order events

Notification outbox

durable order events

Telegram initData is verified on the server. The resulting session is a signed HttpOnly cookie, and admin rights are checked from ADMIN_TELEGRAM_IDS on every request.

Request path and data ownership

Authentication

Telegram identity, verified on the server

The Mini App sends Telegram.WebApp.initData to FastAPI. The API validates the HMAC signature and auth_date freshness before it reads a Telegram ID.

  • Official initData HMAC check against the bot token
  • auth_date freshness window; expired payloads are rejected
  • Telegram ID extracted only from verified initData
  • Own signed HttpOnly session cookie instead of browser storage
  • Admin access resolved from ADMIN_TELEGRAM_IDS on the server
  • Browser sandbox identities are isolated and never admin

Request flow

  1. 01The Mini App opens with initData supplied by Telegram.
  2. 02FastAPI verifies the signature and the auth_date timestamp.
  3. 03A user row is created or loaded by Telegram ID.
  4. 04A signed session cookie is issued; the admin flag is never stored in it.
  5. 05Cart and order requests resolve the user from the session, not from a request body.

Demo modes

A real Telegram path and an explicit sandbox

The two modes share the same API but never share identity or data.

Browser Demo Mode

Sandbox
  • Auto-creates an isolated sandbox user per browser
  • Separate cart and orders from every Telegram account
  • Enabled locally, or in production only with PUBLIC_SANDBOX
  • Never receives admin rights and can be reset

Live Telegram Mini App

Production path
  • Requires a configured bot token and HTTPS
  • initData is verified before any session is issued
  • Admin dashboard follows ADMIN_TELEGRAM_IDS
  • Bot commands and outbox notifications are implemented; live delivery needs a bot token and an HTTPS Mini App URL

Engineering decisions

What shaped the implementation

Constraints were chosen to keep the demo honest and operable without extra infrastructure.

  1. 01

    Server-owned pricing and stock

    The client sends product IDs and quantities only. The backend re-reads the cart, checks availability, recalculates totals and stores a snapshot of every order line.

  2. 02

    Idempotent order creation

    Checkout sends an Idempotency-Key. A unique constraint on user and key turns a repeated submit into the same order instead of a duplicate.

  3. 03

    Signed HttpOnly sessions

    Telegram identity is exchanged for a short-lived signed cookie. No token or admin flag is exposed to client JavaScript, and permissions are re-checked per request.

  4. 04

    Transactions plus an outbox

    Order and stock changes commit in one transaction. Notification events are written to an outbox so the Telegram API is never on the checkout path.

  5. 05

    Modular monolith

    One FastAPI module and one Next.js app. No microservices, Redis, Celery or Kubernetes; the demo stays reproducible on a single host.

  6. 06

    Documented route deviation

    The specification names /demos/telegram-commerce/admin. The implementation uses /work/telegram-commerce/admin to keep all case studies under the same namespace; the deviation is recorded in the decisions log.

Scope and limits

What this demo deliberately does not claim

The project demonstrates the flow, not commercial operation.

  • No payment provider is connected; checkout creates a pending order only.
  • No customer reviews, ratings, sales metrics or client logos.
  • The catalog is a seeded demo assortment with generated artwork.
  • The full Docker Compose stack (PostgreSQL, migrations, API, web) was built and run end-to-end locally; public deployment with TLS is not included.
  • The bot is implemented and tested, but it has not been connected to a live Telegram token in this environment, so live command delivery is not verified.

Try it

Walk through the store in your browser

Demo Mode creates a disposable sandbox with its own cart and orders. You can reset it at any time.

Open browser demo