Sitemap

Aspire in Action: Real-Time AI Streaming

7 min readMay 22, 2025

--

Aspire in Action: Real-Time AI Streaming

Introduction

In the fast-evolving landscape of modern software, simply building a modular system isn’t enough. We’ve championed a pragmatic approach in our previous article, .NET Aspire in Action: Building Modular, Event-Driven Systems,” where we introduced a robust hybrid architecture. That model, blending the clarity of Clean Architecture with the agility of Vertical Slices, lets us map features directly to isolated, maintainable units, orchestrated effortlessly by .NET Aspire. It’s a structure designed to scale without fragmenting into chaotic microservices, ensuring we build what’s truly needed.

But what happens when ‘scalable’ also demands ‘intelligent’ and ‘real-time’? As applications demand instant insights and dynamic interactions driven by advanced AI, the challenge shifts. How do we imbue our well-structured, modular systems with a living, thinking core, without sacrificing the very clarity and control we’ve fought so hard to achieve? How do we stream complex AI responses directly to the user in real-time, integrating seamlessly into our existing architecture?

This is where the true architectural “surgery” begins. we’re not just adding a feature; we’re fundamentally enhancing the intelligence of our IESuite system. This article will guide you through the meticulous process of introducing the IESuite.Brain — a central, intelligent AI unit — into our existing Aspire orchestration. We’ll unveil how this powerful core connects to its primary interface, IESuite.Neural (our nervenode client), forming a complete, responsive neural system.

You’ll gain deep insights into mastering real-time AI streaming using SignalR, witnessing firsthand how .NET Aspire flawlessly orchestrates these intelligent components and their high-speed communication. By the end, you’ll understand not just how to build a responsive, AI-driven application, but why this architectural approach is superior for integrating cutting-edge intelligence with precision, maintainability, and control. This isn’t just an upgrade; it’s a transformation.

The IESuite’s New Brain: Architecture Overview

At the heart of our new intelligent capabilities lies the IESuite.Brain. Conceived as a central AI unit, this dedicated .NET service is designed to encapsulate all core artificial intelligence logic and interactions. In a modular system, the Brain’s role is to provide intelligent services without tightly coupling them to specific consumer applications. It acts as the cognitive core, processing complex requests and generating insights that can then be distributed across various channels.

Think of the IESuite.Brain not as a simple API endpoint, but as a specialized processor for cognitive tasks. Its independent nature ensures that our core business modules within IESuite remain lean and focused, offloading complex AI computations and interactions to a dedicated, scalable service. For example, our ChatStreamService resides here, responsible for interacting with external AI models like OpenAI and managing the real-time flow of their responses.

More broadly, the IESuite.Brain is designed with provider agnosticism at its core. It can seamlessly integrate with any AI provider — be it OpenAI, Google Gemini, or others — and can be programmed to orchestrate these providers to work either individually for specialized tasks or cooperatively for more complex, multi modal responses. This flexibility extends to various AI modalities, from text and chat to future capabilities like image or video generation, establishing the Brain as a truly versatile cognitive engine.

The Brain also has critical dependencies, managed seamlessly by Aspire:

  • Azure Key Vault: Essential for securely managing API keys for services like OpenAI, ensuring our secrets are never hardcoded.
  • Azure SignalR Service: The backbone of our real-time communication, allowing the Brain to push dynamic content directly to connected clients.

This deliberate separation of concerns, orchestrated by Aspire, sets the stage for a highly intelligent yet remarkably maintainable system.

Building the Neural Interface: IESuite.Neural (Nervenode)

Every brain needs a way to interact with the world, and in our IESuite system, that role falls to IESuite.Neural. This is our Next.js client application, which you’ll find defined in our Aspire host as the nervenode resource. IESuite.Neural serves as the user’s primary “nerve node” — the crucial interface that establishes a real-time connection to the IESuite.Brain, enabling direct user interaction and the reception of streaming AI insights.

While currently showcasing a real-time chat interface (affectionately dubbed Synapse Talk), the application is designed for far greater things. Its name. “Neural,” signifies its role as a versatile connection point to the cognitive core, extensible to support a myriad of intelligent interactions. In future iterations, this same “nerve node” can evolve into sophisticated dashboards, specialized data query tools, or even an “operation room” for advanced financial insights, all powered by the central Brain. This approach allows us to unify the user experience under a single, intelligent interface, growing its capabilities without having to spin up entirely new applications for every new feature.

Synapse Talk

The Real-Time Connection: SignalR & OpenAI Streaming

The magic of instantaneous interaction between IESuite.Neural and the IESuite.Brain is powered by SignalR. Our ChatStreamService within the IESuite.Brain is a testament to real-time architecture, directly streaming OpenAI chat chunks to the frontend.

Unlike traditional request-response APIs, the StreamMessageToClientAsync method in ChatStreamService does not return a response. Instead, it pushes data directly over a WebSocket connection using hubContext.Clients.Client(connectionId).SendAsync. This push-based model is fundamental to providing that fluid, console-like AI experience users expect. It ensures that as soon as the Brain receives a chunk from OpenAI, it’s immediately forwarded to the connected IESuite.Neural client, creating a seamless, live dialogue.

Aspire: The Orchestra Conductor

None of this seamless integration would be possible without .NET Aspire acting as our intelligent orchestrator. Aspire doesn’t just simplify local development; it provides a robust, opinionated framework for composing and deploying distributed applications, handling networking, environment variables, and crucial configurations like CORS with precision.

The .NET Aspire Dashboard provides a clear graph view of our IESuite’s orchestrated services, running seamlessly on Ubuntu.

Here’s how our AppHost (Program.cs) brings the IESuite.Brain and IESuite.Neural together:

var builder = DistributedApplication.CreateBuilder(args);

var keyVault = builder.AddConnectionString("key-vault");

var signalr =builder.AddConnectionString("signalr");

var nervechat = builder
.AddNpmApp("nervenode", "../IESuite.Neural/nervenode", "dev")
.WithHttpEndpoint(name: "nervenodehttp", env: "PORT");

var brain = builder.AddProject<Projects.IESuit_Brain>("brain")
.WithHttpEndpoint(name: "brainapi")
.WithReference(keyVault)
.WithReference(signalr)
.WaitFor(signalr)
.WithReference(nervechat);

nervechat.WithEnvironment("NEXT_PUBLIC_BRAIN_HUB_URL", brain.GetEndpoint("brainapi"));

builder.Build().Run();

Every line in this Program.cs is critical. Aspire orchestrates the services, injects connection strings, and manages environment variables like NEXT_PUBLIC_BRAIN_HUB_URL, which is dynamically populated with the brainapi endpoint for IESuite.Neural to connect to. This ensures that our Next.js app always knows how to find its Brain, regardless of the deployment environment.

A prime example of Aspire’s power and strictness is in handling CORS (Cross-Origin Resource Sharing). For IESuite.Neural (our client) to securely connect to the IESuite.Brain’s SignalR Hub, the Brain must explicitly allow nervenode’s origin. Aspire exposes dynamically assigned service URLs through its configuration, making this robust and automated:

string urlConfigKey = "services:nervenode:nervenodehttp:0"; 
var allowedOrigin = builder.Configuration[urlConfigKey];
if (!string.IsNullOrEmpty(allowedOrigin))
{
var originUri = new Uri(allowedOrigin);
var formattedOrigin = $"{originUri.Scheme}://{originUri.Authority}";
policyBuilder.WithOrigins(formattedOrigin)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials(); // ESSENTIAL FOR SIGNALR
Console.WriteLine($"CORS (Brain/SignalR Hub): Allowing origin: {formattedOrigin}");

This demonstrates how Aspire manages the intricate networking details behind the scenes, ensuring that even highly sensitive configurations like CORS are handled dynamically and correctly, reinforcing why precision in Aspire’s orchestration rules is paramount.

From Concept to Code: Key Architectural Decisions

Our commitment to a hybrid architectural model — blending Clean Architecture’s clear domain boundaries with Vertical Slices’ feature-first approach — proved invaluable during this “Brain implantation.” This flexible structure allowed us to:

  • Isolate AI Logic: The IESuite.Brain exists as a distinct project, encapsulating AI complexities without polluting our core business modules.
  • Feature-Driven Development: The nervenode client app’s development, including ChatStream, directly mapped to user stories, resulting in well-defined, modular components within its Features/ directory. This is how we turn a feature request into tangible structure, avoiding ‘spaghetti code’ and ensuring every line serves a clear purpose.
  • Pragmatic Layering: We pushed infrastructure concerns (like SignalR client connections and OpenAI SDK usage) to the edge layers, keeping our core domain logic clean and testable, even while interacting with sophisticated external services.

This approach validates our core philosophy: building systems that are not only powerful and intelligent but also maintainable, testable, and adaptable to future demands.

Conclusion

We’ve embarked on a significant architectural “surgery” for the IESuite, successfully implanting a central IESuite.Brain and connecting it via a responsive IESuite.Neural interface. By leveraging the orchestration power of .NET Aspire and the real-time capabilities of SignalR, we’ve demonstrated how to build a truly intelligent, interactive system that handles complex AI streaming with elegance and efficiency.

This article showcases not just the technical ‘how,’ but the architectural ‘why’ — proving that advanced AI can be integrated into robust, modular systems without sacrificing clarity or control. The IESuite is now equipped with a dynamic neural core, ready for future expansions into sophisticated tools like the FX Dashboard, specialized RAG functionalities, and beyond.

We invite you to explore the accompanying GitHub repository for the full code. Your insights and contributions are always welcome as we continue to evolve the IESuite towards its full potential as a beacon of modern, intelligent software architecture. Feel free to share your thoughts in the comments below

--

--

Ali Alkhateeb
Ali Alkhateeb

Written by Ali Alkhateeb

0 followers

Lead Solutions Architect and Software Engineer. I teach, prototype, and share architectural solutions to empower the engineers of tomorrow.

Responses (1)