Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
99 changes: 99 additions & 0 deletions AGENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# AGENT.md

## Purpose

This file helps AI coding agents work effectively in this repository. Use it as a fast orientation guide before making changes.

## Project Overview

This repository is a Clean Architecture Blazor Server solution template built for long-term maintainability, modular feature development, and enterprise-style application patterns.

The main application layers are:

- `Domain`: core entities, domain events, and business rules
- `Application`: use cases, DTOs, validation, pipeline behaviors, and application abstractions
- `Infrastructure`: persistence, external integrations, identity, caching, and runtime services
- `Server.UI`: Blazor Server UI, pages, components, and client-facing application wiring
- `Migrators`: EF Core migration entry points and database update tooling

## Solution Map

- `src/Application`
Application logic and feature implementation. Start here for commands, queries, validators, specifications, and service contracts.
- `src/Domain`
Domain model and business concepts. Keep this layer independent of UI and infrastructure concerns.
- `src/Infrastructure`
EF Core, authentication, file services, caching, background jobs, and other external dependencies.
- `src/Migrators`
Database migration projects used for provider-specific EF Core migration work.
- `src/Server.UI`
Blazor Server host, pages, components, menus, dialogs, and UI services.
- `tests/Application.UnitTests`
Unit tests for application-layer behavior.
- `tests/Application.IntegrationTests`
Integration-style tests for application workflows and persistence-backed behavior.
- `tests/Domain.UnitTests`
Unit tests focused on domain behavior.
- `tests/Infrastructure.UnitTests`
Tests for infrastructure services and related helpers.
- `docs/`
Supporting project documentation.
- `docs/superpowers/`
Recommended place for design notes, plans, and implementation specs when a task needs explicit planning.

## Working Guidance

- Preserve Clean Architecture boundaries. Avoid introducing UI or infrastructure concerns into `Domain`.
- Prefer existing repository patterns over inventing new ones. Match nearby features before creating new abstractions.
- When adding a new feature, inspect similar modules in `Application`, `Infrastructure`, and `Server.UI` first.
- Keep changes targeted. Do not refactor unrelated areas unless the task requires it.
- Update documentation when setup steps, commands, or workflows change.
- If a task benefits from explicit design or planning, add artifacts under `docs/superpowers/` rather than inventing a separate process.

## Common Commands

Build the solution:

```bash
dotnet build CleanArchitecture.Blazor.slnx
```

Run tests:

```bash
dotnet test CleanArchitecture.Blazor.slnx
```

Run the Blazor Server app:

```bash
dotnet run --project src/Server.UI
```

Add an EF Core migration for SQL Server:

```bash
dotnet ef migrations add InitialCreate --project src/Migrators/Migrators.MSSQL --startup-project src/Server.UI --context ApplicationDbContext
```

Apply database updates:

```bash
dotnet ef database update --project src/Migrators/Migrators.MSSQL --startup-project src/Server.UI --context ApplicationDbContext
```

## Where To Look First

- `README.md` for project overview, setup, and supported workflows
- `docs/` for additional repository documentation
- existing feature folders in `src/Application/Features` and related UI pages in `src/Server.UI`
- `docs/superpowers/` for prior design notes and implementation plans when available

## Expected Output Style

When making changes in this repository:

- favor small, reviewable edits
- explain assumptions when behavior is unclear
- verify builds or tests when the task meaningfully changes behavior
- keep new guidance aligned with the current repository structure instead of generic best practices
3 changes: 0 additions & 3 deletions CleanArchitecture.Blazor.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@
<Project Path="tests/Application.UnitTests/Application.UnitTests.csproj" />
<Project Path="tests/Domain.UnitTests/Domain.UnitTests.csproj" />
</Folder>
<Project Path="docker-compose.dcproj">
<Build />
</Project>
</Solution>
26 changes: 17 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
# apt update and install fonts
RUN echo "deb http://deb.debian.org/debian/ bookworm main contrib" > /etc/apt/sources.list && \
echo "deb-src http://deb.debian.org/debian/ bookworm main contrib" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org/ bookworm-security main contrib" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/ bookworm-security main contrib" >> /etc/apt/sources.list
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
RUN apt-get install -y fonts-noto-cjk fontconfig openssl
# Add 'contrib' component (needed for ttf-mscorefonts-installer) and install fonts
# Handles both DEB822 format (trixie+) and traditional sources.list (bookworm)
RUN if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i 's/^Components: main$/Components: main contrib/' /etc/apt/sources.list.d/debian.sources; \
elif [ -f /etc/apt/sources.list ]; then \
sed -i '/contrib/!s/main/main contrib/' /etc/apt/sources.list; \
fi && \
apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
openssl \
ttf-mscorefonts-installer \
fonts-noto-cjk \
fontconfig && \
update-ca-certificates --fresh && \
rm -rf /var/lib/apt/lists/*



Expand Down Expand Up @@ -60,4 +68,4 @@ FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

ENTRYPOINT ["dotnet", "CleanArchitecture.Blazor.Server.UI.dll"]
ENTRYPOINT ["dotnet", "CleanArchitecture.Blazor.Server.UI.dll"]
108 changes: 20 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This repository provides a **production-grade Blazor Server solution template**

Built on **.NET 10**, the template demonstrates a **well-structured, scalable, and maintainable architecture** for developing complex business systems. It integrates **advanced code generation capabilities**, **AI-assisted development workflows**, and **specification-driven design patterns**, enabling teams to accelerate development while preserving architectural consistency and code quality.

This project has officially said goodbye to **MediatR** and **AutoMapper**, replacing them with **Mediator** and **Mapster** for a simpler and more modern architecture.

The solution is intended to serve both as a **reference implementation** for Blazor Clean Architecture best practices and as a **ready-to-use foundation** for enterprise-level applications that require long-term maintainability, extensibility, and high development efficiency.


Expand All @@ -28,6 +30,7 @@ The solution is intended to serve both as a **reference implementation** for Bla
- **🌐 Multi-tenancy**: Built-in tenant isolation and management
- **📊 Advanced Data Grid**: Sorting, filtering, pagination, and export capabilities
- **🎨 Code Generation**: Visual Studio extension for rapid development
- **🔄 Modern Application Pipeline**: `Mediator` and `Mapster` replace the previous `MediatR` and `AutoMapper` stack
- **🐳 Docker Ready**: Complete containerization support
- **📱 Progressive Web App**: PWA capabilities for mobile experience

Expand Down Expand Up @@ -59,7 +62,7 @@ Experience the application in action:
| Layer | Technologies |
|-------|-------------|
| **Frontend** | Blazor Server, MudBlazor, SignalR |
| **Backend** | .NET 10, ASP.NET Core, Mediator, FluentValidation |
| **Backend** | .NET 10, ASP.NET Core, Mediator, Mapster, FluentValidation |
| **Database** | Entity Framework Core, MSSQL/PostgreSQL/SQLite |
| **Authentication** | ASP.NET Core Identity, OAuth 2.0, JWT |
| **Caching** | FusionCache, Redis |
Expand Down Expand Up @@ -121,7 +124,7 @@ The project includes a comprehensive [Development Workflow](docs/) with:

3. **Setup Database**
```bash
dotnet ef database update --project src/Migrators/Migrators.MSSQL
dotnet ef migrations add InitialCreate --project src/Migrators/Migrators.MSSQL --startup-project src/Server.UI --context ApplicationDbContext
```

4. **Run the Application**
Expand Down Expand Up @@ -158,98 +161,27 @@ See [Docker Setup Documentation](#docker-setup-for-blazor-server-application) fo
- **[Deployment Guide](docs/)**: Production deployment instructions
- **[Contributing Guidelines](CONTRIBUTING.md)**: How to contribute to the project

## 📐 Using OpenSpec for Feature Development

OpenSpec enables spec-driven, reviewable changes with clear proposals, deltas, and tasks. This repo includes guidance in `openspec/AGENTS.md` and a project context in `openspec/project.md`.

- Read the quickstart: `openspec/AGENTS.md`
- Project conventions and patterns: `openspec/project.md` (see "New Entity/Feature Guide (Contacts Pattern)")

### Workflow

1) Plan a change
- Review specs and pending changes
- `openspec list --specs`
- `openspec list`
- Pick a unique, verb-led change id (e.g., `add-customer-management`).

2) Create the change folder and docs
- Create: `openspec/changes/<change-id>/`
- Add files:
- `proposal.md` – Why, What Changes, Impact
- `tasks.md` – Implementation checklist
- Optional `design.md` – Architecture decisions when needed
- Spec deltas: `openspec/changes/<change-id>/specs/<capability>/spec.md`
- Spec delta format must include sections like:
- `## ADDED|MODIFIED|REMOVED Requirements`
- At least one `#### Scenario:` per requirement (use the exact header text)

3) Validate and iterate
- `openspec validate <change-id> --strict`
- Fix any issues before requesting review/approval.

4) Implement after approval
- Follow the tasks in `tasks.md` sequentially and mark them complete.
- Use the patterns in `openspec/project.md`:
- For data access in handlers use `IApplicationDbContextFactory` and per-operation context lifetime:
- `await using var db = await _dbContextFactory.CreateAsync(cancellationToken);`
- Follow mediator pipeline behaviors, caching tags, and specification patterns.
- Mirror the Contacts module for a new entity's DTOs, commands, queries, specs, security, and UI pages/components.

5) Archive after deployment
- Move `openspec/changes/<id>/` to `openspec/changes/archive/YYYY-MM-DD-<id>/` (or use the CLI archive helper if available).
- Re-run `openspec validate --strict`.

### Example change scaffold

- Change id: `add-customer-management`
- Files:
- `openspec/changes/add-customer-management/proposal.md`
- `openspec/changes/add-customer-management/tasks.md`
- `openspec/changes/add-customer-management/specs/customers/spec.md`
## 📐 Using Superpowers for Design and Planning

`proposal.md` skeleton:
This repository recommends using the content under `docs/superpowers/` for design notes, implementation plans, and workflow guidance when a change needs more than a quick edit.

```
## Why
Introduce Customer management to track client records.

## What Changes
- Add Customer entity, CRUD flows, and pages
- Add permissions and navigation

## Impact
- Affected specs: customers
- Affected code: Domain, Application (Contacts-like), Infrastructure, Server.UI
```
### Recommended Workflow

`tasks.md` sample:
1. Explore the existing implementation first.
Review similar features in `src/Application/Features`, related UI pages in `src/Server.UI`, and the current setup instructions in `README.md`.
2. Write down design or planning notes when the task is non-trivial.
Store them under `docs/superpowers/specs/` or `docs/superpowers/plans/`.
3. Implement by following existing repository patterns.
Reuse the Contacts-style module structure, current pipeline behaviors, validation approach, and navigation conventions where applicable.
4. Verify the change before finishing.
Run the relevant build and test commands, then update documentation if setup or workflow steps changed.

```
## 1. Implementation
- [ ] 1.1 Domain entity + events
- [ ] 1.2 EF configuration + seeding
- [ ] 1.3 Application commands/queries/specs/security/caching
- [ ] 1.4 UI pages + dialog
- [ ] 1.5 Tests (unit/integration)
```

Spec delta snippet:

```
## ADDED Requirements
### Requirement: Manage Customers
The system SHALL allow users to create, edit, view, list, and delete customers with proper authorization.

#### Scenario: Create customer
- **WHEN** a user submits a valid form
- **THEN** the system saves the customer and returns an id
```
### Tips

Tips
- Use Contacts as the reference implementation for structure and conventions.
- Use existing modules as the reference implementation for structure and conventions.
- Add menu entries in `src/Server.UI/Services/Navigation/MenuService.cs`.
- Define permissions under `Permissions.<Module>` and they'll be picked up during seeding.
- Define permissions under `Permissions.<Module>` so they are included during seeding.
- For data access in handlers, prefer the current per-operation context lifetime patterns already used in the repository.

## 🔧 Code Generation

Expand Down
11 changes: 1 addition & 10 deletions docker-compose.dcproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
<DockerServiceName>dashboard</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.yml" />
<None Include="docker-compose.override.yml" />
<None Include=".dockerignore" />
<None Include="docs\Serilog-Configuration-Migration.md" />
</ItemGroup>
<ItemGroup>
<None Remove="launchSettings.json" />
</ItemGroup>
<ItemGroup>
<None Remove="src\**" />
<None Include=".github\copilot-instructions.md" />
</ItemGroup>
</Project>
8 changes: 2 additions & 6 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
version: '3.4'

services:
services:
dashboard:
environment:
- "ASPNETCORE_ENVIRONMENT=Development"
sqldb:
ports:
- "1433:1433"

Loading
Loading