Cursor rule
.cursor/rules/service-layer.mdcGuidelines for Service Layer
Cursor rules
Quality
66/100
Scores the file, not the repository.Length
374 words
11 headings · 2 code blocksRepository
15
— · pushed 231 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Guidelines for Service Layer78## Purpose and Overview9The service layer is responsible for orchestrating business logic and coordinating data access operations. It sits between the UI (components, hooks) and the data access layer, providing a clear separation of concerns. Services should handle:10111. Orchestration of multiple data operations122. Business logic implementation133. Data transformation and validation144. Error handling and logging1516## Structure and Organization1718### Service Layer Module Structure19```20src/21├── services/ # Shared service layer module22│ └── [entity]23 └── [operation-entity-name].ts # Shared service implementations24└── features/25 └── [feature-name]/26 └── _services/ # Feature-specific services27 └── [operation-entity-name].ts # Feature-specific service implementations28```2930## Naming Conventions3132### Functions33- `[operation][Entity]Service`: For service functions (e.g., `getFeatureFlagService`, `createUserService`)3435### Types36- `[Operation][Entity]ServiceArgs`: Arguments for service functions37- `[Operation][Entity]ServiceDependencies`: Dependencies for service functions38- `[Operation][Entity]ServiceResult`: Return type for service functions (if needed)3940## Implementation Guidelines4142### Service Layer43- Services should receive data access functions as dependencies44- Dependencies should be injected with default values45- Services should be pure functions that don't manage state46- Services should handle error cases and transformations47- Services should be testable by allowing dependency injection4849### Example Service Function50```typescript51import { getUserData } from '@/data/users/get-user';52import { getFeatureFlagData } from '@/data/feature-flags/get-feature-flag';53import { type DbClient } from '@/db/create-db-client';54import { type Session } from '@/types/auth';5556export type GetFeatureFlagServiceDependencies = {57 getUserData: typeof getUserData;58 getFeatureFlagData: typeof getFeatureFlagData;59};6061export type GetFeatureFlagServiceArgs = {62 dbClient: DbClient;63 payload: { session: Session };64 dependencies?: GetFeatureFlagServiceDependencies;65};6667export async function getFeatureFlagService({68 dbClient,69 payload,70 dependencies = {71 getUserData,72 getFeatureFlagData,73 },74}: GetFeatureFlagServiceArgs) {75 const userData = await dependencies.getUserData({76 dbClient,77 id: payload.session.id,78 });7980 const featureFlagData = await dependencies.getFeatureFlagData({81 dbClient,82 role: userData.role,83 });8485 return featureFlagData;86}87```8889## When to Use Service Layer9091Services should be used when:92931. You need to coordinate multiple data access operations942. There is complex business logic to implement953. You need to transform or validate data before returning it964. You need to handle specific error cases or implement retry logic975. You want to make the code more testable through dependency injection9899If an operation is simple and only involves a single data access call with minimal transformation, it might not need a service layer.
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/data-access-via-api.mdc · 15 | Cursor rules | teststylearchtypes+1 | 74/100 | 3 days ago | |
| 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/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/data-access-via-api.mdc 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/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 |
