ln-642-layer-boundary-auditor by levnikolaevich/claude-code-skills
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-642-layer-boundary-auditorPaths: File paths (
shared/,references/,../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root. Ifshared/is missing, fetch files via WebFetch fromhttps://raw.githubusercontent.com/levnikolaevich/claude-code-skills/master/skills/{path}.
L3 工作器,用于审计架构层级边界并检测违规行为。
不在范围内(由 ln-628-concurrency-auditor 负责):
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
- architecture_path: string # 指向 docs/architecture.md 的路径
- codebase_root: string # 要扫描的根目录
- skip_violations: string[] # 要跳过的文件(遗留文件)
- output_dir: string # 例如,"docs/project/.audit/ln-640/{YYYY-MM-DD}"
# 领域感知(可选,来自协调器)
- domain_mode: "global" | "domain-aware" # 默认:"global"
- current_domain: string # 例如,"users", "billing"(仅在 domain-aware 模式下)
- scan_path: string # 例如,"src/users/"(仅在 domain-aware 模式下)
当 domain_mode="domain-aware" 时: 对所有 Grep/Glob 操作使用 scan_path 而不是 codebase_root。用 domain 字段标记所有发现。
必须阅读: 加载 shared/references/two_layer_detection.md 以了解检测方法。
必须阅读: 加载 ../ln-640-pattern-evolution-auditor/references/layer_rules.md — 使用架构预设(备用方案)、I/O 模式边界规则(阶段 2)、覆盖率检查(阶段 4)、跨层级一致性规则(阶段 3)。
Read docs/architecture.md
Extract from Section 4.2 (Top-Level Decomposition):
- architecture_type: "Layered" | "Hexagonal" | "Clean" | "MVC" | etc.
- layers: [{name, directories[], purpose}]
Extract from Section 5.3 (Infrastructure Layer Components):
- infrastructure_components: [{name, responsibility}]
IF architecture.md not found:
Use fallback presets from layer_rules.md
Build ruleset:
FOR EACH layer:
allowed_deps = layers that can be imported
forbidden_deps = layers that cannot be imported
scan_root = scan_path IF domain_mode == "domain-aware" ELSE codebase_root
FOR EACH violation_type IN layer_rules.md I/O Pattern Boundary Rules:
grep_pattern = violation_type.detection_grep
forbidden_dirs = violation_type.forbidden_in
matches = Grep(grep_pattern, scan_root, include="*.py,*.ts,*.js")
FOR EACH match IN matches:
IF match.path NOT IN skip_violations:
IF any(forbidden IN match.path FOR forbidden IN forbidden_dirs):
violations.append({
type: "layer_violation",
severity: "HIGH",
pattern: violation_type.name,
file: match.path,
line: match.line,
code: match.context,
allowed_in: violation_type.allowed_in,
suggestion: f"Move to {violation_type.allowed_in}"
})
是什么: 在不一致的层级(仓库 + 服务 + API)调用 commit()/rollback()
检测:
repo_commits = Grep("\.commit\(\)|\.rollback\(\)", "**/repositories/**/*.py")
service_commits = Grep("\.commit\(\)|\.rollback\(\)", "**/services/**/*.py")
api_commits = Grep("\.commit\(\)|\.rollback\(\)", "**/api/**/*.py")
layers_with_commits = count([repo_commits, service_commits, api_commits].filter(len > 0))
安全模式(忽略):
_callbacks.py 结尾的文件(进度通知器)# UoW boundary 注释违规规则:
| 条件 | 严重性 | 问题 |
|---|---|---|
| layers_with_commits >= 3 | CRITICAL | 跨所有层混合了 UoW 所有权 |
| repo + api commits | HIGH | 事务控制绕过了服务层 |
| repo + service commits | HIGH | 模糊的 UoW 所有者(仓库 vs 服务) |
| service + api commits | MEDIUM | 事务控制跨越了服务和 API 层 |
例外: Saga 模式 / 具有显式补偿操作的分布式事务 → 将 CRITICAL 降级为 MEDIUM。UoW 边界用 // architecture decision 或 ADR 记录 → 跳过。
建议: 选择单一的 UoW 所有者(推荐服务层),从其他层移除 commit()
工作量: L(需要架构决策 + 重构)
是什么: 在同一调用链中混合了依赖注入注入的会话和本地创建的会话
检测:
di_session = Grep("Depends\(get_session\)|Depends\(get_db\)", "**/api/**/*.py")
local_session = Grep("AsyncSessionLocal\(\)|async_sessionmaker", "**/services/**/*.py")
local_in_repo = Grep("AsyncSessionLocal\(\)", "**/repositories/**/*.py")
违规规则:
| 条件 | 严重性 | 问题 |
|---|---|---|
| di_session AND local_in_repo in same module | HIGH | 仓库创建自己的会话,而 API 注入了不同的会话 |
| local_session in service calling DI-based repo | MEDIUM | 调用链中的会话不匹配 |
建议: 一致地使用依赖注入 或 一致地使用本地会话。记录例外情况(例如,遥测)
工作量: M
是什么: 服务层函数调用其他服务,而这些服务又调用其他服务 — 深度编排链。
检测: 必须阅读: 加载 shared/references/ai_ready_architecture.md — 映射服务导入,查找链深度。
违规规则:
| 条件 | 严重性 | 问题 |
|---|---|---|
| 服务链 >= 3 (A→B→C→D) | HIGH | 深度编排 |
| 服务链 = 2 (A→B→C) | MEDIUM | 考虑扁平化 |
建议: 提取编排器,在同一层级调用所有服务。每个服务成为一个接收端。
工作量: L
# HTTP 客户端覆盖率
all_http_calls = Grep("httpx\\.|aiohttp\\.|requests\\.", codebase_root)
abstracted_calls = Grep("client\\.(get|post|put|delete)", infrastructure_dirs)
IF len(all_http_calls) > 0:
coverage = len(abstracted_calls) / len(all_http_calls) * 100
IF coverage < 90%:
violations.append({
type: "low_coverage",
severity: "MEDIUM",
pattern: "HTTP Client Abstraction",
coverage: coverage,
uncovered_files: files with direct calls outside infrastructure
})
# 错误处理重复
http_error_handlers = Grep("except\\s+(httpx\\.|aiohttp\\.|requests\\.)", codebase_root)
unique_files = set(f.path for f in http_error_handlers)
IF len(unique_files) > 2:
violations.append({
type: "duplication",
severity: "MEDIUM",
pattern: "HTTP Error Handling",
files: list(unique_files),
suggestion: "Centralize in infrastructure layer"
})
必须阅读: 加载 shared/references/audit_worker_core_contract.md 和 shared/references/audit_scoring.md。
必须阅读: 加载 shared/references/audit_worker_core_contract.md 和 shared/templates/audit_worker_report_template.md。
# 在内存中构建 markdown 报告,包含:
# - AUDIT-META(基于标准惩罚:分数、计数)
# - 检查表(io_isolation, http_abstraction, error_centralization, transaction_boundary, session_ownership)
# - 发现表(按严重性排序的违规项)
# - DATA-EXTENDED: {architecture, coverage}
IF domain_mode == "domain-aware":
Write to {output_dir}/642-layer-boundary-{current_domain}.md
ELSE:
Write to {output_dir}/642-layer-boundary.md
Report written: docs/project/.audit/ln-640/{YYYY-MM-DD}/642-layer-boundary-users.md
Score: 4.5/10 | Issues: 8 (C:1 H:3 M:4 L:0)
必须阅读: 加载 shared/references/audit_worker_core_contract.md。
必须阅读: 加载 shared/references/audit_worker_core_contract.md。
{output_dir}/642-layer-boundary[-{domain}].md(原子性的单次写入调用)../ln-640-pattern-evolution-auditor/references/layer_rules.md../ln-640-pattern-evolution-auditor/references/scoring_rules.md版本: 2.1.0 最后更新: 2026-02-08
每周安装次数
140
代码仓库
GitHub 星标数
245
首次出现
2026年2月2日
安全审计
安装于
claude-code129
cursor129
gemini-cli127
codex127
opencode127
github-copilot125
Paths: File paths (
shared/,references/,../ln-*) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root. Ifshared/is missing, fetch files via WebFetch fromhttps://raw.githubusercontent.com/levnikolaevich/claude-code-skills/master/skills/{path}.
L3 Worker that audits architectural layer boundaries and detects violations.
Out of Scope (owned by ln-628-concurrency-auditor):
- architecture_path: string # Path to docs/architecture.md
- codebase_root: string # Root directory to scan
- skip_violations: string[] # Files to skip (legacy)
- output_dir: string # e.g., "docs/project/.audit/ln-640/{YYYY-MM-DD}"
# Domain-aware (optional, from coordinator)
- domain_mode: "global" | "domain-aware" # Default: "global"
- current_domain: string # e.g., "users", "billing" (only if domain-aware)
- scan_path: string # e.g., "src/users/" (only if domain-aware)
When domain_mode="domain-aware": Use scan_path instead of codebase_root for all Grep/Glob operations. Tag all findings with domain field.
MANDATORY READ: Load shared/references/two_layer_detection.md for detection methodology.
MANDATORY READ: Load ../ln-640-pattern-evolution-auditor/references/layer_rules.md — use Architecture Presets (fallback), I/O Pattern Boundary Rules (Phase 2), Coverage Checks (Phase 4), Cross-Layer Consistency rules (Phase 3).
Read docs/architecture.md
Extract from Section 4.2 (Top-Level Decomposition):
- architecture_type: "Layered" | "Hexagonal" | "Clean" | "MVC" | etc.
- layers: [{name, directories[], purpose}]
Extract from Section 5.3 (Infrastructure Layer Components):
- infrastructure_components: [{name, responsibility}]
IF architecture.md not found:
Use fallback presets from layer_rules.md
Build ruleset:
FOR EACH layer:
allowed_deps = layers that can be imported
forbidden_deps = layers that cannot be imported
scan_root = scan_path IF domain_mode == "domain-aware" ELSE codebase_root
FOR EACH violation_type IN layer_rules.md I/O Pattern Boundary Rules:
grep_pattern = violation_type.detection_grep
forbidden_dirs = violation_type.forbidden_in
matches = Grep(grep_pattern, scan_root, include="*.py,*.ts,*.js")
FOR EACH match IN matches:
IF match.path NOT IN skip_violations:
IF any(forbidden IN match.path FOR forbidden IN forbidden_dirs):
violations.append({
type: "layer_violation",
severity: "HIGH",
pattern: violation_type.name,
file: match.path,
line: match.line,
code: match.context,
allowed_in: violation_type.allowed_in,
suggestion: f"Move to {violation_type.allowed_in}"
})
What: commit()/rollback() called at inconsistent layers (repo + service + API)
Detection:
repo_commits = Grep("\.commit\(\)|\.rollback\(\)", "**/repositories/**/*.py")
service_commits = Grep("\.commit\(\)|\.rollback\(\)", "**/services/**/*.py")
api_commits = Grep("\.commit\(\)|\.rollback\(\)", "**/api/**/*.py")
layers_with_commits = count([repo_commits, service_commits, api_commits].filter(len > 0))
Safe Patterns (ignore):
_callbacks.py (progress notifiers)# UoW boundary commentViolation Rules:
| Condition | Severity | Issue |
|---|---|---|
| layers_with_commits >= 3 | CRITICAL | Mixed UoW ownership across all layers |
| repo + api commits | HIGH | Transaction control bypasses service layer |
| repo + service commits | HIGH | Ambiguous UoW owner (repo vs service) |
| service + api commits | MEDIUM | Transaction control spans service + API |
Exception: Saga pattern / distributed transactions with explicit compensating actions → downgrade CRITICAL to MEDIUM. UoW boundary documented with // architecture decision or ADR → skip.
Recommendation: Choose single UoW owner (service layer recommended), remove commit() from other layers
Effort: L (requires architectural decision + refactoring)
What: Mixed DI-injected and locally-created sessions in same call chain
Detection:
di_session = Grep("Depends\(get_session\)|Depends\(get_db\)", "**/api/**/*.py")
local_session = Grep("AsyncSessionLocal\(\)|async_sessionmaker", "**/services/**/*.py")
local_in_repo = Grep("AsyncSessionLocal\(\)", "**/repositories/**/*.py")
Violation Rules:
| Condition | Severity | Issue |
|---|---|---|
| di_session AND local_in_repo in same module | HIGH | Repo creates own session while API injects different |
| local_session in service calling DI-based repo | MEDIUM | Session mismatch in call chain |
Recommendation: Use DI consistently OR use local sessions consistently. Document exceptions (e.g., telemetry)
Effort: M
What: Service-layer functions calling other services that call yet other services — deep orchestration chains.
Detection: MANDATORY READ: Load shared/references/ai_ready_architecture.md — map service imports, find chain depth.
Violation Rules:
| Condition | Severity | Issue |
|---|---|---|
| Service chain >= 3 (A→B→C→D) | HIGH | Deep orchestration |
| Service chain = 2 (A→B→C) | MEDIUM | Consider flattening |
Recommendation: Extract orchestrator calling all services at same level. Each service becomes a sink.
Effort: L
# HTTP Client Coverage
all_http_calls = Grep("httpx\\.|aiohttp\\.|requests\\.", codebase_root)
abstracted_calls = Grep("client\\.(get|post|put|delete)", infrastructure_dirs)
IF len(all_http_calls) > 0:
coverage = len(abstracted_calls) / len(all_http_calls) * 100
IF coverage < 90%:
violations.append({
type: "low_coverage",
severity: "MEDIUM",
pattern: "HTTP Client Abstraction",
coverage: coverage,
uncovered_files: files with direct calls outside infrastructure
})
# Error Handling Duplication
http_error_handlers = Grep("except\\s+(httpx\\.|aiohttp\\.|requests\\.)", codebase_root)
unique_files = set(f.path for f in http_error_handlers)
IF len(unique_files) > 2:
violations.append({
type: "duplication",
severity: "MEDIUM",
pattern: "HTTP Error Handling",
files: list(unique_files),
suggestion: "Centralize in infrastructure layer"
})
MANDATORY READ: Load shared/references/audit_worker_core_contract.md and shared/references/audit_scoring.md.
MANDATORY READ: Load shared/references/audit_worker_core_contract.md and shared/templates/audit_worker_report_template.md.
# Build markdown report in memory with:
# - AUDIT-META (standard penalty-based: score, counts)
# - Checks table (io_isolation, http_abstraction, error_centralization, transaction_boundary, session_ownership)
# - Findings table (violations sorted by severity)
# - DATA-EXTENDED: {architecture, coverage}
IF domain_mode == "domain-aware":
Write to {output_dir}/642-layer-boundary-{current_domain}.md
ELSE:
Write to {output_dir}/642-layer-boundary.md
Report written: docs/project/.audit/ln-640/{YYYY-MM-DD}/642-layer-boundary-users.md
Score: 4.5/10 | Issues: 8 (C:1 H:3 M:4 L:0)
MANDATORY READ: Load shared/references/audit_worker_core_contract.md.
MANDATORY READ: Load shared/references/audit_worker_core_contract.md.
{output_dir}/642-layer-boundary[-{domain}].md (atomic single Write call)../ln-640-pattern-evolution-auditor/references/layer_rules.md../ln-640-pattern-evolution-auditor/references/scoring_rules.mdVersion: 2.1.0 Last Updated: 2026-02-08
Weekly Installs
140
Repository
GitHub Stars
245
First Seen
Feb 2, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
claude-code129
cursor129
gemini-cli127
codex127
opencode127
github-copilot125
代码库搜索技能指南:精准查找函数、追踪依赖、理解架构与定位错误
10,900 周安装