These instructions define how AI assistance (GitHub Copilot / Chat) must collaborate on this repository. All generated code must reflect these standards. Deviation requires explicit human approval.
MoMo.Net is a .NET 10 LTS (latest available LTS) class library delivering:
- A themable design system (design tokens + semantic theming)
- A suite of Blazor-compatible UI controls (server + WebAssembly targets)
- High accessibility (WCAG 2.1 AA) and performance focus
If .NET 10 is not yet GA locally, use the newest installed LTS (verify via "C:\Program Files\dotnet\dotnet.exe" --info) but keep code forward-compatible with .NET 10 (no obsolete APIs knowingly introduced).
- SOLID strictly applied (Single Responsibility; Open for extension/Closed for modification; Liskov; Interface Segregation; Dependency Inversion)
- CLEAN architecture layering:
- Domain: design tokens, theme contracts, core abstractions
- Application: services orchestrating theme resolution, component state logic
- Interface (UI): Razor components, rendering adapters
- Infrastructure: persistence (if later), configuration providers, resource loaders
- DRY: Reuse via small internal building blocks and extension methods; avoid copy-paste duplication.
- Prefer composition over inheritance for component behaviors.
- Public API surface must be minimal, intentional, and documented.
src/
MoMo.Net/ -> Root library (core tokens, theming engine)
Theming/ -> Theme manager, palette builders
Tokens/ -> Design token definitions (color, spacing, typography)
Components/ -> Base component abstractions (non-UI)
Extensions/ -> Helpful extension methods (guard clauses, etc.)
MoMo.Net.Blazor/ -> Blazor components (Razor + partial C# classes)
Components/ -> Individual UI controls (Button, Card, Modal, etc.)
Styling/ -> CSS / SCSS (or generated classes) + design token mapping
Rendering/ -> Render fragments, wrappers, A11y helpers
tests/
MoMo.Net.Tests/ -> Unit tests for core library (xUnit)
MoMo.Net.Blazor.Tests/ -> Component tests (bUnit + xUnit)
docs/ -> Architecture, design system reference
build/ -> CI/CD scripts, packaging specs
Namespaces should mirror folders exactly. Avoid generic names like Utils; be explicit (ThemeResolution, ColorContrast).
- Tokens are immutable value objects (e.g.,
ColorToken,SpacingToken). - Themes are compositions of token sets with semantic roles (e.g.,
PrimaryBackground,AccentText). - Provide a layered resolution order: User Theme > App Default > Fallback.
- Runtime theme switching should be supported without full page reload (Blazor cascading values + event callbacks).
- Support dark/light base themes; extendable via custom palettes.
- Each component => Razor file (
.razor) + code-behind partial class (.razor.cs). - Parameters must be validated (null checks, range checks) in
OnParametersSetor earlier. - Avoid logic inside Razor markup: move to the code-behind.
- Expose events via
EventCallback(EventCallback<T>preferred for strongly typed data). - A11y: Always include appropriate ARIA attributes and keyboard interaction patterns (e.g., Space/Enter activation).
- CSS class generation centralized (no scattered string concatenation). Provide helper service.
Every feature follows Red → Green → Refactor:
- Write failing test (unit or component).
- Implement minimal code to pass.
- Refactor safely (tests remain green).
Testing stack:
- xUnit for unit tests (use built-in
Assertmethods only). - bUnit for Blazor component tests.
- Optional: Verify library-level contracts with snapshot tests (only if stable and reviewed; avoid flaky snapshots).
PROHIBITED in tests:
- FluentAssertions or any third-party assertion libraries. Use xUnit's built-in
Assertclass exclusively. - Sleeping / timing hacks.
- Reliance on external network or file system (unless explicitly added infra layer with abstractions + test doubles).
Coverage goals:
- Core theming & token logic: ~100% statement/branch.
- Component rendering paths: high coverage of branches & states.
- Public API methods: must have at least one direct test.
- C# latest language features allowed if supported by target LTS.
- Use explicit types (avoid
varexcept when RHS is obvious or anonymous). - No magic strings/numbers: centralize in constants or enums.
- Guard clauses at method entry; fail fast with specific exceptions.
- Favor small pure functions over large procedural methods.
- Asynchronous code: use
async/awaitend-to-end; avoid fire-and-forget unless encapsulated + documented. - Nullability: enable
<Nullable>enable</Nullable>; avoid!suppressions. - Logging (if introduced later): structured, no string interpolation for dynamic fields.
- Document all public types/members with XML docs (summary + param + returns + remarks if non-trivial).
- Keep surface area lean; internalize helpers.
- Breaking changes require: (a) justification comment in PR, (b) version bump following SemVer.
- Semantic Versioning: MAJOR.MINOR.PATCH.
- Start at
0.xuntil first stable milestone; move to1.0.0after API review. - Include SourceLink + deterministic builds.
- Provide README + icon + license metadata in
.csproj.
Path Rule (Cross-Platform):
- Commands available on the system
PATH(e.g.,dotnet,git,pwsh,bash,nuget) MAY be invoked directly without full executable path. - All repository-relative references (solution, project directories, output paths) MUST use fully qualified absolute paths appropriate to the current OS (Windows:
C:\ws\MoMo.Net\src\MoMo.Net; Linux/macOS:/home/dev/ws/MoMo.Net/src/MoMo.Net). - Do not rely on implicit working directory; always specify paths explicitly in examples, scripts, and documentation.
Examples (Windows + Linux):
dotnet new classlib --name MoMo.Net --framework net10.0 --output "C:\ws\MoMo.Net\src\MoMo.Net"
dotnet new classlib --name MoMo.Net --framework net10.0 --output /home/dev/ws/MoMo.Net/src/MoMo.Net
Executable fully qualified (optional, for deterministic CI):
"C:\Program Files\dotnet\dotnet.exe" build "C:\ws\MoMo.Net\src\MoMo.Net" /warnaserror
/usr/share/dotnet/dotnet build /home/dev/ws/MoMo.Net/src/MoMo.Net /warnaserror
Preferred default: use short form (dotnet) unless multiple SDK paths or isolation is required (CI, container, version pinning scenarios).
Scaffold commands:
dotnet new classlib --name MoMo.Net --framework net10.0 --output "C:\ws\MoMo.Net\src\MoMo.Net"
dotnet new razorclasslib --name MoMo.Net.Blazor --framework net10.0 --output "C:\ws\MoMo.Net\src\MoMo.Net.Blazor" --support-pages-and-views false
dotnet new xunit --name MoMo.Net.Tests --framework net10.0 --output "C:\ws\MoMo.Net\tests\MoMo.Net.Tests"
dotnet new xunit --name MoMo.Net.Blazor.Tests --framework net10.0 --output "C:\ws\MoMo.Net\tests\MoMo.Net.Blazor.Tests"
dotnet new classlib --name MoMo.Net --framework net10.0 --output /home/dev/ws/MoMo.Net/src/MoMo.Net
dotnet new razorclasslib --name MoMo.Net.Blazor --framework net10.0 --output /home/dev/ws/MoMo.Net/src/MoMo.Net.Blazor --support-pages-and-views false
dotnet new xunit --name MoMo.Net.Tests --framework net10.0 --output /home/dev/ws/MoMo.Net/tests/MoMo.Net.Tests
dotnet new xunit --name MoMo.Net.Blazor.Tests --framework net10.0 --output /home/dev/ws/MoMo.Net/tests/MoMo.Net.Blazor.Tests
If net10.0 not recognized, temporarily use latest LTS (e.g., net8.0) but keep this file unchanged—upgrade upon .NET 10 availability.
Use the dotnet CLI (package manager) with fully qualified path:
"C:\Program Files\dotnet\dotnet.exe" add "C:\ws\MoMo.Net\tests\MoMo.Net.Blazor.Tests" package bunit
Do NOT pin versions unless:
- A regression exists in latest.
- A preview feature required and stability proven. When pinning, justify in PR description.
- Keep external dependencies minimal (prefer core BCL & internal abstractions).
- Evaluate footprint on Blazor WebAssembly (bundle size) before adding packages.
- Wrap dependencies behind interfaces for testability (Dependency Inversion).
- Before duplicating logic, extract to: (a) private method, (b) internal service, (c) extension method.
- Periodically run architectural review (e.g., after each minor version) to consolidate patterns.
- Avoid unnecessary re-renders: use
ShouldRenderoverrides when beneficial. - Precompute static token mappings.
- Ensure color contrast >= WCAG AA; provide utility to validate contrast in tests.
- No dynamic
RenderFragmentinjection from untrusted sources without sanitization. - Avoid reflection unless absolutely necessary; if used, justify.
- Use safe encoding for any HTML injection points.
- Build: restore, build, test, pack.
- Fail build if coverage below threshold (to be defined, e.g., 85%).
- Publish via
dotnet pack+dotnet nuget push(scripted with fully qualified path).
- Conventional Commits:
feat:,fix:,refactor:,test:,docs:,chore:. - PR must include: Purpose, Design Notes, Test Coverage Summary, Potential Follow-ups.
- Include screenshots or HTML diff for visual changes (once UI exists).
- Always respect these instructions before suggesting code.
- For multi-step tasks: propose plan → implement iteratively.
- Never introduce a dependency solely to reduce a few lines of code unless justified (perf, security, maintainability).
- Model name disclosure only if user explicitly asks (reply: using GPT-5).
- Provide minimal unrelated commentary—focus on actionable changes.
- Never output license headers unless explicitly requested.
- Tests: All new code covered & pass.
- SOLID: No class with >1 responsibility.
- DRY: No copy-paste duplication in diff.
- Public API: Intentional & documented.
- Exceptions: Specific and meaningful messages.
- Dependencies: Justified in PR.
- Accessibility: ARIA roles/states appropriate.
- Write bUnit test: expect default button renders primary style.
- Run tests (fail).
- Implement minimal markup & style mapping.
- Re-run tests (pass).
- Refactor: extract style resolver service.
- Add secondary variant test.
- Add theme editor tooling.
- Provide CSS variable generation pipeline.
- Integrate color contrast auto-fix suggestions.
This file governs all AI-assisted contributions. Update only via reviewed PRs.