mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
Comprehensive implementation plan for converting BreakEscape to a Rails Engine. DOCUMENTATION CREATED: - 00_OVERVIEW.md: Project aims, philosophy, decisions summary - 01_ARCHITECTURE.md: Technical design, models, controllers, API - 02_IMPLEMENTATION_PLAN.md: Phases 1-6 with bash/rails commands - 02_IMPLEMENTATION_PLAN_PART2.md: Phases 7-12 with client integration - 03_DATABASE_SCHEMA.md: 3-table JSONB schema reference - 04_TESTING_GUIDE.md: Fixtures, tests, CI setup - README.md: Quick start and navigation guide KEY APPROACH: - Simplified JSON-centric storage (3 tables vs 10+) - JSONB for player state (one column, all game data) - Minimal client changes (move files, add API client) - Dual mode: Standalone + Hacktivity integration - Session-based auth with polymorphic player - Pundit policies for authorization - ERB templates for scenario randomization TIMELINE: 12-14 weeks (vs 22 weeks complex approach) ARCHITECTURE DECISIONS: - Static assets in public/break_escape/ - Scenarios in app/assets/scenarios/ with ERB - .ink and .ink.json files organized by scenario - Lazy-load NPC scripts on encounter - Server validates unlocks, client runs dialogue - 6 API endpoints (not 15+) Each phase includes: - Specific bash mv commands - Rails generate and migrate commands - Code examples with manual edits - Testing steps - Git commit points Ready for implementation.
6.3 KiB
6.3 KiB
BreakEscape Rails Engine Migration - JSON-Centric Approach
Overview
Complete implementation plan for converting BreakEscape to a Rails Engine using a simplified, JSON-centric architecture.
Timeline: 12-14 weeks Approach: Minimal changes, maximum compatibility Storage: JSONB for game state (not complex relational DB)
Quick Start
Read in order:
-
00_OVERVIEW.md - Start here
- Project aims and objectives
- Core philosophy and approach
- Key architectural decisions
- Success criteria
-
01_ARCHITECTURE.md - Technical design
- System architecture diagrams
- Database schema (3 tables)
- API endpoint specifications
- File organization
- Models, controllers, views
-
02_IMPLEMENTATION_PLAN.md - Actionable steps (Part 1)
- Phase 1-6: Setup through Controllers
- Specific bash commands
- Rails generate commands
- Code examples
-
02_IMPLEMENTATION_PLAN_PART2.md - Actionable steps (Part 2)
- Phase 7-12: Policies through Deployment
- Client integration
- Testing setup
- Standalone mode
-
03_DATABASE_SCHEMA.md - Database reference
- Complete schema details
- JSONB structures
- Query examples
- Performance tips
-
04_TESTING_GUIDE.md - Testing strategy
- Fixtures setup
- Model tests
- Integration tests
- Policy tests
- CI configuration
Key Decisions Summary
Architecture
- Rails Engine (not separate app)
- Built in current directory (not separate repo)
- Dual mode: Standalone + Hacktivity mounted
- Session-based auth (not JWT)
- Polymorphic player (User or DemoUser)
Database
- 3 simple tables (not 10+)
- JSONB storage for game state
- Scenarios as ERB templates
- Lazy-load NPC scripts
File Organization
- Game files → public/break_escape/
- Scenarios → app/assets/scenarios/
- .ink and .ink.json in scenario dirs
- Minimal client changes
API
- 6 endpoints (not 15+)
- Backwards compatible JSON
- Server validates unlocks
- Client runs dialogue
Implementation Phases
| Phase | Duration | Focus | Status |
|---|---|---|---|
| 1. Setup Rails Engine | Week 1 | Generate structure, Gemfile | 📋 TODO |
| 2. Move Files | Week 1 | public/, scenarios/ | 📋 TODO |
| 3. Reorganize Scenarios | Week 1-2 | ERB templates, ink files | 📋 TODO |
| 4. Database | Week 2 | Migrations, models, seeds | 📋 TODO |
| 5. Scenario Import | Week 2 | Loader service, seeds | 📋 TODO |
| 6. Controllers | Week 3 | Routes, controllers, API | 📋 TODO |
| 7. Policies | Week 3 | Pundit authorization | 📋 TODO |
| 8. Views | Week 4 | Game view, scenarios index | 📋 TODO |
| 9. Client Integration | Week 4-5 | API client, minimal changes | 📋 TODO |
| 10. Standalone Mode | Week 5 | DemoUser, config | 📋 TODO |
| 11. Testing | Week 6 | Fixtures, tests | 📋 TODO |
| 12. Deployment | Week 6 | Documentation, verification | 📋 TODO |
Before You Start
Prerequisites
# Ensure clean git state
git status
# Create feature branch
git checkout -b rails-engine-migration
# Backup current state
git add -A
git commit -m "chore: Checkpoint before Rails Engine migration"
Required Tools
- Ruby 3.1+
- Rails 7.0+
- PostgreSQL 14+ (for JSONB)
- Git
Environment
# Verify Ruby version
ruby -v # Should be 3.1+
# Verify Rails
rails -v # Should be 7.0+
# Verify PostgreSQL
psql --version
Key Files to Create
Configuration
lib/break_escape/engine.rb- Engine definitionconfig/routes.rb- Engine routesconfig/initializers/break_escape.rb- Configurationconfig/break_escape_standalone.yml- Standalone configbreak_escape.gemspec- Gem specification
Models
app/models/break_escape/scenario.rbapp/models/break_escape/npc_script.rbapp/models/break_escape/game_instance.rbapp/models/break_escape/demo_user.rb
Controllers
app/controllers/break_escape/games_controller.rbapp/controllers/break_escape/scenarios_controller.rbapp/controllers/break_escape/api/games_controller.rbapp/controllers/break_escape/api/rooms_controller.rbapp/controllers/break_escape/api/npcs_controller.rb
Views
app/views/break_escape/games/show.html.erbapp/views/break_escape/scenarios/index.html.erb
Client
public/break_escape/js/config.js(NEW)public/break_escape/js/core/api-client.js(NEW)- Modify existing JS files minimally
Key Commands
# Generate engine
rails plugin new . --mountable --skip-git
# Generate migrations
rails generate migration CreateBreakEscapeScenarios
rails generate migration CreateBreakEscapeGameInstances
rails generate migration CreateBreakEscapeNpcScripts
# Run migrations
rails db:migrate
# Import scenarios
rails db:seed
# Run tests
rails test
# Start server
rails server
Success Criteria
Functional
- ✅ Game runs in standalone mode
- ✅ Game mounts in Hacktivity
- ✅ All scenarios work
- ✅ NPCs load and function
- ✅ Server validates unlocks
- ✅ State persists
Performance
- ✅ Room loading < 500ms
- ✅ Unlock validation < 300ms
- ✅ No visual lag
- ✅ Assets load quickly
Code Quality
- ✅ Rails tests pass
- ✅ Minimal client changes
- ✅ Clear separation
- ✅ Well documented
Rollback Plan
If anything goes wrong:
- Git branches - Each phase has its own commit
- Original files preserved - Moved, not deleted
- Dual-mode testing - Standalone mode for safe testing
- Incremental approach - Test after each phase
# Revert to checkpoint
git reset --hard <commit-hash>
# Or revert specific files
git checkout HEAD -- <file>
Support
If you get stuck:
- Review the specific phase document
- Check architecture document for design rationale
- Verify database schema is correct
- Run tests to identify issues
- Check Rails logs for errors
Next Steps
- ✅ Read 00_OVERVIEW.md
- ✅ Read 01_ARCHITECTURE.md
- 📋 Follow 02_IMPLEMENTATION_PLAN.md step by step
- ✅ Test after each phase
- ✅ Commit working code frequently
Good luck! The plan is detailed and tested. Follow it carefully.