|
| 1 | +--- |
| 2 | +authors: |
| 3 | + - Martin Stühmer (https://github.com/samtrion) |
| 4 | + |
| 5 | +applyTo: |
| 6 | + - "src/ForgingBlazor/**/*.cs" |
| 7 | + - "src/ForgingBlazor/**/*.razor" |
| 8 | + - "src/ForgingBlazor.Extensibility/**/*.cs" |
| 9 | + - "specs/routing.md" |
| 10 | + |
| 11 | +created: 2026-01-25 |
| 12 | + |
| 13 | +lastModified: 2026-01-25 |
| 14 | + |
| 15 | +state: accepted |
| 16 | + |
| 17 | +instructions: | |
| 18 | + ForgingBlazor uses content-based routing with compile-time segment discovery. |
| 19 | + MUST define all routes via ConfigureRouting<TApp, THome>() - no runtime discovery. |
| 20 | + MUST use ForgingRouter/ForgingRouteView instead of Blazor Router/RouteView. |
| 21 | + Template components MUST NOT contain @page or @layout directives. |
| 22 | + MUST use Static Assets caching in wwwroot with ExcludeFromCache() for dynamic content. |
| 23 | + MUST use TimeProvider via constructor injection for time-based operations. |
| 24 | + MUST use separate IAssetProvider for images/CSS (not in content folders). |
| 25 | + Route constraints: Blazor standard + alpha (slugs) + lang (culture with inheritance). |
| 26 | + Segment nesting: Soft limit 5 levels (warning), hard limit 8 levels (error). |
| 27 | +--- |
| 28 | + |
| 29 | +# Content-Based Routing Architecture |
| 30 | + |
| 31 | +This ADR documents the architectural decisions for ForgingBlazor's content-based routing system. |
| 32 | + |
| 33 | +## Context |
| 34 | + |
| 35 | +ForgingBlazor requires a routing mechanism that serves content from multiple storage providers (Physical FileSystem, Azure Blob Storage) while maintaining compatibility with Blazor's component model. |
| 36 | + |
| 37 | +Key requirements: |
| 38 | + |
| 39 | +- Support content-based routing from configurable storage providers |
| 40 | +- Enable content synchronization between local and cloud storage |
| 41 | +- Maintain Blazor compatibility for non-content routes |
| 42 | +- Support multi-language content with culture fallback |
| 43 | +- Provide efficient caching for static content |
| 44 | + |
| 45 | +## Decision |
| 46 | + |
| 47 | +### 1. Compile-Time Segment Discovery |
| 48 | + |
| 49 | +All routes MUST be explicitly defined via `ConfigureRouting<TApp, THome>()`. Runtime discovery from storage structure is not supported. |
| 50 | + |
| 51 | +**Rationale:** |
| 52 | + |
| 53 | +- Type safety: All routes validated at compile-time |
| 54 | +- Performance: No storage scanning at startup or runtime |
| 55 | +- Security: No unintended routes exposed |
| 56 | +- Predictability: Route structure explicit in code |
| 57 | + |
| 58 | +### 2. ForgingRouter and ForgingRouteView |
| 59 | + |
| 60 | +Custom router components replace Blazor's `Router` and `RouteView`: |
| 61 | + |
| 62 | +- `ForgingRouter`: Combines Blazor `@page` routes with ForgingBlazor content routes |
| 63 | +- `ForgingRouteView`: Provides content via `CascadingParameter<ResolvedContent<T>>` |
| 64 | + |
| 65 | +ForgingBlazor routes take precedence over `@page` routes for same paths. |
| 66 | + |
| 67 | +### 3. Template Component Restrictions |
| 68 | + |
| 69 | +Components used as `TPageTemplate` or `TSegmentTemplate` MUST NOT contain: |
| 70 | + |
| 71 | +- `@page` directive (routing managed by ForgingBlazor) |
| 72 | +- `@layout` directive (layout inherited through routing hierarchy) |
| 73 | + |
| 74 | +**Enforcement:** Roslyn Analyzer (warning) + Runtime validation (error). |
| 75 | + |
| 76 | +### 4. Route Constraints |
| 77 | + |
| 78 | +Blazor/ASP.NET Core standard constraints plus ForgingBlazor extensions: |
| 79 | + |
| 80 | +- `alpha`: URL-friendly slugs (`a-zA-Z0-9-`) |
| 81 | +- `lang`: Culture codes with automatic inheritance to nested elements |
| 82 | + |
| 83 | +### 5. Static Asset Caching |
| 84 | + |
| 85 | +Content is rendered to static HTML files in `wwwroot`. Web server serves files directly, bypassing application code. |
| 86 | + |
| 87 | +**Cache Invalidation Triggers:** |
| 88 | + |
| 89 | +- Content change: Remove specific static asset |
| 90 | +- Application restart: Clear all static assets |
| 91 | +- `ExcludeFromCache()`: Opt-out for dynamic content |
| 92 | + |
| 93 | +### 6. Segment Nesting Limits |
| 94 | + |
| 95 | +- Soft Limit: 5 levels (warning) |
| 96 | +- Hard Limit: 8 levels (error) |
| 97 | + |
| 98 | +### 7. Asset Management |
| 99 | + |
| 100 | +Assets managed via separate `IAssetProvider` interface with dedicated storage directory. Assets are NOT stored within content folders. |
| 101 | + |
| 102 | +### 8. TimeProvider Usage |
| 103 | + |
| 104 | +`TimeProvider` provided via constructor injection for all time-based operations (publish dates, expiry dates). |
| 105 | + |
| 106 | +### 9. Storage Provider Architecture |
| 107 | + |
| 108 | +- Core library (`ForgingBlazor`): Physical FileSystem provider + synchronization |
| 109 | +- Separate library (`ForgingBlazor.Providers.AzureBlob`): Azure Blob Storage provider |
| 110 | +- Synchronization uses fast-exit pattern (no-op for single provider) |
| 111 | + |
| 112 | +### 10. Culture Fallback Chain |
| 113 | + |
| 114 | +For requested culture `de-DE`: |
| 115 | + |
| 116 | +``` |
| 117 | +de-DE → de → en-US → en → (no suffix) |
| 118 | +``` |
| 119 | + |
| 120 | +## Consequences |
| 121 | + |
| 122 | +### Benefits |
| 123 | + |
| 124 | +| Benefit | Description | |
| 125 | +| ------------------------ | ----------------------------------------------------- | |
| 126 | +| **Type Safety** | Compile-time route validation | |
| 127 | +| **Performance** | Static file serving, no runtime content resolution | |
| 128 | +| **Blazor Compatibility** | Standard `@page` routes work alongside content routes | |
| 129 | +| **Flexibility** | Multiple storage providers, culture support | |
| 130 | +| **Testability** | TimeProvider injection enables time-based testing | |
| 131 | + |
| 132 | +### Trade-offs |
| 133 | + |
| 134 | +| Trade-off | Mitigation | |
| 135 | +| ------------------------------- | ------------------------------------------------------- | |
| 136 | +| **No Dynamic Segments** | Use parameterized pages (`{slug}`) for flexible content | |
| 137 | +| **Deployment for New Segments** | Redeploy application with updated segment definitions | |
| 138 | +| **Cache Staleness** | Application restart or explicit invalidation | |
| 139 | + |
| 140 | +### Risks |
| 141 | + |
| 142 | +| Risk | Mitigation | |
| 143 | +| ------------------ | -------------------------------------------------- | |
| 144 | +| **Disk Space** | Monitor `wwwroot` folder size in production | |
| 145 | +| **Layout Changes** | Application restart invalidates all cached content | |
| 146 | + |
| 147 | +## Alternatives Considered |
| 148 | + |
| 149 | +### Runtime Segment Discovery |
| 150 | + |
| 151 | +**Rejected:** Would compromise type safety, performance, and security. |
| 152 | + |
| 153 | +### In-Memory Caching |
| 154 | + |
| 155 | +**Rejected:** Static assets provide better performance and CDN compatibility. |
| 156 | + |
| 157 | +### Integrated Asset Storage |
| 158 | + |
| 159 | +**Rejected:** Separate storage enables CDN integration and independent asset management. |
| 160 | + |
| 161 | +### TimeProvider via Static Property |
| 162 | + |
| 163 | +**Rejected:** Constructor injection provides better testability and consistency. |
| 164 | + |
| 165 | +## Related Decisions |
| 166 | + |
| 167 | +- [DateTimeOffset and TimeProvider Usage](./2026-01-21-datetimeoffset-and-timeprovider-usage.md) - TimeProvider injection pattern |
| 168 | +- [Folder Structure and Naming Conventions](./2025-07-10-folder-structure-and-naming-conventions.md) - Project organization |
| 169 | +- [.NET 10 / C# 13 Adoption](./2025-07-11-dotnet-10-csharp-13-adoption.md) - Framework version |
| 170 | + |
| 171 | +## Related Specifications |
| 172 | + |
| 173 | +- [Routing Specification](../specs/routing.md) - Complete technical specification |
| 174 | +- [Layout Change Detection](../specs/layout-change-detection.md) - Future consideration |
| 175 | +- [Route Conflict Resolution](../specs/route-conflict-resolution.md) - Future consideration |
| 176 | +- [Content Authorization](../specs/content-authorization.md) - Future consideration |
| 177 | +- [Content SEO](../specs/content-seo.md) - Future consideration |
0 commit comments