Cursor rule
.cursor/rules/data-access-via-api.mdcGuidelines for Data Access Layer via API
Cursor rules
Quality
74/100
Scores the file, not the repository.Length
421 words
11 headings · 4 code blocksRepository
15
— · pushed 231 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Guidelines for Data Access Layer via API78## Purpose & Overview9These rules define the standard patterns for implementing CRUD operations in the data access layer. The guidelines are based on the implementation of the 'users' module and should be followed for all API operations to maintain consistency across the codebase.1011## File Structure1213### Shared Domain1415By default, place all data access files in the shared data directory. Only use feature domains when explicitly specified in requirements.1617```18src/data/[entity-name]/19├── create-[entity].ts # Create operation20├── get-[entity].ts # Get single entity21├── get-[entity]s.ts # Get multiple entities22├── update-[entity].ts # Update operation23├── delete-[entity].ts # Delete operation24├── search-[entity]s.ts # Search with filters25└── __test-utils__/ # Test utilities26```2728### Feature Domain2930When a prompt/requirement explicitly specifies that code should be organized in a feature domain, follow this structure:3132```33src/features/[feature-name]/34└── _data/[entity-name]/ # Feature-specific data access layer35 ├── create-[entity].ts # Create operation36 ├── get-[entity].ts # Get single entity37 ├── get-[entity]s.ts # Get multiple entities38 ├── update-[entity].ts # Update operation39 ├── delete-[entity].ts # Delete operation40 ├── search-[entity]s.ts # Search with filters41 └── __test-utils__/ # Test utilities42```4344## Naming Conventions4546### Function Naming47- `create[Entity]Data`: For creating resources via API48- `get[Entity]Data`: For retrieving a single resource via API49- `get[Entity]sData`: For retrieving multiple resources via API50- `update[Entity]Data`: For updating resources via API51- `delete[Entity]Data`: For deleting resources via API52- `search[Entity]sData`: For searching resources with filters via API5354### Type Naming55- `[Entity]`: Main entity type from API schema56- `Create[Entity]`: Type for creating entity, typically omitting auto-generated fields57- `Update[Entity]`: Type for updating entity, typically partial of the main entity58- `[Operation][Entity]DataArgs`: Type for function arguments59- `[Operation][Entity]DataResponse`: Type for function return value6061## Implementation Patterns626364## Test Utilities65Create test utilities in the `__test-utils__` directory to help with testing:6667```typescript68// __test-utils__/make-fake-entity.ts69import { type Entity } from '@/data/schema';70import { faker } from '@faker-js/faker';7172// Create a fake entity with realistic test data73export function makeFake[Entity] {74 return {75 id: faker.string.uuid(),76 created_at: faker.date.recent(),77 updated_at: faker.date.recent(),78 deleted_at: null,79 // ... entity-specific fields with realistic fake data80 ...overrides,81 } satisfies Entity;82}83```8485### Create Operation86```typescript87// create-[entity].ts88import { type Entity } from './schema';8990export type CreateEntityDataArgs = {91 // Entity properties to be sent to API92};9394export async function createEntityData(args: CreateEntityDataArgs): Promise<Entity> {95 const response = await fetch('https://api.example.com/entities', {96 method: 'POST',97 headers: {98 'Content-Type': 'application/json',99 },100 body: JSON.stringify(args),101 });102103 if (!response.ok) {104 throw new Error(`API error: ${response.status}`);105 }106107 return await response.json();108}109```
Also in constROD/template-react-vite
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| constROD/template-react-vite.cursor/rules/design-system.mdc · 15 | Cursor rules | lint-formatstylearchui | 58/100 | 3 days ago | |
| constROD/template-react-vite.cursor/rules/mutation-hooks.mdc · 15 | Cursor rules | stylearchtypes | 70/100 | 3 days ago | |
| constROD/template-react-vite.cursor/rules/project-structure.mdc · 15 | Cursor rules | stylearchdependencies | 78/100 | 3 days ago | |
| constROD/template-react-vite.cursor/rules/query-hooks.mdc · 15 | Cursor rules | stylearchtypesperformance | 70/100 | 3 days ago | |
| constROD/template-react-vite.cursor/rules/service-layer.mdc · 15 | Cursor rules | stylearchtypes | 66/100 | 3 days ago | |
| constROD/template-react-vite.cursor/rules/styling.mdc · 15 | Cursor rules | archui | 58/100 | 3 days ago | |
| constROD/template-react-vite.cursor/rules/zustand-store.mdc · 15 | Cursor rules | teststylearchtypes+1 | 74/100 | 3 days ago | |
| constROD/template-react-viteAGENTS.md · 15 | AGENTS.md | testlint-formatstylearch+3 | 90/100 | 3 days ago | |
| constROD/template-react-viteCLAUDE.md · 15 | CLAUDE.md | testlint-formatstylearch+3 | 90/100 | 3 days ago |
Diff against .cursor/rules/design-system.mdc Diff against .cursor/rules/mutation-hooks.mdc Diff against .cursor/rules/project-structure.mdc Diff against .cursor/rules/query-hooks.mdc Diff against .cursor/rules/service-layer.mdc Diff against .cursor/rules/styling.mdc Diff against .cursor/rules/zustand-store.mdc Diff against AGENTS.md Diff against CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
