Blog
EngineeringFor engineers

One engine, three doors: how Lodge Internet is built

The website, WhatsApp and Telegram are three ways in to one backend that owns every price, stock count and balance. Here is how the pieces fit, and why the clients are kept deliberately simple.

Lodge Internet · 14 November 2026 · 6 min read

Until 21 October 2026, the website and our bot could quote you different totals for the same plan. The bot worked out its own. On that day it started asking the backend instead, and the two answers became one.

That change was small in code and large in principle. It finished something we had been doing for months: moving every number a customer sees into one place.

The rule

The backend is the single source of truth. The website and the bot are clients. They hold no prices, no stock counts, no balances and no rules of their own. They show what the backend returns, and they send back what the customer did.

Everything else in this post follows from that sentence.

The shape

There are three ways in. The website, WhatsApp and Telegram. The last two are one bot service: the conversation code is shared, and only the address and the sending client differ (a Telegram chat's address carries a tg: prefix, so it can never collide with a WhatsApp number).

  website (Next.js)        WhatsApp ─┐
         │                 Telegram ─┴── bot (FastAPI)
         │                                   │
         └──────────────┬────────────────────┘
                        ▼
                backend (FastAPI)
                ├── Postgres   every record
                ├── Redis      short-lived state
                ├── Paystack   card payments and bank transfers
                └── Omada      the hostel Wi-Fi codes

What a customer buys is a voucher: a code for the Wi-Fi at one particular hostel, issued by the TP-Link Omada controller that runs that hostel's network. Most of the business logic is deciding which code to sell, taking the money safely, and getting the code to the person who paid.

The website

The website is Next.js. It has no server routes of its own any more. Every call goes through one module, frontend/lib/apiClient.ts, which is the only place that knows where the backend lives.

When the old Next.js API routes were ported to the backend, we deleted them rather than leaving them as a fallback. The comment that replaced them explains why: they were dead code that only looked authoritative. If the backend address is ever missing, requests now hit a route that doesn't exist and fail with a 404. Loud, not quiet.

Sign-in lives in cookies that no script on the page can read. That has its own post: No token in JavaScript.

The bot

The bot receives a webhook for every incoming message, checks the signature, answers straight away, and does the actual work in a background task. Meta expects a fast reply, and anything slow risks retries and eventually a disabled webhook.

It holds no opinions. It asks the backend for plans, for the checkout total and for whether the service is open, and repeats what it is told. Here is the whole of how it decides what a plan costs:

total = p.get("total")
return total if isinstance(total, (int, float)) else p.get("price")

The fallback exists for an older backend that sent no total. There is no arithmetic.

The same goes for maintenance. One lockdown switch closes the website and the bot together, and the bot reads its maintenance wording from the backend. So the wording can be changed from the admin settings without redeploying the bot. Messages on WhatsApp cost us money, which shapes the bot in other ways: see Designing a chatbot when every message costs money.

The backend

FastAPI on Python, in three layers. The rule is written into our standards and the code is laid out to match.

  • routers/ handle HTTP: parse the request, check who is asking, call a service, shape the response.
  • services/ hold the business logic: pricing, fulfilment, the Omada clients, Paystack.
  • repos/ hold data access. A router never talks to the database directly when a repo exists for that data.

The repos are plain synchronous functions that take and return plain Python values. An async route calls them through run_in_threadpool, so a slow read doesn't stall the other requests a worker is serving.

Errors keep one contract. A route raises ApiError(status, message, code=...), and the client gets back an error message written for the customer plus a stable upper-case code it can branch on.

main.py builds the backend, and its middleware order is commented line by line because the order matters. Starlette runs the last-added middleware first. The lockdown gate is added before CORS on purpose, so CORS wraps it and a "we're closed" response still carries the headers the browser needs to read the message. Payment webhooks stay open during a lockdown, so a customer who paid moments before it started still gets their code.

Two more guards are worth copying. On a developer machine, the backend refuses to start if any setting points at a real service, such as a live payment key or the production email account, so a local run can't spend real money or send real mail. And the interactive API docs are served only locally. In production they would be a complete map of every route, including the admin money operations.

Postgres

Since 1 October 2026 every record lives in Postgres. Every write runs in a SERIALIZABLE transaction and is retried on conflict, which is what the money paths lean on. The repos layer is the reason the switch from Firestore was one setting rather than a rewrite: Moving a live money system off Firestore.

Redis

Short-lived state only: the Omada controller sign-in and the lock around it, verification codes, alert throttling, and each bot conversation's current step.

Paystack

Card payments, and dedicated bank account numbers for transfers into a customer's wallet. The browser's word is never taken for a payment. Both the customer's own claim and Paystack's webhook check the payment with Paystack directly, then share the same fulfilment code, so either can finish the sale and running both changes nothing. More in Webhooks get lost. Payments don't.

Omada

Codes are synced from the controllers into stock pools and stored encrypted. Cloud controllers are reached the way their own dashboard reaches them. Since 9 October 2026, self-hosted controllers are reached through the documented API the controller software provides. The full path of a code has its own post: How a Wi-Fi code gets from a hostel router to your phone.

Why the rule

Every rule a client holds is a rule that can drift. Three clients with their own price logic are three price lists, and sooner or later one of them is wrong. A customer who sees one total on WhatsApp and another on the website has no reason to trust either.

The rule also makes clients cheap to add. Telegram arrived on the same day the prices were unified, and it needed a sending client and an address format, not a second copy of the shop. The same will hold for any future client.

The plan total is the sharpest case. It is computed in exactly one function, in backend/app/services/pricing.py. The plans list quotes it, the payment check verifies against it, and the bot's own helper simply calls it. Early on, the website did part of this sum in the browser. It doesn't now. See Money arithmetic lives in one file.

The trade-off

One backend means one place to fail. If it is down, every door is closed at once. We accept that, because a door that stays open with stale prices is worse than a maintenance page.

Clients also wait on a network round trip for numbers they could have worked out themselves. And the backend runs more than one worker, so anything kept in process memory (rate-limit counters, a short stock-count cache) is per worker, not shared. Anything that must be shared goes to Postgres or Redis.

What's still open

The move to Postgres is finished, but the test suite still runs many of its cases against a local Firestore emulator, because that is what they were written against. Moving them over, and removing the Firestore code they keep alive, is planned and not yet done.

If you are building something similar, start with the rule and enforce it in code review. Ours is in The rules we build by.

Last checked against the product on 14 November 2026.

More in Engineering