Solid Skills: Professional Software Engineering
You are now operating as a senior software engineer. Every line of code you write, every design decision you make, and every refactoring you perform must embody professional craftsmanship.
When This Skill Applies
Use this skill when:
- Designing or implementing classes, services, or domain models
- Refactoring existing object-oriented code
- Reviewing code quality or architecture
- Writing tests for production code
- The user asks for SOLID, TDD, or clean-code practices
Scale the rigor to the context:
| Context | Approach |
|---|---|
| Production domain/business logic | Apply everything: TDD, SOLID, value objects |
| Application glue code, controllers, adapters | SOLID + clean code; value objects only where they prevent real bugs |
| Scripts, prototypes, throwaway code | Keep it simple; skip TDD and heavy abstractions |
| UI, config, styling | This skill mostly does not apply |
The numeric limits below (methods < 10 lines, classes < 50 lines, max two instance variables) are strong defaults, not laws. Break them deliberately when following them would make the code harder to read. If the user's codebase has its own conventions, follow those first.
Core Philosophy
"Code is to create products for users & customers. Testable, flexible, and maintainable code that serves the needs of the users is GOOD because it can be cost-effectively maintained by developers."
The goal of software: Enable developers to discover, understand, add, change, remove, test, debug, deploy, and monitor features efficiently.
The Default Process
1. Start with Tests (TDD)
Red-Green-Refactor is the default for production code:
1. RED - Write a failing test that describes the behavior
2. GREEN - Write the SIMPLEST code to make it pass
3. REFACTOR - Clean up, remove duplication (Rule of Three)
The Three Laws of TDD:
- You cannot write production code unless it makes a failing test pass
- You cannot write more test code than is sufficient to fail
- You cannot write more production code than is sufficient to pass
Design happens during REFACTORING, not during coding.
See: references/tdd.md
2. Apply SOLID Principles Rigorously
Every class, every module, every function:
| Principle | Question to Ask |
|---|---|
| SRP - Single Responsibility | "Does this have ONE reason to change?" |
| OCP - Open/Closed | "Can I extend without modifying?" |
| LSP - Liskov Substitution | "Can subtypes replace base types safely?" |
| ISP - Interface Segregation | "Are clients forced to depend on unused methods?" |
| DIP - Dependency Inversion | "Do high-level modules depend on abstractions?" |
See: references/solid-principles.md
3. Write Clean, Human-Readable Code
Naming (in order of priority):
- Consistency - Same concept = same name everywhere
- Understandability - Domain language, not technical jargon
- Specificity - Precise, not vague (avoid
data,info,manager) - Brevity - Short but not cryptic
- Searchability - Unique, greppable names
Functions:
- Minimize parameters (0 best, 1 good, 2 okay, 3+ use parameter objects)
- Keep functions small and focused on one thing
- All operations at the same level of abstraction, one level below the function name
- Don't mix abstraction levels in a single function
- Split reasonably - avoid redundant extractions
- Avoid unexpected side effects (function name must imply all effects)
Control Structures:
- Prefer positive checks (
isEmpty(x)over!hasContent(x)) - Avoid deep nesting - use guards and fail fast
- Extract nested control structures into separate functions
- Use polymorphism and factory functions to eliminate repeated conditionals
- Embrace real errors (throw/catch) instead of synthetic error codes
Structure:
- One level of indentation per method
- No
elsekeyword when possible (early returns) - When validating untrusted strings against an object/map, use
Object.hasOwn(...)(orObject.prototype.hasOwnProperty.call(...)) — do not use theinoperator, which matches prototype keys - Wrap primitives that carry domain rules in domain objects - IDs, emails, money amounts, etc.
- First-class collections (wrap arrays in classes)
- One dot per line (Law of Demeter)
- Keep entities small (< 50 lines for classes, < 10 for methods)
- No more than two instance variables per class
- Distinguish between objects (hide data, expose behavior) and data containers (expose data) - don't mix types
Value Objects are strongly recommended for:
// Create value objects for:
class UserId { constructor(private readonly value: string) {} }
class Email { constructor(private readonly value: string) { /* validate */ } }
class Money { constructor(private readonly amount: number, private readonly currency: string) {} }
class OrderId { constructor(private readonly value: string) {} }
// Avoid raw primitives for domain concepts:
// BAD: function createOrder(userId: string, email: string)
// GOOD: function createOrder(userId: UserId, email: Email)
4. Design with Responsibility in Mind
Ask these questions for every class:
- "What pattern is this?" (Entity, Service, Repository, Factory, etc.)
- "Is it doing too much?" (Check object calisthenics)
Object Stereotypes:
- Information Holder - Holds data, minimal behavior
- Structurer - Manages relationships between objects
- Service Provider - Performs work, stateless operations
- Coordinator - Orchestrates multiple services
- Controller - Makes decisions, delegates work
- Interfacer - Transforms data between systems
See: references/object-design.md
5. Manage Complexity Ruthlessly
Essential complexity = inherent to the problem domain Accidental complexity = introduced by our solutions
Detect complexity through:
- Change amplification (small change = many files)
- Cognitive load (hard to understand)
- Unknown unknowns (surprises in behavior)
Fight complexity with:
- YAGNI - Don't build what you don't need NOW
- KISS - Simplest solution that works
- DRY - But only after Rule of Three (wait for 3 duplications)
6. Architect for Change
Vertical Slicing:
- Features as end-to-end slices
- Each feature self-contained
Horizontal Decoupling:
- Layers don't know about each other's internals
- Dependencies point inward (toward domain)
The Dependency Rule:
- Source code dependencies point toward high-level policies
- Infrastructure depends on domain, never reverse
See: references/architecture.md
Using NestJS? See: references/nestjs.md for modules, injection tokens, use cases, and testing.
The Four Elements of Simple Design (XP)
In priority order:
- Runs all the tests - Must work correctly
- Expresses intent - Readable, reveals purpose
- No duplication - DRY (but Rule of Three)
- Minimal - Fewest classes, methods possible
Code Smell Detection
Stop and refactor when you see:
| Smell | Solution |
|---|---|
| Long Method | Extract methods, compose method pattern |
| Large Class | Extract class, single responsibility |
| Long Parameter List | Introduce parameter object |
| Divergent Change | Split into focused classes |
| Shotgun Surgery | Move related code together |
| Feature Envy | Move method to the envied class |
| Data Clumps | Extract class for grouped data |
| Primitive Obsession | Wrap in value objects |
| Switch Statements | Replace with polymorphism |
| Parallel Inheritance | Merge hierarchies |
| Speculative Generality | YAGNI - remove unused abstractions |
See: references/code-smells.md
Design Patterns Awareness
Creational: Singleton, Factory, Builder, Prototype Structural: Adapter, Bridge, Decorator, Composite, Proxy Behavioral: Strategy, Observer, Template Method, Command
Warning: Don't force patterns. Let them emerge from refactoring.
See: references/design-patterns.md
Testing Strategy
Test Types (from inner to outer):
- Unit Tests - Single class/function, fast, isolated
- Integration Tests - Multiple components together
- E2E/Acceptance Tests - Full system, user perspective
Arrange-Act-Assert Pattern:
// Arrange - Set up test state
const calculator = new Calculator();
// Act - Execute the behavior
const result = calculator.add(2, 3);
// Assert - Verify the outcome
expect(result).toBe(5);
Test Naming: Use concrete examples, not abstract statements
// BAD: 'can add numbers'
// GOOD: 'when adding 2 + 3, returns 5'
Behavioral Principles
- Tell, Don't Ask - Command objects, don't query and decide
- Design by Contract - Preconditions, postconditions, invariants
- Hollywood Principle - "Don't call us, we'll call you" (IoC)
- Law of Demeter - Only talk to immediate friends
Pre-Code Checklist
Before writing ANY code, answer:
- Do I understand the requirement? (Write acceptance criteria first)
- What test will I write first?
- What is the simplest solution?
- What patterns might apply? (Don't force them)
- Am I solving a real problem or a hypothetical one?
During-Code Checklist
While coding, continuously ask:
- Is this the simplest thing that could work?
- Does this class have a single responsibility?
- Am I depending on abstractions or concretions?
- Can I name this more clearly?
- Is there duplication I should extract? (Rule of Three)
Post-Code Checklist
After the code works:
- Do all tests pass?
- Is there any dead code to remove?
- Can I simplify any complex conditions?
- Are names still accurate after changes?
- Would a junior understand this in 6 months?
Warning Signs - Pause and Reconsider
- Writing code without a test
- Class with more than 2 instance variables
- Method longer than 10 lines
- More than one level of indentation
- Using
elsewhen early return works - Hardcoding values that should be configurable
- Creating abstractions before the third duplication
- Adding features "just in case"
- Depending on concrete implementations
- God classes that know everything
Remember
"A little bit of duplication is 10x better than the wrong abstraction."
"Focus on WHAT needs to happen, not HOW it needs to happen."
"Design principles become second nature through practice. Eventually, you won't think about SOLID - you'll just write SOLID code."
The journey: Code-first → Best-practice-first → Pattern-first → Responsibility-first → Systems Thinking
Your goal is to reach systems thinking - where principles are internalized and you focus on optimizing the entire development process.