module-pattern
БесплатноБез исполняемых скриптовНе проверенRules for building, naming, and importing modules in klex. Use when creating modules, adding files to existing modules, writing cross-module imports, or…
от stagewise-io★ 44 звезды на GitHubОб этом скилле
Module Pattern
Apply to every module in klex. No exceptions.
File structure
Each module lives in its own folder. Two files are required:
- Named entry file — same name as the folder. Contains all implementation (class, factory, interfaces, types).
index.tsbarrel — re-exports all public symbols from the entry file. This is what consumers import from.
config/
config.ts # implementation: ConfigModule, createConfig, Config interface
config.test.ts # tests import from './config'
types.ts # internal type definitions (not re-exported unless public)
index.ts # export * from './config'; export * from './types';
- Entry file name = folder name.
config/config.ts, notconfig/index.ts. index.tsonly re-exports. No logic, no implementation.- Tests sit next to the entry file:
config.test.ts, notindex.test.ts. - Internal helpers within a module keep their own descriptive names (
server.ts,migrate.ts).
Import paths
- Cross-module imports use the
@/alias + barrel:from '@/config',from '@/model-provider'. - Intra-module imports stay relative:
from './server',from './types'. - Never bubble up relative paths (
../../config) — use@/instead.
// Good — cross-module via alias + barrel
import { createConfig } from '@/config';
import type { ModelProvider } from '@/model-provider';
// Good — intra-module relative
import { createAdminApp } from './server';
import type { Config } from './config'; // within same module folder
Infrastructure
The @/ alias requires configuration in three places — all must stay in sync:
tsconfig.json:paths: { "@/*": ["./src/*"] }. NobaseUrl(TS 7+ removed it).build.ts(esbuild):alias: { "@/": "./src/" }.vitest.config.ts:resolve.alias: { "@/": <src path> }.
Rules
Implement each module as a class.
Instantiate modules only through a factory function. Never
newoutside the factory.Factory returns the module's public handle — the interface consumers use.
export interface AgentRuntime {
start(): Promise<void>;
run(input: AgentInput): Promise<AgentResult>;
close(): Promise<void>;
}
class AgentRuntimeModule implements AgentRuntime {
// implementation
}
export function createAgentRuntime(
deps: AgentRuntimeDependencies,
): AgentRuntime {
return new AgentRuntimeModule(deps);
}
Keep implementation classes private unless direct construction or extension is explicitly supported.
Constructors only store configuration and dependencies. Async initialization belongs in
start().Lifecycle-managed modules expose idempotent
start()andclose(). Callingstart()twice = no-op. Callingclose()beforestart()= no-op.A module owns and closes only the child modules and resources it creates. Injected dependencies are borrowed — never close them.
Start owned children in dependency order. Close them in reverse order.
Clean up already-started children when startup fails. Partial startup → rollback.
Keep dependencies explicit. No mutable global singletons.
Module folder name = entry file name.
admin-api/admin-api.ts,router/router.ts. Entry file holds all implementation.index.tsbarrel re-exports only public symbols. No logic. Consumers import from the barrel (@/config), never directly from the entry file across modules.
Установить module-pattern в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл module-pattern?
Rules for building, naming, and importing modules in klex. Use when creating modules, adding files to existing modules, writing cross-module imports, or setting up import paths.
Как установить скилл module-pattern?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл module-pattern запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic