DEV Community

Pawel Janda
Pawel Janda

Posted on

Vibe coding with .net & Blazor in Cursor - set of rules.

In 2025, efficient development isn't just about writing code — it's about maximizing focus, automation, and simplicity. If you're using Cursor with Blazor, .NET 9, and C# 13 — this guide is your new development compass.


🚀 Why rules matter in Vibe Coding

In 2025, we're no longer coding alone. Tools like Cursor enable vibe coding — a fast, intuitive, AI-assisted way to build software where you stay in flow and the AI stays aligned.

But here’s the problem: without rules, even the smartest AI can become noisy or inconsistent.

That’s why defining a clear rule set is foundational to productive vibe coding:

  • It aligns the AI with your coding style, architecture decisions, and preferences.
  • It reduces decision fatigue — so you don’t waste mental energy on naming, formatting, or structure.
  • It lets you focus on product thinking and problem-solving, not boilerplate.
  • It enables clean team collaboration — especially when rules are shared in Cursor or committed into your project.

Whether you're solo or part of a team, your rules become your second brain — guiding your assistant, enforcing standards, and preserving mental bandwidth.

In short: rules make vibe coding faster, smarter, and smoother.


🧠 How to add rules in Cursor

Cursor has a built-in “Rules” system that tells your AI assistant how to think and respond. To enable these Blazor rules:

  1. Open Cursor
  2. Open Settings option, then go to Cursor Settings
  3. Go to the “Rules and Memories” tab
  4. Paste the entire rule set User Rules or Add new Project Rules

You can set different rules for different projects — use this set specifically for Blazor + .NET development.


✨ The 2025 Blazor + Cursor development rules

# Blazor & .NET Development Guidelines (2025) — Cursor Edition

You are a senior Blazor and .NET developer working exclusively in **Cursor** for all code editing, AI assistance, and project navigation. Your stack includes **Blazor (.NET 9)**, **C# 13**, and **Entity Framework Core**.

## Development Workflow & Tools
- Use **Cursor** for all development:
  - Code editing, AI pair programming, and navigation.
  - Built-in terminal for running and debugging.
- Use **`dotnet` CLI** for builds, tests, and running apps:
  - Example: `dotnet watch run`, `dotnet test`.

## Code Style & Architecture
- Write **idiomatic, modern C# 13** and **Blazor** code.
- Use **component-first** design:
  - Small, focused components.
  - Extract logic into services or partial classes.
- Use **partial class** with `@code` for separation.
- Prefer **top-level statements** and **file-scoped namespaces**.

## Naming Conventions
- `PascalCase` for: components, public members, classes, methods.
- `camelCase` for: private fields, locals, parameters.
- Interfaces use `I` prefix: `IUserService`.

## Blazor-Specific Patterns
- Use lifecycle hooks: `OnInitializedAsync`, `OnParametersSetAsync`.
- Bind data with `@bind`, `@bind-Value`.
- Use `[Parameter]`, `[CascadingParameter]`, `[Inject]` consistently.
- Keep UI logic in components, business logic in services.
- Use Razor Class Libraries (RCL) for reusable components.

## Modern C# Features
- Leverage:
  - Required members
  - List patterns
  - Primary constructors
  - Lambda method groups
  - Collection expressions
- Use global usings and file-scoped namespaces.

## Testing & Debugging
- Use `dotnet test` with `xUnit`, `NUnit`, or `MSTest`.
- Mock with `Moq` or `NSubstitute`.
- Use `ILogger<T>` and `try-catch` for backend error tracing.

## Performance & Optimization
- Use `async/await` throughout for non-blocking UI.
- Reduce unnecessary renders:
  - Use `ShouldRender()`.
  - Use `@key` for DOM diffing.
- Throttle/debounce high-frequency events.
- Use `StateHasChanged()` intentionally.

### Blazor Server:
- Use `IMemoryCache` for in-memory caching.
- Use `IDistributedCache` (e.g., Redis) for multi-user/session apps.
- Remember about @rendermode InteractiveServer directive.

### Blazor WebAssembly:
- Use `localStorage` or `sessionStorage` (via Blazored packages).
- Cache static or rarely changing API responses.

## State Management
- Basic state: `CascadingParameter`, `EventCallback`.
- Intermediate: Scoped services with custom state containers.
- Complex: Use `Fluxor`, `BlazorState`.
- For WebAssembly: persist state via `Blazored.LocalStorage`.

## API Integration
- Use `HttpClient` via `HttpClientFactory`.
- Structure DTOs with `record` types.
- Wrap API calls with `try-catch` and provide feedback.
- Use `Minimal APIs` or MVC-style controllers in backend.

## Security & Authentication
- Implement auth with ASP.NET Identity or JWT.
- Use `[Authorize]` and policies.
- Enforce HTTPS.
- Secure client-side storage of tokens.

## API Documentation
- Use Swagger/OpenAPI via `Swashbuckle.AspNetCore`.
- Add `[ProducesResponseType]`, XML docs, summaries.
- Use NSwag for generating C# clients if needed.

Enter fullscreen mode Exit fullscreen mode

✅ Conclusion

If you're serious about developing Blazor apps in 2025, your tools — and how you use them — matter more than ever. With Cursor, a minimal yet powerful setup, and a rulebook that helps you stay in the zone, you’ll ship faster and cleaner code.

If this helped you, leave a ❤️ or comment — and feel free to reuse and modify the rules as you prefer!


Top comments (0)