home / skills / xfstudio / skills / software-architecture

software-architecture skill

/software-architecture

This skill guides quality-focused software architecture using Clean Architecture and DDD principles to improve design, maintainability, and scalability.

npx playbooks add skill xfstudio/skills --skill software-architecture

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

Files (1)
SKILL.md
3.5 KB
---
name: software-architecture
description: Guide for quality focused software architecture. This skill should be used when users want to write code, design architecture, analyze code, in any case that relates to software development.
---

# Software Architecture Development Skill

This skill provides guidance for quality focused software development and architecture. It is based on Clean Architecture and Domain Driven Design principles.

## Code Style Rules

### General Principles

- **Early return pattern**: Always use early returns when possible, over nested conditions for better readability
- Avoid code duplication through creation of reusable functions and modules
- Decompose long (more than 80 lines of code) components and functions into multiple smaller components and functions. If they cannot be used anywhere else, keep it in the same file. But if file longer than 200 lines of code, it should be split into multiple files.
- Use arrow functions instead of function declarations when possible

### Best Practices

#### Library-First Approach

- **ALWAYS search for existing solutions before writing custom code**
  - Check npm for existing libraries that solve the problem
  - Evaluate existing services/SaaS solutions
  - Consider third-party APIs for common functionality
- Use libraries instead of writing your own utils or helpers. For example, use `cockatiel` instead of writing your own retry logic.
- **When custom code IS justified:**
  - Specific business logic unique to the domain
  - Performance-critical paths with special requirements
  - When external dependencies would be overkill
  - Security-sensitive code requiring full control
  - When existing solutions don't meet requirements after thorough evaluation

#### Architecture and Design

- **Clean Architecture & DDD Principles:**
  - Follow domain-driven design and ubiquitous language
  - Separate domain entities from infrastructure concerns
  - Keep business logic independent of frameworks
  - Define use cases clearly and keep them isolated
- **Naming Conventions:**
  - **AVOID** generic names: `utils`, `helpers`, `common`, `shared`
  - **USE** domain-specific names: `OrderCalculator`, `UserAuthenticator`, `InvoiceGenerator`
  - Follow bounded context naming patterns
  - Each module should have a single, clear purpose
- **Separation of Concerns:**
  - Do NOT mix business logic with UI components
  - Keep database queries out of controllers
  - Maintain clear boundaries between contexts
  - Ensure proper separation of responsibilities

#### Anti-Patterns to Avoid

- **NIH (Not Invented Here) Syndrome:**
  - Don't build custom auth when Auth0/Supabase exists
  - Don't write custom state management instead of using Redux/Zustand
  - Don't create custom form validation instead of using established libraries
- **Poor Architectural Choices:**
  - Mixing business logic with UI components
  - Database queries directly in controllers
  - Lack of clear separation of concerns
- **Generic Naming Anti-Patterns:**
  - `utils.js` with 50 unrelated functions
  - `helpers/misc.js` as a dumping ground
  - `common/shared.js` with unclear purpose
- Remember: Every line of custom code is a liability that needs maintenance, testing, and documentation

#### Code Quality

- Proper error handling with typed catch blocks
- Break down complex logic into smaller, reusable functions
- Avoid deep nesting (max 3 levels)
- Keep functions focused and under 50 lines when possible
- Keep files focused and under 200 lines of code when possible

Overview

This skill guides quality-focused software architecture using Clean Architecture and Domain-Driven Design principles. It helps you make pragmatic choices about structure, dependencies, naming, and reuse so systems stay maintainable and evolvable. Use it to reduce technical debt and keep business logic isolated from infrastructure concerns.

How this skill works

The skill inspects design choices, coding patterns, and module organization and recommends concrete changes based on proven rules: early returns, decomposition limits, separation of concerns, and library-first evaluation. It flags anti-patterns like mixing UI and business logic, generic dumping-ground modules, and unnecessary custom solutions, then suggests safer alternatives and naming conventions. It also enforces size and complexity limits for functions and files and promotes proper error handling.

When to use it

  • Designing a new service or bounded context and defining its module boundaries
  • Reviewing or refactoring existing code to reduce technical debt
  • Choosing between building custom logic or adopting third-party libraries
  • Establishing team coding standards around naming, file size, and complexity
  • Preparing code for scalability, maintainability, or cross-team ownership

Best practices

  • Always search for and evaluate existing libraries or SaaS before building custom code
  • Follow Clean Architecture and DDD: keep domain logic framework-agnostic and use domain-specific names
  • Favor early returns and avoid deep nesting (max 3 levels) for readability
  • Decompose long functions (>80 lines) and split files if >200 lines; keep functions under ~50 lines
  • Avoid generic modules like utils/helpers; give each module a single, clear domain purpose

Example use cases

  • Refactoring a legacy controller that mixes DB queries, validation, and response formatting
  • Deciding whether to implement a custom retry mechanism or use a battle-tested library
  • Naming and organizing modules when launching a new bounded context (e.g., OrderCalculator)
  • Auditing codebase for NIH anti-patterns and replacing with standardized solutions
  • Creating guidelines for file length, function complexity, and error handling across a team

FAQ

When is custom code justified instead of using a library?

Custom code is justified for unique business logic, performance-critical paths, security-sensitive logic, or when evaluated libraries do not meet requirements after thorough analysis.

What are the most harmful naming mistakes to avoid?

Avoid dumping grounds like utils.js, helpers, common, or shared. Prefer domain-specific names that express single responsibility, e.g., InvoiceGenerator or UserAuthenticator.