Production-ready monorepo for Telegram Mini Apps and web applications.
Vue.js or React. Telegram-native or web-only. Type-safe from database to UI.
Live Demo (React) · Live Demo (Vue)
TypeScript edition: gramkit-ts: the same API, schema and UI on Hono + Drizzle, running on Node or Bun (2.3–3.1× the users on the same box).
| Feature | What You Get |
|---|---|
| Authentication | Email + OTP verification, Telegram OAuth, password reset, account linking |
| Role-Based Access | Admin/Owner/User roles, protected routes, permission checks |
| Real-Time Data | WebSocket, polling, AI streaming, optimistic updates |
| Mobile-First | Responsive layouts, bottom navigation, Telegram Mini App detection |
| Type-Safe API | Auto-generated TypeScript hooks from OpenAPI schema (Kubb) |
| i18n + Theming | Multi-language support, dark/light mode out of the box |
| Payments | YooKassa (cards, embedded widget, auto-renewal) and Telegram Stars (one-time + subscriptions), refunds, hardened money path |
| Bot Notifications | Scheduled per-user-local-time sends with a delivery log and blocked-bot detection |
| Admin Alerts | Purchase / renewal / cancel / failure alerts and deploy announcements in Telegram, with tappable hashtags |
| Background Jobs | ARQ for async tasks, email sending, scheduled jobs, nightly backups |
| Load-tested | Measured against the plain-FastAPI reference of Arjay McCandless's server challenge on the same box: Performance |
Telegram features are opt-in. Leave
BOT__TOKENempty and you have a standard web app.
| Template | Stack | Best For | Demo |
|---|---|---|---|
| React | Next.js 16 + React 19 + Turbopack | SSR, larger ecosystem | react.antonchaynik.ru |
| Vue | Vue 3 + Vite + Pinia | Lighter bundle, simpler state | vue.antonchaynik.ru |
Both include:
- 5 production pages — Home, demos, profile, admin panel (overview, users, analytics, audit log, tasks, broadcasts, marketing links), auth flows
- 17 tech demos — Caching, mutations, infinite scroll, streaming, suspense
- Full auth system — Email+OTP, Telegram OAuth, password reset, session management
- Tailwind CSS v4 + shadcn — Consistent design system, dark mode
- Dev debug panel — "TG Mock" (pretend to run inside Telegram) and "Login as" (switch mock users), independently
core/
├── backend/ # FastAPI, SQLAlchemy, auth, payments, notifications, bot, worker
├── frontend/ # Vue.js shared code (platform, errors, analytics)
└── frontend-react/ # React shared code (platform, errors, analytics)
Write once in core/, import into any app. No copy-paste between projects.
What core gives every app:
- Payments — one
PaymentsServiceover YooKassa and Telegram Stars.- YooKassa: idempotency keys on every charge, the webhook re-fetches the payment instead of trusting the body, at most one live subscription per user (DB-enforced), a dunning state machine for failed renewals (
PAST_DUEwith grace and daily retries), refund webhooks, and an owner alert when a webhook fails. - Telegram Stars: one-time purchases and Stars subscriptions that renew and cancel correctly, plus Stars refunds.
- PostHog events for payment success/failure, including how the user paid and why it failed.
- YooKassa: idempotency keys on every charge, the webhook re-fetches the payment instead of trusting the body, at most one live subscription per user (DB-enforced), a dunning state machine for failed renewals (
- Notifications engine — templates sent in morning/evening slots in each user's local time; a
notification_deliverieslog (one row per attempt) for caps; users who blocked the bot (users.bot_blocked_at) are skipped and un-skipped when they come back. Templates can send text, photos or native polls. seen_features— a per-user JSONB map plusPATCH /users/me/seen-features(atomic merge) for one-time reveals, coachmarks, "what's new" and capped nudges, so each new one is frontend-only.- Telegram admin messages — one sender (HTML with escaping, optional rich body, plain-text fallback so an alert never drops), contextual purchase/renewal/cancel alerts with customer context,
#hashtagsfor tap-to-filter, and a silent🚀 <app> <version> · webhook startedannouncement when each process starts in production. - Ops —
GET /healthreturnsversionandstarted_at, so a rollout is one request to check; nightly database backups to the owners in Telegram and an owner-only/backupcommand (a failedpg_dumpis reported, never sent as an empty file);make backup-db/make restore-db(restores older dumps and fast-forwards migrations). - Errors — API errors reach the UI as an
ApiErrorwith the backend'smessageandcode, for object details and 422 validation errors alike.
| Layer | Technology |
|---|---|
| Backend | Python 3.14+, FastAPI, SQLAlchemy 2.0, Alembic, Pydantic |
| Frontend (Vue) | Vue 3, Vite, TanStack Query, Pinia, shadcn-vue |
| Frontend (React) | Next.js 16, React 19, Turbopack, TanStack Query, shadcn/ui |
| Database | PostgreSQL, Redis |
| Styling | Tailwind CSS v4, CSS variables theming |
| Type Generation | OpenAPI → Kubb → TypeScript hooks |
| Observability | Sentry, Logfire, PostHog (all optional) |
| Optional | aiogram 3.x (Telegram Bot), Cloudflare Tunnel |
The frontend dev server runs natively on your machine; the backend runs in Docker.
http://localhost:3001/template-react
http://localhost:5174/template-vue/
- Fast warm starts (Turbopack / Vite)
- Direct API calls (CORS enabled in dev)
Via nginx + Cloudflare tunnel — for Telegram Mini App testing.
https://local.<your-domain>/template-react
https://local.<your-domain>/template-vue
- HTTPS with valid certificate
- Telegram WebApp authentication works
- Production-like environment
# Clone git clone https://github.com/tonysafonov/gramkit.git cd gramkit # Shared config (Cloudflare tunnel token is optional) cp .env.example .env # App config — pick a template cp apps/template-vue/.env.example apps/template-vue/.env # Vue.js cp apps/template-react/.env.example apps/template-react/.env # React/Next.js # Start (backend in Docker + frontend dev server) make up APP=template-vue # or APP=template-react # Open # http://localhost:5174/template-vue/ or http://localhost:3001/template-react
See docs/guides/NEW_APP_FROM_TEMPLATE.md. In short:
cp -r apps/template-react apps/myapp
# Update: package.json, docker-compose*.yml, .env, ports
make upgrade APP=myapp
make up APP=myappCore has no migrations of its own: each app's Alembic history covers core's models too, so a core model
change needs make migration APP=<app> in every app.
CLAUDE.md → always-on rules, conventions, make workflow
.claude/rules/ → layer conventions, auto-loaded by path (backend, testing, vue, react, errors, ...)
.claude/hooks/ → hard stops for the "never" rules (git add -A, --no-verify, raw pytest, editing gen/)
.mcp.json → Chrome DevTools MCP (headless) for checking UI changes in a browser
Generic work leans on Claude Code's built-ins: /code-review, /security-review, /deep-research,
the Plan / Explore agents and the Workflow tool for multi-agent fan-out. Parallel sessions run in
worktrees (claude -w <name>); .worktreeinclude copies the .env files in.
80/15/5 rule: Contract tests (API, bot) → Business logic → Regression.
| Package | Purpose |
|---|---|
| testcontainers | Real PostgreSQL, not SQLite |
| pytest-xdist | Parallel execution |
| pytest-testmon | Incremental (only changed code) |
| inline-snapshot | Snapshot assertions |
| respx | HTTP mocking (LLM, payments) |
make test APP=myapp # Full parallel suite (app + core) make test-quick APP=myapp # Incremental — sub-second feedback
Each test runs in an isolated transaction with automatic rollback. Core ships reusable contract suites
(core/testing/contracts/) that apps subclass.
gramkit is load-tested the way Arjay McCandless scores servers in his "how many users can this server hold" videos: his multicore server challenge (a 19-endpoint Medium clone, the RealWorld "Conduit" API, on Postgres behind nginx) built as a gramkit app, measured with the challenge's own load generator against the challenge's plain FastAPI example on the same box, same day.
- Box: 2 dedicated vCPU / 4 GB VPS (Xeon Platinum 8260, the challenge's CPU), Postgres and nginx on the same box; the load generator on a separate box in the same datacenter (0.2 ms RTT).
- Score: the most users held for a 5-minute hold with p95 < 500 ms, p99 < 1 s and < 1 % errors (each user reads and writes with think times, like a person).
| Conduit, users held 5 min (2026-11-06) | Users | req/s | p95 / p99 |
|---|---|---|---|
Reference: plain FastAPI + asyncpg, no ORM, no middleware, 2 workers (one per core) (examples/python) |
3,000–3,100 | ~795 | 222 / 717–822 ms |
| gramkit, one worker per core (2 workers, like the reference) | 1,300 | 336–341 | 133–310 / 232–652 ms |
| gramkit, template default (1 uvicorn worker: one core busy, the other idle) | 710 | 182 | 421 / 657 ms |
| gramkit a release earlier, as shipped (2026-11-01, 1 worker) | 220 | 56 | 314 / 610 ms |
With the same worker count, gramkit holds about 42 % of the bare reference, at ~4 ms of app CPU per request against ~1.3 ms. That gap is the price of what the reference leaves out: SQLAlchemy ORM and one transaction per request, the middleware stack (request id, security headers, CORS, access log), the service layer and Pydantic models. 0 errors in every hold.
The 6× from 220 came from profiling under load: one Telegram Bot and one arq pool per process instead of per
request, a DB pool bounded below Postgres' max_connections, pure-ASGI middleware, core's real dependencies instead of
FastAPI dependency_overrides (which rebuild the dependency tree on every request), and log writes off the event
loop. Details in CHANGELOG.md. In production, run one uvicorn worker per core
(--workers N) and size DB__POOL_SIZE so that every process together stays under max_connections.
gramkit-ts is this framework ported to TypeScript (Hono, Drizzle, postgres.js; the same REST API, schema and UI). Both ran the same Conduit bench back to back on 2026-11-08, 2 workers each:
| Conduit, users held 5 min (2026-11-08) | Users | req/s | App CPU per request |
|---|---|---|---|
| gramkit (Python) | 1,200 | 315 | 3.9 ms |
| gramkit-ts on Node | 2,700 | 677 | 1.5 ms |
| gramkit-ts on Bun | 2,800 | 706 | 1.3 ms |
| gramkit-ts on Node, hot queries prepared | 3,300 | 836 | 1.4 ms |
| gramkit-ts on Bun, hot queries prepared | 3,700 | 953 | 1.1 ms |
| Reference: plain FastAPI + asyncpg, no ORM | 2,700 | 709 | 1.4 ms |
The box ran ~10 % slower that night than on 11-06 (the reference: 2,700 vs 3,000–3,100), so compare rows within a table,
not across dates. Details, both benches and raw results:
gramkit-ts docs/benchmarks/2026-11-08-conduit.md.
The method, scripts and pitfalls are packaged as a Claude Code skill:
howmanyusers.
All make commands require APP=<name>:
# Docker make up APP=template-vue # Start services + frontend dev server make down APP=template-vue # Stop services make logs APP=template-vue # View logs make shell-webhook APP=template-vue # Backend shell # Backend make test APP=template-vue # Run tests make lint APP=template-vue # Ruff + import-linter make typecheck APP=template-vue # Pyright make migration msg="..." APP=template-vue # Create migration make upgrade APP=template-vue # Apply migrations make schema APP=template-vue # Generate TypeScript types make backup-db APP=template-vue # Dump the local DB to ./backups/ make restore-db file=<dump> APP=template-vue # Install a dump (wipe + restore + migrate) # Release (optional): bump, push dev, then merge to main and tag make release-dev APP=template-vue BUMP=patch make release-main APP=template-vue # Frontend cd apps/template-vue/frontend pnpm dev # Dev server pnpm build # Production build pnpm typecheck # Type checking
gramkit/
├── .claude/
│ ├── rules/ # Layer conventions, auto-loaded by path
│ └── hooks/ # Guard + session-start hooks
├── core/
│ ├── backend/ # Shared Python (FastAPI, SQLAlchemy)
│ ├── frontend/ # Shared Vue.js code
│ └── frontend-react/ # Shared React code
├── apps/
│ ├── template-vue/ # Vue.js template
│ └── template-react/ # React/Next.js template
├── docs/ # Guides, architecture notes
├── nginx/ # Gateway configuration
├── scripts/ # release.sh, template sync checks
└── Makefile # Unified commands
- Docker & Docker Compose
- Node.js 20+ & pnpm
- Python 3.14+ & uv
- Make
Optional:
- Telegram Bot Token (from @BotFather)
- Cloudflare Tunnel (for TMA testing)
- YooKassa shop credentials (card payments)
- Not a tutorial — Production patterns from real apps shipping to users
- Type-safe end-to-end — Change backend, frontend types update automatically
- Monorepo done right — Shared core without dependency hell
- Escape hatches — Every feature can be disabled or swapped
- Claude Code native — Rules and guard hooks tuned to this codebase
- Two frameworks — Same patterns in Vue and React, pick your preference
See CHANGELOG.md. Upgrading from an earlier sync? Read its Breaking section first: several releases add core columns that need a migration in every app.
- Fork the repository
- Create a branch:
git checkout -b feature/your-feature - Make changes and test:
make test APP=template-vue - Commit:
git commit -m "feat: your feature" - Push and open a Pull Request
MIT — See LICENSE