mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 15:47:24 +01:00
* docs: archive point-in-time records, drop broken guide symlinks Status reports, progress trackers, audits, session summaries, completed migration plans and the 2025 roadmap move to docs/archive/ (same relative path), with a README saying they describe the day they were written. .ai-guides/ held only symlinks into a docs/guides/ai/ that no longer exists, tests/unit/docs/ held a stray copy of an old getting-started page, and docs/operations/PORT_MANAGEMENT_README.md duplicated port-management.md; all three are deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJkbo18cRNXtgPWZN2S9cD * docs: correct drifted paths, links and versions in current docs Fix in place the reference docs agents use: point paths at where the code lives now (src/stores/auth.ts, src/lib/supabase/*, scripts/dev/*, docs/reference/api/CONVENTIONS.md, the squashed baseline migration), rewrite the development, features, operations and API index pages to list documents that exist, say plainly where something is gone (/api/metrics, the CSP report route, .envrc in the repo, Loki's `migrate` script), and correct the Next.js major. docs-truth findings: 468 -> 2 (both "Next 30/90 Days" headings in the legal overview, a checker false positive). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PJkbo18cRNXtgPWZN2S9cD --------- Co-authored-by: Claude <noreply@anthropic.com>
🗄️ Database Architecture Documentation
Overall Rating: 9.2/10 (2025 self-score) | Status: Stale 2025-12-21 snapshot — not a current Production Ready claim | Simplified MVP Architecture
Last Updated: December 21, 2025 (stale; honesty pass 2026-09-03) Database: Supabase PostgreSQL Version: Production v2.0 (Simplified) Tables: 5 core tables (down from 10+)
📋 Quick Navigation
🚀 Getting Started
- QUICK_REFERENCE.md - Essential commands & links (start here!)
- IMPROVEMENTS_SUMMARY.md - What we built & how to deploy
- DEPLOYMENT_GUIDE.md - Step-by-step deployment instructions
Core Documentation
- Schema Overview - High-level architecture and design patterns
- Analysis & Rating - Comprehensive 9.2/10 analysis of simplified architecture
- Current Schema - Complete database schema reference
- Migration Guide - Database migration instructions
Current Tables (5 Core Tables)
- profiles - User profiles with Bitcoin features (15 essential fields)
- projects - Unified fundraising entity (replaces campaigns + projects)
- transactions - Multi-entity Bitcoin payments (any → any)
- organizations - Group entities for collaborative fundraising
- organization_members - Simple team management
Key Features
- Multi-Entity Transactions - Any entity can donate to any other entity
- Bitcoin Wallet Integration - Lightning/Bitcoin addresses for all entities
- Transparency by Default - Public transaction visibility and audit trails
- Simplified Permissions - Clear role-based access control
Database Benefits
- ✅ 60% Fewer Tables - 5 core tables vs 10+ complex tables
- ✅ Bitcoin-Native - Lightning/Bitcoin addresses for all entities
- ✅ Transparent - Public transaction visibility and audit trails
- ✅ Scalable - Proper indexing and minimal JOINs
- ✅ Maintainable - Simple relationships and clear data flow
Analysis & Roadmap
- Architecture Analysis & Rating - Comprehensive 9.2/10 analysis of simplified architecture
- Improvements Roadmap - Planned enhancements for current schema
🎯 Database at a Glance
Statistics
- 5 Core Tables - Essential entities for Bitcoin crowdfunding
- Multi-Entity Transactions - Any entity can donate to any other
- Bitcoin Wallet Support - Lightning/Bitcoin addresses for all entities
- Row Level Security - Comprehensive access control
- 2025 snapshot claimed production-ready - do not treat as today's gate
- 3 Helper Functions - Wallet balance and transaction history queries
- 15+ RLS Policies - Comprehensive security coverage
- 15+ Indexes - Strategic performance optimization
- 3 Custom ENUMs - Type-safe status management
Key Features
1. Bitcoin-Native Architecture (9/10)
- ✅ Precise decimal handling:
numeric(20,8)for satoshi precision - ✅ Multiple payment methods: On-chain + Lightning Network
- ✅ Address validation with regex patterns
- ✅ Lightning addresses, node IDs, payment preferences
- ✅ Organization treasury management
- ✅ Revenue sharing via
reward_percentage
2. Polymorphic Associations (10/10)
- ✅ Flexible entity relationships in single table
- ✅ Temporal relationships (starts_at, ends_at)
- ✅ Version tracking for change history
- ✅ Multi-level visibility controls
- ✅ Complete audit trail
3. Security First (8.5/10)
- ✅ RLS enabled on all tables
- ✅ Principle of least privilege
- ✅ Role-based access for organizations
- ✅ SECURITY DEFINER functions for controlled escalation
4. Performance Optimized (8/10)
- ✅ GIN trigram indexes for fuzzy search
- ✅ Partial indexes for hot queries
- ✅ Denormalized counters with triggers
- ✅ Composite indexes for complex queries
🚀 Quick Start
Accessing the Database
# Using Supabase CLI
supabase db pull
# Connect to production
psql $DATABASE_URL
Environment Variables
NEXT_PUBLIC_SUPABASE_URL=https://supabase.orangecat.ch
NEXT_PUBLIC_SUPABASE_ANON_KEY=<your-anon-key>
SUPABASE_SERVICE_ROLE_KEY=<your-service-role-key>
Common Queries
-- Get profile with associations
SELECT p.*,
(SELECT COUNT(*) FROM follows WHERE following_id = p.id) as follower_count,
(SELECT COUNT(*) FROM follows WHERE follower_id = p.id) as following_count
FROM profiles p
WHERE p.username = 'orangecat';
-- Get active projects
SELECT * FROM funding_pages
WHERE status = 'active'
ORDER BY created_at DESC;
-- Check transaction status
SELECT * FROM transactions
WHERE status IN ('pending', 'processing');
📊 Design Patterns Used
- Polymorphic Associations - Flexible entity relationships
- Soft Deletes - status = 'deleted' vs hard delete
- Denormalized Counters - With trigger maintenance
- Temporal Data - Time-bound relationships
- Version Tracking - Association versioning
- Audit Trails - created_by, last_modified_by
- JSONB for Extensibility - Schema evolution
- Partial Indexing - Performance + storage optimization
- Check Constraints - Business rules at DB level
- Security Definer Functions - Controlled privilege escalation
⚠️ Important Notes
Current Limitations
- Transactions table not partitioned (will need this as volume grows)
- No dedicated audit log table (recommended for compliance)
- Missing index on
transactions.status(being added)
Planned Improvements
See Improvements Roadmap for:
- Table partitioning strategy
- Audit logging implementation
- Materialized views for analytics
- Archival strategy for old data
🔗 Related Documentation
- Database Schema (Legacy) - Original simplified docs
- Association System Design - Deep dive into polymorphic associations
- Supabase Schema Guide - Setup and migration guide
- API Documentation - API endpoints using these tables
🛠️ Maintenance
Regular Tasks
- Weekly: Review slow query logs
- Monthly: Check index usage statistics
- Quarterly: Analyze table bloat and vacuum
- As needed: Update RLS policies for new features
Monitoring
-- Check table sizes
SELECT
schemaname,
tablename,
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
-- Check index usage
SELECT
schemaname,
tablename,
indexname,
idx_scan,
idx_tup_read,
idx_tup_fetch
FROM pg_stat_user_indexes
ORDER BY idx_scan ASC;
Status: Stale 2025-12-21 snapshot (not a current Production Ready claim) | Rating: 9.2/10 (then) | Architecture: Simplified MVP | Last Updated: December 21, 2025