Skip to content
Maxwell CollinsContact

Code-cited documentation method for AI-written docs

A method for a property software suite: AI agents writing its documentation must cite the code behind every claim.

What it achieved

AI agents can no longer document software that doesn't exist, and faults where products meet are caught before any product is built on them.

The short version

AI agents can no longer document software that doesn't exist, and faults where products meet are caught before any product is built on them. Every claim an agent writes about the property software suite must cite the source code or an audited registry that proves it. Maxwell built this documentation method for the suite's thirteen property-software products. It runs in 25 phases from research to launch. A registry of facts is built from the code before any writing starts, and a claim-checking server answers agents' questions from the source. Throwaway test versions of the products call the real platform to prove it works where products meet. The method reversed a cascade of more than 500 documents describing a platform that never existed.

The problem

AI agents writing documentation read documents, not code, unless something forces them to. On the property suite, agents checked each new document against the ones before it, all resting on a 15,273-line design blueprint of plans. The result was more than 500 documents describing a platform that didn't exist: 39 database tables where the code had 28 to 32, and API routes that had never been written.

In use

  1. Before any writing starts, a registry of facts is built from the code.
  2. An agent writing a document has to cite the code or the registry for every claim, and an uncited claim fails.
  3. When a fact is in doubt, the agent asks the claim-checking server, which answers from the source.
  4. Before products are built on the API, throwaway client products call it for real and prove it works where products meet.

What it achieved

  • Faults where the products meet the platform are caught before any product is built on them: throwaway client products call the real API through the whole chain from token to service, which mocked unit tests never see.
  • Stopped thirteen products being designed against fiction: it reversed a cascade of more than 500 AI-written documents describing a platform that did not exist (39 database tables where the code had 28 to 32) and rebuilt the architecture from the code.
  • Any statement about the platform can be checked on demand: an agent asks the claim-checking server and gets confirmed or contradicted, with the evidence from the code. A prospective partner's 95-question technical review was answered at source-code level, with file and line references.
  • Nothing the old products did can be dropped by accident: every capability is listed, cited to its file and line, and must be carried forward, improved or removed.

The full record

On this page
In one sentence

Maxwell built the source-grounded documentation method, a 25-phase build-governance method for the property suite ecosystem of thirteen property-software products, in which every claim a document makes about what the software does must cite the source code or an audited registry that proves it, a rule that reversed a 500-document hallucination cascade in which AI-written documents had been citing each other instead of the code, and whose 135-test cross-product validation suite runs as throwaway client products against the real 110,000-line API, across a documentation estate of 781 working documents, 13 audited contract registries, a 14-tool claim-checking server and 198 commits in its governing repository. He builds by directing AI agents, and he built this method that way.

governed documents
781
documents in the cascade reversed
500
phases
25
cross-product validation tests
135
integration bugs caught
6

What it does

The method governs how a large software platform is researched, designed, documented, validated and built by AI agents, so that nothing written about the platform can drift away from what the platform really does. It was built for the property suite, a property-software ecosystem whose products (the owner portal, the inspection app, the field-service app, the property-management app, a shared AI intelligence layer and a single sign-on Hub) all sit on one central API of about 110,000 lines, and whose earlier generation was a large estate of legacy PHP.

The 25 phases

The method is written as a 1,206-line playbook in seven parts. Its sequence is load-bearing: no phase is skipped, and each produces named documents the next phase depends on. It is written for one operator directing AI agents, with no team.

Part 1, Research

  1. Market and competitive research: the competitive landscape, feature gaps, market size, pricing, technology trends, regulation and the user-experience workflows competitors use.
  2. User research and customer discovery: personas, jobs-to-be-done maps, current workflows, pain points, willingness to pay and switching signals, built from public reviews. A further gap-closure step (phase 2.5) adds feature teardown matrices, cross-product integration patterns, cross-industry interface patterns and review mining by feature.

Part 2, Strategy, both phases under a mandatory source-verification banner

  1. Strategic thesis and ecosystem vision: the thesis, the value of each product, the revenue model, the network-effect case, the stack and build-versus-buy decisions.
  2. Product portfolio strategy: the dependency map, the anchor product, the build sequence, the roadmap and kill criteria.

Part 3, Architecture

  1. Enterprise architecture foundation: principles, the domain model, service topology, shared versus product-specific components, communication patterns and architecture decision records.
  2. Data architecture and ownership: the master data catalogue, who owns which data, data flows, the unified data model, the observation registry (named the first rebuild-prevention artifact), the shared enumeration registry, caching, governance and privacy.
  3. API contract and integration design: API standards, the platform's OpenAPI specification, the AI layer's tool contracts, an additive-only versioning rule, consumer-driven contract testing, the event catalogue and the gateway.
  4. Identity and access: nine documents and 3,785 lines covering tokens, single sign-on, authorization, service-to-service authentication, provisioning, multi-tenancy and the Hub's token-claims contract (the second rebuild-prevention artifact).
  5. Security and compliance: threat model, zero trust, encryption, compliance mapping, security testing, the incident runbook and the dependency policy.
  6. Design system and user experience: principles, design tokens, the component library, layouts, accessibility and maintenance rules.
  7. Frontend architecture: the monorepo, shared packages, state, routing, testing, pipeline and performance budget.
  8. Mobile architecture: platform choices, offline design, the sync engine, camera and media, shared patterns and app-store compliance.
  9. Infrastructure, DevOps and observability: cloud, CI/CD, infrastructure as code, monitoring, alerting, disaster recovery, cost and capacity.
  10. The AI intelligence layer: concept, blueprint, tool contracts, the copilot, SMS and chat intake, adapters, knowledge-base seeding, the operations guide and the technical architecture.
  11. Governance and documentation strategy: coding standards, the decision-record process, testing standards, review, documentation rules, technical debt and release.

Part 4, Validation

  1. Proof of concept and technical validation: throwaway mock versions of the consumer products (Hub, the owner portal, the inspection app, the field-service app, the property-management app and the AI layer) driven against the real API, in three rounds: four proofs of concept with benchmarks, seven gap-closure batches, and the 135-test cross-product re-validation.

Part 5, Product design

  1. Individual product specifications: for each of 13 products, its features, flows, wireframes, data model, API requirements, a product-to-API mapping, AI-layer integration and non-functional requirements, 43 documents in four waves, closed by a pre-build compatibility gate that checks every endpoint, observation type, AI tool and token claim against the contracts.

Part 6, Build, each phase run through an eight-step cycle: top-level documents, then detailed documents, then validation of the product-to-API mapping (stop on any incompatibility), task breakdown, test-driven development, review, the full gate with contract tests and AI-tool contract validation, then staging and production.

  1. Shared platform and intelligence layer: the Hub, event bus, component library, CI/CD, observability, the AI-layer skeleton, knowledge base, worker pools and the AI client package.
  2. Anchor products: full web, mobile and backend, with contract and AI integration tests.
  3. Secondary products: cross-product flows and cross-domain intelligence.
  4. Tertiary products and mobile: the remaining backends and frontends, every mobile app and the offline AI queue.

Part 7, Quality and launch

  1. Integration testing and performance: cross-product flows, single sign-on, events, the AI layer across products, graceful degradation, knowledge-base accuracy, load, chaos, data consistency and mobile sync.
  2. Security audit and compliance: static, dynamic and dependency scanning, API and database audits, prompt-injection, data-isolation and token-cost audits for the AI layer, an external penetration test, SOC 2, GDPR, a license audit, remediation and the report.
  3. Release management and launch: dogfooding, closed beta, open beta, general availability and launch monitoring.
  4. Post-launch operations: runbooks, service-level monitoring, the feedback channel, golden signals, knowledge-base operations, model evolution, security operations, analytics and technical-debt paydown.

Structure around the phases: a three-level documentation hierarchy in which a lower-level document may never contradict a higher one; sizing rules (no file over 500 lines or 100 KB, agent instruction files held to 75 lines, an index in any folder of three or more files); the frameworks it draws on (TOGAF, domain-driven design, OWASP secure-by-design, consumer-driven contracts); a quality-enforcement appendix; and resume prompts so any session can pick up exactly where the last one stopped.

The code-citation rule

The rule is short: any document that states what the platform does must cite the source code or an audited registry, and never another document alone. Every platform claim is tagged as current (true in the code today), target state (designed, not yet in the code) or unverified. The citation names the exact source file, for example the property entity in the API's source tree.

How the rule is enforced, not merely stated:

  • 13 audited contract registries hold the machine-readable truth about the platform: permission levels, error codes, rate limits, domain events, the metrics baseline and more.
  • A claim-checking server with 14 tools lets any agent ask whether a statement about the platform is true. Its validate-claim tool returns CONFIRMED or CONTRADICTED, with the evidence drawn from the registries and the source code.
  • Write-time blocking rules refuse fabrication patterns, documents with missing sources and mocked platform behavior, and flag any architecture document that cites the old aspirational blueprint as its source.
  • A fact registry is built before any writing starts, and the source truth overrides everything else in the document.
  • The strategy-writing skill fails any uncited claim in its first pass: a platform claim with no citation within two lines does not pass. The architecture-writing skill has three stop gates.
  • A start-up hook injects the anti-hallucination rules into every helper agent the moment it starts.
  • A legacy capability registry of 9 files and 1,782 lines lists every capability of the legacy PHP products, each row cited to its file and line, built by mechanical extraction with codex-audit, fresh AI audits with mandatory file-and-line citations, and cross-reference checks. A coverage gate requires every one of those capabilities to be dispositioned: carried forward, improved or removed. Nothing the old products did can be dropped by accident.

The 135-test cross-product validation suite

Phase 16 builds disposable versions of the consumer products and drives them against the real API, testing the whole path a real request takes (token, guard, controller, service) instead of the mocked pieces a unit test sees. The full suite is 135 tests in 14 batches across three passes: regression, new coverage, and integration (consumer journeys, cross-product flows, load and certification), spanning the owner portal, the inspection app, the field-service app, the property-management app, the AI layer and the Hub.

Unit tests mock users and guards, so they never exercise the full chain from token to service; the cross-product suite does, covering sessions across devices, the guards that read the user, role checks, webhook registration and event delivery under a burst of load. Every finding is filed as a tracked issue, fixed in the API and re-validated, with the full gate reporting 7,485 tests passing.

What it achieved

  • A 500-document hallucination cascade reversed. The method found that AI agents had been verifying documents against other documents, archived the contaminated set, rebuilt the architecture phases from the source code and the registries, and deleted every decision record that described a decision never made in the code.
  • Faults where products meet caught before any product was built on them, each of which would have reached every client product that touched it.
  • A documentation estate held to the code: 781 working documents (284 research, 18 strategy, 113 architecture, 110 product specifications, 95 validation, 15 on the AI system, 13 decision records), 13 product specifications sets of 43 documents, 13 audited registries and a 14-tool claim checker.
  • Every legacy capability accounted for, each cited to its file and line and given a disposition.
  • Source-level answers on demand: a 95-question technical deep dive for a prospective partner was answered at source-code level, with file references and line numbers.
  • It grew out of his earlier seven-phase pre-build methodology for a founder who directs AI agents and judges their work by the evidence it produces, and carries its cardinal rule forward: no production code until the plan is complete.

The problem it solves

When AI agents write a platform's documentation, they read documents, not code, unless something forces them to. On the property suite, a 15,273-line aspirational design blueprint had been treated as the truth about the platform, and agents verified each new document against the documents before it. The loop was closed: nothing told any agent to read the source. The result was a cascade of more than 500 documents describing a platform that did not exist. They claimed 39 database tables where the code had 28 to 32, described a token scheme the code did not use, a permission model the code did not have, a webhook format the code did not send, and API routes that had never been written. Every product designed from those documents would have been designed against a fiction.

Unit tests cannot catch faults where products meet, because they mock exactly those pieces. The method answers both: documents must cite code, and the platform is proved by products that really call it.

How he built it

Maxwell wrote the playbook for one operator directing AI agents. When the cascade surfaced, he ran a reconciliation audit (679 lines, sorting every claim into diverges from the code, aspirational or matches), traced the cause to the closed document-to-document loop, and directed a four-part repair: fix contamination inside the platform repository itself, rewrite the documentation system so it requires source code, archive the contaminated documents, and rebuild phases 5 to 16 from the source and the registries, followed by verification. The old blueprint was moved out of the platform repository with a warning attached.

He then turned the rule into machinery so that no agent could repeat the mistake: the contract registries, the claim-checking server, the blocking rules, the fact-registry step, the stop gates in the writing skills, the hook that briefs every helper agent and the legacy coverage gate. A written AI governance system describes the whole arrangement, its anti-hallucination section setting out every layer. Validation was run in rounds (24 tests across four proofs of concept, then 62 gap-closure tests, then the 135-test cross-product suite), each round's findings filed as tracked issues, fixed in the API and re-tested. The governing repository carries 198 commits and the API it governs 353.