Architecture
Database Reorganization - Visual Guide

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/Drizzle

Proposed 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 schemas

Side-by-Side Comparison

Finding League Schema

TaskCurrent (Before)Proposed (After)
Find League JSON Schemaschemas/domain/v1/league_payload_schema.jsonschemas/domain/v1/json/league.schema.json
or schemas/domain/v1/api/league-master.schema.json?(Clear location!)
(Multiple options - confusing!)
Find League Neo4j Schemasql/neo4j_comprehensive_schema.cypherschemas/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 ConstraintsSearch sql/neo4j_comprehensive_schema.cypherschemas/domain/v1/neo4j/constraints.cypher
(200+ lines to scan)(Dedicated file!)
Find PostgreSQL Schemasql/core-schema.sqlschemas/infrastructure/postgresql/core-schema.sql
or sql/main_schema.sql?(Clear location!)
or sql/unified.postgresql.schema.sql?

Adding New Entity

StepCurrent (Before)Proposed (After)
1. Create JSON SchemaAdd to schemas/domain/v1/new_entity.schema.jsonAdd to schemas/domain/v1/json/new_entity.schema.json
2. Add Neo4j NodeEdit sql/neo4j_comprehensive_schema.cypherAdd to schemas/domain/v1/neo4j/nodes.cypher
(Append to 200+ line file)(Small focused file)
3. Add ConstraintsEdit same sql/neo4j_comprehensive_schema.cypherAdd to schemas/domain/v1/neo4j/constraints.cypher
(Find right section in big file)(Dedicated file for constraints)
4. Add IndexesEdit same sql/neo4j_comprehensive_schema.cypherAdd 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 navigate

Proposed: 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.prisma

Mental 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

AspectBeforeAfterImprovement
Neo4j locationsql/ (confusing!)schemas/domain/v1/neo4j/βœ… Logical grouping
Neo4j files3 files, unclear which is current4 focused files (split by purpose)βœ… Clear organization
JSON schemasScattered across v1/Grouped in json/βœ… Easy to find
InfrastructureMixed in sql/schemas/infrastructure/βœ… Clear separation
Prisma/DrizzleNo clear homeschemas/infrastructure/βœ… Logical location
VersioningFiles at v1 levelEntire v1/ versioned togetherβœ… Easier v2 migration

Next Step: Review REORGANIZATION_PROPOSAL.md for migration plan

Platform

Documentation

Community

Support

partnership@altsportsdata.comdev@altsportsleagues.ai

2025 Β© AltSportsLeagues.ai. Powered by AI-driven sports business intelligence.

πŸ€– AI-Enhancedβ€’πŸ“Š Data-Drivenβ€’βš‘ Real-Time