Copilot Code Comment Generator
Added Apr 2, 2026
About This Prompt
This prompt adds professional-quality documentation comments to existing code without modifying the code itself. Good comments explain the why, not the what, and this prompt follows that principle by adding context about design decisions, complexity implications, known limitations, and non-obvious behavior. The output includes file-level documentation, function signatures with full parameter descriptions, strategic inline comments, and technical debt markers. This is particularly useful when onboarding new team members to a codebase, preparing code for open-source release, or retrofitting documentation into legacy code that lacks it.
Variables to Customize
[LANGUAGE]
The programming language
Example: Python
[PROJECT_TYPE]
Type of project
Example: Django REST API
[FUNCTIONALITY]
What this code does
Example: user permission checking and role-based access control
[CODE_BLOCK]
The code to add comments to
Example: # paste your code here
Tips for Best Results
- Include the broader project context so comments can reference how this module fits into the system
- Review generated comments and remove any that merely restate obvious code behavior
- Use this as a starting point and add domain-specific context that only you know about
Example Output
"""
Permission Service - Role-Based Access Control (RBAC)
Central authorization layer for the API. All endpoint decorators
and middleware route through this module to verify user permissions.
Architecture note: Uses a hierarchical role model where admin > editor > viewer.
Permissions are cached per-request in the user object to avoid repeated DB queries.
See also: auth/models.py for Role definitions, middleware/auth.py for request integration.
"""
def check_permission(user: User, resource: str, action: str) -> bool:
"""
Verify if a user has permission to perform an action on a resource.
Args:
user: Authenticated user object with .roles populated
resource: Resource identifier (e.g., 'posts', 'users', 'settings')
action: CRUD action ('create', 'read', 'update', 'delete')
Returns:
True if the user has sufficient permissions
Raises:
PermissionDenied: If user.roles is empty (indicates auth middleware was bypassed)
Example:
if check_permission(request.user, 'posts', 'delete'):
post.delete()
"""
# FIXME: Role cache is not invalidated when admin changes user roles mid-session
...