Monster Compendium Engineering Notes
The monster compendium has been re-engineered from a static markdown generator to a dynamic Single Page Application (SPA) powered by Supabase. This transition allows for real-time data fetching, dynamic stat calculation, and a more robust filtering system.
monsters table.monster-service.js.monster_features table) to build the stat block.The architecture separates data fetching, routing, and view rendering into distinct ES6 modules.
/assets/js/monster/
monster-app.js: The application entry point and Router. Handles URL hash changes to toggle between views.monster-service.js: The Data Layer. Handles all asynchronous calls to the Supabase client./assets/js/monster/views/
monster-library.js: View Controller for the main list. Handles filtering (Species, Usage, CR, Size) and grid rendering.monster-detail.js: View Controller for the single monster page. Handles the responsive layout, D&D stat math, and Markdown parsing for descriptions.| Script | Description |
|---|---|
monster-app.js |
Router: Listens for window hash changes (e.g., #/:slug) and initializes the appropriate view handler. |
monster-service.js |
Service: Exports getMonsters() and getMonsterBySlug(). Joins data from monsters, monster_features, and discord_users. |
monster-library.js |
View: Renders the searchable grid. Contains logic for client-side filtering of the monster dataset. |
monster-detail.js |
View: Renders the full statblock. Calculates derived stats (e.g., calculatePB, calculateXP) and injects HTML into the container. |
monster-detail.js injects view-specific CSS styles dynamically to handle complex statblock layouts and mobile responsiveness (e.g., switching from grid to flex-column on small screens).