agentleFS
pvnarppvnarp/agent-skills/skills/best-practices/SKILL.md

best-practices

Skill1 starsChanged 9 months agoMITView on GitHub

Enforces software design principles including separation of concerns, error handling patterns, thread safety, and code quality standards. Use when writing new code, reviewing patterns, or making design decisions.

20 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use web-quality-audit, core-web-vitals and 4 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • RodrigoTomeESSkill

    web-quality-audit

    Comprehensive web quality audit covering performance, accessibility, SEO, and best practices. Use when asked to "audit my site", "review web quality", "run lighthouse audit", "check page quality", or "optimize my website".

    Also in 5 projects that use this

  • thisisAhsanIqbalSkill

    core-web-vitals

    Audits HTML patterns that affect Core Web Vitals (LCP, CLS, INP). Checks for layout shift causes, largest contentful paint blockers, and interaction responsiveness issues. Use when optimising page performance or fixing Google PageSpeed Insights warnings.

    Also in 5 projects that use this

  • pluginagentmarketplaceSkill

    performance

    Optimize application performance through caching strategies, load balancing, database scaling, and monitoring. Build systems handling thousands of concurrent users.

    Also in 5 projects that use this

  • iamladiSkill

    seo

    Comprehensive programmatic SEO (pSEO) skill for auditing, architecting, and scaling to 100k+ pages. Covers metadata, schemas, internal linking, content strategy, and Core Web Vitals. Use when planning or auditing SEO at scale.

    Also in 4 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 5 projects that use this

  • VercelSkill

    frontend-design

    Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 6 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 17 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never swallow exceptions: If you catch it, log it or propagate it.

    line 44
  2. Distinctive:

    Validate at boundaries, trust internally: Don't re-validate inside every function - validate once at the system edge.

    line 46
  3. Distinctive:

    YAGNI: - Don't build for hypothetical requirements.

    line 84
  4. Distinctive:

    No magic: - Avoid implicit behavior, hidden side effects, action at a distance.

    line 87
  5. Distinctive:

    Fewer is better: Every dependency is code you don't control that can break, have vulnerabilities, or go unmaintained.

    line 107
  6. Distinctive:

    Wrap third-party interfaces: Don't spread a library's API throughout your codebase.

    line 110

“Common” is measured: kept by at least 6 in 10 of the 17 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Best Practices

These are principles, not rules. Apply judgment. The goal is code that is correct, maintainable, and simple - in that order.

Separation of Concerns

Each module/class has one job. Common layer boundaries:

Presentation  - HOW things look (UI, API responses, formatting)
Business Logic - WHAT happens (rules, calculations, workflows)
Data Access    - WHERE data lives (DB, APIs, files, cache)
Infrastructure - HOW systems connect (config, logging, auth, messaging)

The dependency rule: Dependencies point inward. Business logic never imports presentation or infrastructure. Data access doesn't know about UI. Inner layers define interfaces; outer layers implement them.

Signs of leaking concerns:

  • UI component makes direct database calls
  • Business logic formats error messages for display
  • Data layer catches and handles business exceptions
  • Controller contains calculation logic

Error Handling

Where to Handle Errors

Handle errors at the level where you have enough context to do something useful. Not lower (you don't know the intent). Not higher (you've lost the details).

LevelResponsibility
Boundary (user input, external API)Validate, reject bad input early, return clear errors
Service (business logic)Catch domain-specific failures, apply business rules for fallbacks
Infrastructure (DB, network, filesystem)Retry transient failures, convert to domain errors, never leak implementation details

Error Handling Rules

  1. Never swallow exceptions. If you catch it, log it or propagate it. Silent failures are the worst bugs.
  2. Distinguish recoverable from fatal. Transient network error → retry. Corrupt data → crash with clear message.
  3. Validate at boundaries, trust internally. Don't re-validate inside every function - validate once at the system edge.
  4. Use typed errors where the language supports it. Avoid stringly-typed error checking (if err.message.includes("not found")).
  5. Error messages for two audiences: users get actionable guidance, developers get diagnostic details (in logs).

Hot Path Performance

For code that runs frequently (request handlers, event loops, inner loops):

DODON'T
Pre-allocate buffers and collectionsAllocate in tight loops
Use efficient data structures for the access patternUse a list when you need a map
Batch I/O and network operationsMake one call per item
Cache expensive computationsRecompute on every access
Profile before optimizingGuess at bottlenecks

The rest of the code: Optimize for readability, not speed. Premature optimization makes code harder to change.

Thread Safety

  1. Minimize shared mutable state. The safest shared state is no shared state.
  2. When sharing is necessary, use the simplest correct mechanism: atomic > lock > mutex > channel.
  3. Document ownership. Which thread/process owns which state? Is this object safe to share?
  4. Prefer message passing over shared memory when architecturally appropriate.
  5. Never hold a lock while doing I/O. Hold locks for the minimum duration.

Common Concurrency Bugs

BugPatternPrevention
Race conditionRead-modify-write without lockAtomic operations or mutex
DeadlockLock A then B in one thread, B then A in anotherConsistent lock ordering
Lost updateTwo threads read same value, both writeCompare-and-swap or serialized access
Stale readCached value not invalidatedVolatile/atomic read, or invalidation protocol

Code Quality Principles

  1. Clarity over cleverness - Code is read 10x more than written. Optimize for the reader.
  2. YAGNI - Don't build for hypothetical requirements. Build what's needed now.
  3. Minimal surface area - Expose only what consumers need. Keep internals private.
  4. Fail fast - Detect and report errors close to the source. Don't propagate bad state.
  5. No magic - Avoid implicit behavior, hidden side effects, action at a distance. Make code discoverable.
  6. Delete aggressively - Dead code, unused abstractions, stale comments - remove them. Version control remembers.

Naming

Good names eliminate the need for comments.

EntityConventionExample
BooleanQuestion it answersisValid, hasPermission, canRetry
FunctionVerb phrase for what it doescalculateTotal, fetchUser, validateInput
CollectionPlural nounusers, orderItems, pendingTasks
Predicateis/has/can/should prefixisExpired(), hasChildren()
Factorycreate/build/make prefixcreateConnection(), buildQuery()
Converterto/from patterntoJSON(), fromDTO()

Avoid: generic names (data, info, temp, result, handle), abbreviations (mgr, ctx, impl), and type-in-name (userList, nameString).

Dependencies

  • Fewer is better. Every dependency is code you don't control that can break, have vulnerabilities, or go unmaintained.
  • Evaluate before adding: How active is the maintainer? How many transitive deps? Could you write the 20 lines yourself?
  • Pin versions in production. Use lockfiles. Update deliberately, not automatically.
  • Wrap third-party interfaces. Don't spread a library's API throughout your codebase. One adapter module makes it replaceable.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.