Skip to content

Conversation

@7174Andy
Copy link
Collaborator

@7174Andy 7174Andy commented Nov 29, 2025

Summary

This PR enhances the LabLink documentation by replacing ASCII art diagrams with interactive Mermaid diagrams and adding visual representations of key workflows. The changes improve documentation clarity, consistency, and developer understanding of the system architecture.

Changes Made

Phase 1: Convert Existing ASCII Diagrams ✓

  1. Docker Build Decision Flow (workflows.md:220-248)

    • Converted ASCII flowchart to Mermaid
    • Shows decision tree for Dockerfile selection (dev vs prod)
  2. System Architecture Overview (architecture.md:7-66)

    • Replaced ASCII art with Mermaid graph diagram
    • Visualizes GitHub → AWS infrastructure with all components
  3. VM Request Flow (architecture.md:245-273)

    • Converted to Mermaid sequence diagram
    • Shows User → Flask → Database → Client interaction
  4. VM Creation Flow (architecture.md:277-304)

    • Converted to Mermaid sequence diagram
    • Shows Admin → Flask → Terraform → EC2 → Docker process
  5. Health Check Flow (architecture.md:308-331)

    • Converted to Mermaid sequence diagram
    • Shows periodic GPU health monitoring workflow

Phase 2: Add New Workflow Diagrams ✓

  1. CI/CD Pipeline Overview (workflows.md:18-74)

    • New Mermaid flowchart showing all GitHub Actions workflows
    • Visualizes triggers, relationships, and deployment flow
  2. Production Release Workflow (workflows.md:292-322)

    • New Mermaid sequence diagram for two-step release process
    • Shows PyPI publish → Docker build workflow
  3. VM State Machine (architecture.md:164-206)

    • New Mermaid state diagram for VM lifecycle
    • Shows transitions: available → in_use → available/failed

Phase 3: Add Supporting Diagrams ✓

  1. Deployment Methods Decision Tree (deployment.md:18-49)

    • New Mermaid flowchart for deployment method selection
    • Guides users through environment-specific deployment choices
  2. Database Schema ER Diagram (database.md:22-47)

    • New Mermaid ER diagram showing actual database schema
    • Based on actual code from generate_init_sql.py
    • Shows all 20 columns including timing metrics
  3. PostgreSQL NOTIFY/LISTEN Flow (database.md:104-174)

    • New Mermaid sequence diagram showing real-time update mechanism
    • Accurately represents HTTP long-polling with internal LISTEN/NOTIFY
    • Shows complete flow: Client → HTTP → Allocator → LISTEN → NOTIFY → HTTP response → Client execution

Additional Updates ✓

  • MkDocs Configuration (mkdocs.yml)
    • Added pymdownx.superfences custom fences for Mermaid support (lines 73-77)
    • Added Mermaid JavaScript library via extra_javascript (line 131-132)

Design Decisions

Diagram Types Selected

  • Flowcharts: Decision trees and workflow branching (Docker build, CI/CD, deployment)
  • Sequence Diagrams: Component interactions and API flows (VM request/creation, NOTIFY/LISTEN)
  • State Diagrams: Lifecycle and state transitions (VM state machine)
  • ER Diagrams: Database schema and relationships
  • Graph Diagrams: System architecture and infrastructure layout

Color Scheme

  • Current Approach: Fill-based colors for visual distinction
  • Known Limitation: Fill colors have reduced contrast in dark mode
  • Example Colors:
    • Development builds: fill:#e1f5ff (light blue)
    • Production builds: fill:#fff4e1 (light orange)
    • Flask/Services: fill:#4a90e2,color:#fff (blue with white text)
    • PostgreSQL: fill:#336791,color:#fff (dark blue with white text)

Future Considerations

  • Dark Mode Compatibility: Consider implementing theme-aware styling or CSS overrides
  • Alternative Approach: Stroke-based styling with classDef for better dark mode compatibility (previously attempted but rolled back per user preference)

Accuracy from Source Code

All diagrams were verified against actual implementation:

  • Database Schema: Generated from packages/allocator/src/lablink_allocator_service/generate_init_sql.py
  • NOTIFY/LISTEN Flow: Based on actual code from:
    • Client: packages/client/src/lablink_client_service/subscribe.py
    • Allocator: packages/allocator/src/lablink_allocator_service/main.py and database.py
  • VM State Machine: Reflects actual state transitions and update_inuse_status behavior

Example: CI/CD Pipeline Overview

flowchart TD
    Start[Trigger Event] --> PRCheck{Pull Request?}
    PRCheck -->|Yes| CIWorkflow[ci.yml]
    PRCheck -->|No| PushCheck{Push to branch?}
    
    PushCheck -->|main| BuildImages[lablink-images.yml]
    PushCheck -->|test| BuildImages
    PushCheck -->|docs| DocsDeploy[docs.yml]
    
    Tag[New Tag Created] --> PublishPyPI[publish-pip.yml]
    PublishPyPI --> ManualTrigger[Manual: Build Production Images]
Loading

Benefits

  1. Visual Clarity: Complex workflows are easier to understand with diagrams
  2. Consistency: All diagrams follow consistent styling and conventions
  3. Completeness: All major workflows and architectures are now visualized
  4. Maintainability: Diagrams are text-based (Mermaid) for easy updates in version control
  5. Accessibility: Diagrams render correctly in all supported browsers with light/dark theme support
  6. Accuracy: Diagrams reflect actual implementation verified from source code

Testing

  • ✅ All diagrams render correctly in mkdocs serve
  • ✅ Diagrams are readable in light mode
  • ⚠️ Diagrams have reduced contrast in dark mode (known limitation, future improvement planned)
  • ✅ MkDocs builds successfully
  • ✅ All cross-references updated

Files Modified

  • mkdocs.yml - Added Mermaid support configuration
  • docs/workflows.md - Added 3 new diagrams, converted 1 ASCII diagram
  • docs/architecture.md - Added 1 new diagram, converted 4 ASCII diagrams
  • docs/deployment.md - Added 1 new diagram
  • docs/database.md - Added 2 new diagrams
  • CLAUDE.md - Corrected in_use status definition

Total Impact

  • 11 Mermaid diagrams added across 4 documentation pages
  • 5 ASCII diagrams converted to interactive Mermaid
  • 6 new diagrams for previously text-only workflows
  • 1 critical correction to in_use status definition

@7174Andy 7174Andy marked this pull request as ready for review November 29, 2025 18:08
@7174Andy 7174Andy added the documentation Improvements or additions to documentation label Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants