Skip to content

Add C#/.NET architectural guardrails rule#291

Open
agenticstandardcontact-byte wants to merge 3 commits into
PatrickJS:mainfrom
agenticstandardcontact-byte:add-csharp-dotnet-architecture-rule
Open

Add C#/.NET architectural guardrails rule#291
agenticstandardcontact-byte wants to merge 3 commits into
PatrickJS:mainfrom
agenticstandardcontact-byte:add-csharp-dotnet-architecture-rule

Conversation

@agenticstandardcontact-byte
Copy link
Copy Markdown

@agenticstandardcontact-byte agenticstandardcontact-byte commented May 20, 2026

What this adds

  • New rule file: rules/csharp-dotnet-architecture.mdc
  • README entry in Backend and Full-Stack linking to the new file

Why

The current README has no dedicated C#/.NET entry under Backend and Full-Stack (Java/Spring, Rails, Laravel, FastAPI, NestJS are all represented, but not .NET). This contribution fills that gap with a scoped rule focused on the architectural concerns senior .NET developers actually want enforced by an AI pair.

What the rule does

Activates on **/*.cs, **/*.csproj, **/*.sln. Five operating principles:

  1. Respect layer boundaries ??? detects the project layer from the file path (Domain / Application / Infrastructure / Api) and refuses to suggest code that crosses it (e.g. blocks Microsoft.EntityFrameworkCore references in Domain, blocks raw IConfiguration reads in Application).
  2. Refuse Big-Ball-of-Mud shortcuts ??? specific concrete smells: HttpClient instantiated with new, captured DateTime.Now in domain code, async void outside event handlers, Task.Result/.Wait() in async paths, throw ex;.
  3. Honest uncertainty ("pause" protocol) ??? when the model doesn't know whether a service is Scoped or Singleton, it must ask one targeted question instead of inventing.
  4. Minimal, reversible diffs ??? discourages "while we're at it" mega-refactors; surfaces follow-up suggestions separately.
  5. .NET idioms short list ??? nullable reference types, record vs class, constructor injection, IOptions<T>, CancellationToken flow.

Frontmatter

Follows the format from CONTRIBUTING.md:

---
description: "C#/.NET architectural guardrails. Enforces layer boundaries (Onion/Clean/Hexagonal), pushes back on Big-Ball-of-Mud smells, and requires the model to pause and ask when context is missing rather than invent."
globs: **/*.cs, **/*.csproj, **/*.sln
alwaysApply: false
---

Attribution / licensing

Adapted from the open-source arch-core-lite.mdc which is MIT-licensed. The original is mine; the file in this PR has been edited for tone and to remove product chrome per the CONTRIBUTING guideline ("keep descriptions neutral, practical, and focused on reusable Cursor rule value").

Checklist

  • New rule file added under rules/ with required frontmatter
  • README updated under the matching category (Backend and Full-Stack)
  • Description is neutral and rule-focused
  • Globs scoped to relevant file types (not **/*)

Summary by CodeRabbit

  • Documentation
    • Added architectural guidelines and best practices for C# and .NET projects, defining layer boundaries, identifying code smells to avoid, and establishing standards for design patterns including nullability handling, dependency injection, configuration options, and async workflows.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new Cursor rule file that defines architectural guardrails and best practices for C# and .NET projects. The rule enforces layer separation, rejects common anti-patterns, requires explicit clarification when context is uncertain, and documents preferred .NET idioms and change practices.

Changes

C# and .NET Architectural Rule

Layer / File(s) Summary
Cursor rule for C# and .NET architecture
rules/csharp-dotnet-architecture.mdc
New rule file establishes guardrails for layer boundaries (Domain/Application/Infrastructure/Api), forbids infrastructure coupling and incorrect async patterns, enforces a pause-and-question protocol for uncertain decisions, and enumerates idiomatic .NET practices including nullability, constructor injection, options patterns, cancellation tokens, and record/class conventions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • PatrickJS

Poem

🐰 A rule hops into the rules directory so neat,
C# and .NET get guardrails complete,
Layer boundaries dance, anti-patterns take flight,
Architecture whispers, keeping things right! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a new C#/.NET architectural guardrails rule.
Description check ✅ Passed The description comprehensively addresses all template sections: it explains what is being added, the contribution type, value to users, files changed, and completes the quality checklist with relevant details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rules/csharp-dotnet-architecture.mdc`:
- Line 25: Update the rule that currently forbids "DateTime.Now" so it also
explicitly forbids "DateTime.UtcNow" (i.e., change the prohibition from
DateTime.Now to include DateTime.UtcNow) to match the anti-pattern section; edit
the line that lists forbidden APIs in the Domain rule (the entry containing
DateTime.Now) to add DateTime.UtcNow so both UTC and local DateTime access are
consistently disallowed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7b05aa41-9f85-4e7d-b41a-16a49ce993cc

📥 Commits

Reviewing files that changed from the base of the PR and between ae5dc7d and 5d49b8c.

📒 Files selected for processing (2)
  • README.md
  • rules/csharp-dotnet-architecture.mdc


Treat the codebase as a layered system (whatever flavour: Onion, Clean, Hexagonal, classic n-tier). **Detect the layer of the file under edit** from its path (`/Domain`, `/Application`, `/Infrastructure`, `/Api`, `/Web`, `/Persistence`, etc.). Then enforce:

- **Domain** never references `Microsoft.EntityFrameworkCore`, `HttpClient`, `IConfiguration`, `ILogger<T>`, `DateTime.Now`, `Environment.*`, or any concrete I/O.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Align DateTime prohibition with the anti-pattern section.

Line 25 forbids DateTime.Now but omits DateTime.UtcNow, while Line 40 bans both. Add DateTime.UtcNow here too so boundary checks stay consistent and don’t leave a loophole.

Suggested wording tweak
-- **Domain** never references `Microsoft.EntityFrameworkCore`, `HttpClient`, `IConfiguration`, `ILogger<T>`, `DateTime.Now`, `Environment.*`, or any concrete I/O.
+- **Domain** never references `Microsoft.EntityFrameworkCore`, `HttpClient`, `IConfiguration`, `ILogger<T>`, `DateTime.Now`, `DateTime.UtcNow`, `Environment.*`, or any concrete I/O.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rules/csharp-dotnet-architecture.mdc` at line 25, Update the rule that
currently forbids "DateTime.Now" so it also explicitly forbids "DateTime.UtcNow"
(i.e., change the prohibition from DateTime.Now to include DateTime.UtcNow) to
match the anti-pattern section; edit the line that lists forbidden APIs in the
Domain rule (the entry containing DateTime.Now) to add DateTime.UtcNow so both
UTC and local DateTime access are consistently disallowed.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants