Clean code

From operately/operately · View interactive version

Clean code is an AI agent skill from the GitHub repository operately/operately. Clean-code engineering standards for writing, refactoring, and reviewing code in any programming language. Use this whenever the user asks to write clean code, follow clean-code principles, refactor for clarity, improve naming, reduce complexity or duplication, separate concerns, tighten error handl

How to use this skill

Skill file

Clean Code

These are mandatory engineering standards for any code you write, change, or

review while this skill is active. They are language-agnostic: apply them in

whatever language the project uses, respecting that language's idioms.

If there is tension between speed and cleanliness, choose the clean solution

unless there is a demonstrated operational emergency. If a shortcut is

unavoidable, contain it, make it obvious, and leave the code safe to clean up

later.

For detailed rationale, examples, and design heuristics, read

reference.md — consult it when a rule needs interpretation or

when you face a non-obvious design decision.

Core Rules

1. Leave the code cleaner

Every change must improve at least one of: clarity, naming, simplicity,

cohesion, testability, error handling, duplication removal, or separation of

concerns. Do not add code that is merely functional — add code that is

understandable.

2. Optimize for readers

3. Use strong names

stuff, manager, helper, util, misc, handle, temp, obj unless

they are genuinely correct in the domain or an external protocol.

retryable?), following the language's convention.

(calculate_invoice_total, not do_invoice).

4. Keep methods small and focused

recovery in one method. Extract helpers when a method grows multiple phases.

usually means a missing value object or domain object.

express intent more clearly.

5. Keep abstraction levels separate

separate from I/O, framework glue, and serialization.

6. Make side effects explicit

7. Control conditionals

8. Treat errors as design

without reason.

9. Keep modules and classes cohesive

10. Remove duplication at the right level

similar lines. Deduplicate at the right level of meaning.

11. Work test-first

changing behavior, fixing a bug, or adding a feature.

expected outcome. Keep setup small and intention-revealing.

constraints), say so explicitly and add the nearest useful coverage

immediately, leaving the area more testable than before.

12. Refactor while you work

you touch.

leave a clear note.

13. Respect language idioms — without hiding intent

engineer in that language.

state.

the call site and the definition site.

boundaries; keep vendor-specific knowledge from leaking everywhere.

14. Prefer association joins and database-side recursion (Ecto)

When writing Ecto queries in this codebase:

schema association already expresses the relationship. Manual on: is fine

when joining CTEs/string tables, adding conditions beyond the association, or

when no association exists.

with_cte/3, and union_all/2) over Elixir recursion that hits the database

on every iteration. Walk trees and hierarchies in one query when the database

can do it.

interpolated WITH RECURSIVE ...) whenever Ecto can express the same query.

Reserve raw SQL for cases the DSL cannot express cleanly.

See reference.md for examples

from this codebase.

When loading requester-aware resources, use Operately.Repo.Getter. Read

getter.md before adding Getter profiles, alternate access-context

paths, a collection load, or a custom loading wrapper.

15. Model Operately API types and serializers explicitly

values from the domain or Ecto schema source of truth, use the enum in API

inputs and outputs, and convert atoms/strings only at required boundaries.

domain structs through an OperatelyWeb.Api.Serializable implementation in

app/lib/operately_web/api/serializers/; never define inline endpoint

serializers.

relevant types module participates in OperatelyWeb.Api.TypeNames, and call

Serializer.serialize/1 from endpoints.

appropriate API or serializer boundary.

16. Definition of done

Use the internationalization skill when changing product copy or adding a language.

Hardcoded system-authored, user-visible text is forbidden, including API validation/errors, notifications, feeds, exports, pages, and emails. Follow the internationalization guide and its language glossaries: use translation wrappers and include translations for every supported language plus regenerated catalogs/resources in the same PR. Keep machine identifiers and stored activity payloads stable; translate their presentation. Developer-only diagnostics may remain literal, but diagnostics displayed to users need translated presentation. Never edit generated JSON manually or rely on fallback to complete a copy change.

A task is done only when:

those apply (see rule 14)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.