Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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:

  1. Named entry file — same name as the folder. Contains all implementation (class, factory, interfaces, types).
  2. index.ts barrel — 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, not config/index.ts.
  • index.ts only re-exports. No logic, no implementation.
  • Tests sit next to the entry file: config.test.ts, not index.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/*"] }. No baseUrl (TS 7+ removed it).
  • build.ts (esbuild): alias: { "@/": "./src/" }.
  • vitest.config.ts: resolve.alias: { "@/": <src path> }.

Rules

  1. Implement each module as a class.

  2. Instantiate modules only through a factory function. Never new outside the factory.

  3. 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);
}
  1. Keep implementation classes private unless direct construction or extension is explicitly supported.

  2. Constructors only store configuration and dependencies. Async initialization belongs in start().

  3. Lifecycle-managed modules expose idempotent start() and close(). Calling start() twice = no-op. Calling close() before start() = no-op.

  4. A module owns and closes only the child modules and resources it creates. Injected dependencies are borrowed — never close them.

  5. Start owned children in dependency order. Close them in reverse order.

  6. Clean up already-started children when startup fails. Partial startup → rollback.

  7. Keep dependencies explicit. No mutable global singletons.

  8. Module folder name = entry file name. admin-api/admin-api.ts, router/router.ts. Entry file holds all implementation.

  9. index.ts barrel re-exports only public symbols. No logic. Consumers import from the barrel (@/config), never directly from the entry file across modules.

Полный SKILL.md на GitHub

Установить 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), без исполняемых скриптов.

Похожие скиллы

Сравнить module-pattern с