agentleFS
robconeryrobconery/kolea/.claude/skills/solid-principles/SKILL.md

solid-principles

Skill7 starsChanged 3 months agoMITView on GitHub

SOLID object-oriented design principles for TypeScript projects. Use when designing or refactoring classes and modules, reviewing code for design smells (rigid, fragile, tightly coupled code), deciding how to split responsibilities or introduce abstractions, or answering "is this good OO design / which SOLID principle applies here" questions. Covers all five principles with idiomatic TypeScript before/after examples and guidance on when applying them helps and when it is over-engineering.

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use design-patterns.

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.
  • ffsshhttiikkSkill

    design-patterns

    Practical application and coding skills for Design Patterns

    Also in 5 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 1

    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
  1. Distinctive:

    Every rule below earns its keep only if it shrinks the next diff.

    line 27

“Common” is measured: kept by at least 6 in 10 of the 9 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SOLID Principles in TypeScript

Five principles of object-oriented design (Robert C. Martin) that keep code flexible, testable, and resistant to rot — adapted to idiomatic TypeScript, where interfaces, structural typing, union types, and plain functions often satisfy a principle without ceremony.

🎯 Why: Design for Change

The goal of writing software is to be able to change it safely. SOLID is the OO toolkit for that goal: SRP limits what changes when a reason to change appears, OCP lets you extend without editing tested code, LSP keeps substitutions safe, ISP keeps consumers from breaking on unrelated changes, DIP lets you swap implementations without rewriting policy. Every rule below earns its keep only if it shrinks the next diff.

How to use this skill

  1. Match the symptom in the decision guide below to a principle.
  2. Open references/principles.md for the full before/after TypeScript example and the "when this is over-engineering" note for that principle.
  3. Apply the smallest change that removes the actual pain. SOLID is a response to demonstrated change pressure, not a checklist to apply preemptively. A 30-line app does not need an interface per class.

Reference file

  • references/principles.md — all five principles (SRP, OCP, LSP, ISP, DIP) with motivation, a bad example, a refactor, TypeScript-specific notes, and when not to apply each.

The five principles

LetterPrincipleOne-line intent
SSingle ResponsibilityA class/module should have one reason to change.
OOpen/ClosedOpen for extension, closed for modification.
LLiskov SubstitutionSubtypes must be usable wherever their base type is expected.
IInterface SegregationMany small client-specific interfaces beat one fat one.
DDependency InversionDepend on abstractions, not concretions.

Decision guide — symptom → principle

You notice…ApplyLetter
A class changes for unrelated reasons (DB + formatting + business rules)Single ResponsibilityS
Adding a new "type" means editing a growing switch/if-elseOpen/ClosedO
A subclass throws on, no-ops, or weakens a method it inheritedLiskov SubstitutionL
Implementers are forced to stub methods they don't useInterface SegregationI
Business logic imports a concrete DB/HTTP/SDK client directlyDependency InversionD
Unit tests need a real database, network, or clockDependency InversionD
One change ripples across many unrelated filesSingle ResponsibilityS
instanceof chains decide behaviorOpen/Closed (often Strategy/polymorphism)O

TypeScript-specific guidance

  • Interfaces are free and structural. You don't need a class to implement an interface explicitly — any object with the right shape satisfies it. This makes ISP and DIP cheap.
  • Prefer narrow function types over fat interfaces. A dependency that is "something that can save(user)" can be (user: User) => Promise<void>, not a Repository interface — that is ISP and DIP in one move.
  • Union types + exhaustive switch is a valid OCP alternative. When the set of variants is closed and known, a discriminated union with a never-checked switch is often clearer than a class hierarchy.
  • Constructor injection is the default DIP mechanism. Pass collaborators in; let a composition root wire concretions. Avoid new-ing dependencies inside business logic.
  • Don't abstract on speculation. Introduce an interface when you have a second implementation or a real testing need — not "just in case."

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.