5.4 KiB
This file describes the domain model. This description should be translated into standard structs and sqlite schemas in a way that makes sense.
- Fields marked as private should use
#[serde(skip_serializing)]in their definition. - Fields marked as readonly should use
#[serde(skip_deserializing)]in their definition.
Identity
Identity is a description of a user.
pubkey- the user's nostr pubkeyis_admin- whether the user is an adminis_tenant- whether the user has an account
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 IDtenant- a tenant IDcreated_at- unix timestamp when the activity was createdactivity_typeis one of:create_tenantupdate_tenant_billing_anchorupdate_tenant_nwc_urlcreate_relayupdate_relayactivate_relaydeactivate_relayfail_relay_synccreate_invoicemark_invoice_paidmark_invoice_attemptedmark_invoice_sentmark_invoice_closed
resource_typeis a string identifying the resource type being modified.resource_idis a string identifying the resource id being modified.
Plan
A plan represents a rate charged for relays at a given feature/usage limit. Plans aren't saved to the database, but are simply hardcoded. However, they are exposed through the API so they can be used as a single source of truth.
id- the plan slugname- the plan namesats- the plan't cost per monthmembers- the max number of members a relay can have before needing to upgrade. If empty, membership is not limited.blossom- whether blossom media hosting is available on this planlivekit- whether livekit audio/video calls are available on this plan
There are three plans available:
free- 0 sats/mo, up to 10 members, no blossom/livekitbasic- 10k sats/mo, up to 100 members, includes blossom/livekitgrowth- 50k sats/mo, unlimited members, includes blossom/livekit
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_url(private) a 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