|
2 | 2 |
|
3 | 3 | Aspire AI Chat is a full-stack chat sample that combines modern technologies to deliver a ChatGPT-like experience. |
4 | 4 |
|
| 5 | +## Architecture |
| 6 | + |
| 7 | +```mermaid |
| 8 | +graph TB |
| 9 | + User[User Browser] |
| 10 | + |
| 11 | + subgraph "YARP Reverse Proxy" |
| 12 | + YARP[chatui - YARP] |
| 13 | + end |
| 14 | + |
| 15 | + subgraph "Frontend" |
| 16 | + UI[React + TypeScript UI<br/>Vite Build] |
| 17 | + end |
| 18 | + |
| 19 | + subgraph "Backend API" |
| 20 | + API[ChatApi - ASP.NET Core<br/>SignalR Hub] |
| 21 | + end |
| 22 | + |
| 23 | + subgraph "Data Layer" |
| 24 | + PG[(PostgreSQL<br/>Conversation History)] |
| 25 | + Redis[(Redis<br/>Message Stream Cache)] |
| 26 | + end |
| 27 | + |
| 28 | + subgraph "AI Layer" |
| 29 | + LLM{AI Provider} |
| 30 | + Ollama[Ollama<br/>phi4 model<br/>Linux/Windows] |
| 31 | + OpenAI[OpenAI<br/>gpt-4.1<br/>macOS/Production] |
| 32 | + end |
| 33 | + |
| 34 | + User -->|HTTP/WS| YARP |
| 35 | + YARP -->|Static Files| UI |
| 36 | + YARP -->|/api/*| API |
| 37 | + |
| 38 | + API -->|SignalR| User |
| 39 | + API -->|EF Core| PG |
| 40 | + API -->|Pub/Sub| Redis |
| 41 | + API -->|IChatClient| LLM |
| 42 | + |
| 43 | + LLM -.->|Local| Ollama |
| 44 | + LLM -.->|Cloud| OpenAI |
| 45 | + |
| 46 | + style YARP fill:#e1f5ff |
| 47 | + style API fill:#fff3e0 |
| 48 | + style UI fill:#f3e5f5 |
| 49 | + style PG fill:#e8f5e9 |
| 50 | + style Redis fill:#ffebee |
| 51 | + style LLM fill:#fff9c4 |
| 52 | +``` |
| 53 | + |
5 | 54 | ## High-Level Overview |
6 | 55 |
|
7 | 56 | - **Backend API:** |
8 | | - The backend is built with **ASP.NET Core** and interacts with an LLM using **Microsoft.Extensions.AI**. It leverages `IChatClient` to abstract the interaction between the API and the model. Chat responses are streamed back to the client using stream JSON array responses. |
| 57 | + The backend is built with **ASP.NET Core** and interacts with an LLM using **Microsoft.Extensions.AI**. It leverages `IChatClient` to abstract the interaction between the API and the model. Chat responses are streamed back to the client using **SignalR** for real-time communication. |
9 | 58 |
|
10 | 59 | - **Data & Persistence:** |
11 | | - Uses **Entity Framework Core** with **PostgreSQL** for reliable relational data storage. The project includes database migrations for easy setup and version control of the schema. |
| 60 | + Uses **Entity Framework Core** with **PostgreSQL** for reliable relational data storage. **Redis** is used for caching and broadcasting live message streams across multiple clients. |
12 | 61 |
|
13 | 62 | - **AI & Chat Capabilities:** |
14 | | - - Uses **Ollama** (via OllamaSharp) for local inference, enabling context-aware responses. |
15 | | - - In production, the application switches to [**OpenAI**](https://openai.com/) for LLM capabilities. |
| 63 | + - Uses **Ollama** (via OllamaSharp) for local inference on Linux/Windows. |
| 64 | + - On macOS, the application uses [**OpenAI**](https://openai.com/) directly for better compatibility. |
| 65 | + - In production, the application can be configured to use various AI providers through the abstraction layer. |
16 | 66 |
|
17 | 67 | - **Frontend UI:** |
18 | | - Built with **React**, the user interface offers a modern and interactive chat experience. The React application is built and hosted using [**Caddy**](https://caddyserver.com/). |
| 68 | + Built with **React** and **TypeScript** using **Vite** for fast development and builds. The UI provides a modern chat interface with support for markdown rendering and conversation history. |
| 69 | + |
| 70 | +- **Reverse Proxy & Serving:** |
| 71 | + Uses **YARP** (Yet Another Reverse Proxy) to serve the static frontend and proxy API requests, providing a unified endpoint. |
19 | 72 |
|
20 | 73 | ## Getting Started |
21 | 74 |
|
22 | 75 | ### Prerequisites |
23 | 76 |
|
24 | | -- [.NET 9.0](https://dotnet.microsoft.com/en-us/download/dotnet/9.0) |
| 77 | +- [.NET 10.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/10.0) |
25 | 78 | - [Docker](https://www.docker.com/get-started) or [Podman](https://podman-desktop.io/) |
26 | 79 | - [Node.js](https://nodejs.org/) (LTS version recommended) |
27 | 80 |
|
28 | 81 | ### Running the Application |
29 | 82 |
|
30 | | -Run the [AIChat.AppHost](AIChat.AppHost) project. This project uses |
31 | | -[.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview) |
32 | | -to run the application in a container. |
| 83 | +Run the [AIChat.AppHost](AIChat.AppHost) project using the .NET Aspire tooling: |
| 84 | + |
| 85 | +```bash |
| 86 | +aspire run |
| 87 | +``` |
| 88 | + |
| 89 | +This project uses [.NET Aspire](https://learn.microsoft.com/en-us/dotnet/aspire/get-started/aspire-overview) to orchestrate the application components in containers. |
33 | 90 |
|
34 | 91 | ### Configuration |
35 | 92 |
|
36 | | -- By default, the application uses **Ollama** for local inference. |
37 | | -- To use **OpenAI**, set the appropriate configuration values (e.g., API keys, endpoints). |
38 | | -- The PostgreSQL database will be automatically created and migrated when running with Aspire. |
| 93 | +- By default, the application uses **Ollama** (phi4 model) for local inference on Linux/Windows. |
| 94 | +- On **macOS**, it automatically switches to **OpenAI** and will prompt for your OpenAI API key if not already configured. |
| 95 | +- The **PostgreSQL** database and **Redis** cache are automatically provisioned when running with Aspire. |
| 96 | +- Access the Aspire dashboard to monitor resources and view logs. |
| 97 | + |
| 98 | +## CI/CD |
| 99 | + |
| 100 | +The project includes a GitHub Actions workflow that: |
| 101 | + |
| 102 | +- Builds container images for both the API and UI |
| 103 | +- Tags images with format: `<branch>-<build-number>-<git-sha>` |
| 104 | +- Pushes images to GitHub Container Registry (GHCR) |
39 | 105 |
|
| 106 | +Images are available at: `ghcr.io/<owner>/chatapi` and `ghcr.io/<owner>/chatui` |
0 commit comments