# Backend - .NET Aspire Application

.NET Aspire distributed application hosting the AI monitoring system services.

## Solution File

The solution file is `Kds.Ai.slnx` located at the repository root. All global solution-level operations (build, restore, format, test) must target this file:

```bash
# Always reference the solution file from the repo root for global operations
dotnet build /Users/jakubsyty/Projects/LogicControls/KDSAI/Kds.Ai.slnx
dotnet restore /Users/jakubsyty/Projects/LogicControls/KDSAI/Kds.Ai.slnx
dotnet format /Users/jakubsyty/Projects/LogicControls/KDSAI/Kds.Ai.slnx
```

Never build individual projects one by one when a solution-wide operation is intended.

## Build Verification

After completing any implementation work, always run a final build with `TreatWarningsAsErrors` to confirm the solution is truly clean:

```bash
dotnet build /Users/jakubsyty/Projects/LogicControls/KDSAI/Kds.Ai.slnx -p:TreatWarningsAsErrors=true
```

The only acceptable warning to suppress is `NU1902` (MimeKit vulnerability in `Kds.Ai.KnowledgeBase`) — this is a pre-existing third-party issue unrelated to application code. All other warnings must be fixed before the task is considered complete.

## Build & Run

1. **Start with a known state**: Before making any changes, always run the apphost using `aspire run` and inspect the state of resources.
2. **Incremental changes**: Make changes incrementally and run `aspire run` to validate them.
3. **AppHost restarts**: Changes to `apphost.cs` require a restart of the application to take effect.

```bash
# Run the Aspire AppHost (starts all services) using aspire cli
# You can run this comment on any directory level, aspire run figure this out automatically
aspire run
```

If there is already an instance of the application running it will prompt to stop the existing instance.

## .NET Aspire Development & Diagnostics

Refer to the `aspire` skill for guidance on development and diagnostics tasks.

## Browser testing
Use `agent-browser` for functional investigations of the web applications. Refer to the `agent-browser` skill for detailed guidance.

## Code Style

Always use the `csharp-developer` skill for any task related to work in the backend folder (C# coding conventions and best practices).

Always run `dotnet format` at the end of your implementation to ensure code style compliance. To optimize performance, you can pass a list of modified files using the `--include` parameter:
```bash
dotnet format --include path/to/file1.cs path/to/file2.cs
```

## Data Layer

Use the `efcore-data-layer` skill for Entity Framework Core conventions, repository patterns, and data seeding.

## Tests

Refer to the `tunit-testing` skill for all testing guidance, patterns, and conventions (for both unit and integration testing).

## Querying Microsoft Documentation

You have access to MCP tools called `microsoft_docs_search`, `microsoft_docs_fetch`, and `microsoft_code_sample_search` - these tools allow you to search through and fetch Microsoft's latest official documentation and code samples, and that information might be more detailed or newer than what's in your training data set.

When handling questions around how to work with native Microsoft technologies, such as C#, F#, ASP.NET Core, Microsoft.Extensions, NuGet, Entity Framework, the `dotnet` runtime - please use these tools for research purposes when dealing with specific / narrowly defined questions that may occur.

## Official Documentation

Always prefer official documentation when available:
1. [Aspire.dev](https://aspire.dev)
2. [Microsoft Learn - .NET Aspire](https://learn.microsoft.com/dotnet/aspire)
3. [NuGet.org](https://nuget.org) (for specific integration package details)
