aeren/solid icon
public
Published on 7/10/2025
# SOLID, DRY, OOP Best Practices, and Design Patterns LLM Rules

Rules

SOLID, DRY, OOP Best Practices, and Design Patterns LLM Rules

A comprehensive ruleset guiding the LLM to produce robust, maintainable, and clean object-oriented code and architectural advice.


enforce-solid-principles

Rule:
Always follow the SOLID principles in OOP designs and code examples:

  • Single Responsibility Principle (SRP): A class should have one, and only one, reason to change.
  • Open/Closed Principle (OCP): Software entities should be open for extension but closed for modification.
  • Liskov Substitution Principle (LSP): Derived classes must be substitutable for their base classes without altering the correctness of the program.
  • Interface Segregation Principle (ISP): Prefer many small, specific interfaces over large general-purpose ones.
  • Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules; both should depend on abstractions.

Description:
Enforces writing clean, maintainable, and flexible object-oriented code.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

enforce-dry-principle

Rule:
Never duplicate logic or code. Encourage refactoring to reusable functions, classes, or modules whenever repeated patterns are detected.

Description:
Promotes maintainability and reduces bugs caused by duplicate logic.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

prefer-encapsulation

Rule:
Encapsulate class fields and internal logic. Expose only necessary APIs. Avoid public mutable fields unless justified.

Description:
Protects internal state and reduces unintended side effects.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

favor-composition-over-inheritance

Rule:
Prefer composing objects to adding unnecessary inheritance hierarchies. Recommend using interfaces or protocols to define behavior when possible.

Description:
Reduces tight coupling and promotes flexible architecture.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

promote-interface-use

Rule:
Encourage defining contracts via interfaces or abstract classes instead of using concrete classes directly.

Description:
Improves flexibility and testability of code.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

enforce-single-level-of-abstraction

Rule:
Maintain a single level of abstraction within methods and classes. Avoid mixing high-level and low-level operations in the same function.

Description:
Keeps code easy to read and maintain.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

prefer-small-methods

Rule:
Keep methods small (generally under 20-30 lines). If a method grows large, refactor it into smaller helper methods.

Description:
Improves readability and reduces cognitive load.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

enforce-meaningful-names

Rule:
Use clear, meaningful names for classes, methods, variables, and interfaces. Avoid ambiguous short names unless context is clear (e.g., i in a loop).

Description:
Improves readability and maintainability.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

promote-testability

Rule:
Encourage writing code that is easily testable, with dependencies injected via interfaces or constructors, and minimal static or global state.

Description:
Improves code quality and long-term stability.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

suggest-design-patterns

Rule:
Recommend applying appropriate design patterns for solving common architectural or design problems. When suggesting a pattern, include:

  • Pattern name
  • Problem it solves
  • Context for when it’s suitable
  • Example code snippet (language-specific)

Supported Patterns Include:

  • Singleton
  • Factory Method
  • Abstract Factory
  • Strategy
  • Observer
  • Decorator
  • Adapter
  • Facade
  • Builder
  • Dependency Injection
  • Command
  • Chain of Responsibility
  • Proxy
  • Template Method
  • Mediator
  • State
  • Visitor
  • Composite
  • Flyweight
  • Memento

Description:
Empowers developers to solve problems with proven solutions.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

enforce-clean-architecture

Rule:
Encourage clean architecture principles:

  • Separate concerns into distinct layers (e.g., domain, application, infrastructure).
  • Keep business logic independent of frameworks.
  • Use dependency inversion to isolate inner layers from outer layers.

Description:
Promotes long-term maintainability and flexibility.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

prefer-immutable-objects

Rule:
Favor immutable objects where feasible, especially for data transfer objects and value objects. Use read-only properties and immutable collections where supported.

Description:
Prevents accidental state mutation and simplifies reasoning about code.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

avoid-god-objects

Rule:
Discourage creating large classes or services that handle unrelated responsibilities. Recommend breaking them into smaller classes aligned with single responsibilities.

Description:
Prevents high complexity and promotes separation of concerns.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs

document-public-apis

Rule:
Whenever suggesting public classes, methods, or interfaces, generate concise documentation comments (e.g. JSDoc, TSDoc, JavaDoc) describing purpose, parameters, and return values.

Description:
Improves code understanding and collaboration.

Globs:

  • *.ts
  • *.js
  • *.java
  • *.cs