| name | add-module |
| description | Create a new core infrastructure module with standard API, lazy init, and proper structure |
| aliases | ["new-module","create-module"] |
Add Module Skill
Usage
/add-module <ModuleName>
Note: Modules are core infrastructure (always-on). For toggleable functionality, use /add-feature instead.
Step 1: Ask Questions
1. Module Purpose
What infrastructure does this module provide?
Brief description:
2. Data Source
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: ___
3. Dependencies
Which existing modules does it depend on?
[ ] MGData [ ] MGSprite [ ] MGTile
[ ] MGPixi [ ] MGAudio [ ] MGCosmetic
[ ] MGVersion [ ] MGAssets [ ] MGManifest
[ ] MGEnvironment [ ] MGCalculators [ ] None
4. State Type
Does it need runtime state?
A) Yes - Caches data in memory (needs state.ts)
B) No - Stateless utilities only
5. Public API Methods
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
Step 2: Create Structure
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.
Step 3: File Templates
types.ts
export interface <ModuleName>Data {
}
export const <MODULE_NAME>_CONSTANTS = {
} as const;
state.ts (if needed)
import type { <ModuleName>Data } from './types';
let cache: <ModuleName>Data | null = null;
let ready = false;
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;
}
logic/core.ts
import { setCache, getCache } from '../state';
import type { <ModuleName>Data } from '../types';
export async function initialize(): Promise<void> {
const data: <ModuleName>Data = {
};
setCache(data);
}
export function getData(): <ModuleName>Data | null {
return getCache();
}
index.ts
import { initialize, getData } from './logic/core';
import { isReady as checkReady } from './state';
let initialized = false;
async function init(): Promise<void> {
if (initialized) return;
initialized = true;
await initialize();
console.log('[<ModuleName>] Initialized');
}
function isReady(): boolean {
return checkReady();
}
function get() {
return getData();
}
export const MG<ModuleName> = {
init,
isReady,
get,
};
export type { <ModuleName>Data } from './types';
Step 4: Register
Export → src/modules/index.ts
export { MG<ModuleName> } from './<moduleName>';
export type { <ModuleName>Data } from './<moduleName>';
API → src/api/index.ts
import { MG<ModuleName> } from '../modules/<moduleName>';
Modules: {
<ModuleName>: MG<ModuleName>,
}
Bootstrap → src/ui/loader/bootstrap.ts
import { MG<ModuleName> } from '../../modules/<moduleName>';
await MG<ModuleName>.init();
Step 5: Validate
Structure
API
Rules
Registration
Module vs Feature
| 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 |
References
- Rules:
.claude/rules/modules.md
- Existing modules:
src/modules/*/