com um clique
understanding-architecture
// 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.
// 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.
| name | understanding-architecture |
| description | 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. |
Load this skill when: Understanding system design, debugging state transitions, tracing SSE events, or updating architecture documentation.
| Layer | Tech | Port | Entry Point |
|---|---|---|---|
| Frontend | React 19 + Vite | 5173 | frontend/src/App.tsx |
| Backend | ASP.NET Core 9 | 8080 | backend/WebApp.Api/Program.cs |
| Auth | MSAL.js → JWT Bearer | — | frontend/src/config/authConfig.ts |
| AI SDK | Azure.AI.Projects (GA) + Azure.AI.Extensions.OpenAI | — | backend/.../AgentFrameworkService.cs |
User → ChatInput → CHAT_SEND_MESSAGE → ChatService.sendMessage()
→ POST /api/chat/stream (JWT) → AgentFrameworkService.StreamMessageAsync()
→ AI Foundry → SSE chunks → parseSseLine() → Reducer actions → UI update
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
| State | Input Enabled | streamingMessageId |
|---|---|---|
idle | ✅ Yes | undefined |
sending | ❌ No | undefined |
streaming | ❌ No | Message ID |
error | If recoverable | undefined |
initializing ──AUTH_INITIALIZED──► authenticated ──AUTH_TOKEN_EXPIRED──► unauthenticated
│ │
└───────────AUTH_INITIALIZED──────────┘
| SSE Event | Backend Method | Frontend Action | Reducer Effect |
|---|---|---|---|
conversationId | WriteConversationIdEvent | CHAT_START_STREAM | Set conversationId |
chunk | WriteChunkEvent | CHAT_STREAM_CHUNK | Append content |
annotations | WriteAnnotationsEvent | CHAT_STREAM_ANNOTATIONS | Add citations |
mcpApprovalRequest | WriteMcpApprovalRequestEvent | CHAT_MCP_APPROVAL_REQUEST | Show approval UI |
usage | WriteUsageEvent | CHAT_STREAM_COMPLETE | Add token counts |
done | WriteDoneEvent | CHAT_STREAM_COMPLETE | Finalize |
error | WriteErrorEvent | CHAT_ERROR | Set error state |
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)
| File | Purpose |
|---|---|
frontend/src/types/appState.ts | State & action type definitions |
frontend/src/reducers/appReducer.ts | All state transitions |
frontend/src/contexts/AppContext.tsx | Provider + dev logging |
| File | Purpose |
|---|---|
backend/WebApp.Api/Program.cs | SSE endpoints + Write*Event helpers |
frontend/src/services/chatService.ts | SSE client + action dispatch |
frontend/src/utils/sseParser.ts | Line parsing + event types |
| File | Purpose |
|---|---|
backend/.../AgentFrameworkService.cs | Agent loading + streaming |
backend/.../Models/StreamChunk.cs | Chunk types (text, annotations, MCP) |
backend/.../Models/ChatRequest.cs | Request payload structure |
For complete diagrams and detailed flows, see:
Update the architecture document when:
| Change Type | What to Update |
|---|---|
| New SSE event type | Section 1.5 (Backend SSE Event Types), Section 2.8 (SSE → Action Mapping) |
| New reducer action | Section 2.7 (Action Reference), state machine diagrams |
| New API endpoint | Section 1.1 (Request Pipeline flowchart) |
| New auth state | Section 2.1 (Authentication State Machine) |
| New chat state | Section 2.2 (Chat State Machine) |
| File moved/renamed | Part 6 (File Reference tables) |
| Validation rules changed | Section 5.1 (Attachment Validation) |
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)
| Document Section | Source 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 |
# 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"
DeepWiki (https://deepwiki.com/microsoft-foundry/foundry-agent-webapp) indexes the repo automatically. After major architecture changes:
See ARCHITECTURE-FLOW.md#2.3 - End-to-End Message Flow sequence diagram.
ChatService.cancelStream() sets streamCancelled = true and calls abort()CHAT_CANCEL_STREAM action dispatchedstatus: idle, clears streamingMessageId, enables inputStreamChunk.McpApproval when McpToolCallApprovalRequestItem receivedCHAT_MCP_APPROVAL_REQUEST with approval detailsidle (but input stays disabled)ChatService.sendMcpApproval() resumes with approval responseProgram.cs → AddMicrosoftIdentityWebApi() + RequireAuthorization(ScopePolicyName) on each endpoint.
ChainedTokenCredential(AzureCliCredential, AzureDeveloperCliCredential)ManagedIdentityCredential(miClientId) (user-assigned MI with MANAGED_IDENTITY_CLIENT_ID)Provides deployment commands and troubleshooting for Azure Container Apps. Use when running azd commands, deploying containers, debugging deployment failures, or updating infrastructure in this repository.
Provides SSE streaming patterns for the chat API and frontend. Use when implementing or modifying chat streaming, handling SSE events, or troubleshooting message flow between frontend and backend.
Provides research patterns for Foundry Agent Service SDK. Use when implementing agent features, looking up SDK methods, finding code samples, or troubleshooting Azure.AI.Projects API usage.
Provides C# and ASP.NET Core coding standards for this repository. Use when writing or modifying C# code, implementing API endpoints, configuring middleware, or working with authentication in the backend.
Diagnose and fix incomplete local development setup. Use when dev servers fail to start, env vars are missing, authentication errors occur, or before running any dev commands for the first time.
Provides TypeScript and React coding standards for this repository. Use when writing or modifying TypeScript code, creating React components, implementing MSAL authentication, or working with the frontend.