How f4cio/aichatbot works
Purpose and topology
AiChatBot is a .NET 10 n-tier chatbot that sends user messages to Anthropic Claude Managed Agents. It has three interchangeable hosts: an ASP.NET Core REST API, console REPL, and Htmx UI; a separate React 19 SPA consumes the API. There is no application database or authentication; durable context is delegated to Claude’s Memory store.
Key entry points:
• SourceCode/F4CIO.AiChatBot.UiApi/Program.cs
• SourceCode/F4CIO.AiChatBot.UiConsole/Program.cs
• SourceCode/F4CIO.AiChatBot.UiHtmx/Program.cs
• SourceCode/F4CIO.AiChatBot.UiWeb/src/main.tsx
Shared domain and service boundary
Entities define configuration, request/response, error, and streaming DTO shapes shared across layers. IChatService is the primary host-to-business-logic boundary, allowing API and console clients to invoke the same chat capability without depending on Claude details.
• SourceCode/F4CIO.AiChatBot.Common.Entities/Configuration.cs
• SourceCode/F4CIO.AiChatBot.Common.Entities/Dtos.cs
• SourceCode/F4CIO.AiChatBot.Common.Entities/DtosStreaming.cs
• SourceCode/F4CIO.AiChatBot.Contracts/IChatService.cs
Chat orchestration and Claude integration
ChatService implements request handling and streaming behavior. Conversation-specific handling separates local conversation state/logging concerns from the Anthropic integration. HandlerForClaude encapsulates the beta Managed Agents SDK surface, making it the key isolation point for Anthropic API changes.
At startup/use, the integration finds or creates configured Claude Environment, Agent, and Memory store resources. Each session attaches the Memory store, so Anthropic persists durable memory while the API process retains only in-memory run/session continuity.
• SourceCode/F4CIO.AiChatBot.BusinessLogic/ChatService.cs
• SourceCode/F4CIO.AiChatBot.BusinessLogic/ChatService.Streaming.cs
• SourceCode/F4CIO.AiChatBot.BusinessLogic/HandlerForClaude.cs
• SourceCode/F4CIO.AiChatBot.BusinessLogic/HandlerForClaude.Streaming.cs
• SourceCode/F4CIO.AiChatBot.BusinessLogic/HandlerForConversation.cs
API host and streaming boundary
The ASP.NET Core API exposes chat endpoints through its controller and publishes Swagger/OpenAPI for client generation. Startup establishes dependency injection, configuration, CORS, and HTTP pipeline behavior. API exceptions are translated by a dedicated handler; server-sent events provide incremental Claude output to streaming clients.
• SourceCode/F4CIO.AiChatBot.UiApi/Controllers/ChatController.cs
• SourceCode/F4CIO.AiChatBot.UiApi/HandlerForStartup.cs
• SourceCode/F4CIO.AiChatBot.UiApi/HandlerForServerSentEvents.cs
• SourceCode/F4CIO.AiChatBot.UiApi/HandlerForApiExceptions.cs
Front-end variants
The React SPA is a static Vite build with a single application screen. Its generated typed API client follows the API OpenAPI contract; streaming and runtime API-base resolution are handled in the API modules. public/config.js is deployed separately so the API URL can change without rebuilding the SPA.
• SourceCode/F4CIO.AiChatBot.UiWeb/src/App.tsx
• SourceCode/F4CIO.AiChatBot.UiWeb/src/api/apiClient.ts
• SourceCode/F4CIO.AiChatBot.UiWeb/src/api/stream.ts
• SourceCode/F4CIO.AiChatBot.UiWeb/public/config.js
The Htmx host is an alternative server-rendered single-screen UI with its own controller and Razor page/partial rendering, plus browser streaming support.
• SourceCode/F4CIO.AiChatBot.UiHtmx/Controllers/ChatController.cs
• SourceCode/F4CIO.AiChatBot.UiHtmx/Pages/Index.cshtml
• SourceCode/F4CIO.AiChatBot.UiHtmx/Pages/Shared/_MessagePartial.cshtml
• SourceCode/F4CIO.AiChatBot.UiHtmx/wwwroot/js/stream.js
Operational boundaries
Common infrastructure centralizes structured error IDs, host-owned logs, conversation transcript files, and path resolution. Hosts supply configuration, including the Claude API key, model, named Managed Agent resources, API URL, and CORS origins.
• SourceCode/F4CIO.AiChatBot.Common/HandlerForLogging.cs
• SourceCode/F4CIO.AiChatBot.Common/HandlerForErrors.cs
• SourceCode/F4CIO.AiChatBot.Common/HandlerForConversationLog.cs
• SourceCode/F4CIO.AiChatBot.UiApi/appsettings.json
Deployment targets Windows/IIS: the API can be self-contained behind ASP.NET Core Module, while React is static content with IIS rewrite support. Published outputs are staged under Published/.
• Published/F4CIO.AiChatBot.UiApi/web.config
• Published/F4CIO.AiChatBot.UiWeb/web.config
Main entry points: ChatService.cs ChatService · Program.cs ASP.NET Core API · ChatController.cs Chat API controller · IChatService.cs IChatService
Components 22
Shared Core
- Shared DTOs & config · Request, response, streaming, error, and configuration shapes.
SourceCode/F4CIO.AiChatBot.Common.Entities/Dtos.cs - IChatService · Primary host-to-chat boundary.
SourceCode/F4CIO.AiChatBot.Contracts/IChatService.cs
Hosts
- ASP.NET Core API · Configures DI, CORS, and HTTP pipeline.
SourceCode/F4CIO.AiChatBot.UiApi/Program.cs - Chat API controller · Exposes chat and OpenAPI contract.
SourceCode/F4CIO.AiChatBot.UiApi/Controllers/ChatController.cs - SSE handler · Publishes incremental chat output.
SourceCode/F4CIO.AiChatBot.UiApi/HandlerForServerSentEvents.cs - API exception handler · Translates server errors into API responses.
SourceCode/F4CIO.AiChatBot.UiApi/HandlerForApiExceptions.cs - Console REPL · Alternative interactive chat host.
SourceCode/F4CIO.AiChatBot.UiConsole/Program.cs - Htmx chat controller · Alternative browser chat host.
SourceCode/F4CIO.AiChatBot.UiHtmx/Controllers/ChatController.cs - Htmx Razor screen · Renders chat page and message partials.
SourceCode/F4CIO.AiChatBot.UiHtmx/Pages/Index.cshtml - Htmx browser stream
SourceCode/F4CIO.AiChatBot.UiHtmx/wwwroot/js/stream.js - React SPA · Static React 19 chat application.
SourceCode/F4CIO.AiChatBot.UiWeb/src/main.tsx - Chat screen · Single application screen.
SourceCode/F4CIO.AiChatBot.UiWeb/src/App.tsx - Typed API client · Generated client for the API contract.
SourceCode/F4CIO.AiChatBot.UiWeb/src/api/apiClient.ts - SPA stream client · Consumes incremental API output.
SourceCode/F4CIO.AiChatBot.UiWeb/src/api/stream.ts
Claude Integration
- ChatService · Handles chat requests and streaming.
SourceCode/F4CIO.AiChatBot.BusinessLogic/ChatService.cs - Conversation handler · Manages local session continuity and transcript concerns.
SourceCode/F4CIO.AiChatBot.BusinessLogic/HandlerForConversation.cs - HandlerForClaude · Isolation boundary for Managed Agents SDK calls.
SourceCode/F4CIO.AiChatBot.BusinessLogic/HandlerForClaude.cs - Anthropic Managed Agents · Provides Environment, Agent, runs, and Memory resources.
- Claude Memory store · Anthropic-owned durable conversation memory.
Operations & Deployment
- Runtime API config · Allows API URL changes without rebuilding the SPA.
SourceCode/F4CIO.AiChatBot.UiWeb/public/config.js - Logging & transcripts · Hosts own logs; conversation transcripts are file-backed.
SourceCode/F4CIO.AiChatBot.Common/HandlerForLogging.cs - IIS published outputs · API runs behind ASP.NET Core Module; SPA is static content.
Published/F4CIO.AiChatBot.UiApi/web.config
Connections 25
- ASP.NET Core API → Chat API controller: routes requests
- ASP.NET Core API → API exception handler: handles failures
- Chat API controller → IChatService: invokes
- Chat API controller → SSE handler: streams via
- Console REPL → IChatService: invokes
- Htmx chat controller → IChatService: invokes
- Htmx Razor screen → Htmx browser stream: loads
- Htmx browser stream → Htmx chat controller: chat stream
- React SPA → Chat screen: renders
- Chat screen → Typed API client: sends chat
- Chat screen → SPA stream client: receives stream
- Runtime API config → Typed API client: sets API base
- Typed API client → Chat API controller: REST / OpenAPI
- SPA stream client → SSE handler: SSE
- IChatService → ChatService: implemented by
- ChatService → Shared DTOs & config: uses DTOs
- ChatService → Conversation handler: coordinates
- ChatService → HandlerForClaude: delegates agent calls
- Conversation handler → Logging & transcripts: writes transcripts
- HandlerForClaude → Anthropic Managed Agents: Managed Agents SDK
- Anthropic Managed Agents → Claude Memory store: attaches per session
- ASP.NET Core API → Logging & transcripts: host logs
- Console REPL → Logging & transcripts: host logs
- IIS published outputs → ASP.NET Core API: hosts API
- IIS published outputs → React SPA: serves SPA build