Code documenter

From TerminalSkills/skills · View interactive version

Code documenter is an AI agent skill from the GitHub repository TerminalSkills/skills. Generate comprehensive documentation for undocumented or poorly documented codebases. Use when a user asks to document code, add JSDoc/docstrings, create README files, generate architecture docs, explain what a codebase does, produce onboarding guides, or document internal APIs. Works with any langu

How to use this skill

Skill file

Code Documenter

Overview

Analyzes source code to generate accurate, context-aware documentation at multiple levels: inline comments for complex logic, function/class docstrings, module-level overviews, architecture documents, and onboarding guides. Understands control flow, data transformations, side effects, and cross-module dependencies.

Instructions

When asked to document code:

  1. Determine the documentation level needed:
  1. For function/method documentation, extract:
  1. For complex logic, add inline comments explaining:
  1. For architecture documentation:
  1. Language-specific format:
  1. Verify: run the project's doc tooling after writing (for example cargo test --doc or cargo doc, go vet ./..., python -m doctest -v module.py, npx tsc --noEmit) so examples and syntax are checked, not assumed. Keep documentation in the existing style of the repository.
  1. Quality rules:

Examples

Example 1: Document a Python function

Input:

def process_payment(user_id, amount, currency, idempotency_key=None):
    user = db.users.find(user_id)
    if not user:
        raise ValueError("User not found")
    if user.balance < amount and not user.credit_enabled:
        return {"status": "declined", "reason": "insufficient_funds"}
    intent = stripe_client.v1.payment_intents.create(
        params={
            "amount": int(amount * 100),
            "currency": currency,
            "customer": user.stripe_id,
            "payment_method": user.default_payment_method,
            "confirm": True,
            "off_session": True,
        },
        options={"idempotency_key": idempotency_key},
    )
    db.transactions.insert({
        "user_id": user_id, "amount": amount,
        "payment_intent_id": intent.id, "created_at": datetime.now(timezone.utc)
    })
    if user.balance < amount:
        user.balance = user.balance - amount
        db.users.update(user)
    return {"status": "success", "payment_intent_id": intent.id}

Output:

def process_payment(user_id, amount, currency, idempotency_key=None):
    """Process a payment by charging the user's saved Stripe payment method.

    Validates the user's balance (unless credit is enabled), creates and confirms
    a Stripe PaymentIntent, records the transaction, and deducts from the user's internal balance
    if applicable.

    Args:
        user_id: Internal user identifier (e.g., "usr_8f2k3j").
        amount: Charge amount in major currency units (e.g., 49.99).
        currency: ISO 4217 currency code (e.g., "usd", "eur").
        idempotency_key: Optional key to prevent duplicate charges on retry.
            Recommended for all production calls.

    Returns:
        dict: {"status": "success", "payment_intent_id": "pi_..."} on success,
              {"status": "declined", "reason": "insufficient_funds"} if balance
              is too low and credit is not enabled.

    Raises:
        ValueError: If user_id does not match any user in the database.
        stripe.CardError: If the card is declined by Stripe.
        stripe.InvalidRequestError: If Stripe parameters are invalid.

    Side Effects:
        - Creates and confirms a Stripe PaymentIntent (external API call)
        - Inserts a row into the transactions table
        - May update the user's balance

    Example:
        >>> result = process_payment("usr_8f2k3j", 49.99, "usd", idempotency_key="pay_retry_001")
        >>> result
        {'status': 'success', 'payment_intent_id': 'pi_3Kx9mPqR2s'}

    Note:
        ⚠ Potential bug: balance deduction only happens when balance < amount,
        but the charge always goes through. If balance >= amount, the user is
        charged via Stripe but their internal balance is not deducted.
        Also, ``int(amount * 100)`` truncates instead of rounding (19.99
        becomes 1998 cents); use ``round(amount * 100)`` or ``Decimal``.
    """

Example 2: Generate architecture overview

Input:

Document the architecture of our notification service in src/services/notifications/

Output:

# Notification Service — Architecture

## Purpose
Delivers user notifications across email, push, and in-app channels.
Handles template rendering, delivery scheduling, preference checking,
and delivery status tracking.

## Module Map
  notifications/
  ├── router.ts          — HTTP endpoints for notification preferences and history
  ├── service.ts         — Core orchestration: resolves channel, renders template, dispatches
  ├── channels/
  │   ├── email.ts       — SendGrid integration (SMTP fallback)
  │   ├── push.ts        — Firebase Cloud Messaging (HTTP v1 API)
  │   └── in-app.ts      — WebSocket broadcast + database persistence
  ├── templates/
  │   ├── renderer.ts    — Handlebars template engine with i18n support
  │   └── templates/     — .hbs files organized by notification type
  ├── preferences.ts     — User channel preferences (opt-in/opt-out per type)
  └── queue.ts           — BullMQ queue consumer for async delivery

## Key Data Flow: Sending a Notification
  1. API call or internal event → service.send(userId, type, data)
  2. service.ts checks user preferences → skips opted-out channels
  3. renderer.ts renders template with user's locale
  4. Dispatch queued via BullMQ (Redis-backed) for reliability
  5. Channel adapter delivers and records status in notifications table

## External Dependencies
  - SendGrid API (email delivery)
  - Firebase Cloud Messaging (push notifications)
  - Redis (BullMQ queue backing store)
  - PostgreSQL (notification history, preferences, templates metadata)

## Environment Variables
  SENDGRID_API_KEY, GOOGLE_APPLICATION_CREDENTIALS (FCM service account), REDIS_URL, NOTIFICATION_FROM_EMAIL

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.