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
2025-02-14 05:28:45 +08:00
│ ├── queryKeys.ts # Contains query key definitions for TanStack Query
│ └── [other].ts # Optional additional type files
2025-02-08 10:45:48 +08:00
```
## Rules and Guidelines
1. Each namespace MUST have:
- An `index.ts` file that exports all types
- An `interfaces.ts` file containing type definitions
2025-02-14 05:28:45 +08:00
- A `queryKeys.ts` file that defines query key options for TanStack Query
2025-02-08 10:45:48 +08:00
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`
2025-02-14 05:28:45 +08:00
3. Query Keys File (`queryKeys.ts`) Requirements:
- Defines reusable query keys and query options for TanStack React Query
- Uses `queryOptions` to create predefined query configurations
- Ensures consistent and structured key usage across API queries
- Example:
```typescript
import { queryOptions } from '@tanstack/react-query';
import type { BusterChat } from './chatInterfaces';
const chatsGetChat = (chatId: string) =>
queryOptions<BusterChat>({
2025-02-18 13:22:32 +08:00
queryKey: ['chats', chatId, 'get'] as const,
2025-02-14 05:28:45 +08:00
staleTime: 10 * 1000
});
```
4. Index File (`index.ts`) Requirements:
2025-02-08 10:45:48 +08:00
- Must re-export all types from `interfaces.ts`
- Should not contain any type definitions
- May include type utility functions if needed
2025-02-14 05:28:45 +08:00
5. General Guidelines:
2025-02-08 10:45:48 +08:00
- 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;
}
2025-02-14 05:28:45 +08:00
// queryKeys.ts
import { queryOptions } from '@tanstack/react-query';
import type { IApiResponse } from './interfaces';
const fetchDataQuery = (id: string) =>
queryOptions<IApiResponse<any>>({
queryKey: ['data', 'fetch', id] as const,
staleTime: 60 * 1000
});
2025-02-08 10:45:48 +08:00
// index.ts
export * from './interfaces';
2025-02-14 05:28:45 +08:00
export * from './queryKeys';
2025-02-08 10:45:48 +08:00
```
## Purpose
2025-02-14 05:28:45 +08:00
This directory serves as the single source of truth for API response types and query keys across the application. It ensures type safety, consistency, and provides proper TypeScript intellisense when working with API responses and queries.