home / skills / getcosmos / agent-skills / cosmos-coding-standards

cosmos-coding-standards skill

/cosmos-coding-standards

This skill helps enforce coding standards and best practices for readable, maintainable, and testable code across features, refactoring, reviews, and UI

npx playbooks add skill getcosmos/agent-skills --skill cosmos-coding-standards

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.4 KB
---
name: cosmos-coding-standards
description: Coding standards for readable, maintainable, testable code including SOLID principles, clean code practices, DDD, and TDD. Use when implementing new features, refactoring code, performing code reviews, ensuring code quality, or when frontend changes are made that require UI testing.
---

# Coding Standards & Best Practices

Implementing effective coding standards, architecture, and practices is crucial for developing software that is readable, maintainable, and testable. High-quality code is designed for change, with a focus on low coupling, high cohesion, and clear, intent-revealing structures.

## Coding Standards & Best Practices (Readability)

**Consistency**: Use automated formatting tools (e.g., Biome, typecheck) to enforce consistent indentation, line length, and styling. Code is not complete if linting errors exist.

**Naming Conventions**: Use descriptive, noun-based names for variables and classes, and camelCase for methods. Avoid abbreviations. Use prefixes like `is` for booleans.

**Self-Documenting Code**: Code should communicate its intent without excessive comments. If comments are necessary, they should explain "why" rather than "what".

**Small Functions**: Break large functions into smaller, single-purpose chunks (e.g., `buildSchedule()` instead of a large `process()` method).

**No Magic Numbers**: Replace raw, hard-coded numbers or strings with named constants.

## Architectural Principles (Maintainability)

**SOLID Principles**: Adhere to Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.

**Separation of Concerns**: Separate business logic from I/O operations (database, UI, network).

**Low Coupling & High Cohesion**: Components should depend on abstractions (interfaces) rather than concrete implementations to reduce interdependencies.

**Domain-Driven Design (DDD)**: Model software based on the domain, keeping domain logic independent of external frameworks.

**Avoid Anti-Patterns (KISS)**: Steer clear of "God Objects" (classes with too many responsibilities) and widespread "Copy & Paste" programming.

## Testable Code Design (Testability)

**Dependency Injection (DI)**: Pass dependencies into functions/classes rather than creating them internally, enabling the use of mocks or stubs.

**Unit Test Isolation**: Ensure units of code can be tested in isolation without needing to connect to databases or live systems.

**Predictable Input/Output**: Write pure functions where possible—same input always yields the same output.

**Independence**: Tests should be independent of one another, with clear setup and teardown strategies. Review how they are done in the project and continue best practices.

## UI Testing

When frontend changes are made, perform UI testing using browser tools to verify visual and functional correctness.

## Summary Table of Key Principles

| Principle | Goal | Actionable Advice |
|-----------|------|-------------------|
| SOLID | Scalability | Build loosely coupled components. |
| Clean Code | Readability | Use meaningful names; keep functions small. |
| DDD | Maintainability | Separate domain logic from infrastructure. |
| TDD/DI | Testability | Inject dependencies; minimize side effects. |
| Automation | Consistency | Use linting/formatting tools in CI/CD. |
| UI Testing | Quality Assurance | aLL frontend changes require manual browser testing. |

Overview

This skill codifies coding standards for readable, maintainable, and testable code, covering SOLID, clean code practices, Domain-Driven Design (DDD), and Test-Driven Development (TDD). It focuses on concrete habits and rules teams can apply during feature work, refactors, and code reviews. The guidance includes formatting, naming, architectural boundaries, dependency management, and UI testing requirements.

How this skill works

The skill inspects code practices and recommends changes to improve clarity, reduce coupling, and increase testability. It emphasizes automated formatting and linting, descriptive naming, small single-purpose functions, and replacing magic values with constants. Architectural checks promote SOLID, separation of concerns, and DDD patterns, while testability checks encourage dependency injection, isolated unit tests, and predictable I/O. For frontend changes, it mandates manual browser-based UI verification alongside automated tests.

When to use it

  • Implementing new features to ensure consistent design and testability from the start.
  • Refactoring code to reduce complexity, remove god objects, and improve cohesion.
  • Performing code reviews to enforce naming, formatting, and architectural rules.
  • Writing or updating tests to keep units isolated and reliable.
  • Making frontend changes that require visual and functional UI validation.

Best practices

  • Enforce automated formatting and linting in CI so code is not merged with style errors.
  • Prefer descriptive, intent-revealing names; avoid abbreviations and magic numbers (use named constants).
  • Keep functions and classes small and single-purpose; apply SOLID principles consistently.
  • Design domain logic independent of frameworks (DDD) and separate I/O from business rules.
  • Use dependency injection to enable mockable units and write isolated, repeatable tests.
  • Require browser-based UI checks for frontend changes in addition to automated tests.

Example use cases

  • Creating a new service: define a single-responsibility class, inject its dependencies, and cover it with isolated unit tests.
  • Refactoring a large controller: extract domain logic into domain services and replace direct database calls with repository interfaces.
  • Code review checklist: verify naming, small functions, no magic numbers, SOLID adherence, and presence of tests.
  • Onboarding new team members: use these standards to align code style, architecture expectations, and testing practices.
  • Frontend change rollout: run unit and E2E tests, then perform targeted manual browser checks for visual regressions.

FAQ

Do I have to follow all rules strictly for small fixes?

Apply pragmatic judgment: keep fixes minimal but avoid introducing anti-patterns. If a quick change reveals design issues, file a follow-up refactor ticket.

When should I prefer DDD over simpler layering?

Use DDD when business rules are complex and evolving. For simple CRUD features, clear separation of concerns and SOLID principles are usually sufficient.