ISSUE-059: Missing API Documentation
Description
The project lacks comprehensive API documentation. Public functions, classes, and methods in the src/ directory have minimal or no docstrings, making the codebase difficult to understand and maintain.
Current State
What Exists:
- Basic docstrings on some model classes
- Minimal docstrings on some functions
- No API documentation for public modules
- No generated documentation (Sphinx, MkDocs, etc.)
What's Missing:
- Detailed docstrings for public functions
- Parameter descriptions with types
- Return value descriptions
- Exception documentation
- Usage examples
- Module-level documentation
- Generated HTML documentation
Impact
- Hard to Understand: Need to read code to understand usage
- Onboarding Difficult: New developers struggle to contribute
- Maintenance Burden: Hard to remember function details
- No Reference: No quick reference for APIs
- Poor Developer Experience: IDE shows limited help
Expected Documentation Standards
1. Module Docstrings
Every module should have a docstring explaining its purpose:
"""
Employee model and business logic.
This module contains the Employee model and related business logic
for managing employee records, including:
- Employee CRUD operations
- Relationship management (CACES, medical visits, trainings)
- Employee calculations (age, seniority, etc.)
Example:
>>> from employee.models import Employee
>>> emp = Employee.get_by_id(1)
>>> print(emp.full_name)
"John Doe"
"""
2. Class Docstrings
class ExportController:
"""
Controller for Excel export operations.
This controller manages the export of employee data to Excel format,
including employees, CACES certifications, medical visits, and training records.
Attributes:
exporter: DataExporter instance for performing exports
exporting: Boolean flag indicating if export is in progress
Example:
>>> controller = ExportController()
>>> controller.export_employees(
... output_path="employees.xlsx",
... employees=employee_list,
... include_caces=True
... )
"""
3. Function/Method Docstrings
Use Google style docstrings:
def get_employees_with_expiring_items(days: int = 30) -> list[Employee]:
"""
Get employees with expiring certifications or medical visits.
This function queries the database for employees who have at least one
certification or medical visit that will expire within the specified number of days.
Args:
days: Number of days to look ahead from today. Must be positive.
Default is 30 days.
Returns:
List of Employee objects with at least one expiring item.
Returns empty list if no employees have expiring items.
Raises:
ValueError: If days is negative or zero.
Example:
>>> from employee.queries import get_employees_with_expiring_items
>>> expiring = get_employees_with_expiring_items(days=60)
>>> print(f"Found {len(expiring)} employees with expiring items")
Found 15 employees with expiring items
"""
if days <= 0:
raise ValueError("Days must be positive")
# ... implementation ...
Proposed Solution
Phase 1: Add Module Docstrings (2-3 days)
Modules to document:
src/employee/models.py - Employee models
src/employee/queries.py - Employee queries
src/employee/calculations.py - Employee calculations
src/controllers/*.py - All controllers
src/utils/validation.py - Validation utilities
src/utils/file_validation.py - File validation
src/export/data_exporter.py - Export functionality
src/excel_import/excel_importer.py - Import functionality
Template:
"""
[One-line summary of module purpose].
[Detailed description of module functionality and what it provides].
Key Features:
- [Feature 1]
- [Feature 2]
- [Feature 3]
Classes:
- [ClassName]: [Brief description]
Functions:
- [function_name]: [Brief description]
Example:
[Usage example]
See Also:
- [Related module or documentation]
"""
Phase 2: Add Class Docstrings (1-2 days)
For each public class, add comprehensive docstring:
Template:
class ClassName:
"""
[One-line summary of class purpose].
[Detailed description of what the class does and how to use it].
This class is responsible for [what it does]. It should be used when
[when to use it].
Attributes:
attr1: Description of attribute1
attr2: Description of attribute2
Args:
param1: Description of parameter1
param2: Description of parameter2
Raises:
ErrorType: Description of when this error is raised
Example:
>>> obj = ClassName(param1="value", param2="value")
>>> obj.method()
result
Note:
[Any important notes about usage]
Warning:
[Any warnings about usage or behavior]
"""
Phase 3: Add Function/Method Docstrings (2-3 days)
For each public function/method, add comprehensive docstring:
Priority:
- All controller methods
- All query functions
- All validation functions
- All export/import functions
- Public utility functions
Phase 4: Setup Documentation Generation (1-2 days)
1. Install Sphinx
# pyproject.toml
[dependency-groups.docs]
sphinx = [
"sphinx>=7.0.0",
"sphinx-rtd-theme>=2.0.0",
"sphinx-autodoc-typehints>=2.0.0",
]
2. Create Sphinx Configuration
# docs/conf.py
project = 'Wareflow EMS'
copyright = '2024, Wareflow'
author = 'Wareflow'
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx_autodoc_typehints',
]
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
autodoc_default_options = {
'members': True,
'member-order': 'bysource',
'special-members': '__init__',
'undoc-members': True,
'exclude-members': '__weakref__'
}
typehints_defaults = 'comma'
3. Create API Documentation Files
# docs/api/reference.rst
API Reference
=============
.. toctree::
:maxdepth: 4
employee
controllers
utils
export
import
# docs/api/employee.rst
Employee Module
===============
Models
------
.. automodule:: employee.models
:members:
:undoc-members:
:show-inheritance:
Queries
-------
.. automodule:: employee.queries
:members:
:undoc-members:
Calculations
------------
.. automodule:: employee.calculations
:members:
:undoc-members:
4. Build Documentation
cd docs
sphinx-build -b html api build/html
Phase 5: Add to CI (0.5 day)
# .github/workflows/docs.yml
name: Documentation
on:
push:
branches: [main]
paths: ['src/**', 'docs/**']
jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.14'
- name: Install dependencies
run: |
pip install sphinx sphinx-rtd-theme sphinx-autodoc-typehints
- name: Build documentation
run: |
cd docs
sphinx-build -b html api build/html
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build/html
Documentation Standards
Google Style (Recommended)
def function(arg1, arg2):
"""Summary line.
Extended description of function.
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Description of return value
Raises:
ErrorType: Description of when error is raised
"""
reStructuredText Style
def function(arg1, arg2):
"""Summary line.
Extended description of function.
:param arg1: Description of arg1
:param arg2: Description of arg2
:returns: Description of return value
:raises ErrorType: Description of when error is raised
"""
Dependencies
- New dependencies (docs):
sphinx>=7.0.0
sphinx-rtd-theme>=2.0.0
sphinx-autodoc-typehints>=2.0.0
Related Issues
- ISSUE-041: No User Documentation
- ISSUE-042: No Troubleshooting Guide
- ISSUE-068: Missing Type Hints
Acceptance Criteria
Estimated Effort
Total: 5-7 days
- Add module docstrings: 2-3 days
- Add class docstrings: 1-2 days
- Add function docstrings: 2-3 days
- Setup Sphinx and CI: 1-2 days
Notes
This is a large task that should be done incrementally. Start with critical modules (models, controllers, queries) and work through the codebase systematically. Documentation should be updated whenever code changes.
Documentation Quality Checklist
For each docstring:
References
ISSUE-059: Missing API Documentation
Description
The project lacks comprehensive API documentation. Public functions, classes, and methods in the
src/directory have minimal or no docstrings, making the codebase difficult to understand and maintain.Current State
What Exists:
What's Missing:
Impact
Expected Documentation Standards
1. Module Docstrings
Every module should have a docstring explaining its purpose:
2. Class Docstrings
3. Function/Method Docstrings
Use Google style docstrings:
Proposed Solution
Phase 1: Add Module Docstrings (2-3 days)
Modules to document:
src/employee/models.py- Employee modelssrc/employee/queries.py- Employee queriessrc/employee/calculations.py- Employee calculationssrc/controllers/*.py- All controllerssrc/utils/validation.py- Validation utilitiessrc/utils/file_validation.py- File validationsrc/export/data_exporter.py- Export functionalitysrc/excel_import/excel_importer.py- Import functionalityTemplate:
Phase 2: Add Class Docstrings (1-2 days)
For each public class, add comprehensive docstring:
Template:
Phase 3: Add Function/Method Docstrings (2-3 days)
For each public function/method, add comprehensive docstring:
Priority:
Phase 4: Setup Documentation Generation (1-2 days)
1. Install Sphinx
2. Create Sphinx Configuration
3. Create API Documentation Files
4. Build Documentation
cd docs sphinx-build -b html api build/htmlPhase 5: Add to CI (0.5 day)
Documentation Standards
Google Style (Recommended)
reStructuredText Style
Dependencies
sphinx>=7.0.0sphinx-rtd-theme>=2.0.0sphinx-autodoc-typehints>=2.0.0Related Issues
Acceptance Criteria
Estimated Effort
Total: 5-7 days
Notes
This is a large task that should be done incrementally. Start with critical modules (models, controllers, queries) and work through the codebase systematically. Documentation should be updated whenever code changes.
Documentation Quality Checklist
For each docstring:
References