Building a family budget bot on $0: Telegram, free-tier AI fallbacks, and Arabic RTL
For four years I tracked my family's spending in an Excel sheet. It died the way most budget sheets die: logging a purchase took too long, and nobody but me ever opened the file. Mizan is what I built to replace it. You message a Telegram bot ("bread 50", a voice note, a photo of a receipt), it saves the entry, and each morning it tells the household how much it can spend today. This post covers…
Four years ago, Mizan's family tracked their spending using an Excel sheet. However, the process became cumbersome, and the file was seldom accessed. To address this, Mizan developed a Telegram bot that allows users to send messages, voice notes, or photos of receipts to log purchases. The bot then provides daily updates on how much the household can spend.
The development of Mizan was guided by a single rule - all services must fit within a free tier and have no long-running servers. This led to the choice of a Next.js 16 App Router for the web + API layer, Hono as the API layer mounted at /api/v1/*, Supabase for database and authentication, and Drizzle for handling queries. The hosting was done through Netlify free tier using OpenNext.
The bot's architecture is divided into layers, with routes and server actions kept thin. They validate input using Zod and call services, which hold the business rules. Repositories are used for Drizzle queries. Every service function that interacts with household data calls requireMembership or requireAdmin first. Drizzle connects as a role bypassing Postgres row-level security.
Telegram's webhook retry policy was considered during development. The handler checks the secret header Telegram sends, deduplicates updates, returns 200, and performs the real work after the webhook response. A slow model call doesn't allow Telegram to resend the message and create a duplicate entry.
Mizan's AI fallbacks include using Text and receipts with Gemini Flash-Lite, then Gemini Flash, followed by Groq gpt-oss-120b and gpt-oss-20b. For voice input, Groq whisper-large-v3 is used first, followed by Gladia, and then Gemini with audio input. If the model fails, the system falls back to local resolutions, such as using bread 50, how much is left, and previously logged items.
The bot supports three currencies - Syrian pounds, dollars, and euros. Amounts are stored in PostgreSQL's numeric type, and arithmetic is handled by a decimal-safe helper. Dates are stored in the household's timezone and displayed accordingly. The app is a PWA, with offline support through IndexedDB and syncs once upon regaining connectivity.
The development process involved unit tests in Vitest for cycle math, currency conversion, daily numbers, and membership checks. The rest of the testing was done using 41 end-to-end scripts that run headless Edge against the dev server. The bot is live and free for any household at https://mizans.netlify.app.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.