Source: data_layer/docs/REORGANIZATION_VISUAL.md
Database Reorganization - Visual Guide
π― Goal: Simplify and Clarify Schema Organization
Current Structure (Confusing!)
database/
βββ schemas/
β βββ domain/
β β βββ v1/
β β βββ league_payload_schema.json β JSON Schema here
β β βββ team_schema.json
β β βββ player_schema.json
β β βββ api/
β β β βββ league-master.schema.json β More JSON here?
β β β βββ league-extracted.schema.json
β β βββ combat/ β Sport-specific?
β β βββ fighting/
β β
β βββ infrastructure/
β β βββ prisma/ β Should this exist?
β β βββ schema.prisma
β β
β βββ generated/ β Auto-generated (OK)
β βββ adapters/
β βββ models/
β
βββ sql/ β β οΈ CONFUSING!
βββ neo4j_comprehensive_schema.cypher β Neo4j in "sql"?
βββ neo4j_league_mvp_schema.cypher β Which Neo4j file?
βββ optimized.neo4j.schema.cypher β Which is current?
βββ core-schema.sql β PostgreSQL
βββ supabase_*.sql β More PostgreSQL
βββ unified.postgresql.schema.sql β Even more!
Problems:
β Neo4j (Cypher) mixed with PostgreSQL (SQL) in "sql/" directory
β Multiple Neo4j files - unclear which to use
β JSON schemas scattered across domain/v1/
β No clear home for Prisma/DrizzleProposed Structure (Clear!)
database/
βββ schemas/ # π’ ALL SCHEMAS HERE
β β
β βββ domain/ # π’ BUSINESS DOMAIN MODELS
β β βββ v1/ # (Source of truth)
β β β
β β βββ json/ # JSON Schema (validation)
β β β βββ league.schema.json
β β β βββ team.schema.json
β β β βββ player.schema.json
β β β βββ contract.schema.json
β β β βββ README.md
β β β
β β βββ neo4j/ # Neo4j Cypher (graph)
β β β βββ constraints.cypher # CREATE CONSTRAINT
β β β βββ indexes.cypher # CREATE INDEX
β β β βββ nodes.cypher # Node definitions
β β β βββ relationships.cypher # Relationship patterns
β β β βββ README.md
β β β
β β βββ README.md # Domain v1 overview
β β
β βββ infrastructure/ # π’ INFRASTRUCTURE/ORM SCHEMAS
β β β # (Implementation layer)
β β βββ postgresql/ # Raw PostgreSQL DDL
β β β βββ core-schema.sql
β β β βββ supabase/
β β β β βββ prospective_leagues.sql
β β β β βββ migrations/
β β β β β βββ 001_initial.sql
β β β β βββ README.md
β β β βββ migrations/
β β β βββ README.md
β β β
β β βββ prisma/ # Prisma ORM
β β β βββ schema.prisma
β β β βββ migrations/
β β β βββ README.md
β β β
β β βββ drizzle/ # Drizzle ORM (future)
β β βββ schema.ts
β β βββ migrations/
β β βββ README.md
β β
β βββ generated/ # π’ AUTO-GENERATED (do not edit!)
β βββ adapters/
β β βββ python/v1/ # Pydantic models
β β βββ typescript/v1/ # TS + Zod
β β βββ drizzle/v1/ # Drizzle tables
β βββ models/ # Legacy (deprecated)
β
βββ docs/ # π’ DOCUMENTATION
β βββ SCHEMA_MAPPING.md
β βββ SCHEMA_WORKFLOW.md
β βββ ADR-001-SCHEMA-ARCHITECTURE.md
β
βββ scripts/ # π’ UTILITIES
β βββ validate_schema_sync.py
β βββ regenerate_adapters.sh
β
βββ CLAUDE.md
Benefits:
β
Neo4j schemas grouped with JSON schemas (both domain models)
β
Clear separation: domain vs infrastructure
β
Split Neo4j file = easy to find constraints vs indexes
β
Clear home for Prisma/Drizzle
β
Version folders (v1, v2) group related schemasSide-by-Side Comparison
Finding League Schema
| Task | Current (Before) | Proposed (After) |
|---|---|---|
| Find League JSON Schema | schemas/domain/v1/league_payload_schema.json | schemas/domain/v1/json/league.schema.json |
or schemas/domain/v1/api/league-master.schema.json? | (Clear location!) | |
| (Multiple options - confusing!) | ||
| Find League Neo4j Schema | sql/neo4j_comprehensive_schema.cypher | schemas/domain/v1/neo4j/nodes.cypher |
or sql/neo4j_league_mvp_schema.cypher? | + schemas/domain/v1/neo4j/constraints.cypher | |
or sql/optimized.neo4j.schema.cypher? | (Split by purpose!) | |
| (Which one is current??) | ||
| Find League Constraints | Search sql/neo4j_comprehensive_schema.cypher | schemas/domain/v1/neo4j/constraints.cypher |
| (200+ lines to scan) | (Dedicated file!) | |
| Find PostgreSQL Schema | sql/core-schema.sql | schemas/infrastructure/postgresql/core-schema.sql |
or sql/main_schema.sql? | (Clear location!) | |
or sql/unified.postgresql.schema.sql? |
Adding New Entity
| Step | Current (Before) | Proposed (After) |
|---|---|---|
| 1. Create JSON Schema | Add to schemas/domain/v1/new_entity.schema.json | Add to schemas/domain/v1/json/new_entity.schema.json |
| 2. Add Neo4j Node | Edit sql/neo4j_comprehensive_schema.cypher | Add to schemas/domain/v1/neo4j/nodes.cypher |
| (Append to 200+ line file) | (Small focused file) | |
| 3. Add Constraints | Edit same sql/neo4j_comprehensive_schema.cypher | Add to schemas/domain/v1/neo4j/constraints.cypher |
| (Find right section in big file) | (Dedicated file for constraints) | |
| 4. Add Indexes | Edit same sql/neo4j_comprehensive_schema.cypher | Add to schemas/domain/v1/neo4j/indexes.cypher |
| (Scroll through file) | (Dedicated file for indexes) | |
| 5. Generate Adapters | ./scripts/regenerate_adapters.sh | ./scripts/regenerate_adapters.sh |
| (Same!) | (Same!) |
Neo4j Schema Split Example
Current: One Big File (neo4j_comprehensive_schema.cypher)
// =================================================================
// COMPREHENSIVE NEO4J GRAPH SCHEMA FOR SPORTS BUSINESS ECOSYSTEM
// =================================================================
// Enable constraints and indexes for performance
// Run these first to ensure data integrity
// =================================================================
// CONSTRAINTS AND INDEXES
// =================================================================
// Primary entity constraints
CREATE CONSTRAINT user_id_unique IF NOT EXISTS FOR (u:User) REQUIRE u.id IS UNIQUE;
CREATE CONSTRAINT league_id_unique IF NOT EXISTS FOR (l:League) REQUIRE l.id IS UNIQUE;
CREATE CONSTRAINT team_id_unique IF NOT EXISTS FOR (t:Team) REQUIRE t.id IS UNIQUE;
// ... 20 more constraints ...
// Performance indexes
CREATE INDEX user_email_idx IF NOT EXISTS FOR (u:User) ON (u.email);
CREATE INDEX league_name_idx IF NOT EXISTS FOR (l:League) ON (l.name);
// ... 15 more indexes ...
// =================================================================
// CORE ENTITIES
// =================================================================
// Users (League Owners, Administrators, Stakeholders)
CREATE (user_props {
id: 'unique_id',
email: 'user@example.com',
// ... 50 more lines ...
});
// Organizations
CREATE (organization_props {
// ... 30 more lines ...
});
// ... 500+ more lines ...
Problems:
β Hard to find specific constraint
β Hard to find specific index
β Constraints + indexes + nodes all mixed
β 700+ lines to navigateProposed: Split into Focused Files
schemas/domain/v1/neo4j/constraints.cypher (30 lines)
// =================================================================
// NEO4J CONSTRAINTS - Uniqueness and Existence
// =================================================================
// Apply first: cypher-shell < constraints.cypher
// Uniqueness constraints
CREATE CONSTRAINT user_id_unique IF NOT EXISTS
FOR (u:User) REQUIRE u.id IS UNIQUE;
CREATE CONSTRAINT league_id_unique IF NOT EXISTS
FOR (l:League) REQUIRE l.id IS UNIQUE;
CREATE CONSTRAINT team_id_unique IF NOT EXISTS
FOR (t:Team) REQUIRE t.id IS UNIQUE;
// ... more constraints ...schemas/domain/v1/neo4j/indexes.cypher (20 lines)
// =================================================================
// NEO4J INDEXES - Performance Optimization
// =================================================================
// Apply after constraints: cypher-shell < indexes.cypher
CREATE INDEX user_email_idx IF NOT EXISTS
FOR (u:User) ON (u.email);
CREATE INDEX league_name_idx IF NOT EXISTS
FOR (l:League) ON (l.name);
// ... more indexes ...schemas/domain/v1/neo4j/nodes.cypher (200 lines)
// =================================================================
// NEO4J NODE DEFINITIONS - Property Templates
// =================================================================
// Reference only - shows expected properties
// User node template
// Properties: id, email, name, role, created_at
CREATE (user:User {
id: 'unique_id',
email: 'user@example.com',
name: 'Full Name',
role: 'league_owner'
});
// ... more node definitions ...schemas/domain/v1/neo4j/relationships.cypher (100 lines)
// =================================================================
// NEO4J RELATIONSHIPS - Connection Patterns
// =================================================================
// League β Team
CREATE (team:Team)-[:COMPETES_IN {
season: '2025',
division: 'Eastern'
}]->(league:League);
// ... more relationships ...Benefits:
β
Easy to find: "Where are constraints?" β constraints.cypher
β
Small files (30-200 lines vs 700+ lines)
β
Apply incrementally (constraints first, then indexes)
β
Clear separation of concerns
Directory Tree: Before vs After
Before (Current)
database/
βββ schemas/domain/v1/
β βββ league_payload_schema.json
β βββ team_schema.json
β βββ api/
β β βββ league-master.schema.json
β β βββ league-extracted.schema.json
β βββ combat/fighting/...
β
βββ sql/
βββ neo4j_comprehensive_schema.cypher β Neo4j (700 lines)
βββ neo4j_league_mvp_schema.cypher β Another Neo4j?
βββ optimized.neo4j.schema.cypher β Which one?
βββ core-schema.sql β PostgreSQL
βββ main_schema.sql β More PostgreSQL?
βββ supabase_tier1_schema.sql β More?
βββ unified.postgresql.schema.sql β Which is current?After (Proposed)
database/
βββ schemas/
βββ domain/v1/ β Domain models
β βββ json/ β JSON Schema (validation)
β β βββ league.schema.json
β β βββ team.schema.json
β β βββ player.schema.json
β β βββ contract.schema.json
β β
β βββ neo4j/ β Neo4j (graph)
β βββ constraints.cypher β 30 lines
β βββ indexes.cypher β 20 lines
β βββ nodes.cypher β 200 lines
β βββ relationships.cypher β 100 lines
β
βββ infrastructure/ β Infrastructure layer
βββ postgresql/ β Raw PostgreSQL
β βββ core-schema.sql
β βββ supabase/
β βββ prospective_leagues.sql
β
βββ prisma/ β Prisma ORM
βββ schema.prismaMental Model
Current (Confusing)
"Where's the Neo4j schema?"
β Look in sql/ (but why? Cypher isn't SQL!)
β Find 3 Neo4j files (which one is current??)
β Open 700-line file
β Search for specific constraint...
"Where's the League JSON Schema?"
β Look in schemas/domain/v1/
β Find league_payload_schema.json
β Wait, there's also api/league-master.schema.json?
β Which one should I use??Proposed (Clear)
"Where's the Neo4j schema?"
β Look in schemas/domain/v1/neo4j/
β constraints.cypher for constraints
β indexes.cypher for indexes
β nodes.cypher for node definitions
β Clear and focused!
"Where's the League JSON Schema?"
β schemas/domain/v1/json/league.schema.json
β One file, clear location!Summary
| Aspect | Before | After | Improvement |
|---|---|---|---|
| Neo4j location | sql/ (confusing!) | schemas/domain/v1/neo4j/ | β Logical grouping |
| Neo4j files | 3 files, unclear which is current | 4 focused files (split by purpose) | β Clear organization |
| JSON schemas | Scattered across v1/ | Grouped in json/ | β Easy to find |
| Infrastructure | Mixed in sql/ | schemas/infrastructure/ | β Clear separation |
| Prisma/Drizzle | No clear home | schemas/infrastructure/ | β Logical location |
| Versioning | Files at v1 level | Entire v1/ versioned together | β Easier v2 migration |
Next Step: Review REORGANIZATION_PROPOSAL.md for migration plan