How manusajith/ex_mmog works
Project type and purpose
• This is a full-stack, browser-based multiplayer online game built with Elixir and the Phoenix framework.
• Purpose: render a 2D grid in the browser, allow players to move, attack, die, respawn, and see each other in real time.
File structure
• Top-level:
• assets/ – JavaScript/CSS, Webpack config, static files (frontend build pipeline).
• lib/ex_mmog/ – core game logic and OTP application entry point.
• lib/ex_mmog_web/ – Phoenix web layer: endpoint, router, controllers, LiveView, channels, templates, views.
• config/ – environment settings and release configuration.
• priv/ – gettext translations.
• test/ – unit tests for game logic and web layer.
• Patterns:
• MVC + real-time channels / LiveView.
• OTP supervision: Application.ex boots the endpoint, PubSub, GameSupervisor, etc.
• Game logic isolated in lib/ex_mmog/game/* following a state-machine pattern (actions, state, players).
README for additional insights
• Confirms real-time browser game at /game.
• Game mechanics: move, attack within radius, respawn.
• No external database: state is held in memory via GenServers.
• Deployed as an Elixir Release to Gigalixir.
a. Client Side
• Browser UI (HTML/CSS/JS built by Webpack, rendered via templates and LiveView)
• WebSocket connection (Phoenix Channels / LiveView socket)
b. Server Side
• Phoenix Endpoint (HTTP & WebSocket listener)
• Router → directs /game to GameController or GameLive
• GameController (initial page load)
• GameLive (LiveView process handling UI updates and events)
• UserSocket → Channel(s) for presence and real-time messaging
• GameSupervisor → supervises dynamic game GenServers
• GameServer (per-game or single shared GenServer)
• Game modules: Board, State, Players, Actions (attack, move, join, cleanup)
• PubSub (Phoenix.PubSub) for broadcasting state changes
c. Optional
• I18n via Gettext (priv/gettext)
• Deployment (Release, Gigalixir)
Relationships and interactions
• Browser sends HTTP GET /game → Phoenix Endpoint → Router → GameController → renders template + mounts GameLive.
• GameLive opens WebSocket to UserSocket → joins “game:lobby” channel or mounts LiveView.
• Player actions (clicks, keypresses) → pushed as events over socket → GameLive.handle_event or Channel.handle_in.
• Those handlers invoke GameServer via GenServer.call/cast.
• GameServer updates its state (Board, Players, State modules).
• After state change, GameServer publishes update via PubSub.
• GameLive or Channels subscribe and broadcast to connected clients → UI rerenders.
Architectural patterns & principles
• MVC for initial requests; real-time MVU (Model-View-Update) with LiveView/Channels.
• OTP: supervision tree, fault tolerance, stateful GenServers.
• Single or small set of GameServer processes rather than database persistence—low latency in-memory state.
• Clear separation: web concerns (controllers/views/templates) vs. game logic modules.
Technologies / frameworks to label
• Elixir & OTP (Supervisor, GenServer)
• Phoenix (Endpoint, Router, Controllers, Views, Templates)
• Phoenix LiveView / Channels (real-time updates)
• Webpack / Babel / npm (frontend asset pipeline)
• Gigalixir + Elixir Releases (deployment)