Skip to content

Add C#/.NET architectural guardrails rule#291

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

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

Conversation

@agenticstandardcontact-byte

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

Copy link
Copy Markdown

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 C#/.NET architectural guardrails covering layer boundaries (Domain/Application/Infrastructure/API), common “Big Ball of Mud” smells to avoid, and recommended .NET idioms (nullability, constructor injection, options pattern, cancellation-token flow).
    • Updated the README to include and link the new C#/.NET architecture rules, with an explicit pause-and-ask protocol when context is insufficient.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f72a4be-0eb4-4f5b-b064-29f81ca41bd9

📥 Commits

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

📒 Files selected for processing (2)
  • README.md
  • rules/csharp-dotnet-architecture.mdc
💤 Files with no reviewable changes (1)
  • README.md
✅ Files skipped from review due to trivial changes (1)
  • rules/csharp-dotnet-architecture.mdc

📝 Walkthrough

Walkthrough

This PR adds a new Cursor rule for C# and .NET architectural guardrails and adds a README entry linking to it from the backend and full-stack rules list.

Changes

C# and .NET Architectural Rule

Layer / File(s) Summary
Cursor rule and README entry
rules/csharp-dotnet-architecture.mdc, README.md
Adds the C#/.NET rule frontmatter, architectural boundary and anti-pattern guidance, pause-and-ask protocol, .NET idioms, attribution, and a README link to the new rule.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • PatrickJS

Poem

🐰 I hopped through rules with architectural cheer,
C# and .NET now have guardrails near.
A README crumb, a rule file bright,
Keeps layers tidy and hops just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly names the new C#/.NET architectural guardrails rule added by the PR.
Description check ✅ Passed The PR includes a detailed summary, rationale, rule behavior, frontmatter, attribution, and checklist, covering the template's main requirements.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

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.

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

Comment thread rules/csharp-dotnet-architecture.mdc Outdated
saccoman1974 and others added 2 commits May 21, 2026 22:03
Co-authored-by: Cursor <cursoragent@cursor.com>
Rebase onto current main to clear README conflict (UTF-8), add self-repo
Backend listing for rules/csharp-dotnet-architecture.mdc, and align Domain
layer rule with DateTime.UtcNow prohibition (CodeRabbit).

Co-authored-by: Cursor <cursoragent@cursor.com>
@agenticstandardcontact-byte

agenticstandardcontact-byte commented Jun 25, 2026

Copy link
Copy Markdown
Author

All pull_request_target checks are passing after rebasing onto current main and resolving the README conflict.

awesome-lint and test show as skipped on that event (by design in main.yml). Could you approve the fork workflow run so the separate pull_request jobs can execute?

Happy to adjust anything else you need. Thanks.

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