Skip to content
Back to skills

Code Structure

ASecurity

Read-only review of the code structure of a whole repo (tree, manifests, import graph, entrypoints, docs, ADRs and git history), not line by line. Looks for module or layer boundaries that are not respected, dependency cycles, the same problem solved several ways, god-modules, files across modules that always change together, unused code and packages, and docs or ADRs that contradict the code. Ships deterministic scripts for the import graph (TS/JS, Python, Go) and the history. Reports and st...

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 17, 2026
developmentpythonrustgojavac#dockergitapici/cdsecurity

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned November 17, 2026

npx -y skills add OmarAlex24/audit-skills --skill code-structure --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Code Structure?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Code Structure
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/omaralex24-code-structure/badge)](https://www.skillsdirectory.com/skills/omaralex24-code-structure)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: code-structure
description: Read-only review of the code structure of a whole repo (tree, manifests, import graph, entrypoints, docs, ADRs and git history), not line by line. Looks for module or layer boundaries that are not respected, dependency cycles, the same problem solved several ways, god-modules, files across modules that always change together, unused code and packages, and docs or ADRs that contradict the code. Ships deterministic scripts for the import graph (TS/JS, Python, Go) and the history. Reports and stops. Use it for "review the code structure", "find circular dependencies", "find dead code", "are module boundaries respected", "does this module do too much?", "what always changes together", even if they never say "structure". Not for system design (architecture-review), infra (infra-review) or line-by-line bugs (correctness-review and the others). Also triggers on Spanish requests such as "revisa la estructura del código", "¿hay dependencias circulares?", "¿qué código está muerto?" or "¿se respetan las capas?".
---

# Code structure review

A structure review answers one question: is the code organized the way the team and its docs say, and does that organization help change it, or does every change cross half the repo? The evidence is structural: who imports whom, what changes together in the history, what nobody uses, what the docs say. It does not read line by line looking for bugs; the other skills do that.

Material: [references/signals.md](references/signals.md) (catalog), [references/report-template.md](references/report-template.md), [references/sources.md](references/sources.md) and deterministic scripts in `scripts/` (`import-graph.py` and `git-history.py`, which share `lines.py`).

Write the report in the user's language.

**Provenance.** This project's Arjay McCandless videos do not cover this topic. Everything in this skill is **(added)**, established practice, or **(doc)**, checked in the documentation of a tool or a standard, dated in [sources.md](references/sources.md). Do not cite a video for this.

## Rules

- **Read-only.** Phases 0 to 4 change nothing: no code, no git, no dependencies. You do not install tools (`knip`, `madge`, `dependency-cruiser`, `vulture`): if the repo already has them configured, you may read their config and their committed results; run them only if the user asks. Git is used only to read (`git --no-optional-locks log`, `ls-files`), with no fetch or checkout.
- **The scripts give facts, not verdicts.** A cycle, a file with no importers or a pair that changes together is a candidate. It becomes a finding when you read the code and the context and it is not ruled out.
- **A written decision with its reason is not a finding.** If an ADR or a doc says "`core` may import `db` because…", that is not reported. If the reason no longer holds, it is, citing the decision.
- **Report first, apply only what the user picks** (phase 5).
- **Each topic in its skill.** System design (requirements, data, APIs, availability, monolith or microservices as a decision) belongs to `architecture-review`; IaC, environments, Docker and compose, K8s, CI/CD, deploy, config and secrets management, backups and restore, monitoring and alarms, platform limits, infrastructure single points, pinned versions and infra cost, to `infra-review`; measuring latency or load, to `perf-diagnosis`; transactions, dual writes, idempotency and consistency, to `data-consistency`; auth, secrets and rate limiting, to `api-security-review`; a `status` written from many places, to `implicit-state-machines`; a formula, a boundary, a condition, a parsing step or a default value that gives a wrong result, to `correctness-review`; the code that calls an LLM (prompt injection, tools, unvalidated output, cost, provider failures), to `llm-app-review`. What comes in here is the shape of the code: if "the same problem solved several ways" loses data, the data finding belongs to `data-consistency`, and if one of the copies gives a wrong total, the calculation error belongs to `correctness-review`; the duplication stays here. When a signal falls in another skill, note it under "Not covered" with the skill it goes to and do not develop it.

## Phase 0: scope and context

1. **Scope.** The whole repo, unless the user says otherwise. This skill looks at relationships between parts; a single file has no structure to review.
2. **Context.** Read AGENTS.md, CLAUDE.md, README, `docs/`, ADRs and the config of any structure tools that already exist (`dependency-cruiser` rules, `import-linter` contracts, `knip.json`, ESLint import rules, `CODEOWNERS`). Note each structure rule the repo declares: those are checked first.
3. **Inventory.** Manifests (`package.json` and workspaces, `pyproject.toml`, `go.mod`, `Cargo.toml`), entrypoints (servers, CLIs, workers, `package.json` scripts, `__main__`, `cmd/`) and the tree down to two or three levels.

## Phase 1: graph and history

Run the two scripts on the repo, with the output outside it (for example, a temporary directory):

```sh
python3 -I scripts/import-graph.py <repo> --output <dir> [--exclude '<glob>' ...]
python3 -I scripts/git-history.py <repo> --output <dir> [--exclude '<glob>' ...]
```

Both only read and are deterministic: same HEAD, same result. `graph.md` gives the modules with their incoming and outgoing imports, the edges between modules, the module and file cycles, the imports into another module's internals, the files with no importers and the ones only tests import. `history.md` gives the files that change most and the pairs of files from different modules that change together. Both say what they did not understand (languages they do not resolve, dynamic imports, skipped commits): that goes to "Not covered"; it is not guessed.

If `python3` is not available or the repo is not a git repo, continue by hand with what there is and say so. In a repo in another language (Java, Rust, C#), the graph does not cover it: use the manifests and the imports you read, and say so.

## Phase 2: go through the signals

With the graph, the history and the declared rules, go through [signals.md](references/signals.md): N module and layer boundaries, P cycles, Q the same problem solved several ways, T god-modules and change coupling, U unused code and packages, V docs and ADRs against the code. Start with the rules the repo declares (phase 0) and with what the graph flags; then look for what the graph does not see (Q's duplication is found by reading, not by imports).

## Phase 3: confirm or rule out each candidate

1. **Read the evidence.** Open both ends of each suspicious import or pair. A cycle may be type-only (`import type`), a file "with no importers" may be loaded by framework convention, by config or by a string.
2. **Try to rule it out** with its signal's "false positive" and with the written decisions.
3. **Say how confident you are.** **Confirmed** if you read every step (the import and what it brings, the written rule it breaks). **Likely** if it depends on something you did not check (a dynamic loader, config outside the repo); name that step. **Smell** if it is a pattern with no demonstrated cost.
4. **Say what it costs.** A structure finding is justified by what it makes more expensive: a change that forces touching several modules (with the history as evidence), a module that cannot be tested or deployed on its own, a doc that leads someone to change the wrong thing. If you cannot name the cost, it is a Smell or it is ruled out.
5. **Classify it**: **finding**, **open question** or **ruled out** ("reviewed, does not apply because…", with its line).

## Phase 4: propose, report and stop

For each finding, the fix from the lightest to the heaviest: write the missing rule (a doc, an ADR, an import lint rule), move a file or a function, extract an interface, split a module. Prefer the one that makes the rule verifiable in CI with the least movement. Write the report with [report-template.md](references/report-template.md), end by asking what to apply, with your recommended order, and offer in one line to save the report to a file. **Then stop.**

## Phase 5: apply (only what the user picked)

Confirm in one line what you will apply. Then, one by one: the smallest move, following the repo's patterns, without mixing a structure refactor with behavior changes. Run the project's checks (lint, typecheck, tests) and run the graph again to show the cycle or the import is gone. No commits, push or PRs unless asked.

## Common mistakes

- Reporting every cycle or every file with no importers the script gives without reading it: type imports, entrypoints by convention and plugins loaded by name are frequent false positives.
- Proposing a layered architecture the repo never declared and calling whatever does not follow it a "violation". The rule has to be written in the repo, or the finding is a question.
- Counting lines or files as if they were the problem: a large module that changes little and drags nobody along is not a god-module.
- Reading the history as a judgment about people. The pairs that change together describe the code, not who writes it.
- Proposing a split into packages or microservices as the first fix.

## Swarm mode

It turns on when the invocation brings a swarm brief (between `[swarm brief]` and `[end of brief]`), with `contract:`, `map:`, `structure:`, `output:` and `data:`. Used on its own, the skill follows the procedure above unchanged, report included. In this mode:

- **Phases:** follow phases 0 to 3 and, from phase 4, only the lightest fix for each finding, its risk and its test; you apply nothing. The brief's map replaces the context reading of phase 0, but read what the map points to (modules, entrypoints, doc claims) and whatever it is missing.
- **Graph and history already done:** you do not run the phase 1 scripts. The coordinator already ran them; `graph.md`, `graph.json`, `history.md` and `history.json` are in the `structure:` folder. If they are missing, say so in `not_covered` and continue with what you can read.
- **No questions and no waiting:** what you would ask the user goes to the `questions` field; you do not stop to wait for an answer.
- **No subagents or reviewers:** the swarm does the independent verification. Make the pass that tries to rule out each finding yourself and declare in `not_covered` what you did not cover.
- **Data:** you do not need it. You never open connections or read `.env` looking for credentials.
- **Scope:** the brief brings `scope:` instead of `slice:`. You run once over the whole repo and read structure, not line by line; the per-slice auditors cover the fine-grained code. `outside_slice` stays empty. If the brief brings `exclude:`, the scope is the repo minus what is excluded: you do not audit it, do not cite it as evidence and do not report anything whose main location falls there; you may open it only to understand a call or a dependency that leaves the scope, and you say so in `not_covered`.
- **Limits:** you do not modify the audited repo and you do not read other audit runs or other auditors' folders, except what the brief gives you: contract, map, `structure:` and your folder.
- **Metric:** fill `metric` in each finding per `before-after.md` (next to the contract the brief gives), with this skill's row of its "Guide per skill" as the hint: import cycles, unused files or imports that cross layers, counted with the scripts in `code-structure/scripts/` or the files in `structure:`. A metric is a command that is run again, never a count of findings, and you do not invent its result: `{not_measurable: "<why>"}` is valid.
- **Output:** a single file, `findings.json`, in the folder the brief gives (`your folder:`), with the contract's object, and that same object as your answer. In swarm mode you write no readable report and no other file: the report template is for normal mode and the swarm's plan comes from the `findings.json` files. Use the contract's vocabulary: confidence, method, severity, effort and action.

Files in this skill

  • SKILL.md11.8 KB
  • references/report-template.md3.3 KB
  • references/signals.md14.2 KB
  • references/sources.md3.2 KB
  • scripts/git-history.py7.8 KB
  • scripts/import-graph.py31.1 KB
  • scripts/lines.py10.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.