r/codereview • • 3d ago

Rust Code review request : multi-tenant isolation & state handling for Telegram back-office (daybook)

I'm building Daybook in Rust—a self-hosted Telegram bot, Axum web console, SQLite layer, and MCP endpoint for selling paid-channel access, bookings, and activation codes. It's currently Alpha and not used with real customer funds yet (tracking pre-real-money items in issue #1).

I'd love a second pair of eyes on src/web/finance.rs (payout,reund) execute state handling , src/web/admin_console.rs and src/db.rs

Specifically, I'm looking for feedback on:

  1. Any subtle ways a seller/user could cross tenant or permission boundaries.

  2. Edge cases or race conditions in state transitions / async tasks.

  3. Any Rust/Axum/SQLite patterns that look overly complex or brittle.

Repo: https://github.com/meshdev26/daybook

Even a quick note on one module or pattern would be super helpful.

2 Upvotes

5 comments sorted by

2

u/LaneyrieHafijur 3d ago

Are you enforcing tenant boundaries purely at the handler level, or passing a scoped context down into the db module? Relying on route handlers to always pass the right ID gets brittle fast as the surface area grows, imo.

1

u/Western_College3228 3d ago

it's already a hybrid. Handlers get the user server-side (403 on bad IDs), scoped DB methods check seller_id in SQL (separate from owner sweeps), and 18 isolation tests cover REST, MCP, web, and bot. Weak spots: handlers still pick the scope, get_payout / set_payout_status only check IDs + owner role, and owner bot-scope filtering happens in the web layer instead of SQL. I'm open to a Principal-based scope context and thin DB facade that forces tenant checks, with explicit owner/global methods for sweeps. Any good patterns for that in a single-connection SQLite setup?

0

u/[deleted] 3d ago

[removed] — view removed comment

1

u/Western_College3228 3d ago

Thanks for checking the code! I looked at the current files, and it seems there might be a small mix-up: ​1. We use seller_id (not tenant_id), and payouts don't change a balance column. State changes already run inside transactions with session checks on every request. ​2. Refund queries already use safe parameters (params!), not raw strings. ​3. There is no WebSocket here—just regular web pages and form posts that check the user's session on every request. ​If you saw an issue in a specific place, please share the file and line number so I can fix it. Adding seller_id to those checks is a good extra safety idea too—thanks again!