improvement: some files replaced, lots of them i shall say. AGENT.MD file created. some rules and skills added for cursor agent.

This commit is contained in:
2026-07-12 21:08:29 +03:30
parent 1cdf853d32
commit 0d3fb0a51d
86 changed files with 4758 additions and 4260 deletions

View File

@@ -0,0 +1,28 @@
---
description: Error codes backend ↔ frontend and i18n message keys
globs: backend/src/common/errors/**,frontend/src/components/shared/formatApiError.ts,frontend/messages/**
alwaysApply: false
---
# API errors & translations
## Adding a new error
1. Add code to `backend/src/common/errors/error-codes.ts`
2. Throw via `AppException` (or validation DTO with that code)
3. Add matching key under `errors` in **all three** message files:
- `frontend/messages/en.json`
- `frontend/messages/fa.json`
- `frontend/messages/nl.json`
4. Frontend catch: `getUserFacingError(err, tErrors, t('fallbackKey'))`
## Validation field errors
Backend returns `{ success: false, error: { code, details: [{ field, code }] } }`.
Frontend maps `details[].code` through the `errors` namespace.
## Do not
- Show raw `error.message` or stack traces to users.
- Add English-only strings inline in components.

View File

@@ -0,0 +1,41 @@
---
description: Backend NestJS modules, Prisma, permissions, guards
globs: backend/src/**
alwaysApply: false
---
# Backend conventions
## Module layout
`backend/src/modules/{feature}/` → `{feature}.module.ts`, `.controller.ts`, `.service.ts`, `dto/`.
Register new modules in `app.module.ts`.
## Errors
Use coded errors — not raw user-facing strings:
```typescript
throw new AppException(ErrorCode.PERMISSION_DENIED, HttpStatus.FORBIDDEN);
```
- Codes: `backend/src/common/errors/error-codes.ts`
- DTO validation: `{ message: ErrorCode.VALIDATION_* }` on class-validator decorators
- Global filter: `HttpExceptionFilter` in `main.ts`
## Permissions
- Check access with `hasEffectivePermission(membership, 'TAB_*')` from `common/membership-permissions.ts`.
- Clinic-only routes: `ClinicOrgGuard`. Lab-only: `LabOrgGuard`.
- Feature-specific checks belong in the **service**, not only the controller.
## Prisma
- Schema: `backend/prisma/schema.prisma`
- Always add a migration for schema changes (`npm run prisma:migrate` in backend).
- Seed permissions stay in sync with `ALL_TAB_PERMISSIONS` in `common/permissions.ts`.
## API responses
Prefer `{ success: true, data: ... }` shape consistent with existing modules.

View File

@@ -0,0 +1,29 @@
---
description: Dyolink project context — stack, org types, git safety, verification
alwaysApply: true
---
# Dyolink overview
Monorepo: `backend/` (NestJS + Prisma), `frontend/` (Next.js + next-intl), `infrastructure/` (Docker).
## Domain
- **CLINIC** orgs: patients, appointments, treatment, staff.
- **LAB** orgs: cases, tasks, lab workflows.
- Tab access: `TAB_*_READ` / `TAB_*_EDIT` in `backend/src/common/permissions.ts`. EDIT implies READ.
## Agent behavior
- Read `AGENTS.md` and file-scoped rules before large changes.
- **Never commit or push** unless the user explicitly asks.
- Prefer minimal diffs; reuse existing components and API patterns.
- After cross-cutting changes: `backend` → `npm run build`; `frontend` → `npx tsc --noEmit`.
## i18n
All user-visible strings: `frontend/messages/en.json`, `fa.json`, `nl.json` — add keys to **all three**.
## Treatment / appointment colors
Treatment-type colors and labels: `components/shared/treatmentTypeDisplay.ts` + `catalog-type-colors.ts`. UI badges: `components/ui/treatment/TreatmentTypeBadge.tsx`.

View File

@@ -0,0 +1,47 @@
---
description: Frontend folder structure — ui vs non-ui, thin pages, feature layout
globs: frontend/src/**
alwaysApply: false
---
# Frontend component structure
## Rules
| Kind | Location |
|------|----------|
| Cross-feature UI | `components/ui/shared/` |
| Feature UI | `components/ui/{feature}/` |
| Cross-feature non-UI | `components/shared/` |
| Feature non-UI | `components/{feature}/` |
| Route logic | `components/ui/{feature}/{Feature}Page.tsx` |
| App routes | `app/**/page.tsx` — **thin wrapper only** |
## Thin page pattern
```tsx
'use client';
import { PatientsPage } from '@/components/ui/patient/PatientsPage';
export default function Page() {
return <PatientsPage />;
}
```
Reference: `app/.../treatment/page.tsx` + `components/ui/treatment/TreatmentWorkspace.tsx`.
## Do not
- Put React components (`.tsx` with JSX) in `components/` outside `ui/`.
- Put pure helpers (`.ts`, no JSX) inside `components/ui/`.
- Put business logic, API calls, or large forms directly in `app/**/page.tsx`.
## API & errors
- API clients: `lib/api/`.
- Catch blocks: `getUserFacingError(err, tErrors, fallback)` from `components/shared/formatApiError.ts`.
## When adding UI
1. Check `components/ui/shared/` for an existing primitive.
2. Check the feature's `ui/{feature}/` folder for an existing pattern.
3. Add i18n keys to en, fa, and nl.

View File

@@ -0,0 +1,35 @@
---
description: When and how to update AGENTS.md, rules, and skills after new conventions
alwaysApply: true
---
# Maintaining agent docs
Rules and skills **load automatically** but **do not self-update**. Update them when the user establishes a durable convention.
## Update when the user says (or clearly means)
- "Remember this" / "Save as convention" / "Add to project rules"
- "Document this for future agents"
- "We always do X in this project" (and it is not already in rules/skills)
## Where to put new knowledge
| Kind of knowledge | Update |
|-------------------|--------|
| Always true, 15 bullets | `.cursor/rules/*.mdc` (pick existing file or create new, <50 lines) |
| Multi-step workflow | `.cursor/skills/{name}/SKILL.md` |
| Project map / onboarding | `AGENTS.md` (index only — link to rules/skills) |
## Do not auto-update when
- One-off task instructions ("fix this bug today")
- Experimental code not yet agreed as standard
- User did not ask to persist the pattern
## After updating
- Keep rules concise; split if a file grows past ~50 lines.
- Tell the user which file(s) changed in one sentence.
Use skill `.cursor/skills/capture-convention/` for the full workflow.