Create a new core infrastructure module with standard API, lazy init, and proper structure
/add-module <ModuleName>
Note: Modules are core infrastructure (always-on). For toggleable functionality, use /add-feature instead.
What infrastructure does this module provide?
Brief description:
Where does the module get its data?
A) Game runtime - Hooks into game code
B) Network - Captures WebSocket/HTTP
C) Assets - Game assets (sprites, audio, etc.)
D) Computed - Derives from other modules
E) Other: ___
Which existing modules does it depend on?
[ ] MGData [ ] MGSprite [ ] MGTile
[ ] MGPixi [ ] MGAudio [ ] MGCosmetic
[ ] MGVersion [ ] MGAssets [ ] MGManifest
[ ] MGEnvironment [ ] MGCalculators [ ] None
Does it need runtime state?
A) Yes - Caches data in memory (needs state.ts)
B) No - Stateless utilities only
What methods should the module expose?
(Besides required init/isReady)
Examples:
- get(key) - Get data by key
- calculate(params) - Perform calculation
- render(target) - Render something
src/modules/<moduleName>/
βββ index.ts # Public faΓ§ade (MG<ModuleName>)
βββ types.ts # Type definitions
βββ state.ts # Runtime state (if needed)
βββ logic/
βββ core.ts # Business logic
No logic/index.ts - Import directly from logic files.
/**
* <ModuleName> Module Types
*/
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Types
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export interface <ModuleName>Data {
// Define data structures
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Constants
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const <MODULE_NAME>_CONSTANTS = {
// Define constants
} as const;
/**
* <ModuleName> Module State
*
* Runtime cache/state management.
*/
import type { <ModuleName>Data } from './types';
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// State
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
let cache: <ModuleName>Data | null = null;
let ready = false;
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Accessors
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export function getCache(): <ModuleName>Data | null {
return cache;
}
export function setCache(data: <ModuleName>Data): void {
cache = data;
ready = true;
}
export function isReady(): boolean {
return ready;
}
export function reset(): void {
cache = null;
ready = false;
}
/**
* <ModuleName> Core Logic
*/
import { setCache, getCache } from '../state';
import type { <ModuleName>Data } from '../types';
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Initialization
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export async function initialize(): Promise<void> {
// Initialization logic
// Capture data, setup hooks, etc.
const data: <ModuleName>Data = {
// ...
};
setCache(data);
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Public Methods
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export function getData(): <ModuleName>Data | null {
return getCache();
}
/**
* <ModuleName> Module
*
* <Brief description>
*
* @example
* ```typescript
* await MG<ModuleName>.init();
* const data = MG<ModuleName>.get();
* ```
*/
import { initialize, getData } from './logic/core';
import { isReady as checkReady } from './state';
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// State
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
let initialized = false;
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Public API
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
/**
* Initialize the module
* Idempotent - safe to call multiple times
*/
async function init(): Promise<void> {
if (initialized) return;
initialized = true;
await initialize();
console.log('[<ModuleName>] Initialized');
}
/**
* Check if module is ready
*/
function isReady(): boolean {
return checkReady();
}
/**
* Get module data
*/
function get() {
return getData();
}
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Export
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
export const MG<ModuleName> = {
// Required (standard API)
init,
isReady,
// Module-specific
get,
// Add other public methods
};
export type { <ModuleName>Data } from './types';
src/modules/index.tsexport { MG<ModuleName> } from './<moduleName>';
export type { <ModuleName>Data } from './<moduleName>';
src/api/index.tsimport { MG<ModuleName> } from '../modules/<moduleName>';
Modules: {
// ... existing
<ModuleName>: MG<ModuleName>,
}
src/ui/loader/bootstrap.tsimport { MG<ModuleName> } from '../../modules/<moduleName>';
// In initModules():
await MG<ModuleName>.init();
index.ts exports MG<ModuleName>types.ts defines types/constantsstate.ts exists (if stateful)logic/ folder for business logiclogic/index.ts barrel fileinit() - Required, idempotentisReady() - Required, returns booleansrc/modules/index.tssrc/api/index.ts| Aspect | Module | Feature |
|---|---|---|
| Toggle | Always on | enabled: boolean |
| Location | src/modules/ |
src/features/ |
| Purpose | Infrastructure | Enhancement |
| API | MG<Name> |
MG<Name> |
| Storage | MODULE_KEYS (rare) |
FEATURE_KEYS |
.claude/rules/modules.mdsrc/modules/*/