Use when setting up architecture dependency validation for TypeScript/JavaScript projects. Provides Clean Architecture and DDD dependency direction rules.
View on GitHubsizukutamago/dev-tools-plugin
dev-tools-plugin
skills/dependency-cruiser/SKILL.md
February 5, 2026
Select agents to install to:
npx add-skill https://github.com/sizukutamago/dev-tools-plugin/blob/main/skills/dependency-cruiser/SKILL.md -a claude-code --skill dependency-cruiserInstallation paths:
.claude/skills/dependency-cruiser/# dependency-cruiser アーキテクチャ検証
TypeScript/JavaScript プロジェクトの依存方向ルールを検証するためのガイドライン。
## 前提条件
- `dependency-cruiser` がインストール済み(`bun add -D dependency-cruiser` または `npm install -D dependency-cruiser`)
- TypeScript/JavaScript プロジェクト
## ワークフロー
1. **設定ファイル作成**: プロジェクトルートに `.dependency-cruiser.cjs` を作成
2. **ルール定義**: 下記の推奨設定をベースにカスタマイズ
3. **実行**: `bunx depcruise src` で検証(設定ファイルは自動検出)
4. **CI 連携**: package.json に `"lint:deps": "depcruise src"` 追加
## 推奨設定
### ベース設定(Clean Architecture)
```javascript
/** @type {import('dependency-cruiser').IConfiguration} */
module.exports = {
extends: 'dependency-cruiser/configs/recommended',
forbidden: [
{
name: 'no-infrastructure-to-services',
comment: 'repositories/db は services に依存してはいけない',
severity: 'error',
from: { path: 'src/(repositories|db)' },
to: { path: 'src/services' },
},
{
name: 'no-services-to-routes',
comment: 'services は routes に依存してはいけない',
severity: 'error',
from: { path: 'src/services' },
to: { path: 'src/routes' },
},
{
name: 'no-circular',
severity: 'error',
from: {},
to: { circular: true },
},
],
options: {
tsPreCompilationDeps: true,
doNotFollow: { path: 'node_modules' },
},
};
```
## ルール解説
### no-infrastructure-to-services
インフラ層(repositories, db)からドメイン層(services)への依存を禁止。
<Bad>
```typescript
// repositories/userRepository.ts
import { validateUser } from '../services/userService'; // ❌ 違反
export function findUser(id: string) {
const user = db.query(...);
return validateUser(user); // services のロジックを呼んでいる
}
```
</Bad>
<Good>
```typescript
// repositories/userRepository.ts
export function findUser(id: string) {
return db.query(...); // ✅ データ取得のみ
}
// services/userService.ts
import { findUser } from '../repositories/userRepository';
export function getValidatedUser(id: string) {
const user = findUser(id);
return validateUser(user); // services 内でバリデーション
}
```
</Good>
### no-