5.1 KiB
5.1 KiB
Purpose and goals of our principles
- Efficiently and sustainably deliver technical solutions with fewer bugs that are easier to resolve.
- Make our technical solutions easier to maintain and further develop.
Principles
- Make invalid states unrepresentable.
- Example: using a time-only type in the database when we actually want to store a time of day introduces risk for errors.
- Always store timestamps as full ISO datetime in UTC.
- Always communicate timestamps as full ISO datetime in UTC from APIs with database access.
- Always grant explicit access to data, both read and write.
- One owner per value; a reader can name every writer.
- The test: from the code in front of them, can a reader list every writer to this value, and the order those writers run in?
- BANNED: a record passed to 24 functions, 13 of which mutate it and return nothing. GOOD: one type owns the value, the rest call it and take a result.
- BANNED:
fill(set)thenadjust(set), where swapping the two lines changes the output. GOOD:const filled = fill(); const adjusted = adjust(filled); - BANNED:
stackandedges, two arrays a comment says must stay in step. GOOD:edgesderived fromstack, or one array whose element type holds both. - Allowed, never flag: mutation that never leaves the function that made it; a loop counter; data shared and never written; a state machine with named states and one transition function.
- Validate data and build DTOs as early as possible.
- For example, parse a form into a strictly typed DTO as the first thing that happens instead of passing strings down to be validated deep inside a service.
- Always use explicit state machines.
- Most, if not all, code should have automated tests.
- Test coverage should not decline.
- Idempotent data writing.
- Typical example:
PUT /resource/{id}instead ofPOST /resource+ Idempotent-Id header.
- Typical example:
- Handle errors explicitly, as values — avoid the exception path.
- Enumerate the cases that can go wrong and return them as explicit results (e.g. a result DTO with an optional error), so failure is part of the signature instead of a hidden second channel.
- try/catch lives only at the edges, wrapped tightly around the call that can actually throw (DB, HTTP, filesystem), converting the exception into an explicit result right there. Pure functions and core logic never throw or catch for control flow.
- Commands and Queries Separation (CQS)-ish
- Queries must never modify data, commands may only return data that is the result of their change.
- Copy important contextual information on buisness transactions and equal data, instead of referencing it.
- Example set order.client_firstname instead of order.client_id and fetching firstname from the clients table.
- Explicit over implicit.
- Avoid magic, avoid "clever" solutions, only abstract when the API can clearly describe what is happening.
- Deterministic order wherever order carries no meaning.
- Sort it, on a key that does not move: the name a line introduces, never where it came from. A sorted list is searchable, its diff shows only what changed, and two edits to it conflict only where they mean to.
- Keep It Simple, Stupid (KISS).
- Keep solutions simple and easy to understand, so it is dead easy to grasp what they do.
- Don't Repeat Yourself (DRY).
- Reuse code instead of duplicating it; one concept, one implementation.
- All critical flows should have good traces, from where something was initiated until it completed.
- Use traceparent OTLP and standardized logging for this.
- Prefer the vendor-neutral option, and know what leaving would cost.
- Where two options do the job, the one that ties us to no supplier wins by default — dependency, protocol, format, service, provider and storage alike. Choosing neutral is usually free; it is the leaving that is expensive, so the test is what an exit costs and whether anyone has priced it.
- Sidestep deliberately, never by drift: a capability only that vendor has, or a vendor that is the target itself (an integration we build, a format we implement). Record which of the two it is and what the tie buys.
- Do not buy portability nobody asked for. An abstraction over one implementation, "in case we swap X", is speculative generality rather than neutrality — prefer the neutral thing, do not build a layer to preserve the option.
- Durable records are the case with no excuse: a decision log, runbook, architecture note or schema is project documentation, living in the repository proper (
docs/), plain and legible with no tool installed. A vendor's directory —.claude/,.vscode/, a CI provider's folder — holds only what that vendor executes, and points at such a record rather than holding it.
- Semantic versioning, read strictly: a minor only adds, and a major is the only release that changes what exists.
- "Exists" is everything a consumer can depend on, not just signatures: an added output column, a removed list value, a changed default, the facts an error names, a dropped runtime version. A consumer takes a minor without editing code, data or scripts.
- Batch breaking changes into few majors. Before 1.0.0 the minor is the breaking unit and a patch never breaks.