Files
2nd/10_Wiki/Topics/Domain_Programming/Architecture/Dependency_Analysis.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

5.6 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-dependency-analysis Dependency Analysis 10_Wiki/Topics verified self
dep-analysis
dependency-graph
code-dependency-tools
none A 0.9 applied
tooling
dependencies
static-analysis
2026-05-10 pending
language framework
javascript madge/depcheck/knip

Dependency Analysis

매 한 줄

"매 import graph 가 매 codebase 의 X-ray". 매 Madge / dependency-cruiser / Knip / depcheck 가 매 dead code, circular deps, layering violations, unused packages 의 surface. 2026 의 매 Knip + dependency-cruiser + Turbo's prune 가 매 monorepo standard combo.

매 핵심

매 question types

  1. Module-level: who imports X? what does X import?
  2. Package-level: which deps are unused? which are dev-only mislabeled?
  3. Architectural: 매 cross-layer 의 import 가 있나?
  4. Cycles: 매 circular dependency.
  5. Reachability: 매 entry-point 의 reachable X 의 dead code.

매 tool matrix

  • Madge — 매 visualization, circular detection (JS/TS).
  • dependency-cruiser — 매 rules engine + violations CI.
  • Knip — 매 unused files/exports/deps (replaces ts-prune + depcheck).
  • depcheck — 매 unused npm deps (older, Knip 가 better).
  • ts-morph / typescript-eslint — 매 custom AST analyzer.
  • Nx graph / Turborepo prune — 매 monorepo affected detection.

매 응용

  1. CI guard — 매 layer violation 시 fail.
  2. Dead-code removal — 매 quarterly cleanup.
  3. Bundle reduction — 매 unused dep removal → smaller install + lockfile.
  4. Refactor planning — 매 high-fan-in module 의 identify.
  5. License audit — 매 transitive dep tree.

💻 패턴

Madge 의 circular detection

npx madge --circular --extensions ts,tsx src/
# 매 circular 가 있으면 fail.

npx madge --image graph.svg src/
# 매 SVG 의 visualization.

dependency-cruiser rules

// .dependency-cruiser.cjs
module.exports = {
  forbidden: [
    { name: 'no-circular', severity: 'error', from: {}, to: { circular: true } },
    { name: 'no-orphans', severity: 'warn', from: { orphan: true, pathNot: '\\.test\\.ts$' }, to: {} },
    { name: 'domain-not-import-ui', severity: 'error',
      from: { path: '^src/domain' }, to: { path: '^src/ui' } },
    { name: 'no-deprecated-core', severity: 'error',
      from: {}, to: { dependencyTypes: ['core'], path: '^(punycode|domain)$' } },
  ],
  options: { tsConfig: { fileName: 'tsconfig.json' } },
};
depcruise --config .dependency-cruiser.cjs src/

Knip (unused exports/files/deps)

// knip.json
{
  "entry": ["src/index.ts", "src/cli.ts"],
  "project": ["src/**/*.{ts,tsx}"],
  "ignoreDependencies": ["husky"]
}
npx knip
# 매 unused files, unused exports, unused deps 의 list.

Turborepo prune (monorepo)

turbo prune --scope=@acme/web --docker
# 매 web 의 deps 만 가진 minimal package.json 의 emit — Docker layer cache 의 efficient.

Nx affected graph

npx nx graph
npx nx affected:test --base=main
# 매 변경된 project 의 transitive consumers 만 test.

Custom AST scanner (ts-morph)

import { Project } from 'ts-morph';
const project = new Project({ tsConfigFilePath: 'tsconfig.json' });
const violations: string[] = [];
for (const sf of project.getSourceFiles()) {
  for (const imp of sf.getImportDeclarations()) {
    const spec = imp.getModuleSpecifierValue();
    if (sf.getFilePath().includes('/domain/') && spec.startsWith('@/ui')) {
      violations.push(`${sf.getFilePath()} -> ${spec}`);
    }
  }
}
if (violations.length) { console.error(violations.join('\n')); process.exit(1); }

Bundle-level (esbuild metafile / vite-bundle-visualizer)

vite build --emptyOutDir
npx vite-bundle-visualizer
# 매 actual shipped bytes per package — install-time deps 의 differ.

License + SBOM cross-check

npx license-checker --production --json > licenses.json
npx @cyclonedx/cyclonedx-npm --output-file sbom.json

매 결정 기준

상황 Approach
Quick circular check Madge
Layer enforcement in CI dependency-cruiser
Unused files/exports/deps Knip
Monorepo affected detection Turbo / Nx
Custom rules ts-morph script
Bundle size (runtime) vite/esbuild visualizer

기본값: Knip + dependency-cruiser in CI; Madge ad-hoc for visualization; Turbo/Nx in monorepos.

🔗 Graph

🤖 LLM 활용

언제: 매 dependency-cruiser rule synthesis from architecture description, 매 Knip output 의 triage (which 의 truly unused), 매 graph interpretation. 언제 X: 매 actual dead-code removal 의 PR (false positive 의 review 필요). 매 production runtime decisions.

안티패턴

  • Run only locally: 매 CI guard 가 X — 매 violation 의 sneak in.
  • Knip 의 trust blindly: 매 dynamic require / framework convention 가 false-positive — ignore glob 사용.
  • No layer rules: 매 architecture 가 silently rot.
  • Visualization only: 매 SVG 가 cool 가, 매 enforcement 가 X.
  • Run on dist/: 매 source 의 analyze, 매 bundled 의 X.

🧪 검증 / 중복

  • Verified (Madge docs, dependency-cruiser docs, Knip docs, Turborepo, Nx).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — dependency analysis tools and CI patterns