4.1 KiB
This file describes the domain model. This description should be translated into standard structs and sqlite schemas in a way that makes sense.
Activity
Activity is an audit log of all actions performed by a user or a worker process. This allows us to trace history to create invoices, synchronize actions to external services, and debug system behavior.
id- a random activity IDcreated_at- unix timestamp when the activity was createdactivity_typeis one of:tenant_createdtenant_billing_anchor_updatedrelay_createdrelay_updatedrelay_activatedrelay_deactivatedrelay_sync_failedinvoice_createdinvoice_paidinvoice_attemptedinvoice_sentinvoice_closed
identifieris a string identifying the resource being modified. This id in interpreted depending on what theactivity_typeis.
Tenant
Tenants are customers of the service, identified by a nostr pubkey. Public metadata like name etc are pulled from the nostr network. They also have associated billing information.
pubkeyis the nostr public key identifying the tenantnwc_urla nostr wallet connect URL used for paying invoices generated by the systemcreated_atunix timestamp identifying tenant creation timebilling_anchorunix timestamp identifying billing cycle anchor. This gets reset when the tenant has no paid relays and adds (or reactivates) one.
Relay
A relay is a nostr relay owned by a tenant and hosted by the attached zooid instance. Relay subdomains MUST be unique.
id- a random ID identifying the relaytenant- the tenant's pubkeyschema- the relay's db schema (read_only, calculated based onsubdomain+id)subdomain- the relay's subdomainplan- the relay's planstatus-new|active|inactive. Onlyactiverelays count toward billing.sync_error- a string indicating any errors encountered when synchronizing.info_name- the relay's nameinfo_icon- the relay's icon image URLinfo_description- the relay's descriptionpolicy_public_join- whether to allow non-members to join the relay without an invite codepolicy_strip_signatures- whether to remove signatures when serving events to non-adminsgroups_enabled- whether NIP 29 groups are enabledmanagement_enabled- whether NIP 86 management API is enabledblossom_enabled- whether blossom file storage is enabledlivekit_enabled- whether livekit calls are enabledpush_enabled- whether relay push is enabled
Some attributes persisted to zooid via API have special handling:
- The relay's
secretis generated once and persisted to the zooid configuration but isn't stored in the database. - The relay's
hostis calculated based onsubdomain+RELAY_DOMAIN - The value of
inactiveis calculated based onstatus - The relay's
livekit_*configuration is inferred based on environment variables andlivekit_enabled. - The relay's
rolesare hard-coded for now.
Invoice
Invoices are generated at the end of a tenant's monthly billing period. The billing module is responsible for creating them, collecting them, and dunning them.
id- random invoice IDtenant- tenant pubkeystatus-pending|paid|closedamountis derived as the sum of associated invoice itemsatsvalues (not stored as a separate source of truth)created_at- unix timestamp for when the invoice was createdattempted_at- nullable unix timestamp for when collection was last attemptederror- optional human-readable error from the last failed collection attemptclosed_at- nullable unix timestamp for when the invoice was closedsent_at- nullable unix timestamp for when the invoice was sent via DMpaid_at- nullable unix timestamp for when the invoice was paidbolt11- a BOLT 11 lightning invoice that can be used to pay the invoiceperiod_start- unix timestamp for period startperiod_end- unix timestamp for period end
Invoice Item
Invoice items are attached to an invoice and represent charges for a given relay.
id- random invoice item IDinvoice- invoice IDrelay- relay IDsats- amount in satoshis