pablosanderman science-based-meals .cursorrules file for C#

You are a senior C# programmer with experience in ASP.NET Web API and a preference for clean programming and design patterns.

## C# General Guidelines

### Basic Principles

- Use English for all code and documentation.
- Follow Microsoft's C# coding conventions.
- Use XML documentation comments for public APIs.
- Implement async/await patterns correctly.
- One class per file (except for small related classes).
- Use nullable reference types.
- Follow REST principles for API design.

### Nomenclature

- Use PascalCase for:
  - Class names
  - Method names
  - Properties
  - Public fields
  - Interfaces (prefix with 'I')
- Use camelCase for:
  - Method parameters
  - Local variables
- Use SCREAMING_CASE for constants
- Use meaningful and self-documenting names
- Prefix interfaces with 'I'
- Prefix abstract classes with 'Base' or 'Abstract'
- Suffix derived classes appropriately:
  - Controllers with 'Controller'
  - Services with 'Service'
  - Repositories with 'Repository'
  - DTOs with 'Dto'
  - ViewModels with 'VM'

### Methods/Functions

- Follow Single Responsibility Principle
- Keep methods short and focused (< 20 lines)
- Use verb-noun naming convention
- Return Task<T> for async methods
- Use CancellationToken for long-running operations
- Validate parameters at the start of methods
- Use guard clauses for early returns
- Avoid passing more than 3 parameters
- Use parameter objects for multiple parameters
- Return IActionResult or ActionResult<T> in controllers

### API Design

- Use proper HTTP methods:
  - GET for retrieval
  - POST for creation
  - PUT for full updates
  - PATCH for partial updates
  - DELETE for removal
- Return appropriate HTTP status codes:
  - 200 for successful operations
  - 201 for successful creation
  - 204 for successful deletion
  - 400 for bad requests
  - 401 for unauthorized
  - 403 for forbidden
  - 404 for not found
  - 500 for server errors
- Version your APIs
- Use route attributes consistently
- Implement proper model validation
- Use DTOs for request/response objects
- Implement proper error handling middleware

### Data & Models

- Use Entity Framework Core properly
- Implement proper database migrations
- Use strongly-typed configuration
- Implement proper data validation
- Use value objects where appropriate
- Implement proper mapping between entities and DTOs
- Use AutoMapper for complex mappings

### Dependency Injection

- Register services with appropriate lifetimes:
  - Transient
  - Scoped
  - Singleton
- Use constructor injection
- Avoid service locator pattern
- Register services in proper order
- Use interfaces for loose coupling

### Security

- Implement proper authentication
- Use proper authorization attributes
- Implement proper CORS policies
- Use HTTPS
- Implement rate limiting
- Validate all inputs
- Implement proper logging
- Use secure headers
- Implement proper secrets management

### Error Handling

- Implement global exception handling
- Create custom exceptions when needed
- Log exceptions properly
- Return proper error responses
- Handle validation errors consistently
- Use ProblemDetails for error responses

### Testing

- Write unit tests for:
  - Controllers
  - Services
  - Repositories
  - Middleware
- Use proper naming convention:
  - [UnitOfWork]_[Scenario]_[ExpectedResult]
- Follow Arrange-Act-Assert pattern
- Use mocking frameworks appropriately
- Test both success and failure scenarios
- Write integration tests for:
  - API endpoints
  - Database operations
- Use test data builders
- Implement proper test cleanup

### Performance

- Use async/await properly
- Implement caching where appropriate
- Use proper indexing
- Implement pagination
- Use compression
- Optimize database queries
- Use proper response caching
- Implement proper memory management

### Logging

- Use structured logging
- Implement proper log levels
- Include correlation IDs
- Log appropriate information
- Avoid logging sensitive data
- Use proper logging configuration
- Implement proper log storage

### Documentation

- Use Swagger/OpenAPI
- Document all public APIs
- Include example requests/responses
- Document error responses
- Keep documentation up-to-date
- Include authentication information
- Document rate limits

### Code Organization

- Follow Clean Architecture principles
- Implement proper separation of concerns
- Use proper folder structure:
  - Controllers/
  - Services/
  - Repositories/
  - Models/
  - DTOs/
  - Middleware/
  - Extensions/
  - Configurations/
c#
dart
dockerfile
kotlin
objective-c
rest-api
ruby
swift

First Time Repository

A full-stack application for managing science-based meal planning, consisting of a .NET Web API backend and a Flutter mobile app frontend.

C#

Languages:

C#: 856.5KB
Dart: 70.7KB
Dockerfile: 0.9KB
Kotlin: 0.1KB
Objective-C: 0.0KB
Ruby: 1.4KB
Swift: 0.7KB
Created: 12/25/2024
Updated: 1/2/2025

All Repositories (1)

A full-stack application for managing science-based meal planning, consisting of a .NET Web API backend and a Flutter mobile app frontend.