BAPBA Protocol
Architecture

Database Architecture

Database schema design for Burning Ash Protocol — tables, relationships, and SQLite/PostgreSQL support.

Database Architecture

BAP uses a relational database with support for both SQLite (development) and PostgreSQL (production).

Database Support

DatabaseUse CaseDriver
SQLiteDevelopment, small deploymentsgorm.io/driver/sqlite
PostgreSQLProductiongorm.io/driver/postgres (via pgx)

Both use the same schema via GORM's database abstraction. Migrations are maintained in parallel for both dialects (api/migrations/sqlite/ and api/migrations/postgres/).

Schema Overview

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   hosts     │────▶│  survivors  │     │   wills     │
└─────────────┘     └─────────────┘     └─────────────┘
       │                   │                   │
       │                   │                   │
       ▼                   ▼                   ▼
┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│  connectors │     │ will_docs   │     │  storages   │
└─────────────┘     └─────────────┘     └─────────────┘
       │                   │                   │
       │                   ▼                   │
       │            ┌─────────────┐           │
       │            │ liveness    │           │
       │            └─────────────┘           │
       │                   │                   │
       │                   ▼                   │
       │            ┌─────────────┐           │
       │            │ transfers   │           │
       │            └─────────────┘           │
       │                   │                   │
       ▼                   ▼                   ▼
┌─────────────────────────────────────────────────┐
│                   audit_log                    │
└─────────────────────────────────────────────────┘

Tables

hosts

Stores Host accounts.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
emailVARCHAR(255)UNIQUE, NOT NULLEmail address
password_hashVARCHAR(255)NOT NULLArgon2 hash
display_nameVARCHAR(100)NOT NULLDisplay name
statusVARCHAR(20)NOT NULLpending_verification, active, disabled
setup_completeBOOLEANDEFAULT falseSetup wizard complete
master_key_encryptedBYTEAEncrypted master key
created_atTIMESTAMPNOT NULLCreation time
updated_atTIMESTAMPNOT NULLLast update

survivors

Stores Survivors for each Host's will.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
host_idUUIDFK → hosts.id, NOT NULLParent host
nameVARCHAR(100)NOT NULLSurvivor name
relationshipVARCHAR(50)e.g., spouse, child
contact_encryptedBYTEANOT NULLEncrypted contact info
sss_share_encryptedBYTEANOT NULLEncrypted SSS share
personal_messageTEXTMessage for survivor
backup_codes_hashBYTEAHash of backup codes
connector_priorityJSONBNOT NULLOTP delivery order
created_atTIMESTAMPNOT NULLCreation time
updated_atTIMESTAMPNOT NULLLast update

wills

Stores will metadata.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
host_idUUIDFK → hosts.id, NOT NULLOwner
statusVARCHAR(30)NOT NULLdraft, active, pending_transfer, etc.
dek_encryptedBYTEAEncrypted DEK
thresholdINTEGERNOT NULLSSS threshold (K)
storage_idUUIDFK → storages.idPrimary storage
created_atTIMESTAMPNOT NULLCreation time
sealed_atTIMESTAMPWhen sealed
last_encrypted_atTIMESTAMPLast encryption time

will_documents

Stores document metadata.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
will_idUUIDFK → wills.id, NOT NULLParent will
filenameVARCHAR(255)NOT NULLOriginal filename
mime_typeVARCHAR(100)NOT NULLMIME type
size_bytesBIGINTNOT NULLFile size
sha256_hashVARCHAR(64)NOT NULLSHA-256 hash
storage_pathVARCHAR(500)NOT NULLPath in storage
created_atTIMESTAMPNOT NULLUpload time

connectors

Stores connector configurations.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
host_idUUIDFK → hosts.id, NOT NULLOwner
typeVARCHAR(20)NOT NULLemail, sms, whatsapp, telegram
nameVARCHAR(100)NOT NULLDisplay name
config_encryptedBYTEANOT NULLEncrypted credentials
priorityINTEGERDEFAULT 0Send priority
is_verifiedBOOLEANDEFAULT falseWorking status
created_atTIMESTAMPNOT NULLCreation time

storages

Stores storage backend configurations.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
host_idUUIDFK → hosts.id, NOT NULLOwner
typeVARCHAR(20)NOT NULLgdrive, dropbox, s3, sftp
nameVARCHAR(100)NOT NULLDisplay name
config_encryptedBYTEANOT NULLEncrypted credentials
directory_pathVARCHAR(255)NOT NULLStorage folder
is_connectedBOOLEANDEFAULT trueConnection status
last_verified_atTIMESTAMPLast successful test
created_atTIMESTAMPNOT NULLCreation time

liveness_checks

Stores liveness check history.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
will_idUUIDFK → wills.id, NOT NULLParent will
check_numberINTEGERNOT NULLSequential check number
statusVARCHAR(20)NOT NULLpending, confirmed, missed
channelVARCHAR(20)Connector used
sent_atTIMESTAMPNOT NULLWhen sent
responded_atTIMESTAMPWhen responded
response_time_msINTEGERResponse duration

transfers

Stores transfer state.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
will_idUUIDFK → wills.id, NOT NULLParent will
statusVARCHAR(30)NOT NULLinitiated, awaiting_auth, etc.
initiated_byUUIDFK → survivors.idWho initiated
initiated_atTIMESTAMPNOT NULLStart time
host_cancel_deadlineTIMESTAMPDeadline to cancel
completed_atTIMESTAMPWhen completed
expires_atTIMESTAMPAccess window expiry

survivor_auth

Stores survivor authentication state during transfer.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
transfer_idUUIDFK → transfers.id, NOT NULLParent transfer
survivor_idUUIDFK → survivors.id, NOT NULLSurvivor
statusVARCHAR(20)NOT NULLpending, verified, failed
otp_session_idUUIDCurrent OTP session
authenticated_atTIMESTAMPWhen verified

otp_sessions

Stores active OTP sessions.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
survivor_idUUIDFK → survivors.id, NOT NULLTarget survivor
code_hashVARCHAR(64)NOT NULLHash of code
expires_atTIMESTAMPNOT NULLExpiration time
attemptsINTEGERDEFAULT 0Attempt count
created_atTIMESTAMPNOT NULLCreation time

audit_log

Append-only audit log.

ColumnTypeConstraintsDescription
idUUIDPKUnique ID
host_idUUIDFK → hosts.idAffected host
actionVARCHAR(50)NOT NULLAction type
resource_typeVARCHAR(30)NOT NULLResource type
resource_idUUIDResource ID
detailsJSONBAdditional details
ip_addressVARCHAR(45)Client IP
created_atTIMESTAMPNOT NULLTimestamp

Indexes

Key indexes for performance:

-- hosts
CREATE INDEX idx_hosts_email ON hosts(email);

-- survivors
CREATE INDEX idx_survivors_host ON survivors(host_id);

-- wills
CREATE INDEX idx_wills_host ON wills(host_id);
CREATE INDEX idx_wills_status ON wills(status);

-- liveness_checks
CREATE INDEX idx_liveness_will ON liveness_checks(will_id);
CREATE INDEX idx_liveness_will_status ON liveness_checks(will_id, status);

-- transfers
CREATE INDEX idx_transfers_will ON transfers(will_id);
CREATE INDEX idx_transfers_status ON transfers(status);

-- audit_log
CREATE INDEX idx_audit_host ON audit_log(host_id);
CREATE INDEX idx_audit_created ON audit_log(created_at);

Migrations

Using sqlc with embedded migrations:

  • Versioned migrations (001_, 002_, etc.)
  • Up/down migration pairs
  • Automatic execution on startup

Security

Encryption at Rest

  • Connector configs encrypted with master key
  • Storage credentials encrypted with master key
  • Contact info encrypted with host key
  • SSS shares encrypted per-survivor

Sensitive Data

DataEncryptedNotes
Password hashN/AArgon2, salted
Master keyN/ANever stored, used from env
DEKEncrypted with KEK
Connector configEncrypted with master key
Storage configEncrypted with master key
Contact infoEncrypted with host key
SSS sharesEncrypted per-survivor
OTP codesN/AHash only
Backup codesN/AHash only

Next Steps

On this page