clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/tinyagent
tinyrelay / internal / daemon / doc.go
doc.go 2.9K
1// Package daemon assembles the services of a multitenant Nostr relay.2// App owns the tenant catalog, telemetry and active Tenant instances. Each3// Tenant owns one store, its policy snapshot, protocol handlers and background4// services. HTTP, WebSocket and management requests reach domain services5// through these adapters.6//7// # Process and tenant lifetimes8//9// New opens the catalog and telemetry and attempts to resume incomplete tenant10// creation.11// Start acquires the serving process lock, opens ready tenants and starts12// catalog reconciliation. The caller serves App as an HTTP handler and calls13// Close after stopping its HTTP listeners. Close stops reconciliation, closes14// tenants, releases shared resources and releases the process lock. The15// optional peer monitor runs under the context passed to PeerMonitorRun.16//17// A tenant initializes community state and its admission gate before building18// the protocol and feature services. Custom-view storage is ready when Git19// initialization can promote repository events; the Git service is then bound20// to the view service. Handler registration completes before worker goroutines21// start. Tenant.Close stops new operations, cancels and joins background work,22// closes live connections and drains active operations before closing storage.23//24// # Admission and persistence25//26// Tenant implements the relay backend and the typed room reader used by the27// web UI. Execute dispatches management methods under the supplied actor's28// current authority. HTTP and WebSocket adapters establish that actor through29// request authentication. Policy returns a read-only snapshot; policy changes30// are serialized and replace the snapshot after persistence succeeds.31//32// Client publication and replication ingestion use eventCommitter to compose33// event storage, domain projections and durable intents. Client entry points34// also process membership, moderation and room actions. The relay router owns35// live event delivery. A repository state stays pending until Git promotion36// makes its referenced objects available.37//38// # Optional work and maintenance39//40// callbackService owns webhook registrations and delivery. customViewService41// owns transform definitions, requests and signed artifacts. eventFollowups42// captures matching registrations and persists planning work with accepted43// events. Planning checks current sources and registrations, uses stable work44// identities and retries within bounded attempts and age. Each feature's45// handler owns its remote delivery or transform policy.46//47// The maintenance gate admits ordinary operations while exclusive maintenance48// is idle. A maintenance operation blocks new admissions and drains active49// operations. Nested calls carry the admission in their context, and callers50// release it with the returned completion function. Workers use the same gate51// while operating on the tenant's services and store.52package daemon