Protect architecture, shared UI, and code quality
A carefully staged workflow can complete every step and still leave the codebase worse than it found it.
An agent can satisfy the ticket while placing business logic in a view, bypassing an existing abstraction, duplicating a shared component, or writing tests that execute code without proving behavior. The feature works, but the codebase is now harder to maintain and the next change is harder to make.
Make architecture legible
When a business rule could plausibly live in a screen, hook, store, or service, different runs may make different choices. Clear layers narrow those choices: React components render state and translate user actions, while the application or domain layer owns business rules. For example, keep checkout price calculation in the domain layer and let the screen display its result. This makes the intended path easier for people and agents to follow.
Make the important architectural boundaries clear to agents as well as people: which packages own a feature, which layers may depend on one another, and where native code belongs.
Keep architectural rules in repository instructions. Use the root file for guidance that applies everywhere and a local file for rules specific to a module. For example:
my-app/
├── AGENTS.md # Shared rules and links to local guidance
├── src/
│ └── checkout/
│ ├── AGENTS.md # Checkout architecture and constraints
│ ├── domain/
│ │ └── calculateTotal.ts # Pricing rules
│ └── ui/
│ └── CheckoutScreen.tsx # Displays the calculated total
└── eslint.config.js # Enforces allowed importsThe root AGENTS.md points agents to the relevant instructions:
Before changing
src/checkout/, readsrc/checkout/AGENTS.md.
The checkout instructions define the boundary and explain why it exists:
Keep pricing calculations in
domain/. UI components display their results. Domain code must not import React Native or UI modules, so pricing can be tested independently.
Keep each rule in one place and reference it from broader instructions. Enforce boundaries mechanically where possible: in this example, a lint rule rejects imports from UI into the domain layer, and CI runs that check.
Before writing code, the agent should check the relevant conventions. The design-system catalog and package templates described in Section 3 make common patterns easier to find; use repository search for unfamiliar or local patterns.
For a layered system, agree on interfaces before delegating implementation. Stable contracts let separate agents work inside individual layers without inventing assumptions that collide later. A change that crosses layers still needs one review of the complete flow.
Clear ownership reduces the search area: when behavior, state, navigation, and tests sit behind a cohesive feature boundary, people and agents can follow a change without touring the whole application. Keep core business logic independent from React Native and volatile third-party systems. When application rules depend on storage, networking, payments, time, analytics, or a device API, place that capability behind a small interface. Production code can use the native or vendor adapter, while tests provide a controlled implementation and exercise the rules in isolation. The real adapter still needs integration or device verification; an isolated test cannot prove that a native SDK works.
Keep each business rule in one clearly identifiable place in the codebase. Extra abstraction adds indirection, so introduce it when it protects a real boundary, not merely because an interface would be easy to mock. The next subsection shows how to turn the boundaries that matter into checks an agent cannot accidentally overlook.
Define what every change includes
Keep one canonical list of standard obligations: behavior tests, affected documentation and module manuals, contract changes, and safety checks. Implementers and reviewers use the same list. A spec need not repeat these obligations, and a spec reviewer should not reject them as unrequested work.
Turn rules into code
Instructions guide an agent. Deterministic checks catch the rules it overlooks.
Use linters such as ESLint or Oxlint for syntax and project conventions. Use dependency-cruiser, or custom checks built on the abstract syntax tree, file paths, or carefully scoped regular expressions, to enforce architectural boundaries. A script can reject imports from forbidden layers, direct use of raw colors, or new UI primitives outside the design system.
Run cheap checks while the task context is still fresh. Git hooks can format staged files, lint changed code, validate architecture, and run focused tests before a commit leaves the workstation. That gives the agent a chance to repair the issue while it still remembers the change.
Assign checks explicitly: workers run focused tests, hooks provide fast feedback, and CI runs the required broader checks. Avoid repeatedly running the same suite at every stage. Protect the authoritative checks and require them at merge; an instruction not to bypass hooks is insufficient.
Dependencies deserve their own rule because they bring code into the repository that the team did not write. Require human approval for a new package and review lockfile changes like any other diff. Pin exact versions and add a cooldown for freshly published releases.
Compromised maintainer accounts can expose even widely used packages. On September 8, 2025, attackers used a phished npm publishing account to release a malicious version of debug. npm removed it that same day, according to the package’s security advisory.
A cooldown gives maintainers and security researchers time to flag malicious releases, though it cannot guarantee safety. An agent should not adopt a version published in the last several days without explicit approval. It should also verify that every package exists in the expected registry. Plausible-sounding, nonexistent, and typosquatted package names are a known failure mode.
Classify every dependency change as JavaScript-only or native-runtime-affecting. A package that adds or changes Swift, Objective-C, Kotlin, Java, C++, native configuration, or a config plugin changes how the application must be built and delivered. Section 6 follows that consequence through testing and release.
Traditional code-quality metrics add another view. Track complexity, maintainability, duplication, dead code, coupling, dependency health, and architectural drift so agents and reviewers can see the direction of the codebase.
For TypeScript and JavaScript projects, Fallow can analyze these signals, report health and refactoring hotspots, and audit changed code in continuous integration. Treat the metrics as decision support and trend signals. A better score cannot prove that the product behaves correctly.
Test behavior, not coverage
Generated tests need the same skepticism as generated implementation. Ask agents to optimize for behavioral confidence rather than a coverage percentage. Behavior is what a user or caller can observe through the public contract, not the internal steps the code happened to take.
In a component test, interact with the interface as a user would and assert what appears on the screen or in the accessibility tree. Enter an invalid value, submit the form, and expect an accessible error message. Do not reach into the component to check whether an internal state flag became true. The implementation may move from local state to a form library without changing the product. A test of the behavior survives that refactor and remains a useful guardrail. This follows the React Native Testing Library guiding principle: tests give more confidence when they resemble how the software is used.
The architectural seams described above let tests replace an external system without replacing the business logic under test. Prefer a small fake when it can express the boundary clearly, and use mocks for narrow interactions where they add useful evidence. Tests that mock away most of the implementation are often long, difficult to read, and weak at catching real failures.
Skip low-value tests. Put more weight on readable domain, integration, and component tests that exercise public contracts, real boundaries, and important failure paths. An agent must never weaken test configuration or exclude difficult files simply to turn the result green.
Prove that tests detect the failure
For important generated or changed tests, deliberately break the behavior in an isolated workspace, run the focused test, and confirm it fails on the intended assertion. Restore the code and confirm the test passes. A red result caused by a typo, setup error, or timeout does not prove the intended behavior.
Check common sources of false confidence: an error assertion that accepts the wrong error, an ordering test that inspects only final state, a title promising behavior with no assertion, or a deadline test that never checks just before and after the boundary. Use mutation testing where it provides useful evidence; prioritize safety and high-risk behavior.
Tests stop at the edge of what they execute. Section 7 takes verification into the running application for keyboard behavior, navigation, permissions, native surfaces, third-party adapters, and state that only appears during a complete flow.