Source: data_layer/docs/REORGANIZATION_PROPOSAL.md
Database Directory Reorganization Proposal
Problem
Current structure mixes concerns:
- Neo4j
.cypherfiles insql/(confusing - Cypher isn't SQL) - JSON Schema domain models mixed with infrastructure models
- Unclear where Prisma/Drizzle schemas should live
- Hard to find the "source of truth" files
Proposed Structure
database/
βββ schemas/ # π’ ALL SCHEMA DEFINITIONS
β βββ domain/ # Business domain schemas
β β βββ v1/ # Version 1 (current)
β β β βββ json/ # JSON Schema (API validation)
β β β β βββ league.schema.json
β β β β βββ team.schema.json
β β β β βββ player.schema.json
β β β β βββ contract.schema.json
β β β β
β β β βββ neo4j/ # Neo4j Cypher schemas
β β β β βββ constraints.cypher # Constraints
β β β β βββ indexes.cypher # Indexes
β β β β βββ nodes.cypher # Node definitions
β β β β βββ relationships.cypher # Relationship patterns
β β β β
β β β βββ README.md # Domain schema documentation
β β β
β β βββ v2/ # Future version
β β
β βββ infrastructure/ # Infrastructure/ORM schemas
β β βββ postgresql/ # PostgreSQL schemas
β β β βββ core-schema.sql
β β β βββ supabase/
β β β β βββ prospective_leagues.sql
β β β β βββ migrations/
β β β βββ migrations/
β β β
β β βββ prisma/ # Prisma ORM schemas
β β β βββ schema.prisma
β β β βββ migrations/
β β β
β β βββ drizzle/ # Drizzle ORM schemas (future)
β β βββ schema.ts
β β βββ migrations/
β β
β βββ generated/ # AUTO-GENERATED (do not edit)
β βββ adapters/
β β βββ python/v1/ # Pydantic models
β β βββ typescript/v1/ # TS types + Zod
β β βββ drizzle/v1/ # Drizzle tables
β β
β βββ models/ # Legacy (deprecated)
β
βββ docs/ # π’ DOCUMENTATION
β βββ SCHEMA_MAPPING.md # JSON β Neo4j mapping
β βββ SCHEMA_WORKFLOW.md # Daily workflow guide
β βββ ADR-001-SCHEMA-ARCHITECTURE.md
β βββ DATABASE_ARCHITECTURE.md
β
βββ scripts/ # π’ UTILITIES
β βββ validate_schema_sync.py # Validation
β βββ setup_neo4j_light.py
β βββ regenerate_adapters.sh
β
βββ prompts/ # π’ AI PROMPTS
βββ output-styles/ # π’ TEMPLATES
βββ storage/ # π’ EXAMPLES/SEEDS
βββ CLAUDE.mdKey Changes
1. Split schemas/domain/v1/ by Database Type
Before:
schemas/domain/v1/*.json # JSON Schema
sql/*.cypher # Neo4j (confusing!)After:
schemas/domain/v1/json/*.json # JSON Schema (validation)
schemas/domain/v1/neo4j/*.cypher # Neo4j (graph)Benefits:
- β Neo4j schemas live with domain schemas (same concern level)
- β
Clear separation:
json/vsneo4j/ - β Version together (v1, v2)
- β Easier to find matching files
2. Create schemas/infrastructure/ for ORMs
Before:
sql/core-schema.sql # PostgreSQL
sql/supabase_*.sql # Supabase schemas
(no clear home for Prisma/Drizzle)After:
schemas/infrastructure/postgresql/ # Raw PostgreSQL
schemas/infrastructure/prisma/ # Prisma ORM
schemas/infrastructure/drizzle/ # Drizzle ORM (future)Benefits:
- β Separate "domain models" from "infrastructure"
- β Clear home for ORM schemas
- β Infrastructure schemas can reference domain schemas
3. Organize Neo4j Schemas by Purpose
Before:
sql/neo4j_comprehensive_schema.cypher # Everything mixed
sql/neo4j_league_mvp_schema.cypher # Subset?
sql/optimized.neo4j.schema.cypher # Which one?After:
schemas/domain/v1/neo4j/
βββ constraints.cypher # Uniqueness, existence constraints
βββ indexes.cypher # Performance indexes
βββ nodes.cypher # Node label definitions
βββ relationships.cypher # Relationship type definitions
βββ README.md # Which file to use whenBenefits:
- β One file per concern
- β Easier to find specific constraint or index
- β Can apply incrementally (constraints first, then indexes)
- β Clearer what each file does
Migration Steps
Phase 1: Reorganize Domain Schemas (Low Risk)
# 1. Create new directories
mkdir -p schemas/domain/v1/json
mkdir -p schemas/domain/v1/neo4j
# 2. Move JSON schemas
mv schemas/domain/v1/*.json schemas/domain/v1/json/
# 3. Move Neo4j schemas (symlink old location for compatibility)
cp sql/neo4j_comprehensive_schema.cypher schemas/domain/v1/neo4j/comprehensive.cypher
ln -s ../../schemas/domain/v1/neo4j/comprehensive.cypher sql/neo4j_comprehensive_schema.cypher
# 4. Update documentation paths
# Edit SCHEMA_MAPPING.md to point to new locationsPhase 2: Split Neo4j Comprehensive Schema (Medium Risk)
# Split comprehensive.cypher into logical files
python scripts/split_neo4j_schema.py \
schemas/domain/v1/neo4j/comprehensive.cypher \
--output schemas/domain/v1/neo4j/
# Result:
# schemas/domain/v1/neo4j/
# βββ constraints.cypher
# βββ indexes.cypher
# βββ nodes.cypher
# βββ relationships.cypherPhase 3: Reorganize Infrastructure Schemas (Medium Risk)
# Create infrastructure directories
mkdir -p schemas/infrastructure/postgresql
mkdir -p schemas/infrastructure/prisma
# Move PostgreSQL schemas
mv sql/*.sql schemas/infrastructure/postgresql/
# Symlink for backward compatibility
ln -s ../schemas/infrastructure/postgresql sqlPhase 4: Update Scripts and Documentation (Low Risk)
# Update paths in:
- scripts/validate_schema_sync.py
- scripts/regenerate_adapters.sh
- docs/SCHEMA_MAPPING.md
- docs/SCHEMA_WORKFLOW.mdComparison: Before vs After
Finding JSON Schema for League
Before:
database/schemas/domain/v1/league_payload_schema.json # Is this it?
database/schemas/domain/v1/api/league-master.schema.json # Or this?After:
database/schemas/domain/v1/json/league.schema.json # Clear!Finding Neo4j Schema
Before:
database/sql/neo4j_comprehensive_schema.cypher # Why in sql/?
database/sql/neo4j_league_mvp_schema.cypher # Which one?
database/sql/optimized.neo4j.schema.cypher # ???After:
database/schemas/domain/v1/neo4j/constraints.cypher # Constraints here
database/schemas/domain/v1/neo4j/indexes.cypher # Indexes here
database/schemas/domain/v1/neo4j/nodes.cypher # Nodes here
database/schemas/domain/v1/neo4j/relationships.cypher # Relationships hereAdding New Entity
Before:
1. Add to schemas/domain/v1/new_entity.schema.json
2. Add to sql/neo4j_comprehensive_schema.cypher (confusing location!)
3. Document in SCHEMA_MAPPING.mdAfter:
1. Add to schemas/domain/v1/json/new_entity.schema.json
2. Add to schemas/domain/v1/neo4j/nodes.cypher (logical location!)
3. Add to schemas/domain/v1/neo4j/constraints.cypher
4. Document in SCHEMA_MAPPING.md (paths clearer!)Updated Documentation Paths
SCHEMA_MAPPING.md
Before:
**JSON Schema:** `database/schemas/domain/v1/league_payload_schema.json`
**Neo4j Cypher:** `database/sql/neo4j_comprehensive_schema.cypher`After:
**JSON Schema:** `database/schemas/domain/v1/json/league.schema.json`
**Neo4j Cypher:**
- Constraints: `database/schemas/domain/v1/neo4j/constraints.cypher`
- Indexes: `database/schemas/domain/v1/neo4j/indexes.cypher`
- Nodes: `database/schemas/domain/v1/neo4j/nodes.cypher`validate_schema_sync.py
Before:
self.json_schema_dir = base_path / "schemas" / "domain" / "v1"
self.neo4j_schema_file = base_path / "sql" / "neo4j_comprehensive_schema.cypher"After:
self.json_schema_dir = base_path / "schemas" / "domain" / "v1" / "json"
self.neo4j_schema_dir = base_path / "schemas" / "domain" / "v1" / "neo4j"Benefits Summary
Clarity
- β
Neo4j schemas in
schemas/(not confusingly insql/) - β Domain vs infrastructure separation clear
- β Version folders group related schemas
Discoverability
- β
Easy to find JSON schema:
schemas/domain/v1/json/ - β
Easy to find Neo4j schema:
schemas/domain/v1/neo4j/ - β
Easy to find infrastructure:
schemas/infrastructure/
Maintainability
- β Related files versioned together (v1, v2)
- β Split Neo4j schema = easier to navigate
- β Clear what to edit vs what's generated
Scalability
- β Easy to add v2 alongside v1
- β
Easy to add new ORM (Drizzle) in
infrastructure/ - β
Validation script can scan
json/andneo4j/dirs
Risks and Mitigations
Risk: Breaking Existing Scripts
Mitigation:
- Phase 1: Create symlinks from old paths to new paths
- Update one script at a time
- Test after each change
Risk: Team Confusion
Mitigation:
- Clear documentation (this file)
- Update CLAUDE.md with new paths
- Announcement in team chat
Risk: Git History Confusion
Mitigation:
- Use
git mvinstead ofmvto preserve history - Document moves in commit message
- Keep old symlinks for a transition period
Rollback Plan
If reorganization causes issues:
# Restore old structure (symlinks still point correctly)
# or
git revert <commit-hash>Next Steps
- Review this proposal - Team approval
- Create migration script - Automate reorganization
- Test in branch - Verify scripts still work
- Update documentation - All paths updated
- Merge to main - Roll out changes
- Remove symlinks - After 1-2 weeks of compatibility
Questions?
Q: Why not keep Neo4j in sql/?
A: Cypher is not SQL. Different syntax, different database. Grouping by database type (PostgreSQL vs Neo4j) is clearer than mixing them in sql/.
Q: Why split Neo4j comprehensive schema? A: Easier to find constraints vs indexes. Can apply incrementally. Clearer what each file does.
Q: What about backward compatibility? A: Use symlinks during transition. Update scripts incrementally.
Q: When to remove symlinks? A: After 1-2 weeks, once all scripts and docs are updated.
Status: π Proposal (not implemented yet) Author: Development Team Date: 2025-01-14 Needs Approval: Yes