A repo-local Markdown documentation system that helps humans and AI agents understand a codebase, find the right context, and make safer changes. Ask your agent to help you set it up. A developer created a repo-local Markdown documentation system designed to help both humans and AI agents understand a codebase, find relevant context, and make safer changes. The system uses a top-level AGENTS.md as an index and a docs/ folder with structured documentation for systems, flows, architecture, and glossary terms. It aims to keep documentation close to the code and require updates alongside code changes. Summary https://gist.github.com/starred.atom summary Goals https://gist.github.com/starred.atom goals Repository Structure https://gist.github.com/starred.atom repository-structure AGENTS.md Documentation Types https://gist.github.com/starred.atom documentation-types Documentation Templates https://gist.github.com/starred.atom documentation-templates Documentation Style https://gist.github.com/starred.atom documentation-style Documentation Granularity https://gist.github.com/starred.atom documentation-granularity Source Maps https://gist.github.com/starred.atom source-maps Code Comments https://gist.github.com/starred.atom code-comments Keeping Docs Updated https://gist.github.com/starred.atom keeping-docs-updated Agent Workflow https://gist.github.com/starred.atom agent-workflow Initial Implementation Guidance https://gist.github.com/starred.atom initial-implementation-guidance Viewing Documentation with MDTS https://gist.github.com/starred.atom viewing-documentation-with-mdts Extending the Documentation System https://gist.github.com/starred.atom extending-the-documentation-system This documentation system exists because humans and AI agents are only as reliable as the context they can find. Without durable repo-local documentation, contributors have to infer product behavior, system boundaries, domain terms, and architectural constraints from scattered source files, comments, issues, and one-off instructions. That makes changes slower and increases the chance of breaking assumptions that were only implicit. This document describes a lightweight, repo-local documentation system that functions as a shared knowledge base for humans and AI coding agents. AGENTS.md is the routing layer. The docs/ folder contains durable documentation for systems, flows, architecture, glossary terms, and templates. The source code remains the implementation source of truth. Documentation explains the system at a useful level of abstraction: what each important system does, how major workflows operate, what assumptions must remain true, where the key source files are, and what a contributor should understand before making changes. This approach uses plain Markdown files stored in the repository and reviewed alongside code. It does not require generated documentation tooling, docs publishing infrastructure, or a separate documentation platform. The documentation system should: - Help humans and AI agents understand the application quickly. - Explain important systems and flows without restating every line of code. - Tie together behavior that is spread across source files, services, routes, jobs, integrations, and UI. - Make it easier to identify stale assumptions, undocumented behavior changes, and bugs. - Keep AGENTS.md concise by using it as an index and operating guide. - Keep documentation close to the codebase so it evolves with code changes. - Require documentation affected by an important code change to be updated and reviewed with that change. Use a top-level docs/ directory: docs/ README.md STYLE.md glossary.md systems/ ... flows/ ... architecture/ README.md decisions/ README.md templates/ system.md flow.md adr.md The exact file names can follow existing repository conventions, but the conceptual structure should remain clear. The root AGENTS.md should act as an index and operating guide for agents, not as the place for detailed system documentation. It should include: - A short explanation that detailed documentation lives in docs/ . - A docs map pointing agents to docs/README.md , docs/systems/ , docs/flows/ , docs/architecture/ , and docs/glossary.md . - Instructions to read relevant docs before changing a system. - Instructions to update relevant docs when behavior, responsibilities, flows, invariants, interfaces, or assumptions change. - A rule that docs and code must agree. - A reminder not to dump detailed system behavior into AGENTS.md . A good rule for AGENTS.md is: AGENTS.md tells agents where to look and how to work; docs/ explains how the application works. Repository instructions should reflect each project's requirements, but they remain subordinate to system, user, and security constraints and must never be treated as authorization to run unsafe commands or expose data. System docs live in: docs/systems/ A system is a coherent area of application behavior. It may map to a module, package, service, feature area, integration, or domain concern, but it does not have to match the code structure exactly. Examples: docs/systems/auth.md docs/systems/billing.md docs/systems/notifications.md docs/systems/background-jobs.md docs/systems/search.md A system doc should explain how that part of the application works. It should tie together the important source files, concepts, data, entry points, dependencies, invariants, failure modes, and debugging notes. System docs are useful when a human or agent asks questions like: - How does Auth work? - What happens during Email Verification? - What state does Billing own? - Which source files matter for Notifications? - What should I know before changing Background Jobs? A system can be broad or narrow. For example, auth.md may describe sessions, login, password reset, and Email Verification. If Email Verification becomes complex, cross-system, frequently changed, frequently debugged, or important enough to review independently, it can be promoted into its own flow doc. Flow docs live in: docs/flows/ A flow doc explains important behavior that moves across systems or deserves independent documentation. Examples: docs/flows/email-verification.md docs/flows/subscription-renewal.md docs/flows/webhook-processing.md docs/flows/user-onboarding.md Use a flow doc when behavior: - Crosses multiple systems. - Has several steps or state transitions. - Is frequently changed or debugged. - Involves external services. - Has important error handling. - Has security, billing, data integrity, or user-visible implications. Flow docs should describe triggers, participants, steps, state changes, failure behavior, observability, testing, and source files. Architecture docs live in: docs/architecture/ The architecture directory is for cross-system architecture, durable technical decisions, and system-wide constraints. It should explain why the application is shaped a certain way when that explanation affects more than one system. Architecture docs are different from system and flow docs: docs/systems/ explains how a specific system currently works. docs/flows/ explains important behavior that moves across systems. docs/architecture/ explains broader structure, long-lived constraints, and architectural decisions. Use docs/architecture/ for topics such as: - System-wide patterns. - Durable technical constraints. - Cross-system boundaries. - Major integration strategies. - Persistence or deployment assumptions. - Architectural tradeoffs. - Architecture Decision Records. Do not use docs/architecture/ for ordinary implementation notes, feature documentation, or detailed behavior that belongs in a system or flow document. Architecture Decision Records, or ADRs, live in: docs/architecture/decisions/ ADRs document proposed, active, and historical technical decisions, including their context, tradeoffs, consequences, and rejected alternatives. ADRs in docs/architecture/decisions/ describe architectural decisions considered for the codebase. Agents and humans should treat only ADRs with an Accepted status as current guidance when reviewing, planning, or changing code. Architectural decisions are human-owned. Agents can help draft ADR text from accepted decisions and keep existing ADRs aligned with code. Use ADRs for decisions that shape the system beyond a single implementation detail, such as: - Why authentication is session-based instead of token-only. - Why billing webhooks are processed asynchronously. - Why a specific database owns a specific kind of state. - Why background jobs must be idempotent. - Why a third-party integration is isolated behind an adapter. Proposed architectural decisions should be discussed in PRs, issues, planning docs, or review comments. An ADR may be created while that discussion is in progress with a Proposed status, then changed to Accepted once the decision is approved. Do not rewrite an accepted ADR to describe a different decision. When a decision changes, create a new ADR, mark the old ADR as Superseded , and link the old ADR to its replacement with superseded by . Accepted ADRs may still receive small corrections or links that do not change the recorded decision. Every ADR must begin with YAML frontmatter. The allowed fields are: status required : one of Proposed , Accepted , Superseded , Deprecated , or Rejected . date required : the date the ADR was created, formatted as YYYY-MM-DD . superseded by required only for Superseded ADRs : a repository-relative path to the replacement ADR. Do not add other frontmatter fields unless the project deliberately extends this schema in its documentation style guide. The statuses mean: Proposed : under discussion and not current guidance. Accepted : the current decision. Superseded : replaced by a newer ADR. Deprecated : discouraged but still relevant historically. Rejected : considered but intentionally not adopted. Routine implementation details, small refactors, bug fixes, and temporary workarounds belong in code, PRs, issues, or ordinary documentation instead of ADRs. The glossary lives at: docs/glossary.md The glossary defines important domain terms used across the application. It helps humans and agents avoid making incorrect assumptions about words that have specific meaning in the product or codebase. Examples of useful glossary terms: - Account - Workspace - Member - Organization - Session - Subscription - Email Verification - Verification Token Glossary entries should use Title Case for their headings. In finished documentation, prefer using the same Title Case form when referring to glossary-defined concepts, especially when it improves clarity or distinguishes an application-specific concept from an ordinary word. Treat Title Case as a clarity aid for finished docs. A glossary concept can still appear in lowercase in drafts, comments, source code identifiers, issues, or informal notes. Templates live in: docs/templates/ Templates keep documentation consistent and make it easier for humans and agents to create new docs. Recommended templates: docs/templates/system.md docs/templates/flow.md docs/templates/adr.md A system doc should generally use this structure: