|
| 1 | +# 📊 Visual Context Protocol: Mermaid Flowcharts |
| 2 | + |
| 3 | +## 🎯 Purpose |
| 4 | +Provide developers and AI agents with a standardized way to visualize project architecture, workflows, and state transitions using [Mermaid.js](https://mermaid-js.github.io/mermaid/). Visual diagrams reduce cognitive load and help AI assistants understand complex relationships faster. |
| 5 | + |
| 6 | +## ⚙️ Why use Mermaid? |
| 7 | +- **Text-Based**: Diagrams are stored as code (Markdown), making them version-controllable and token-efficient. |
| 8 | +- **AI-Friendly**: LLMs are excellent at generating and parsing Mermaid syntax. |
| 9 | +- **IDE Support**: Most modern IDEs (Cursor, VS Code, Obsidian) and GitHub/GitLab render Mermaid natively. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 🏗️ Core Diagram Types |
| 14 | + |
| 15 | +### 1. Architecture Map (High-Level) |
| 16 | +Use flowcharts to map directory structures, service boundaries, and data flow. |
| 17 | + |
| 18 | +```mermaid |
| 19 | +graph TD |
| 20 | + A[User/Client] --> B[API Gateway] |
| 21 | + B --> C[Auth Service] |
| 22 | + B --> D[Product Service] |
| 23 | + D --> E[(PostgreSQL)] |
| 24 | + C --> F[(Redis)] |
| 25 | +``` |
| 26 | + |
| 27 | +### 2. Workflow / Logic Flow |
| 28 | +Visualize complex business logic or AI execution paths. |
| 29 | + |
| 30 | +```mermaid |
| 31 | +graph LR |
| 32 | + Start --> CheckContext{Context Loaded?} |
| 33 | + CheckContext -- No --> Load[Load APCP] |
| 34 | + CheckContext -- Yes --> Task[Execute Task] |
| 35 | + Load --> Task |
| 36 | + Task --> Verify{Verify Quality} |
| 37 | + Verify -- Fail --> Task |
| 38 | + Verify -- Pass --> End |
| 39 | +``` |
| 40 | + |
| 41 | +### 3. State Machine |
| 42 | +Track the lifecycle of a task, order, or system state. |
| 43 | + |
| 44 | +```mermaid |
| 45 | +stateDiagram-v2 |
| 46 | + [*] --> Idle |
| 47 | + Idle --> Processing: New Task |
| 48 | + Processing --> Validating: Code Written |
| 49 | + Validating --> Done: Tests Pass |
| 50 | + Validating --> Processing: Fix Needed |
| 51 | + Done --> [*] |
| 52 | +``` |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## 🤖 Instructions for AI Agents |
| 57 | + |
| 58 | +When an AI agent is asked to "visualize" or "explain the architecture," it should: |
| 59 | +1. **Identify Entities**: Determine the key components, files, or services. |
| 60 | +2. **Define Relationships**: Map how data or control flows between them. |
| 61 | +3. **Generate Mermaid**: Output a valid `mermaid` code block. |
| 62 | +4. **Prefer Flowcharts**: Use `graph TD` (Top-Down) or `graph LR` (Left-Right) for most scenarios. |
| 63 | + |
| 64 | +**Prompt Snippet for Humans:** |
| 65 | +> "Generate a Mermaid flowchart explaining how the [Module Name] interacts with the database and external APIs." |
| 66 | +
|
| 67 | +--- |
| 68 | + |
| 69 | +## 🛠️ Integration with Nexus-APCP |
| 70 | + |
| 71 | +- **Location**: Store complex diagrams in `docs/diagrams/` or embed them directly in `AI_PROJECT_CONTEXT_PROTOCOL.md`. |
| 72 | +- **Decision Logs**: Use Mermaid in `DECISION_LOG_PROTOCOL.md` to show "Before" vs "After" architecture during major refactors. |
| 73 | +- **Task Progress**: Use state diagrams to visualize long-running multi-stage tasks. |
| 74 | + |
| 75 | +--- |
| 76 | +*Nexus-APCP: Visualizing logic for faster engineering.* 📈🚀 |
0 commit comments