askill
swe

sweSafety --Repository

Applies software engineering best practices, design principles, and avoids common anti-patterns. Use when designing systems, reviewing code quality, refactoring legacy code, making architectural decisions, or improving maintainability.

16 stars
1.2k downloads
Updated 3/14/2026

Package Files

Loading files...
SKILL.md

Software Engineering

Core Principles

PrincipleMeaning
SimplicitySimplest code that works; complexity only when required
Single ResponsibilityEach function/class/module does one thing
Self-DocumentingCode explains itself; comments are a smell
Fail FastValidate early, propagate unexpected errors
Test BehaviorWhat code does, not implementation
No Backwards CompatDon't add legacy support unless requested
ConsistencyMatch project conventions over preference

Design

SOLID

PrincipleViolation Sign
Single ResponsibilityClass doing too many things
Open/ClosedModifying existing code for new features
Liskov SubstitutionOverridden methods breaking contracts
Interface SegregationClients depend on unused methods
Dependency InversionHigh-level imports low-level details

Architecture

Presentation → Application → Domain ← Infrastructure
                    ↓
           Dependencies point DOWN only

Rules:

  • Domain depends on nothing
  • Infrastructure implements domain interfaces
  • No circular dependencies

Design Patterns

Use when solving real problems, not preemptively:

PatternUse When
FactoryComplex object creation
BuilderMany optional parameters
AdapterIncompatible interfaces
FacadeSimplifying subsystem
StrategyRuntime algorithm selection
ObserverMany dependents need notification

Security

  • Validate all external input (allowlists > denylists)
  • Encrypt sensitive data at rest and transit
  • Never log secrets
  • Parameterized queries (SQL injection)
  • Escape output (XSS)

Implementation

Naming

TypeConventionExample
VariablescamelCase nounuserName, isValid
FunctionscamelCase verbgetUser, validateInput
Booleansis/has/can prefixisActive, hasPermission
ConstantsUPPER_SNAKEMAX_RETRIES
ClassesPascalCase nounUserService

Rules:

  • Names reveal intent
  • No single-letter params
  • No abbreviations (uruserRepository)

Self-Documenting Code

// ❌ Comment hiding bad code
if (u.r === 1 && u.s !== 0) { ... }

// ✅ Self-documenting
if (user.isAdmin && user.isActive) { ... }

Acceptable comments: RFC links, bug tracker refs, non-obvious warnings

Functions

DoDon't
Small, focusedGod functions (100+ lines)
2-3 params max6+ parameters
Return earlyDeep nesting
Pure when possibleHidden side effects
Single abstraction levelMixed levels

Error Handling

// ❌ Silent catch
try {
  await save(user);
} catch (e) {}

// ❌ Log only
try {
  await save(user);
} catch (e) {
  console.log(e);
}

// ✅ Let propagate or handle specific
try {
  await save(user);
} catch (e) {
  if (e instanceof DuplicateEmail) return { error: "Email taken" };
  throw e;
}

Rules:

  • Empty catch = always wrong
  • Catch only what you can handle
  • Re-throw with context or propagate
  • Crash visibly > fail silently

File Organization

  • Match existing conventions
  • No barrel files (index.ts re-exports)
  • Import from concrete modules
  • Co-locate tests with source
src/users/
  user-service.ts
  user-service.test.ts

Code Smells

SmellFix
God ClassSplit by responsibility
Feature EnvyMove method to data owner
Long Param ListParameter object
Primitive ObsessionValue objects
Dead CodeDelete it

Linting

ToolPurpose
FormatterStyle (Prettier, dprint)
LinterQuality (ESLint, Ruff)
Type CheckerSafety (tsc, mypy)

Rules:

  • Automate formatting
  • Zero warnings in CI
  • Never disable rules—fix the code

Testing

Test Pyramid

    E2E (few) - Critical journeys, slow
   Integration (some) - Component interactions
  Unit (many) - Fast, isolated, business logic

What to Test

TestSkip
Business logicFramework code
Edge casesTrivial getters
Error pathsThird-party libs
Public APIPrivate internals

Test Quality

  • Independent and isolated
  • Deterministic (no flakiness)
  • Fast (< 100ms unit)
  • Single reason to fail
  • Test behavior, not implementation

BDD Structure

describe("UserService", () => {
  describe("given valid data", () => {
    describe("when creating user", () => {
      it("then persists with ID", async () => {
        // arrange, act, assert
      });
    });
  });
});

Anti-Patterns

PatternFix
Ice Cream ConeMore unit, fewer E2E
Flaky TestsFix races, use mocks
Testing ImplementationTest behavior
No AssertionsAdd meaningful checks

Review

Before PR

  • Type check passes
  • Lint passes
  • Tests pass
  • No debug/console.log
  • No commented code
  • Up to date with main

Review Checklist

Correctness:

  • Does it work? Edge cases? Error handling?

Design:

  • Right abstraction? SOLID? Dependencies appropriate?

Readability:

  • Clear names? Straightforward logic? No unnecessary comments?

Security:

  • Input validated? No injection? Secrets handled?

Performance:

  • No N+1? No await in loops? Caching considered?

Tests:

  • Sufficient coverage? Edge cases? Behavior-focused?

For Reviewers

  • Code, not author
  • Questions > demands
  • Explain the "why"
  • Blocking vs nitpick

For Authors

  • Small, focused PRs
  • Context in description
  • Respond to all comments

Maintenance

Refactoring

  1. Ensure test coverage first
  2. Small, incremental changes
  3. Run tests after each change
  4. Refactor OR add features, never both
TechniqueWhen
Extract MethodLong method, reusable logic
Extract ClassMultiple responsibilities
Move MethodUses other class's data more
Introduce Param ObjectLong parameter lists

Technical Debt

TypeHandling
DeliberateDocument, schedule payback
AccidentalFix when discovered
Bit RotRegular maintenance
Outdated DepsRegular updates

Find: unused code, duplicates, circular deps, outdated deps

Performance

  1. Don't optimize prematurely
  2. Measure before optimizing
  3. Focus on hot paths
PitfallFix
N+1 queriesBatch, joins
Blocking I/OAsync
Memory leaksWeak refs, cleanup

Documentation

DocumentSkip
Public APIsObvious code
ADRsImplementation details
Setup/deploySelf-documenting code
Non-obvious behaviorEvery function

Anti-Patterns

PatternProblemFix
Big Ball of MudNo structureDefine boundaries
Spaghetti CodeTangledModularize
Lava FlowDead codeDelete it
Copy-PasteDuplicationExtract
Magic NumbersNo contextNamed constants
Circular DepsCouplingAbstraction layer
Feature FlagsHidden complexityOne code path
Backwards CompatLegacy burdenReplace entirely

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

AI review pending.

Metadata

Licenseunknown
Version-
Updated3/14/2026
Publisherknoopx

Tags

apici-cddatabaselintingsecuritytesting