-
Notifications
You must be signed in to change notification settings - Fork 0
DATABASE_ARCHITECTURE.md
Version: 1.0 Project: CeloHT Primary Database Model: Relational Recommended Technology: PostgreSQL
This document defines the conceptual database architecture for CeloHT applications.
The database stores application information that does not need to exist on the public blockchain.
Blockchain data and application data must remain conceptually separate.
CeloHT Applications
│
▼
API Layer
│
▼
Service Layer
│
▼
Data Access Layer
│
▼
PostgreSQL DB
│
┌─────────────────────┼─────────────────────┐
▼ ▼ ▼
Users Agents Programs
│ │ │
└─────────────────────┼─────────────────────┘
▼
Impact Data
The database may store:
- User profiles
- Agent profiles
- Educational progress
- Program information
- Content metadata
- Application configuration
- Impact records
- Blockchain indexing metadata
The database should not store:
- Seed phrases
- Private keys
- Wallet passwords
- Sensitive secrets
USERS
│
├── PROFILES
│
├── EDUCATION_PROGRESS
│
└── AGENT_RELATIONSHIPS
AGENTS
│
├── AGENT_OPERATIONS
│
└── COMMUNITIES
PROGRAMS
│
├── EDUCATION
└── REFORESTATION
BLOCKCHAIN
│
├── TRANSACTIONS
├── CONTRACTS
└── EVENTS
IMPACT
│
├── TRAINING
├── TRANSACTIONS
├── AGENTS
└── TREES
A conceptual user record may contain:
User
├── id
├── wallet_address
├── created_at
├── updated_at
└── status
Only information required by the application should be stored.
Potential agent information:
Agent
├── id
├── wallet_address
├── status
├── community_id
├── created_at
└── updated_at
Sensitive operational information should be protected.
Potential education records:
Course
├── id
├── title
├── description
└── status
Enrollment
├── id
├── user_id
├── course_id
├── progress
└── completed_at
Community records may contain:
Community
├── id
├── name
├── region
├── status
└── created_at
Sensitive geographic information should not be unnecessarily exposed.
Potential records:
ReforestationProgram
├── id
├── community_id
├── start_date
├── status
└── description
PlantingActivity
├── id
├── program_id
├── quantity
├── date
└── verification_status
Blockchain-related database records should complement—not replace—the blockchain.
Example:
BlockchainTransaction
├── id
├── tx_hash
├── network
├── from_address
├── to_address
├── asset
├── amount
├── status
├── block_number
└── timestamp
The transaction hash should remain the primary external reference.
A contract registry may contain:
Contract
├── id
├── name
├── address
├── network
├── version
├── verification_status
├── deployed_at
└── repository
Indexed events may contain:
BlockchainEvent
├── id
├── tx_hash
├── contract_address
├── event_name
├── block_number
├── payload
└── timestamp
The event record should preserve enough information to trace the original blockchain transaction.
Impact metrics should use explicit definitions.
Examples:
ImpactMetric
├── id
├── metric_name
├── value
├── unit
├── period
├── source
├── verification_status
└── created_at
Security controls include:
- Strong authentication
- Least privilege
- Encryption
- Backups
- Network restrictions
- Monitoring
- Audit logs
Where supported and appropriate, row-level security can restrict which users or roles can access specific records.
Conceptually:
User
│
▼
Authorization
│
▼
Row-Level Policy
│
├── Allowed
└── Denied
Indexes should support common query patterns.
Potential indexes:
- Wallet address
- Transaction hash
- Agent ID
- Community ID
- Course ID
- Timestamp
- Status
Indexes should be introduced based on measured query requirements.
The database should use:
- Primary keys
- Foreign keys
- Unique constraints
- Check constraints
- Transactions
- Appropriate validation
Application validation should complement database constraints.
Database schema changes should be version-controlled.
Migration
│
▼
Review
│
▼
Test
│
▼
Staging
│
▼
Production
Destructive migrations require special review.
Production Database
│
▼
Automated Backup
│
▼
Protected Storage
│
▼
Restore Test
Backups should be tested periodically.
Data should be retained only as long as required.
Sensitive information should have documented retention policies.
Blockchain records are generally immutable and therefore require careful consideration before being written on-chain.
Monitor:
- Database availability
- Query latency
- Connection count
- Storage usage
- Failed queries
- Backup status
- Replication status where applicable
Recovery should support:
- Backup restoration
- Point-in-time recovery where available
- Schema reconstruction
- Application reconnection
- Data integrity validation
- Keep blockchain and application data separate.
- Minimize sensitive data.
- Use relational integrity.
- Encrypt sensitive data where appropriate.
- Use least privilege.
- Version schema changes.
- Test backups.
- Monitor production performance.
- Avoid unnecessary duplication.
- Preserve blockchain transaction references.
Document: Database Architecture Version: 1.0 Recommended Database: PostgreSQL
© 2026 CeloHT - Open Source. Global Impact. Licensed under Apache.