A Telegram bot for expense tracking. You send it a message, and it extracts the transactions with a Mistral LLM, stores them in MongoDB and replies with what it understood.
Supported inputs:
| Input | How it is processed |
|---|---|
| Text | extracted directly by the LLM |
| Photo | OCR, then extraction |
| Audio | transcription, then extraction |
| OCR, then extraction | |
| CSV | parsed from the Bolt ride export |
Commands: /excelreport returns every entry of the chat as an .xlsx spreadsheet, and /ping
replies pong. Each chat is limited to 15 messages per 24 hours, audited in the database.
DDD with Clean Architecture, with the dependency rule always pointing inwards:
src/
├── domain/ entities, domain errors, ports (interfaces) and use cases
├── infra/ adapters: Telegram, Mistral, MongoDB, ExcelJS, CSV
└── main/ composition root, the only place that picks concrete implementations
- Ports & Adapters — the domain only knows interfaces (
IAIClient,ITransactionRepository,IExpenseReportWriter,IFileLinkResolver...). Nothing undersrc/domainimportsinfra/,telegraf,mongodb,exceljsorzod. - Constructor dependency injection, without a container: the object graph is wired in
src/main/container.ts. - Repository + Data Mapper — explicit mappers translate MongoDB documents into entities and back, keeping the database schema out of the domain.
- Value Object —
Amountvalidates currency and value, and owns theisExpense()rule. - Anti-corruption layer —
CsvTransactionParserisolates the format of the Bolt export. - Domain errors — use cases throw typed errors, and the bot layer translates them into the messages sent to the user.
Requires Node 20+, pnpm, a MongoDB instance, a bot created through @BotFather and a Mistral API key.
pnpm install
Create a .env file in the project root:
BOT_TOKEN=your_telegram_token MISTRAL_API_KEY=your_api_key MONGO_URL=mongodb://localhost:27017 MONGO_DB_NAME=expense_manager MAX_FILE_SIZE=5242880 DAILY_MESSAGE_LIMIT=15
MAX_FILE_SIZE (defaults to 5 MB) and DAILY_MESSAGE_LIMIT (defaults to 15) are optional.
pnpm dev # development with tsx pnpm build # compile to dist/ pnpm start # run the build pnpm lint-fix # eslint --fix and prettier