Documentation Generation as You Modernize
The documentation debt problem
Legacy systems accumulate undocumented knowledge. Every architectural decision, workaround, and edge case handler represents understanding that exists only in the minds of the developers who wrote the code. When those developers leave, the knowledge leaves with them.
The numbers are stark. 60% of mainframe specialists are over age 50. By 2027, an estimated 92% of remaining COBOL developers will have retired. The knowledge they carry—decades of understanding about why systems work the way they do—vanishes unless captured.
Traditional documentation efforts fail because they treat documentation as a separate activity from development. Teams plan documentation sprints, hire technical writers, create wiki pages. Within months, the documentation describes a system that no longer exists.
AI changes this. Documentation can be generated during development, verified against actual code, and updated as systems change. The documentation stays synchronized because it emerges from the same process that produces the code.
Generating documentation during modernization
The best documentation emerges as a side effect of modernization work. When an agent refactors a complex function, it necessarily understands what the function does. That understanding can be captured:
After refactoring the calculatePremium function:
1. Generate a prose description of what the function does and why
2. Document the business rules encoded in the conditionals
3. List the edge cases handled and why each exists
4. Create a sequence diagram showing data flow through the function
Format for inclusion in our architecture documentation.This inverts the traditional relationship between code and documentation. Instead of developers writing documentation from memory after the fact, documentation emerges from the act of understanding the code. The agent must understand the code to modify it; documentation captures that understanding.
IBM's watsonx Code Assistant internal testing found 59% reduction in documentation time with this approach. The documentation is also more accurate—it reflects what the agent discovered in the code, not what someone remembered about it.
Generating documentation during refactoring captures the "why" that pure code analysis misses. When an agent encounters a workaround and understands its purpose, document it immediately—don't leave it for later discovery.
Democratizing expert knowledge
Modernization projects often stall because knowledge exists only in individual experts. A senior developer who wrote the original system understands the implicit assumptions, undocumented business rules, and historical reasons for unusual patterns. Without that person, modernization teams must reverse-engineer everything from code alone.
AI agents help in two ways.
First, agents can interview experts and convert tacit knowledge to explicit documentation. Before an expert retires, they can review agent-generated documentation and correct misunderstandings:
I've analyzed the claims processing module and generated documentation.
Please review these findings and correct any misunderstandings:
1. The 45-day holdback appears to satisfy regulatory requirement X—is this correct?
2. The parallel processing exclusion for accounts over $1M—what caused this?
3. The custom rounding in premium calculations—regulatory, legacy compatibility, or both?
Note: I'm asking about the "why" that can't be determined from code alone.The expert reviews AI-generated documentation rather than writing from scratch. This is faster and catches the gaps—the places where code-level analysis misses context that only humans remember.
Second, AI agents make that captured knowledge accessible across the organization. Once documentation exists, any developer can query it. New team members can ask about business rules, architectural decisions, and historical context. They get answers derived from captured expert knowledge, not from interrupting busy humans.
Organizations report that understanding phases which previously took months now complete in weeks. The knowledge of departed developers becomes explicit and searchable. Onboarding time reductions of 40-53% are common when AI documentation tools are available.
Living documentation patterns
Static documentation decays. The moment it is written, it begins drifting from reality. Living documentation maintains synchronization with the actual system.
Documentation-as-code treats documentation files as artifacts in version control alongside the code they describe. Changes to code trigger documentation reviews. Pull requests include both code changes and documentation updates. The documentation evolves with the system.
Continuous verification checks documentation accuracy automatically. Build pipelines can validate that documented APIs match actual implementations. Agents can scan for drift between descriptions and behavior:
Compare our API documentation against the actual endpoint implementations.
Identify:
1. Documented endpoints that no longer exist
2. Actual endpoints missing from documentation
3. Parameter mismatches between documented and implemented
Generate a drift report with specific file references.Regenerative documentation goes further. Instead of updating documentation manually, systems regenerate it from code. Google Code Wiki, introduced in November 2025, continuously synchronizes documentation with code changes. Architecture diagrams, class documentation, and sequence diagrams are generated from actual code and regenerate when that code changes.
Regenerative documentation captures "what" without "why." Agents analyzing code can determine what a function does but not why it was designed that way. The most effective approach combines regenerative technical documentation with human-curated design rationale.
Generated documentation should include a warning: "Gemini can make mistakes, so double-check it" (Google's disclaimer on Code Wiki). Trust generated documentation for structure and relationships. Verify it for business logic and design intent.
The documentation generation workflow
A practical workflow integrates documentation generation into regular development:
1. During refactoring: When modernizing code, request documentation as part of the output. The agent understands the code to modify it; capture that understanding.
2. After refactoring: Run a documentation pass over changed files. Generate function descriptions, update architecture diagrams, note new dependencies.
3. During review: Include documentation quality in code review criteria. Changed code without updated documentation is incomplete.
4. On schedule: Run periodic drift detection. Identify where code has changed but documentation has not.
The 64% of software development professionals now using AI for documentation (Google Cloud DORA 2025 Report) report that integrating documentation into development workflows—rather than treating it separately—produces better documentation and faster development.
Preserving what would disappear
When a function is refactored, the original structure—which may have encoded important context—is gone. Document it before it changes.
When an expert reviews AI-generated documentation, they correct misunderstandings. Those corrections represent knowledge that existed only in their heads until that moment. Capture it.
When a legacy system is retired, its patterns may inform future design. Document the architectural choices and their outcomes—both successes and failures. This is institutional learning.
Organizations that treat modernization as an opportunity for documentation capture emerge with more than updated code. They have explicit knowledge where implicit understanding once lived. Searchable explanations where tribal knowledge once required tracking down specific people. Documentation that reflects what the system actually does, verified against actual code.
Not just modern code, but modern understanding.