/architecture:bulletproof-functionsfrom architecture
Language-agnostic guidelines for writing honest, testable functions with clear boundaries. Covers extraction principles, local reasoning, and avoiding implicit dependencies.
Ships in architecture. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This reference features a language-agnostic set of highly opinionated guidelines on writing robust bulletproof functions and abstractions that will survive the test of maintainability, testability, and production-grade durability.
This is worth asking because fundamentally, machine codes do not care about functions and only operate on assembly instructions. Functions are not hardware-level mechanisms for correctness, performance, or reliability; it has no bearing on the theoretical capabilities of the model of computation.
A shallow view is that functions are meant to deduplicate logic for code reuse, hence style guides dogmatically enforcing the DRY principle (i.e., extraction upon n > 1 occurrences). This perspective is unfortunately limited. Functions serve to abstract implementation details first and foremost. Functions are "bricks" that are laid out so that callers needn't zoom into the details anymore. Code reuse is a second-order effect of this abstraction, but should not be the primary motivation.
We thus fundamentally agree on the following principles:
n = 1 consumers.A function boundary does not require a file. Typically, extract a utility file because meaningful sans-I/O behavior needs a separate colocated test, even with one production consumer. Keep both files under their owner; do not invent tests for trivial glue or count tests as shared ownership.
To align on a shared glossary for the rest of this reference, we define the following terms:
Availability through globals alone does not make language/runtime-owned primitives application dependencies. Use stable APIs such as crypto, Web Crypto, TextEncoder, TextDecoder, atob, btoa, and equivalent standard-library primitives directly. Do not create factories, synthetic environment objects, dependency bags, or wrapper ports merely to inject them. This direct access does not make hidden nondeterminism or side effects honest: mutable, configurable, and policy-controlled global state remains external. Reserve dependency injection and explicit external handles for application-owned or stateful resources such as databases, network clients, file systems, configurable services, test-owned collaborators, and clocks when policy requires control.
Calling honest work does not erase a function's hidden dependencies. Keep application-owned dependencies explicit throughout the call graph. An injected callback is an explicit capability for handling a result, and may perform effects; this does not make the composition pure or expose dependencies hidden inside the callback implementation. Judge the callback's own honesty by the same dependency rule.
Minimize hidden dependencies, not function size. Keep orchestration cohesive; do not add forwarding wrappers to increase the count of honest functions. Honesty does not imply purity: an explicit resource handle still permits I/O, while sans-I/O decisions operate only on values.
def true_pure_function(x: int) -> int:
""" Obviously can compute its output from only the input. """
return x + 1
@dataclass
class Record:
field: int
def accessor_pure_function(record: Record) -> int:
""" Accesses and projects the input faithfully. """
return record.field
impl<T> Vector<T> {
/// Clears the vector's contents completely.
pub fn clear(&mut self) {
// Impure due to mutations, but totally testable and locally reasonable.
// The `this` or `self` reference being mutated is faithfully communicated via its signature.
todo!()
}
}
Iterator remove_if(Range&& iter, Predicate&& predicate) {
// Removes elements from the range that satisfy the predicate, but returns some internally computed state.
// The returned state ultimately informs the caller how to perform succeeding control flow.
return some_local_iterator_state;
}
// Function signature implies no inputs, but there is an implicit state dependency on a global resource.
auto get_required_assets() {
auto assets{...};
erase_if(assets, &Asset::already_loaded); // dishonest implicit dependency!
return assets;
}
// These are functions whose sole purpose is to perform a single unit of side effect/s to an external system.
// Minimize the blast radius of these side effects. Let the more honest orchestrators handle control flow.
void draw_to_screen(const void*);
This type of function doesn't fall neatly into an honest/dishonest taxonomy, but it's still a function that orchestrates external systems. The key realization is that most functions typically serve to abstract the implementation details from the call site, whereas hooks (or event handlers) conversely abstract the call site from the implementation details. It's effectively just "glue code" between the application and the framework.
int main() {
// The C-style `main` function is the canonical example.
// The underlying library runtime abstracts the entry + exit of the program.
}
// Next.js App Router's `page.tsx` is a popular example.
export default function Page() {
return <InternalPage />;
}
// SvelteKit has similar hooks for server-side loaders (`+page.server.ts`), form actions, and server routers (`+server.ts`).
export async function load({ ... }) {
// ...
}
export const actions = {
async default({ request }) { ... },
};
// Arduino features analogous hook-like abstractions for the embedded runtime.
void setup() {
// ...
}
void loop() {
// ...
}
Read the references relevant to the function boundary being designed or reviewed.
references/flexible-generic-parameters.md (opens in a new tab)references/hoisting-external-handles.md (opens in a new tab)references/proof-of-completion-tokens.md (opens in a new tab)references/same-indentation-rule.md (opens in a new tab)references/top-level-injection.md (opens in a new tab)references/transient-params-struct.md (opens in a new tab)references/validated-wrapper-types.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub bastidood/skills --plugin architecture4 skills in this plugin
/code-styleLanguage-agnostic code-design rules for explicit state, failure, ownership, and I/O boundaries. Use when planning, implementing, refactoring, debugging, or reviewing code./testing-guidelinesLanguage-agnostic test-admission rules for project-owned behavior and meaningful sans-I/O evidence. Use when planning, adding, retaining, removing, or reviewing tests./vertically-sliced-feature-modulesFeature-first module architecture for cohesive ownership, recursive import closures, operational entries, and promotion boundaries. Use when designing, moving, refactoring, or reviewing feature and package structure.Other plugins' skills for the same job