This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
FastComponents is a .NET 9.0 Razor Class Library that enables building HTMX-powered web applications using Blazor components with server-side rendering. It provides type-safe C# properties for all HTMX attributes and integrates with ASP.NET Minimal APIs for endpoint routing.
The library simplifies building Multiple Resources Applications (MRA) by combining the component model of Blazor with the simplicity of HTMX, allowing developers to build dynamic web applications without writing JavaScript.
# Build the solution
dotnet build
# Build in Release mode
dotnet build --configuration Release
# Run all tests
dotnet test
# Run tests with coverage and generate HTML report
./coverage.sh
# Run specific test project
dotnet test tests/FastComponents.UnitTests/FastComponents.UnitTests.csproj
dotnet test tests/FastComponents.Generators.UnitTests/FastComponents.Generators.UnitTests.csproj
# Run a single test
dotnet test --filter "FullyQualifiedName~TestMethodName"
dotnet test --filter "DisplayName~TestMethodName"
# Pack NuGet package
dotnet pack --configuration Release
# Run the demo application
dotnet run --project demo/HtmxAppServer/HtmxAppServer.csproj
# Watch mode for development
dotnet watch --project demo/HtmxAppServer/HtmxAppServer.csproj
# Clean build artifacts
dotnet clean- HtmxComponentBase (
src/FastComponents/Components/Base/HtmxComponentBase.cs) - Base class providing HTMX attribute properties for all components - SimpleHtmxComponent (
src/FastComponents/Components/Base/SimpleHtmxComponent.cs) - Simplified base class with automatic route generation - ComponentHtmlResponseService (
src/FastComponents/Services/ComponentHtmlResponseService.cs) - Renders Blazor components as HTML responses for HTMX requests - HtmxComponentEndpoints (
src/FastComponents/Endpoints/HtmxComponentEndpoints.cs) - ASP.NET Minimal API integration for component routing - ClassNamesBuilder (
src/FastComponents/Components/Base/ClassNamesBuilder.cs) - Fluent API for building CSS class names - HtmxBuilder (
src/FastComponents/Builders/HtmxBuilder.cs) - Fluent builder for creating HTMX elements programmatically - FastComponents.Generators (
src/FastComponents.Generators/) - Source generators for parameter method generation
Components inherit from HtmxComponentBase to gain access to HTMX attributes:
- Core attributes: HxGet, HxPost, HxTrigger, HxTarget, HxSwap
- Additional attributes: HxConfirm, HxDisable, HxIndicator, etc.
- CSS classes: HxCssAdded, HxCssRequest, HxCssSwapping, etc.
The project follows an MRA pattern where:
- Server renders Blazor components as HTML
- HTMX handles dynamic updates without full page reloads
- ASP.NET Minimal APIs provide endpoints for component requests
FastComponents provides two API approaches:
-
Explicit Registration - Traditional approach with manual endpoint mapping:
app.MapHtmxGet<CounterComponent, CounterState>("/htmx/counter");
-
Convention-Based Registration - Automatic discovery and registration:
// In Program.cs builder.Services.AddFastComponentsAuto(); app.UseFastComponentsAuto();
Components are automatically discovered and mapped based on naming conventions:
CounterComponent→/htmx/counterMovieCharactersExample→/htmx/movie-characters- Routes are kebab-cased with common suffixes removed
The convention-based approach is implemented in ConventionBasedRegistration.cs and SimplifiedExtensions.cs.
- .NET 9.0 - Target framework
- AngleSharp 1.3.0 - HTML parsing and beautification
- HTMX - Client-side library for dynamic HTML (included in wwwroot)
The project enforces strict code analysis:
- All .NET analyzers enabled with "All" mode
- EditorConfig for consistent formatting
- XML documentation required for public APIs
- Reproducible builds enabled
The project uses xUnit for testing with comprehensive coverage:
- FastComponents.UnitTests - Main library unit tests covering all core components
- FastComponents.Generators.UnitTests - Source generator tests
- coverage.sh - Automated coverage script that generates HTML reports using ReportGenerator
Test files are organized by component and follow the pattern {ComponentName}Tests.cs. All public APIs have corresponding test coverage.
The demo/HtmxAppServer project demonstrates usage patterns:
- Component organization in
/Components/Blocks/ - Service registration in
Program.cs - HTMX route configuration in
HtmxRoutes.cs - Example components: Counter, MovieCharacters
The project uses MinVer for automatic versioning based on Git tags. Package is published to NuGet.org on GitHub release creation.
The project supports AOT (Ahead-Of-Time) compilation with the following considerations:
- The demo app has AOT enabled (
PublishAot=true) - The library is marked as AOT-compatible (
IsAotCompatible=true) - Component rendering and parameter binding use reflection, requiring
RequiresUnreferencedCodeandRequiresDynamicCodeattributes - AOT warnings are suppressed at the application level where HTMX endpoints are mapped