How diogo-vf/rythmtree works
Project Type & Purpose
• RythmTree is a full-stack, real-time rhythm-game web application.
• Frontend (HTML/JS/CSS/SASS) serves the game UI, assets, and lobby.
• Backend (Ruby) handles HTTP page serving, REST/WS APIs, game state, and persistence in MongoDB.
File Structure
• Top-level “client” folder: contains UI views (HTML), scripts (JS modules under core, actions, adapters), styles (SASS → CSS), images, audio assets, and tests.
• Top-level “server” folder: custom HTTP server, WebSocket server, MVC-style controllers and models, configuration, utility scripts, and app_start entry point.
• Config files in both client and server configure ports, pages, and data sources.
• Build scripts: SASS watcher compiles .scss → .css.
README for Insights
• Tech stack: Ruby 2.6.3, MongoDB, SASS for CSS preprocessing.
• Run steps: sass --watch… for styles, ruby server/app_start.rb to launch both HTTP and WS servers.
• Configurable HTTP_PORT, MongoDB driver Gems.
Main Components & Their Interactions
a. Client-side Browser
– Serves static assets: HTML views, JS bundle, CSS.
– Core JS modules manage page navigation, UI rendering, game logic, and WS messaging.
– Initiates WebSocket connections for real-time events and HTTP requests for page loads or REST endpoints (e.g., login, level metadata).
b. HTTP Server (Ruby)
– Listens on configured HTTP_PORT.
– Routes initial page requests to view templates (controllers under server/controllers).
– Exposes REST endpoints for CRUD operations on levels, players, replays, textures, sequences, music.
c. WebSocket Server (Ruby)
– Separate listener for real-time game data (e.g., rhythm cues, player actions).
– Manages persistent WS connections via server/websocket_server/connection.rb.
d. Application Controllers & Models
– Controllers (levels.rb, players.rb, etc.) orchestrate requests, invoke model operations, serialize JSON.
– Models wrap MongoDB collections (mongoDB.rb, level.rb, player.rb, etc.), provide data access and validation.
e. MongoDB
– Stores persistent game entities: level designs, player stats, replays, audio references, textures.
f. Build/Dev Tools
– SASS compiler watches SCSS and outputs CSS.
– Optional file watcher (server/watcher.rb) for automatic reloads.
Architectural Patterns & Design Principles
• MVC pattern on the server: Controllers → Models → MongoDB.
• Modular JS on the client: core modules (boot, builder, pagesManager, wsManager) + adapters + actions.
• Clear separation of concerns: static asset serving vs. API vs. real-time messaging.
• Configuration-driven: config/config.js and config/config.rb drive environment specifics.