code-structure
Skill3 starsChanged 3 months agoMITView on GitHub
MUST USE when creating or editing any code file in any language — deciding how to split files, functions, classes, and modules, or whether to extract a shared helper, base class, or utility from duplicated code. Enforces the Single Responsibility Principle (one reason to change, file/function size limits, separation of concerns) and Avoid-Hasty-Abstractions (AHA / Rule of Three — prefer duplication over the wrong abstraction).
8 other projects use a version of this.
Adopted by
Most recently taken up by
- imornar/skillstheir own version, first seen Sep 17, 2026
- rikvanriel/code-hygienetheir own version, first seen Sep 17, 2026
- Nagacash/nagacodex-factory-skilltheir own version, first seen Sep 15, 2026
- michaelshimeles/skillstheir own version, first seen Sep 4, 2026
- voundbrand/overnighttheir own version, first seen Sep 3, 2026
- kellykampen/agent-skillstheir own version, first seen Jul 28, 2026
Used with
Projects with it also use evidence-driven-testing, greploop-apps and 3 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
kellykampenSkillevidence-driven-testing
Records visual proof while testing UI behavior — screen recording with structured test/assertion annotations — then posts the video and a results summary to the PR and tracker issue. Use whenever a UI change needs verifiable evidence that it works, instead of prose claims.
Also in 4 projects that use this
michaelshimelesSkillgreploop-apps
Iteratively improves a PR (GitHub), MR (GitLab), or shelved changelist (Perforce) until Greptile gives it a 5/5 confidence score with zero unresolved comments. Identical to greploop, but triggers reviews by tagging @greptile-apps, which bypasses Greptile's file-count limit on huge PRs that the plain @greptile mention refuses to review. Use when the user wants to fully optimize a large PR/MR/CL against Greptile's code review standards.
Also in 3 projects that use this
VercelSkillbefore-and-after
Add existing screenshots or screen recordings to a GitHub pull request as a before/after or preview block. Use when a PR needs visual media attached to its description. Browser navigation and capture belong to agent-browser.
Also in 3 projects that use this
undeadlistSkillnew-feature
Develop new features with test-first approach (TDD)
Also in 3 projects that use this
MicrosoftSkillunslop
Cut AI tells from any writing. Must always apply.
Also in 3 projects that use this
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- michaelshimeles/skills★ 1.2ksame name
- kellykampen/agent-skills★ 2same name
- nitikeshq/skills★ 2same name
- voundbrand/overnight★ 2same name
- Nagacash/nagacodex-factory-skill★ 1same name
- IcodeNet/agent-skills★ 0same name
- imornar/skills★ 0same name
- rikvanriel/code-hygiene★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- debuggingSkill
- docker-best-practicesSkill
- drf-best-practicesSkill
- drizzle-ormSkill
- expressSkill
- fastapiSkill
- git-merge-conflictsSkill
- reactSkill
- researchSkill
- security-practicesSkill
- sqlSkill
- tanstack-querySkill
- tanstack-routerSkill
- testing-best-practicesSkill
- typescript-best-practicesSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 56
All callers would break together, for the same reason, if the logic were wrong.
- Distinctive: line 91
Inline a wrong abstraction: before trying to "fix" it with more parameters.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Code Structure — Responsibility & Abstraction
Two complementary disciplines decide how code is shaped. They pull in opposite directions, and good structure is the balance between them:
- Single Responsibility (SRP) — when to split. One unit, one job, one reason to change.
- Avoid Hasty Abstractions (AHA) — when not to extract. Duplication is cheap; the wrong abstraction is expensive.
The synthesis: split on responsibility, never on shape or line count alone. SRP tells you to separate two jobs that happen to sit in one file; AHA tells you not to merge two blocks that merely look alike.
Quick Reference — When to Load What
| Working on… | Read |
| Splitting a file/function/class, separating concerns, file size | SINGLE-RESPONSIBILITY.md |
| Tempted to extract a helper/base class/utility from duplicated code | AVOID-ABSTRACTIONS.md |
Hard Limits
Concrete, enforceable thresholds. Crossing one is a signal to split — not an automatic split, but a prompt to check for a second responsibility.
| Metric | Max | Action |
| File length | 200 lines | Split into smaller modules |
| Function/method body | 30 lines | Extract helpers |
| Function parameters | 3 | Use an options/config object |
| Nesting depth | 3 levels | Early returns or extracted helpers |
| Cyclomatic complexity | 5 branches | Simplify or split |
| Class dependencies | 5 imports | The class knows too much — split |
The Split Test (SRP)
Describe the unit in one sentence. If you need "and", it has more than one responsibility.
"fetches the orders" → one job
"fetches the orders AND formats them for export" → two jobs — splitA unit has one reason to change when it serves one actor. If the business team and the ops team would both edit the same file for unrelated reasons, that file has two responsibilities. See SINGLE-RESPONSIBILITY.md for separation of concerns (computation vs side effects, query vs command, policy vs mechanism).
The Extraction Test (AHA)
Similar-looking code is not a reason to extract. Before pulling out a shared helper, all of these must hold:
- The pattern appears 3+ times with identical intent — not just identical shape.
- You can name it for what it does, not how (
calculateTax, notprocessWithFlags). - No caller needs a boolean or mode parameter to bend it to their case.
- All callers would break together, for the same reason, if the logic were wrong.
# BAD: extracted on shape — a flag now leaks caller-specific behavior
def send(user, kind):
if kind == "welcome": ...
elif kind == "reset": ...
# GOOD: two purpose-named functions; duplication is a vocabulary, not debt
def send_welcome(user): ...
def send_password_reset(user): ...Every boolean parameter hides two functions in a trench coat. If extraction needs a flag, you found two functions, not one abstraction. See AVOID-ABSTRACTIONS.md for the failure pattern and how to undo a wrong abstraction.
When NOT to Split
The two forces meet here. Keep code together when:
- Two things always change together and serve the same actor (verify with
git log, not vibes). - Splitting would add indirection with no testability gain.
- The unit is under ~30 lines and reads clearly as-is.
- Code is merely coincidentally similar — same shape, different intent. Leave it duplicated.
Rules
- Describe a unit in one sentence without "and" — if you can't, it has two jobs; split it.
- Separate computation from side effects, and queries from commands (CQS).
- Never exceed 200 lines/file or 30 lines/function — split before crossing, not after.
- Never nest deeper than 3 levels — use early returns.
- Never mix levels of abstraction in one function.
- Never extract on the second duplication — wait for the third, and only if intent (not just shape) matches.
- Never add a boolean/mode parameter to make a shared helper fit a new caller — split into purpose-named functions.
- Never extract a helper used in exactly one place.
- Split on responsibility, never on line count or visual similarity alone.
- Inline a wrong abstraction before trying to "fix" it with more parameters.
- Don't over-split — only split when there is a real second responsibility.
Reference Files
- SINGLE-RESPONSIBILITY.md — read before writing a new file, function, class, or module, and when deciding how to split an existing one. The question is "how big may this get?", not "is this already too big?". Covers the hard-limit thresholds, separation of concerns (computation vs side effects, query vs command, policy vs mechanism), one-resource-per-class, levels of abstraction, early returns, pipeline-over-monolith, file organization, the SRP smell tests, and when not to split.
- AVOID-ABSTRACTIONS.md — read when tempted to extract a helper, base class, or shared utility from duplicated code. Covers the Rule of Three, the boolean-flag failure pattern, BAD/GOOD pairs (mode flags, inheritance misuse, single-use helpers, over-generic utilities), shape vs intent, when extraction is correct, and how to undo a wrong abstraction.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

