agentleFS
MicrosoftKnown publishermicrosoft-foundry/foundry-agent-webapp/.github/skills/understanding-architecture/SKILL.md

understanding-architecture

Skill124 starsChanged 7 months agoMITView on GitHub

Provides architecture overview with state machines, SSE event flow, and file mappings. Use when understanding system design, debugging state issues, or maintaining ARCHITECTURE-FLOW.md.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Update the architecture document when:

    line 130
  2. Distinctive:

    Before committing architecture doc changes:

    line 144
  3. Distinctive:

    Check DeepWiki re-indexes (usually within 24 hours)

    line 201
  4. Distinctive:

    Verify diagrams match between ARCHITECTURE-FLOW.md and DeepWiki

    line 202

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Understanding Architecture

Load this skill when: Understanding system design, debugging state transitions, tracing SSE events, or updating architecture documentation.

Quick Reference

System Overview

LayerTechPortEntry Point
FrontendReact 19 + Vite5173frontend/src/App.tsx
BackendASP.NET Core 98080backend/WebApp.Api/Program.cs
AuthMSAL.js → JWT Bearer—frontend/src/config/authConfig.ts
AI SDKAzure.AI.Projects (GA) + Azure.AI.Extensions.OpenAI—backend/.../AgentFrameworkService.cs

Data Flow

User → ChatInput → CHAT_SEND_MESSAGE → ChatService.sendMessage()
     → POST /api/chat/stream (JWT) → AgentFrameworkService.StreamMessageAsync()
     → AI Foundry → SSE chunks → parseSseLine() → Reducer actions → UI update

State Machines

Chat States

idle ──CHAT_SEND_MESSAGE──► sending ──CHAT_START_STREAM──► streaming
  ▲                            │                              │
  │                            ▼                              ▼
  └──CHAT_CLEAR_ERROR─── error ◄──CHAT_ERROR──────────────────┤
  │                                                           │
  └──CHAT_STREAM_COMPLETE / CHAT_CANCEL_STREAM / CHAT_MCP_APPROVAL_REQUEST
StateInput EnabledstreamingMessageId
idle✅ Yesundefined
sending❌ Noundefined
streaming❌ NoMessage ID
errorIf recoverableundefined

Auth States

initializing ──AUTH_INITIALIZED──► authenticated ──AUTH_TOKEN_EXPIRED──► unauthenticated
                                         │                                    │
                                         └───────────AUTH_INITIALIZED──────────┘

SSE Event Flow

Backend → Frontend Mapping

SSE EventBackend MethodFrontend ActionReducer Effect
conversationIdWriteConversationIdEventCHAT_START_STREAMSet conversationId
chunkWriteChunkEventCHAT_STREAM_CHUNKAppend content
annotationsWriteAnnotationsEventCHAT_STREAM_ANNOTATIONSAdd citations
mcpApprovalRequestWriteMcpApprovalRequestEventCHAT_MCP_APPROVAL_REQUESTShow approval UI
usageWriteUsageEventCHAT_STREAM_COMPLETEAdd token counts
doneWriteDoneEventCHAT_STREAM_COMPLETEFinalize
errorWriteErrorEventCHAT_ERRORSet error state

Event Sequence

1. conversationId  (always first)
2. chunk           (0-N times)
3. annotations     (0-N times, after item complete)
4. mcpApprovalRequest (0-1 times, pauses stream)
5. usage           (always before done)
6. done            (always last)

Key Files by Domain

State Management

FilePurpose
frontend/src/types/appState.tsState & action type definitions
frontend/src/reducers/appReducer.tsAll state transitions
frontend/src/contexts/AppContext.tsxProvider + dev logging

SSE Streaming

FilePurpose
backend/WebApp.Api/Program.csSSE endpoints + Write*Event helpers
frontend/src/services/chatService.tsSSE client + action dispatch
frontend/src/utils/sseParser.tsLine parsing + event types

AI Integration

FilePurpose
backend/.../AgentFrameworkService.csAgent loading + streaming
backend/.../Models/StreamChunk.csChunk types (text, annotations, MCP)
backend/.../Models/ChatRequest.csRequest payload structure

Full Documentation

For complete diagrams and detailed flows, see:

  • ARCHITECTURE-FLOW.md - Full Mermaid diagrams
  • Part 1: Backend flow (request pipeline, credential resolution, agent loading)
  • Part 2: Frontend state (auth, chat, UI state machines)
  • Part 3: Performance patterns (reducer optimizations)
  • Part 4: Extending the state (adding new actions)
  • Part 5: Backend patterns (validation, error format, async)
  • Part 6: File reference (all key files)

Maintaining ARCHITECTURE-FLOW.md

When to Update

Update the architecture document when:

Change TypeWhat to Update
New SSE event typeSection 1.5 (Backend SSE Event Types), Section 2.8 (SSE → Action Mapping)
New reducer actionSection 2.7 (Action Reference), state machine diagrams
New API endpointSection 1.1 (Request Pipeline flowchart)
New auth stateSection 2.1 (Authentication State Machine)
New chat stateSection 2.2 (Chat State Machine)
File moved/renamedPart 6 (File Reference tables)
Validation rules changedSection 5.1 (Attachment Validation)

Validation Checklist

Before committing architecture doc changes:

□ Mermaid Diagrams
  □ All states match code (appState.ts types)
  □ All transitions match reducer (appReducer.ts cases)
  □ Diagram syntax renders without errors

□ Tables
  □ SSE events match Program.cs Write*Event methods
  □ Actions match AppAction type union
  □ File paths are lowercase (case-sensitive filesystems)

□ Code Snippets
  □ Patterns match actual code
  □ Variable names correct
  □ Examples would compile/run

□ File Links
  □ All referenced files exist
  □ Paths use correct case (chatService.ts not ChatService.ts)

Source of Truth Mapping

Document SectionSource Code
Request Pipeline (1.1)Program.cs middleware + endpoints
Credential Resolution (1.2)AgentFrameworkService.cs constructor
Agent Loading (1.3)AgentFrameworkService.GetAgentAsync()
SSE Events (1.5)Program.cs static Write*Event methods
Auth States (2.1)appState.ts auth.status type
Chat States (2.2)appState.ts chat.status type
Action Reference (2.7)appState.ts AppAction type
SSE → Action (2.8)chatService.ts processStream switch
Attachment Limits (5.1)AgentFrameworkService.cs Max* constants

Quick Sync Commands

# Find all SSE event types in backend
Select-String -Path "backend/WebApp.Api/Program.cs" -Pattern "type.*="

# Find all reducer actions
Select-String -Path "frontend/src/types/appState.ts" -Pattern "type:"

# Find SSE parsing
Select-String -Path "frontend/src/services/chatService.ts" -Pattern "case '"

# Verify file links exist
Get-ChildItem -Recurse -Include "chatService.ts","appReducer.ts","appState.ts"

Cross-Reference with DeepWiki

DeepWiki (https://deepwiki.com/microsoft-foundry/foundry-agent-webapp) indexes the repo automatically. After major architecture changes:

  1. Check DeepWiki re-indexes (usually within 24 hours)
  2. Verify diagrams match between ARCHITECTURE-FLOW.md and DeepWiki
  3. Note: DeepWiki may show older commit - check "Last indexed" date

Common Architecture Questions

"How does a message flow end-to-end?"

See ARCHITECTURE-FLOW.md#2.3 - End-to-End Message Flow sequence diagram.

"What happens when streaming is cancelled?"

  1. User clicks Stop button or presses Escape
  2. ChatService.cancelStream() sets streamCancelled = true and calls abort()
  3. CHAT_CANCEL_STREAM action dispatched
  4. Reducer sets status: idle, clears streamingMessageId, enables input

"How does MCP tool approval work?"

  1. Backend yields StreamChunk.McpApproval when McpToolCallApprovalRequestItem received
  2. Frontend dispatches CHAT_MCP_APPROVAL_REQUEST with approval details
  3. Reducer adds approval message, sets status to idle (but input stays disabled)
  4. User clicks Approve/Deny
  5. ChatService.sendMcpApproval() resumes with approval response

"Where is the JWT validated?"

Program.cs → AddMicrosoftIdentityWebApi() + RequireAuthorization(ScopePolicyName) on each endpoint.

"How are credentials resolved in production vs development?"

  • Development: ChainedTokenCredential(AzureCliCredential, AzureDeveloperCliCredential)
  • Production: ManagedIdentityCredential(miClientId) (user-assigned MI with MANAGED_IDENTITY_CLIENT_ID)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.