Cursor: Rules for AI Code Editor

January 15th, 2025 823 Words

The Cursor AI Code Editor is my default editor these days for writing code. As with other code companions, Cursor offers a chat-like interface to interact with your codebase and their AI services. More important, Cursor supports project-specific customizations; using a file in your project root.

Cursor AI Code Editor: Settings

You need to create a .cursorrules file on the root level of your project and enable the setting in the Cursor settings. The file is a simple plain text file which is picked up by Cursor if the setting is enabled. I use this file, to define basic Core Principles for my project. Additionally, I add specific rules for frameworks, libraries, or other relevant usage information.

# AI Assistant Instructions

When processing these requirements, the AI assistant must:

1. Enforce all standards in code suggestions and recommendations
2. Proactively identify any deviations from these guidelines
3. Provide clear explanations for architectural decisions with references to specific sections
4. Consider security, scalability, and maintainability in all suggestions
5. Validate code against the quality requirements defined herein

# Architectural Foundations

Solutions must align with:

- Domain-Driven Design (DDD) principles
- Twelve-Factor App methodology
- AWS cloud-native architecture
- Controlled vendor lock-in strategy
- Serverless-first approach

## Required Knowledge Domains

Solutions must demonstrate understanding of:

- Team Topologies for organizational design
- Wardley Mapping for strategic planning
- Conway's Law implications
- SOLID principles
- Single Source of Truth
- Bounded Contexts
- Command Query Responsibility Segregation
- Systems Thinking
- Organizational Theory

In addition to this baseline of rules, I add specific rules for frameworks, libraries, or other relevant usage information. Also, providing guidelines for the decision framework is a great way to fine-tune your code results:

## Decision Framework

When evaluating implementation choices, consider:

1. Security Impact:

   - Data protection requirements
   - Authentication/authorization implications
   - Compliance requirements

2. Operational Excellence:

   - Monitoring capabilities
   - Deployment complexity
   - Maintenance overhead

3. Cost Optimization:

   - Resource utilization
   - Scaling characteristics
   - Service selection trade-offs

4. Performance Efficiency:
   - Response time targets
   - Resource constraints
   - Scaling thresholds

Frontend Architecture

When writing frontend code, I primarly rely React and TypeScript. The Ant Design works great with styled-components; for API architecture, I use AWS Amplify and Apollo Client most of the time. All this can be added to the .cursorrules file:

## Frontend Architecture

### Core Technologies:

- React with TypeScript
- styled-components for styling
- Ant Design v6 component library
- AWS Amplify for authentication
- Apollo Client for GraphQL integration

### Required Libraries:

- AWS SDK v3
- Apollo Client (Amplify-based)
- ApolloProvider
- GraphQL query language (gql)

CDK and AWS Infrastructure

Of course, I use AWS Cloud Development Kit (CDK) for creating AWS infrastructure:

## Infrastructure Requirements

Infrastructure as Code must use AWS CDK with TypeScript and follow these standards:

### CDK Implementation:

- Use `aws-cdk-lib` with explicit `aws_*` prefixes
- Implement custom constructs for reusable patterns
- Separate concerns into distinct CloudFormation stacks
- Organise resources by functional groups: storage, compute, authentication, API, access

### Resource Configuration:

Follow AWS Well-Architected Framework principles.

- Lambda: TypeScript implementation on ARM64 architecture
- Authentication: Cognito with OAuth2 and OIDC support
- API: API Gateway with Cognito/IAM authentication
- GraphQL: AppSync with function resolvers, avoid VTL templates
- Workflow: Step Functions for orchestration
- Security: Custom KMS keys and encryption-at-rest
- Observability: Comprehensive logging, metrics, and tracing

### Data Management Standards

- Use DynamoDB as primary data store
- Use expression attributes for reserved words
- Implement pagination with nextToken
- Define explicit partition/sort key strategies

### API Standards:

- Use GraphQL through AppSync
- Use function resolvers exclusively
- Maintain consistent error handling
- Document all schema changes

Local Project Structure

Sometimes, Cursor adds files to the project on weird locations, so I can just add rules about where to put files:

├── aws/
│ ├── constructs/ # CDK custom constructs
│ ├── stacks/ # CloudFormation stack definitions
│ ├── functions/ # Lambda function implementations
│ ├── utils/ # AWS utility functions
│ └── resolvers/ # AppSync resolver implementations
├── src/
│ ├── components/ # React component library
│ ├── hooks/ # Custom React hooks
│ └── utils/ # Frontend utilities
├── config/
│ └── schema.graphql # GraphQL schema definition
└── test/
│ ├─ aws/ # Infrastructure tests
│ └── src/ # Frontend tests

After applying these rules, Cursor rarely places files in incorrect locations.

Language and Style

As mentioned, most of the time I write in TypeScript. I use Prettier on ESLint for formatting:

## Quality Requirements

All code must:

- Maintain strict TypeScript typing with explicit return types
- Pass ESLint with project configuration
- Include comprehensive error handling

Testing

If you care about writing tests for your application, let Cursor know:

## Testing

- Jest for unit testing
- Supertest for API testing
- React Testing Library for component testing
- AWS mocks for cloud resource testing

Especially configuring AWS mocks is way more comfortable with these rules!


  • Deploy Serverless Containers to Scaleway with OpenTofu

    December 5 th, 2025 721 Words

    After building multiarch Docker containers for Rust applications, you want to deploy them somewhere. Scaleway’s serverless container platform offers a straightforward way to run containers without managing infrastructure, and OpenTofu provides the infrastructure-as-code tooling. This guide walks through deploying Docker containers to Scaleway using the OpenTofu provider, from setting up the registry to running your container.

  • Multiarch Docker Containers with Rust

    December 5 th, 2025 395 Words

    This guide shows how to build multiarch Docker containers for Rust applications using cargo zigbuild for cross-compilation and Docker build commands for architecture-specific or multiarch container images. Based on the example for Building a Rust API with Rocket and JWT Authentication, this guide provides the next steps.

  • Building a Rust API with Rocket and JWT Authentication

    December 5 th, 2025 1868 Words

    When building backend APIs, JWT authentication is a common requirement. In Rust, you’ve got several web frameworks to choose from, and Rocket is one that makes request handling feel natural with its request guard system. Combining Rocket with JWTiny for JWT validation and JWKServe as a local identity provider gives you a complete setup for development and testing without external dependencies.

  • JWTiny: Minimal JWT Validation for Rust

    December 4 th, 2025 1340 Words

    I was learning Rust with an example project that needed JWT validation. The popular jsonwebtoken crate depends on serde, but I wanted miniserde instead. That constraint led me to build my own validator — handling signature verification, claims validation, and remote key fetching, designed for reuse across requests. JWTiny is the result.

  • JWKServe: A Fake JWT Authentication Service for Local Development

    December 4 th, 2025 990 Words

    When writing backend services that validate JWT access tokens, you run into a frustrating problem: you need a real identity provider just to test your authentication logic. With Cognito, Auth0, or other OpenID Connect providers, spinning up an authentication service for local development or CI pipelines adds unnecessary complexity. You need valid signatures and correct claims, not the provider itself. That’s where JWKServe comes in.

  • Static Website Hosting in Europe with Free Services

    June 10 th, 2025 303 Words

    The AWS European Sovereign Cloud is maybe the most interesting developments of the current cloud computing era; having AWS create a dedicated branch for european workloads is the next big move. But, how do you run a static website without using US vendors at all?

  • AWS CDK: Serverless WebService Blueprints

    January 19 th, 2025 113 Words

    The past days have been full of content about serverless workloads with AWS AppSync, Amazon Cognito, and AWS Fargate. This guide wraps up all scenarios and is your starting point if you want to build modern serverless applications with AWS using the Cloud Development Kit (CDK).