Skip to content

How to map code folders to the docs they affect

A reviewer cannot guess that `src/billing/` is documented on a page called Invoices. Write the link down once: which files count as docs, which pages to skip, and which code folders map to which pages. Keep the map in the repository, next to the code, and test it with a real changed path.

Updated 5 min read

Step 1. List your docs and your code areas

Start on paper. List the folders that hold user-facing docs, then the code areas that change behavior users see: API handlers, CLI commands, configuration loading, authentication, billing. For each code area, name the page or folder a reader would open to learn about it.

Keep the map short. It only needs the links that names do not make obvious. When src/webhooks/ is documented in docs/webhooks.md, a search for the folder name finds the page without help.

Code that changesDocs a reader opens
src/api/**docs/api/
src/billing/**docs/guides/invoices.md
src/config/env.tsdocs/reference/environment-variables.md
packages/cli/**docs/cli/

Use the map without any tool

A written map already helps. Put it in CONTRIBUTING.md so authors look up the page before they open a pull request. Mirror the docs side in CODEOWNERS so the right team reviews each page. Use the code side in a path-based CI gate that asks for a docs change when a mapped folder changes. The guide on requiring docs updates has an example workflow.

Step 2. Decide which files count as docs

With Rimfe, the map lives in a .rimfe.json file at the repository root. Generate a starting file with npx @rimfe/cli init. It detects Docusaurus, MkDocs, Starlight, Mintlify, GitBook, Sphinx, Antora, Nextra, VitePress, Fumadocs, Fern and plain docs folders, reads only the files git tracks and needs no sign-in.

Then narrow it with three lists. docsGlobs says what is documentation, and it is the only required key. docsIgnorePaths removes pages from the docs, such as generated reference pages or archived versions. ignorePaths keeps changed code files out of the review, such as tests or generated clients.

.rimfe.json
{  "$schema": "https://rimfe.com/schema/rimfe.json",  "docsGlobs": ["README.md", "docs/**/*.{md,mdx}"],  "docsIgnorePaths": ["docs/archive/**", "docs/api/generated/**"],  "ignorePaths": ["**/*.test.ts", "src/generated/**"]}

Step 3. Add the code mappings

Each entry in codeMappings has a source, a glob matched against changed file paths, and a target, a page or a folder ending in / inside your docs scope. When a pull request changes a matching file, Rimfe reads the target pages first. A folder target puts every in-scope page under it first.

Order matters. Earlier mappings rank higher, so put narrow ones before broad ones. Several sources can point at one page, and one source can appear in several mappings.

.rimfe.json
{  "$schema": "https://rimfe.com/schema/rimfe.json",  "docsGlobs": ["README.md", "docs/**/*.{md,mdx}"],  "docsIgnorePaths": ["docs/archive/**", "docs/api/generated/**"],  "ignorePaths": ["**/*.test.ts", "src/generated/**"],  "codeMappings": [    { "source": "src/config/env.ts", "target": "docs/reference/environment-variables.md" },    { "source": "src/billing/**", "target": "docs/guides/invoices.md" },    { "source": "src/api/**", "target": "docs/api/" },    { "source": "packages/cli/**", "target": "docs/cli/" }  ]}

What a mapping does not do

A mapping puts the right page in front of the review. It does not limit the review to that page, and it never forces a finding. Rimfe still finds other passages that name what the change renamed or removed, on any page in scope. To leave code out, use ignorePaths. To leave a page out, use docsIgnorePaths.

Step 4. Commit the file and switch the source

Rimfe reads the file from the branch a pull request targets, never from the pull request's own branch. A change to the file takes effect for pull requests once it merges.

  1. Merge .rimfe.json into the default branch.
  2. In the repository's Settings in Rimfe, open the Advanced tab and set Documentation scope to .rimfe.json at the PR base.
  3. Select Save changes. Rimfe validates the file on the default branch, and the save fails with the reason if the file is invalid.

Or keep the map in the dashboard

The same mappings can live under Code-to-doc mappings on the Docs tab of the repository's Settings, one per line, written as src/api/** => docs/api/. The dashboard and the file are never merged. The Documentation scope setting picks one, and the file keeps the map under review like any other change.

Step 5. Test the map with a real path

Test before the first pull request depends on the map, then again after each change to it.

  1. Select Check setup in the repository's Settings. Matched files lists the first 100 docs files in scope. Look for pages that should not be there.
  2. Under Test the scope, enter a changed file such as src/billing/invoice.ts. Rimfe lists the pages that path reaches and why.
  3. On an open pull request, comment @rimfe config. The reply names where the docs scope comes from, the commit it was read from, the ignored paths and the number of mappings.
  4. After the next review, open the run in the dashboard. A line reading Scope: .rimfe.json with a commit confirms which version of the file that review used.

Monorepos: one file per package

A package can carry its own .rimfe.json, such as packages/sdk/.rimfe.json. Its paths start at the package folder, and a leading / points at the repository root, which is how a package maps its code to shared docs. A pull request that touches the package is reviewed with the root scope plus the package's scope, with the package's mappings ranked first. The root file is still required, and repository-wide keys such as owners belong only in the root file.

apps/api/.rimfe.json
{  "$schema": "https://rimfe.com/schema/rimfe.json",  "codeMappings": [    { "source": "src/routes/**", "target": "/docs/reference/http-api.md" }  ]}

Common mistakes

  • Writing a bare folder in an ignore list. docs/internal matches nothing inside the folder. Write docs/internal/**.
  • Pointing a target outside the docs scope. Saving fails with Code mapping target is outside docs scope until you fix the target or the globs.
  • Fixing .rimfe.json in the pull request it breaks. Reviews read the base branch, so push the fix there and comment @rimfe review.
  • Adding comments or trailing commas. The file must be plain JSON, at most 32,000 bytes.
  • Mapping every folder. Add mappings where the review picks the wrong page, and let search handle the rest.

Takeaway

Write down only the links names do not make obvious, keep them in .rimfe.json next to the code, and test each one with a real changed path before you rely on it.