🎯 Feature: Mermaid Diagrams & Chart.js Integration
Context
The current artifact ecosystem is limited to HTML/CSS tables, grids, and text. While effective, this excludes two major artifact categories that users frequently request:
- Diagrams: flowcharts, architecture maps, sequence diagrams, state machines
- Charts: bar charts, timelines, dashboards, comparison matrices with data visualization
Mermaid and Chart.js are the de facto standards for these use cases in the web ecosystem. Mermaid renders from a simple text DSL; Chart.js renders from a data-driven JSON config. Both are lightweight, dependency-free, and render reliably in any modern browser.
Problem
- Flowcharts (architecture, workflow, decision trees) are requested frequently but require external tools or manual SVG generation
- Data visualization (timelines, bar comparisons, dashboards) is not available natively
- Users who want a chart must pre-generate it or use an external service, breaking the single-command workflow
What This Resolves
Mermaid support:
- Pre-built artifact patterns that include Mermaid block rendering
- Mermaid CDN reference embedded in artifact template
- Syntax validation in
audit-artifact.py to check for malformed Mermaid blocks before delivery
Chart.js support:
- Pre-built chart templates (bar, line, timeline, radar) that accept structured data
- Interactive chart artifacts with copy/export of chart data as JSON
- Chart templates validate input data shape before rendering
Both:
- Functional examples in
examples/ directory
- Integration with existing
audit-artifact.py quality gate
- No external dependencies beyond CDN-loaded libraries
Proposed Approach
Mermaid integration:
- Add Mermaid CDN to the base template in
templates/artifact-explorer.html
- Create
patterns/23-mermaid-flowchart.md and patterns/24-mermaid-architecture.md as new pattern examples
- Add Mermaid validation to
audit-artifact.py:
- Check for
<div class="mermaid"> blocks
- Validate syntax by checking for mismatched brackets, invalid node IDs, missing arrows
- Score contribution:
visual_model check upgraded when Mermaid detected
- Add
examples/mermaid-architecture.example.html as a working Mermaid artifact
Chart.js integration:
- Add Chart.js CDN to base template (Chart.js and date-fns adapter)
- Create
patterns/25-chart-dashboard.md and patterns/26-chart-timeline.md as new patterns
- Add chart validation to
audit-artifact.py:
- Check for
<canvas> elements paired with <script> data blocks
- Validate JSON data structure for common chart types
- Verify required fields (labels, datasets for Chart.js v4)
- Add
examples/chart-dashboard.example.html as a working Chart.js artifact
Mermaid validation in audit-artifact.py:
def mermaid_syntax_valid(html: str) -> bool:
matches = re.findall(r'<div[^>]*class=["']mermaid["'][^>]*>(.*?)</div>', html, re.DOTALL)
for block in matches:
bracket_count = block.count('[') - block.count(']')
if bracket_count != 0:
return False
return True
Example Mermaid artifact structure:
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
<script>mermaid.initialize({ startOnLoad: true });</script>
<div class="mermaid">
flowchart TD
A[User Intent] --> B{Decision}
B -->|Yes| C[Generate Artifact]
B -->|No| D[Return Markdown]
</div>
Example Chart.js artifact structure:
<canvas id="myChart" width="800" height="400"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
<script>
new Chart(document.getElementById('myChart'), {
type: 'bar',
data: { labels: ['Option A', 'Option B'],
datasets: [{ label: 'Score', data: [92, 78] }] }
});
</script>
Acceptance Criteria
Quality Verification
python scripts/audit-artifact.py examples/mermaid-architecture.example.html --json | jq '.checks[] | select(.id=="visual_model")'
# Expected: passed=true
python scripts/audit-artifact.py examples/chart-dashboard.example.html --json | jq '.checks[] | select(.id=="interaction_export")'
# Expected: passed=true
bash scripts/validate-patterns.sh
bash scripts/validate-examples.sh
Labels
enhancement, rich-visual-content, diagrams, charts
Milestone
v1.1 — Collaboration-ready artifacts
🎯 Feature: Mermaid Diagrams & Chart.js Integration
Context
The current artifact ecosystem is limited to HTML/CSS tables, grids, and text. While effective, this excludes two major artifact categories that users frequently request:
Mermaid and Chart.js are the de facto standards for these use cases in the web ecosystem. Mermaid renders from a simple text DSL; Chart.js renders from a data-driven JSON config. Both are lightweight, dependency-free, and render reliably in any modern browser.
Problem
What This Resolves
Mermaid support:
audit-artifact.pyto check for malformed Mermaid blocks before deliveryChart.js support:
Both:
examples/directoryaudit-artifact.pyquality gateProposed Approach
Mermaid integration:
templates/artifact-explorer.htmlpatterns/23-mermaid-flowchart.mdandpatterns/24-mermaid-architecture.mdas new pattern examplesaudit-artifact.py:<div class="mermaid">blocksvisual_modelcheck upgraded when Mermaid detectedexamples/mermaid-architecture.example.htmlas a working Mermaid artifactChart.js integration:
patterns/25-chart-dashboard.mdandpatterns/26-chart-timeline.mdas new patternsaudit-artifact.py:<canvas>elements paired with<script>data blocksexamples/chart-dashboard.example.htmlas a working Chart.js artifactMermaid validation in
audit-artifact.py:Example Mermaid artifact structure:
Example Chart.js artifact structure:
Acceptance Criteria
audit-artifact.pyvalidates Mermaid syntax (blocks without syntax errors pass)audit-artifact.pyvalidates Chart.js data structure (required fields present)patterns/23-*.mdandpatterns/24-*.mdexamples/mermaid-*.example.htmlandexamples/chart-*.example.htmlpatterns/09-architecture-diagram.mdupdated to reference Mermaid approachpatterns/10-process-workflow-flowchart.mdupdated to reference Mermaid approachvalidate-patterns.shpasses with new patternsvalidate-examples.shpasses with new examplesQuality Verification
Labels
enhancement, rich-visual-content, diagrams, charts
Milestone
v1.1 — Collaboration-ready artifacts