Repository Documentation
Have you ever heard of “documentation debt”? It is that mysterious phenomenon where documentation becomes outdated faster than an avocado on a kitchen counter. But fear not! Today we will explore how to keep documentation fresh, updated, and surprisingly useful, all directly in your repository.
Forget external wikis nobody updates and shared documents that vanish into the cosmic void of the cloud. It is time to put documentation where it belongs: right next to the code it describes.
📚 Why Keep It in the Repository?
Keeping documentation in the repository is like having the instruction manual attached to the remote control: it is always there when you need it, and it updates when you change the batteries. The benefits?
- Automatic versioning (goodbye to “documentation_final_v3_definitive_this_time_really.doc”)
- Code reviews that include documentation (there is no escape)
- Single source of truth (no more excuses like “ah, but that was the old version”)
🗂️ Types of Documentation
Derivations and Dependencies 🔄
graph TD
A[API Gateway] --> B[Service A]
A --> C[Service B]
B --> D[(Database)]
C --> D
This is not a family tree of microservices, but it helps you understand who talks to whom.
Text Documentation 📝
Manual
The good old handwritten Markdown, useful when you need to explain complex concepts:
|
|
Generated from Code 🤖
With JSDoc you can generate documentation directly from comments:
|
|
For TypeScript, you can use TypeDoc:
|
|
API Documentation 📡
OpenAPI/Swagger is your best friend here. Example:
|
|
Architectural Diagrams 🏗️
Because an image is worth more than a thousand words (and a thousand meetings):
C4Context
Person(user, "User", "Someone who hopes everything works")
System(sys, "The System", "What should work")
System_Ext(magic, "Magic", "What makes everything work")
🔍 Documentation Validation Tools
📝 Vale: Grammar and Style Checking
Vale is a prose validator that helps you keep a consistent writing style and correct phrasing.
Installation
|
|
Configuration
Create a .vale.ini file at the root:
|
|
📋 Markdownlint: Formatting and Consistency
Markdownlint-cli2 ensures your Markdown follows standard conventions and stays consistently formatted.
Installation
|
|
Configuration
Create a .markdownlint.json file at the root:
|
|
🪝 Git Hooks for Automatic Validation
Git hooks let us run checks automatically before every commit.
Configuring Git Hooks
Create the .githooks directory and the pre-commit file:
|
|
Configure the content of the pre-commit hook:
|
|
Activate the hooks:
|
|
🚀 Automation Is the Key
Integrate documentation validation into your CI:
|
|
Because documentation is like code: if you do not test it, you cannot trust it.
🎭 Best Practices (or “How Not to Annoy Your Colleagues”)
Update Alongside the Code 📝
- If you change a feature, update its documentation
- If you deprecate something, document it (do not leave traps)
Keep It DRY 🌵
- Use cross-references
- Centralize common information
- Automate generation where possible
Clear Structure 🗂️
- README.md in every important directory
- Table of contents for large repositories
- Links between related documents
💡 Conclusion
Documentation in the repository is not just a best practice; it is an act of kindness toward your future self and your colleagues. And remember: “Code says what it does, documentation says why it does it” (and sometimes how it manages to do it, when the code is especially cryptic).