# microsoft/ai-engineering-coach architecture

> Architecture diagram of the GitHub repository microsoft/ai-engineering-coach, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/ai-engineering-coach
- Repository: https://github.com/microsoft/ai-engineering-coach

## Overview

1. **Repository purpose**
   - This is a **VS Code extension** named **AI Engineer Coach**.
   - Its main job is to **read local AI coding-assistant session logs**, analyze them on-device, and present coaching/analytics views in a VS Code webview.
   - The architectural boundary is strong: **analysis is local and read-only**; no session data is meant to leave the machine.

2. **Top-level runtime shape**
   - The extension runs inside the **VS Code extension host**.
   - The UI is rendered mostly in **VS Code webviews** rather than a separate browser app.
   - A separate **MCP/tools surface** exists for exposing selected functionality to model/tool clients, but the primary user experience is the extension dashboard.

3. **Main entry and orchestration**
   - `src/extension.ts` is the extension entrypoint and wires together commands, panels, data access, and analysis services.
   - The extension appears to orchestrate an internal pipeline: **load logs → parse sessions → compute metrics/rules → cache results → render pages/panels**.

4. **Session ingestion and parser boundary**
   - `src/core/parser*.ts` contains multiple adapters for different AI harnesses/tools:
     - Claude, Codex, VS Code, OpenCode, Xcode, and related variants.
   - This is a key boundary in the system: raw log formats are normalized into shared session/data types before any analytics run.
   - `src/core/parser-harnesses.ts` and `src/core/parser-shared.ts` suggest shared normalization across tool-specific formats.

5. **Core analytics engine**
   - `src/core/analyzer*.ts` is the main analytics layer.
   - It produces different domain views such as:
     - dashboard summaries,
     - timeline views,
     - workflow/flow analysis,
     - insights,
     - production/output analysis,
     - context and consumption analysis,
     - image/session artifact analysis.
   - The architecture is modular: each analyzer focuses on one output surface, all fed by the same normalized session data.

6. **Rules, detectors, and anti-pattern scoring**
   - The anti-pattern subsystem is centered around `src/core/rule-*`, `src/core/detectors*`, `src/core/metric-engine.ts`, and `src/core/rules/*.md`.
   - Rule definitions are largely **markdown-driven**, compiled and evaluated by a rule engine, and surfaced as coaching feedback.
   - This layer turns raw behavior into scored signals such as session hygiene, prompt quality, tool usage, context quality, and workflow issues.

7. **DSL and rule authoring**
   - `src/core/dsl/*` provides a custom domain-specific language used for rule logic, filtering, or interactive evaluation.
   - The DSL has its own lexer, parser, interpreter, schema, and safe-regex support, indicating that rule evaluation is a first-class internal language rather than ad hoc string matching.
   - This is important for architecture diagrams because it is a distinct subsystem between “rules authored by humans” and “rules executed against session data.”

8. **Caching and worker-based processing**
   - `src/core/cache.ts`, `cache-write-worker.ts`, `parse-worker.ts`, and `warm-up-worker.ts` show that expensive work is offloaded from the main extension thread.
   - The system likely uses background workers for parsing, warming caches, and persistence to keep the UI responsive.
   - Cache is a core boundary: parsed/derived results are stored for reuse rather than recomputed for every page navigation.

9. **Webview application and page model**
   - `src/webview/*` is the presentation layer.
   - `src/webview/app.ts`, `panel.ts`, `panel-rpc.ts`, `panel-request-service.ts`, and `render.ts` suggest a panel-based architecture with RPC between extension host and webview.
   - Each major product area maps to a page module, such as:
     - dashboard,
     - timeline,
     - output,
     - patterns,
     - anti-patterns,
     - rule editor/playground,
     - data explorer,
     - skills,
     - context management/health,
     - learning,
     - achievements,
     - SDLC,
     - share.
   - The UI is therefore a shell with many feature pages driven by the same underlying analytics services.

10. **Data exploration and feedback loops**
    - Several pages are not just display-only; they support authoring and refinement:
      - `page-rule-editor.ts`,
      - `page-rule-playground.ts`,
      - `page-data-explorer.ts`,
      - `page-context-mgmt.ts`.
    - This means the product has a closed loop:
      - observe usage,
      - inspect data,
      - author/tune rules,
      - re-run evaluation,
      - review improved coaching signals.

11. **Optional LLM-assisted features**
    - `src/chat/*` and parts of the rule/context tooling indicate optional use of the **VS Code built-in Copilot language model API**.
    - The README makes clear these are **explicitly invoked** features, not always-on telemetry.
    - This layer is secondary to the local analytics pipeline and should be drawn as an optional external capability used for tasks like rule compilation, skill discovery, or instruction-file review.

12. **MCP / external tool exposure**
    - `src/mcp/tools.ts` and `src/mcp/formatters.ts` expose selected functionality in a structured tool interface.
    - This is a separate integration boundary from the UI: it packages coach capabilities for tool consumers rather than human-facing dashboards.

13. **Input/output artifacts**
    - The extension consumes local session logs and workspace context.
    - It produces:
      - dashboard metrics,
      - charts/timelines,
      - rule findings,
      - learning content,
      - exportable summaries/Markdown/JSON,
      - optionally a shareable stat card.
    - The shared-data/export boundary is visible in `src/core/summary-export.ts` and `src/summary-export-vscode.ts`.

14. **Tooling, packaging, and validation**
    - The repo is built as a TypeScript VS Code extension with `esbuild`, linting, Playwright, and Vitest.
    - E2E tests under `tests/e2e` validate the webview pages and navigation; many `src/core/*.test.ts` files validate analysis logic.
    - CI and release workflows indicate this is packaged as a distributable VSIX, with docs generated from the `docs/` Hugo site.

15. **How to draw the architecture**
    - A good diagram would show:
      - **local log sources** on the left,
      - **parsers/normalizers** in the middle,
      - **analytics/rules/DSL/cache/workers** as the core engine,
      - **webview pages and panels** as the main UI surface,
      - optional **Copilot/LLM** and **MCP** integrations as side boundaries,
      - and **exports/share summaries** as the output boundary.

Main entry points: [`src/webview/panel.ts`](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/panel.ts) (Webview shell), [`src/extension.ts`](https://github.com/microsoft/ai-engineering-coach/blob/main/src/extension.ts) (Extension), [`src/core/rule-engine.ts`](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/rule-engine.ts) (Rules), [`src/core/analyzer.ts`](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/analyzer.ts) (Analytics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_extension["Extension<br/>entrypoint + orchestration<br/>[extension.ts]"]
  node_workers["Workers<br/>background jobs<br/>[parse-worker.ts]"]
end

subgraph group_ingest["Ingest & Analysis"]
  node_parser["Parsers<br/>log adapters<br/>[parser.ts]"]
  node_normalize["Shared model<br/>session normalization<br/>[parser-shared.ts]"]
  node_analyzer["Analytics<br/>domain analyzers<br/>[analyzer.ts]"]
  node_rules["Rules<br/>anti-pattern scoring<br/>[rule-engine.ts]"]
  node_dsl["DSL<br/>rule language<br/>[index.ts]"]
  node_detectors["Detectors<br/>[detectors.ts]"]
  node_metrics["Metric engine<br/>scoring engine<br/>[metric-engine.ts]"]
  node_cache[("Cache<br/>derived-state store<br/>[cache.ts]")]
end

subgraph group_ui["Webview UI"]
  node_webview["Webview shell<br/>panel shell<br/>[panel.ts]"]
  node_dashboard["Dashboard<br/>page<br/>[page-dashboard.ts]"]
  node_timeline["Timeline<br/>page<br/>[page-timeline.ts]"]
  node_patterns["Patterns<br/>page<br/>[page-patterns.ts]"]
  node_rules_ui["Rule tools<br/>page set"]
  node_learning["Learning<br/>page set<br/>[page-learning.ts]"]
end

subgraph group_support["Support"]
  node_output["Exports<br/>summary export<br/>[summary-export.ts]"]
  node_chat["Copilot chat<br/>optional LLM assistance<br/>[participant.ts]"]
  node_mcp["MCP tools<br/>tool surface<br/>[tools.ts]"]
end

node_extension -->|"loads logs"| node_parser
node_extension -->|"runs analysis"| node_analyzer
node_extension -->|"evaluates rules"| node_rules
node_extension -->|"reads/writes"| node_cache
node_extension -->|"hosts UI"| node_webview
node_extension -->|"exports"| node_output
node_extension -->|"exposes tools"| node_mcp
node_parser -->|"normalizes"| node_normalize
node_normalize -->|"feeds"| node_analyzer
node_analyzer -->|"derives signals"| node_metrics
node_metrics -->|"powers"| node_detectors
node_detectors -->|"informs"| node_rules
node_rules -->|"executes via"| node_dsl
node_rules -->|"persists findings"| node_cache
node_workers -.->|"background parse"| node_parser
node_workers -.->|"warm/persist"| node_cache
node_webview -->|"renders"| node_dashboard
node_webview -->|"renders"| node_timeline
node_webview -->|"renders"| node_patterns
node_webview -->|"renders"| node_rules_ui
node_webview -->|"renders"| node_learning
node_webview -->|"requests data"| node_analyzer
node_webview -->|"reads state"| node_cache
node_output -->|"shows summaries"| node_webview
node_chat -.->|"assists authoring"| node_dsl
node_chat -.->|"supports tuning"| node_rules
node_mcp -->|"queries"| node_analyzer
node_mcp -->|"formats"| node_output

click node_extension "https://github.com/microsoft/ai-engineering-coach/blob/main/src/extension.ts"
click node_workers "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/parse-worker.ts"
click node_parser "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/parser.ts"
click node_normalize "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/parser-shared.ts"
click node_analyzer "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/analyzer.ts"
click node_rules "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/rule-engine.ts"
click node_dsl "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/dsl/index.ts"
click node_detectors "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/detectors.ts"
click node_metrics "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/metric-engine.ts"
click node_cache "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/cache.ts"
click node_webview "https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/panel.ts"
click node_dashboard "https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-dashboard.ts"
click node_timeline "https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-timeline.ts"
click node_patterns "https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-patterns.ts"
click node_rules_ui "https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-rule-editor.ts"
click node_learning "https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-learning.ts"
click node_output "https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/summary-export.ts"
click node_chat "https://github.com/microsoft/ai-engineering-coach/blob/main/src/chat/participant.ts"
click node_mcp "https://github.com/microsoft/ai-engineering-coach/blob/main/src/mcp/tools.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_extension,node_workers toneBlue
class node_parser,node_normalize,node_analyzer,node_rules,node_dsl,node_detectors,node_metrics,node_cache toneAmber
class node_webview,node_dashboard,node_timeline,node_patterns,node_rules_ui,node_learning toneMint
class node_output,node_chat,node_mcp toneRose
```

## Components

### Runtime

VS Code extension host, workers, and integration surfaces

- [Extension](https://github.com/microsoft/ai-engineering-coach/blob/main/src/extension.ts): entrypoint + orchestration · Activates the extension and wires commands, services, panels, and data flow. · `src/extension.ts`
- [Workers](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/parse-worker.ts): background jobs · Offloads parsing, cache writes, and warm-up work from the main thread. · `src/core/parse-worker.ts`

### Ingest & Analysis

Local log parsing, normalization, analytics, and rule evaluation

- [Parsers](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/parser.ts): log adapters · Normalizes Claude, Codex, VS Code, OpenCode, Xcode, and related session logs. · `src/core/parser.ts`
- [Shared model](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/parser-shared.ts): session normalization · Shared parser helpers and harness normalization before analytics runs. · `src/core/parser-shared.ts`
- [Analytics](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/analyzer.ts): domain analyzers · Builds dashboard, timeline, workflow, insights, production, context, and image views. · `src/core/analyzer.ts`
- [Rules](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/rule-engine.ts): anti-pattern scoring · Loads markdown rule definitions and turns behavior into coaching signals. · `src/core/rule-engine.ts`
- [DSL](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/dsl/index.ts): rule language · Custom lexer, parser, interpreter, schema, and safe-regex support for rule logic. · `src/core/dsl/index.ts`
- [Detectors](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/detectors.ts): signal detectors · Scoring and detectors that feed the rule/metric engine. · `src/core/detectors.ts`
- [Metric engine](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/metric-engine.ts): scoring engine · Computes behavior metrics used by rules and anti-pattern analysis. · `src/core/metric-engine.ts`
- [Cache](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/cache.ts): derived-state store · Stores parsed and derived results for reuse across pages and navigations. · `src/core/cache.ts`

### Webview UI

Panel shell and feature pages rendered in VS Code webviews

- [Webview shell](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/panel.ts): panel shell · Panel runtime, RPC bridge, request service, and render pipeline. · `src/webview/panel.ts`
- [Dashboard](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-dashboard.ts): page · High-level coaching overview and summary surface. · `src/webview/page-dashboard.ts`
- [Timeline](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-timeline.ts): page · Session chronology and interaction flow visualization. · `src/webview/page-timeline.ts`
- [Patterns](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-patterns.ts): page · Pattern and anti-pattern exploration pages. · `src/webview/page-patterns.ts`
- [Rule tools](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-rule-editor.ts): page set · Rule editor, playground, data explorer, and context management surfaces. · `src/webview/page-rule-editor.ts`
- [Learning](https://github.com/microsoft/ai-engineering-coach/blob/main/src/webview/page-learning.ts): page set · Learning, achievements, skills, SDLC, and share pages. · `src/webview/page-learning.ts`

### Support

Exports, chat assistance, and external tool exposure

- [Exports](https://github.com/microsoft/ai-engineering-coach/blob/main/src/core/summary-export.ts): summary export · Produces Markdown, JSON, summary cards, and shareable outputs. · `src/core/summary-export.ts`
- [Copilot chat](https://github.com/microsoft/ai-engineering-coach/blob/main/src/chat/participant.ts): optional LLM assistance · Explicitly invoked Copilot language-model features for selected coaching tasks. · `src/chat/participant.ts`
- [MCP tools](https://github.com/microsoft/ai-engineering-coach/blob/main/src/mcp/tools.ts): tool surface · Structured tool interface exposing selected coach capabilities to external clients. · `src/mcp/tools.ts`

## Connections

- Extension → Parsers: loads logs · Reads local session logs through parser adapters.
- Extension → Analytics: runs analysis · Coordinates analytics services for the active workspace.
- Extension → Rules: evaluates rules · Triggers coaching and anti-pattern scoring.
- Extension → Cache: reads/writes · Uses cached derived results to keep navigation responsive.
- Extension → Webview shell: hosts UI · Creates and manages the VS Code panel/webview shell.
- Extension → Exports: exports · Provides summary and export commands.
- Extension → MCP tools: exposes tools · Publishes selected functionality for external tool clients.
- Parsers → Shared model: normalizes · Converts tool-specific logs into shared session types.
- Shared model → Analytics: feeds · Supplies standardized sessions to analysis modules.
- Analytics → Metric engine: derives signals · Computes domain metrics used by downstream scoring.
- Metric engine → Detectors: powers · Provides numeric signals and thresholds for detectors.
- Detectors → Rules: informs · Supports rule evaluation and anti-pattern classification.
- Rules → DSL: executes via · Uses the internal DSL for rule logic and filtering.
- Rules → Cache: persists findings · Stores evaluated rule results for reuse.
- Workers → Parsers: background parse · Moves expensive parsing off the extension host thread.
- Workers → Cache: warm/persist · Handles cache warm-up and write operations.
- Webview shell → Dashboard: renders · Displays the main coaching overview.
- Webview shell → Timeline: renders · Displays session timelines and flow views.
- Webview shell → Patterns: renders · Displays pattern and anti-pattern exploration.
- Webview shell → Rule tools: renders · Hosts rule authoring, playground, explorer, and context tools.
- Webview shell → Learning: renders · Hosts learning, achievements, skills, and share pages.
- Webview shell → Analytics: requests data · Pulls analyzed views through panel RPC.
- Webview shell → Cache: reads state · Uses cached derived data for page hydration.
- Exports → Webview shell: shows summaries · Feeds export previews and shareable artifacts back to the UI.
- Copilot chat → DSL: assists authoring · Optional LLM help for rule and context tooling.
- Copilot chat → Rules: supports tuning · Can help refine coaching rules when explicitly invoked.
- MCP tools → Analytics: queries · Surfaces analysis results to tool clients.
- MCP tools → Exports: formats · Packages summaries and structured results for external consumption.
