Skip to content

Development ​

Prerequisites ​

  • Go 1.27
  • Node.js 26 and npm
  • golangci-lint 2.15 (for make lint)
  • Docker (optional, for the image)

Setup ​

bash
cp .env.example .env   # placeholders only; put a real test bot token here, never commit it
make build             # builds the web app and the binary
make run               # runs with the variables from .env

Open http://localhost:8080. The health check is /healthz.

Day-to-day ​

CommandWhat it does
make testGo tests with the race detector, then web tests
make lintgo vet, golangci-lint, oxlint and the TypeScript check
make webBuilds the web app into web/dist
make buildWeb app + binary with the web app embedded
make dockerBuilds the container image

For fast front-end work run the Go server (make run) and, in another terminal, cd web && npm run dev. The Vite dev server proxies /api and /healthz to localhost:8080. The session cookie (__Host-session, Secure) works on http://localhost in current browsers; use localhost, not 127.0.0.1 or a LAN address.

First run ​

  1. Set BOOTSTRAP_ADMIN_PHONE, open the bot, send /start and share your contact: you become the first admin.
  2. Log in at /login (the code arrives in Telegram) and fill in your name on your user card.
  3. Add the houses (Admin → Houses) and, if needed, residency statuses; registration opens once at least one house and one status exist.
  4. Set the community name and welcome text (Admin → Site). The admin home page (Admin → Overview) lists what is still missing and shows the registration link with its QR code: pin it in the community chat.

Web app ​

  • web/src/api/ — DTO types (types.ts) and one TanStack Query hook per endpoint (public.ts, admin.ts). All calls go through api() in client.ts.
  • web/src/pages/ — one file per screen; web/src/pages/admin/ for the admin panel.
  • The API answers with error codes only. lib/errors.ts turns them into texts: errors.<code> for the request and validation.<reason> for each field.
  • Admin-entered texts are per locale; lib/localized.ts picks the current language, then the site's default language, then any filled value.
  • Tests render the whole app with renderApp(path) (src/test/render.tsx) over a fake API from mockApi(routes) (src/test/api.ts), with synthetic fixtures from src/test/fixtures.ts.

The Telegram bot ​

  • Create a bot with @BotFather and put its token in TELEGRAM_BOT_TOKEN (use a separate test bot locally).
  • The bot reads the community chats it is added to. To receive every group message, turn privacy mode off in @BotFather (/setprivacy → Disable) or make the bot an admin of the group; with privacy mode on, Telegram delivers only commands and replies to the bot. The bot never answers in groups; reactions come later as flows.
  • Chats and labels: add your test bot to a test group from the Telegram account linked to your local admin; the group appears in Chats as accepted. See Telegram bot setup. With PUBLIC_URL=http://localhost:… the bot puts links into the message text instead of buttons (Telegram refuses non-https buttons).
  • Locally the bot uses long polling (TELEGRAM_UPDATES=polling); on Railway use webhook. The webhook path is derived from APP_SECRET, and Telegram's calls must carry TELEGRAM_WEBHOOK_SECRET.

Resident cabinet and PWA ​

  • /my is the resident cabinet (web/src/pages/cabinet/). Its navigation comes from web/src/cabinet/sections.ts and its home page from the card list in web/src/cabinet/homeCards.ts: a module adds a section or a card there, not in the layout.
  • /cabinet in the bot sends a one-time login link (/login/link?t=…, 5 minutes). Opening the page spends nothing; the page's POST /api/v1/auth/link does. Other code can mint a link for one user with AuthService.CreateLoginLink(ctx, userID, "/my/…"); never put such links into group chats.
  • The manifest is generated by the server at /site.webmanifest (community name, start_url /my).
  • web/public/sw.js is a hand-written service worker: it only serves offline.html when a page load fails and never touches /api/, /site/, /mcp, /oauth. It is registered in production builds only, so npm run dev runs without it; check it with make build && make run.

Modules and the information feed ​

  • Built-in modules are Go code registered in cmd/homelander/main.go (ModuleService.Defs); the modules table only keeps an admin's on/off choice and settings (a missing row is the module's default). GET /api/v1/modules gives the cabinet the navigation of the modules that are on.
  • A module owns the data keys under its code (feed.): its items have owner = module:<code>, admins and MCP can change only their visibility, and they are not served while the module is off. ModuleDef.Ensure creates them when the module is turned on and at startup.
  • The feed (internal/domain/feed_service.go): a published post goes once to every chat or topic its labels reach (Notifier.SendToLabels, outbox origin feed:<id>), as a photo when it has an image (the outbox worker loads the asset at send time). The fake Telegram in cmd/homelander records photos as [photo] <caption>.

Backups ​

Locally the service backs ./data/homelander.db up into ./data/backups once a day, and right after the first start. internal/backup holds the snapshot, encryption, history and the scheduler; homelander backup and homelander restore are the command line. To try a restore on a throwaway copy (the restore needs the service stopped):

bash
DATABASE_PATH=/tmp/hl/homelander.db ./homelander backup
DATABASE_PATH=/tmp/hl/homelander.db ./homelander restore --from /tmp/hl/backups/<file> --yes

S3 lives in internal/backup/s3.go (minio-go). Tests never touch the network: internal/backup/s3fake is an in-memory S3 server. To try S3 by hand, run MinIO locally (docker run -p 9000:9000 minio/minio server /data), create a bucket, and set BACKUP_S3_ENDPOINT=http://localhost:9000, BACKUP_S3_PATH_STYLE=path and MinIO's keys.

Details: backups.md.

Deploying on Railway ​

See deploy-railway.md: the infrastructure is a local, git-ignored .railway/railway.ts made from docs/railway.example.ts; secrets are set in the Railway UI.

Documentation site ​

The docs site is VitePress built from docs/ itself; its config is docs/.vitepress/config.mts. make docs-dev serves it with live reload, make docs builds it (a dead link fails the build), and the Docs workflow publishes it to GitHub Pages on every merge to main. docs/superpowers/ is left out.

The build also writes sitemap.xml and gives every page a canonical link and, where an English page has a Ukrainian copy, hreflang links between the two. DOCS_URL sets the public address they use (default https://igorrius.github.io/homelander-bot/), together with DOCS_BASE for another host. The Google Search Console verification tag is in the config's head.

The presentation is two static pages outside VitePress: docs/public/presentation/index.html (English) and docs/public/uk/presentation/index.html (Ukrainian), with the shared deck.css, deck.js and the Railway QR code in docs/public/presentation/. Their screenshots are the docs' own, so make screenshots updates them too. A change to one language goes into the other as well. VitePress's dev server does not open a folder's index.html by itself: in make docs-dev, open /homelander-bot/presentation/index.html.

  • User-facing pages have a Ukrainian copy under docs/uk/ with the same path. Change both in the same pull request. Developer pages (this one, releasing, ADRs) are English only.
  • Ukrainian headings keep the English anchor as a custom id (## Відновлення {#restore}), so #anchor links work in both languages.
  • Bold UI labels match the locale files exactly.
  • A new page goes into the sidebar of both languages in the config.

Screenshots ​

The pictures in the docs and the README come from a made-up community, never from a real one. ./homelander demo runs the service on a throwaway database filled with invented houses, people, chats, posts, rules and penalties, with an offline Telegram, and prints the address and two session cookies (an admin and a resident). It pretends to live at https://homes.example.org (--public-url changes that), so the pictures show a public address and no "works only on this computer" warning. make screenshots builds the binary, runs the demo once per language and photographs the pages with Playwright in light and dark themes into docs/public/screenshots/<lang>/<name>-<theme>.webp. It uses the installed Google Chrome; set PW_CHANNEL= (empty) to use Playwright's own Chromium after npx playwright install chromium.

  • Retake them when a pictured page changes. The list of pages is at the top of scripts/screenshots.mjs; the demo content is in cmd/homelander/demo.go, in both languages.
  • In a page, a picture is two images, one per theme: ![Alt](/screenshots/en/admin-chats-light.webp){.shot .light-only} and the same with dark. Add .phone for a phone-sized shot.

Conventions ​

  • Every feature or behaviour change updates the docs in the same pull request: the admin guide, configuration, bot commands, setup pages — whatever it touches — in English and in docs/uk/, and the README when the feature list or quick start changes. Docs are part of "done".
  • Documentation, code comments and commit messages are in English, except the Ukrainian copies under docs/uk/ and README.uk.md.
  • No real addresses, phone numbers or community names anywhere in the repository, tests included. Use synthetic values such as +380000000000.
  • Every user-facing text goes through the locale files: locales/*.json for the backend and bot, web/src/locales/*.json for the web app. Tests fail when the languages have different keys.
  • Database changes are new files in internal/storage/sqlite/migrations/ named NNNN_name.sql; migrations only move forward.
  • main is protected: work on a branch and open a pull request (squash merge).

Released under the Apache License 2.0.