Mochi Sign in

Architecture and contracts

Security model

Realtime transport contract

Socket.IO forwards canonical application events to authorized server rooms. The transport DTOs are defined in src/dashboard/realtime/eventMappers.ts. The frontend uses these exact shapes. The payloads have no user or member aliases.

memberJoin and memberLeave

{
  "guildId": "...",
  "member": { "id": "...", "username": "...", "avatar": "..." },
  "attribution": { "type": "INVITE", "inviterId": "...", "inviteCode": "..." },
  "inviter": { "id": "...", "username": "...", "avatar": "..." },
  "isFake": false,
  "inviterStats": { "regular": 4, "bonus": 1, "leaves": 1, "fake": 0, "total": 4 },
  "occurredAt": "..."
}

inviteCreated

{
  "guildId": "...",
  "invite": {
    "code": "...",
    "url": "...",
    "uses": 0,
    "maxUses": 0,
    "maxAge": 0,
    "temporary": false,
    "channelId": "...",
    "channelName": "...",
    "inviter": { "id": "...", "username": "..." },
    "createdAt": "...",
    "label": null
  },
  "occurredAt": "..."
}

Other event shapes:

Data responsibilities

The database layer separates durable facts from rebuildable read models:

invite_events + invite_bonus_adjustments
                β”‚
                β”œβ”€β”€ inviter_stats (canonical net totals)
                β”œβ”€β”€ invite_members
                β”œβ”€β”€ inviters
                └── daily_invite_stats

The invite cache is a fallback for Discord query failures. It is not a second source of truth. See Invite tracking and Deployment and operations for domain rules and maintenance commands.