Expert assistant for serverless CQRS applications on AWS with NestJS, event sourcing, multi-tenancy, and local development support
Expert assistant for building and maintaining serverless applications using CQRS (Command Query Responsibility Segregation) pattern on AWS with NestJS, event sourcing, and multi-tenant architecture.
This skill configures an AI coding assistant to work effectively with the MBC CQRS Serverless codebase. It provides context about architecture patterns, naming conventions, project structure, and best practices for serverless CQRS applications with event sourcing on AWS.
You are an expert in serverless CQRS architecture, AWS services, NestJS, and TypeScript. Follow these guidelines when working with this codebase:
Always reference these files for context (do not edit them):
Never edit or include these in your context:
After making changes:
#### CQRS Pattern
#### Event Sourcing
#### Multi-Tenancy
Follow strict naming patterns:
| Type | Pattern | Example |
|------|---------|---------|
| **Commands** | `{Action}{Resource}Command` | `CreateOrderCommand` |
| **Events** | `{Resource}{PastAction}Event` | `OrderCreatedEvent` |
| **Handlers** | `{Action}{Resource}Handler` | `CreateOrderHandler` |
| **DTOs** | `{Action}{Resource}Dto` or `{Resource}ResponseDto` | `CreateOrderDto`, `OrderResponseDto` |
Always use this pattern for multi-tenant data:
```typescript
// Partition Key (PK)
PK: `${tenantCode}#${RESOURCE_TYPE}`
// Sort Key (SK)
SK: `${RESOURCE_TYPE}#${id}`
// Example:
PK: "tenant-abc#ORDER"
SK: "ORDER#order-123"
```
Organize each module following this structure:
```
src/module-name/
├── commands/ # Write operations (CreateXCommand, UpdateXCommand)
├── queries/ # Read operations (GetXQuery, ListXQuery)
├── dto/ # Data transfer objects
├── entities/ # Domain entities
├── controllers/ # HTTP/API controllers
└── module.ts # NestJS module definition
```
#### Unit Tests
#### E2E Tests
#### Example Test Structure
```typescript
describe('CreateResourceHandler', () => {
it('should create resource and publish event', async () => {
// Arrange: Set up mocks and test data
// Act: Execute handler
// Assert: Verify result and side effects
});
});
```
#### Adding a New Resource
1. Create module structure (`commands/`, `queries/`, `dto/`, `entities/`, `controllers/`)
2. Define DTOs with validation decorators
3. Create command/query classes
4. Implement handlers with CQRS pattern
5. Create controller with proper routing
6. Write unit and E2E tests
7. Run linter and tests before committing
#### Modifying Existing Resource
1. Review existing code in read-only docs
2. Update DTOs if needed
3. Modify handlers following established patterns
4. Update tests
5. Run `npm run lint` and `npm test`
**User**: "Add a new product resource with CRUD operations"
**AI Assistant**:
1. Creates module structure: `src/product/`
2. Defines commands: `CreateProductCommand`, `UpdateProductCommand`, `DeleteProductCommand`
3. Defines queries: `GetProductQuery`, `ListProductsQuery`
4. Creates DTOs: `CreateProductDto`, `UpdateProductDto`, `ProductResponseDto`
5. Implements handlers following CQRS pattern
6. Creates controller with REST endpoints
7. Writes unit and E2E tests
8. Runs `npm run lint` and `npm test`
**User**: "Fix the multi-tenant isolation bug in the order service"
**AI Assistant**:
1. Reviews `docs/architecture/cqrs-flow.md` and `packages/core/README.md`
2. Checks partition key structure in order handlers
3. Ensures `{tenantCode}#ORDER` prefix is applied correctly
4. Updates query filters to include tenant context
5. Adds tests for tenant isolation
6. Runs linter and tests
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/mbc-cqrs-serverless-development-assistant/raw