halkyon/apps/todo/halkyon_todo_server/lib/server.dart
Tizian 「ティツィアーン」 65c5cd740d
feat(accounts): one account across an instance's services (ADR 0016)
halkyon_base runs as the instance's register or as one of its members.
The register keeps the ways in, handles and profiles; members ask it
over HTTP with the instance's shared secret (instanceSecret), and open
sessions of their own for its accounts, under the same account ID.

- AccountsMode from the environment: INSTANCE_MEMBERS on the register,
  ACCOUNT_REGISTER_URL on a member. Learn always holds the register
  (Explore joins the profiles); Todo is a member where it is set.
- AccountRegister: LocalRegister, RemoteRegister, an in-memory one in
  tests. Calls between services on the web server, refused without the
  secret (constant-time compare); a server needing it doesn't start
  without it.
- Deleting an account deletes it everywhere: notices per member kept in
  the deletion's transaction (account_deletion_notice), told at once and
  hourly until confirmed; members prune daily whom the register no longer
  knows, never while it knows none of them or can't be reached.
- Deploy: INSTANCE_SECRET and INSTANCE_MEMBERS in compose and .env.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-22 18:11:07 +02:00

33 lines
1.3 KiB
Dart

import 'package:halkyon_base_server/base.dart';
import 'package:halkyon_todo_server/src/generated/serverpod.dart';
import 'package:halkyon_todo_server/src/pruning.dart';
import 'package:halkyon_todo_server/src/todo_base.dart';
import 'package:serverpod_auth_idp_server/core.dart';
/// The starting point of Halkyon Todo's server.
Future<void> run(List<String> args) async {
// The generated Serverpod is already connected with the generated code.
final pod = Serverpod(args);
// What every Halkyon server has (ADR 0014): sign-in, the account and its
// deletion, the pruning, the instance's basics, set up for Todo; a member
// of the instance's register where the operator names one (ADR 0016).
HalkyonBase.configure(
pod,
todoBase(accounts: AccountsMode.fromEnvironment()),
);
// Token managers validate and issue authentication keys; identity
// providers are the ways people can sign in (halkyon_base's
// auth_config.dart).
pod.initializeAuthServices(
tokenManagerBuilders: tokenManagerBuilders,
identityProviderBuilders: identityProviderBuilders(pod),
);
// The calls between the instance's services, on the web server
// (ADR 0016); Caddy never forwards them.
addInstanceRoutes(pod);
await pod.start();
await schedulePruning(pod);
}