buster/web/.cursor/rules/api_buster_asset_rules.mdc

64 lines
2.1 KiB
Plaintext
Raw Normal View History

2025-02-08 10:45:48 +08:00
---
description: Rules and guidelines for the asset_interfaces directory containing TypeScript interface definitions for all API responses
globs: src/api/asset_interfaces/**/*
---
# API Asset Interfaces Directory Rules
This directory (`src/api/asset_interfaces`) contains TypeScript interface definitions for all API responses. Each subdirectory represents a distinct API namespace.
## Directory Structure
```
src/api/asset_interfaces/
├── [namespace]/
│ ├── index.ts # Exports all interfaces and types
│ ├── interfaces.ts # Contains type definitions
│ └── [other].ts # Optional additional type files
```
## Rules and Guidelines
1. Each namespace MUST have:
- An `index.ts` file that exports all types
- An `interfaces.ts` file containing type definitions
2. Interface File (`interfaces.ts`) Requirements:
- Must contain TypeScript interfaces, types, and enums for API responses
- All types must be properly documented with JSDoc comments
- Use strict typing (no `any` types unless absolutely necessary)
- Prefer readonly properties where applicable
- Use proper naming conventions:
- Interfaces: `IPascalCase`
- Types: `TPascalCase`
- Enums: `EPascalCase`
3. Index File (`index.ts`) Requirements:
- Must re-export all types from `interfaces.ts`
- Should not contain any type definitions
- May include type utility functions if needed
4. General Guidelines:
- Keep interfaces focused and single-responsibility
- Use TypeScript's built-in utility types when appropriate
- Document breaking changes in type definitions
- Use discriminated unions for response types that can vary
- Avoid circular dependencies between namespaces
## Example
```typescript
// interfaces.ts
export interface IApiResponse<T> {
readonly data: T;
readonly status: number;
readonly message?: string;
}
// index.ts
export * from './interfaces';
```
## Purpose
This directory serves as the single source of truth for API response types across the application. It ensures type safety and provides proper TypeScript intellisense when working with API responses.