Include Loyalty/Communication/Sports Center backends and registry updates alongside production nginx and compose wiring. Co-authored-by: Cursor <cursoragent@cursor.com>
8.8 KiB
8.8 KiB
Master Prompt — Global Project Rules
Permanent instructions for every AI-assisted implementation on TorbatYar.
Do not copy this file into phase prompts. Phase prompts reference it and describe only the current phase (prompt-rules.md).
Global Project Rules
- TorbatYar is a multi-tenant, modular, API-first, microservice-ready SuperApp SaaS.
- Source of truth for docs:
docs/README.md. Code and docs ship together. - Brand, colors, and secrets are never hardcoded — config /
.env/ database only. - Frontend (
frontend/) and Backend (backend/) are strictly separated (ADR-002). - No phase is complete with failing tests, missing docs, broken links, or leftover TODOs for claimed work.
- If implementation conflicts with architecture or ADRs: stop, explain, fix docs/ADR first, then code.
- Do not modify unrelated completed modules when executing a scoped phase.
- Prefer extending existing patterns from Core, Identity, Accounting, CRM, Loyalty, and Communication over inventing new structures.
Architecture Rules
- Database-per-service — no cross-DB queries or foreign keys (ADR-001).
- Inter-service communication: REST, Webhook, Async Event, Outbox/Inbox only (ADR-006).
- Internal layering:
API → Services → Repositories → Models(service-architecture.md). - Business logic only in Services; repositories are persistence-only; routers stay thin (project-principles.md).
- Respect module-boundaries.md — never take ownership of another module’s aggregates.
- Accounting journal entries only via Posting Engine (ADR-010).
- Product AI is optional and independent (ai-architecture.md) — core flows must work when AI is off.
- New architectural decisions require a new ADR before conflicting implementation (adr/).
Multi-Tenancy Rules
- Every business table carries
tenant_id(ADR-003). - Every business read/write filters by tenant context.
- No cross-tenant queries; platform-admin exceptions must be explicit and audited.
- Resolve tenant via documented order (multi-tenant-architecture.md):
X-Tenant-ID/ slug / host /current_tenant_id. - Tenant-aware APIs require tenant middleware/deps and negative isolation tests.
- Entitlement checks go through Core for gated features.
Service Boundaries
- Each independent service owns exactly one database and its Alembic migrations.
- Services must not import another service’s models, repositories, or private modules.
- Cross-service references use external IDs / refs only — never shared tables.
- Provider adapters live inside the owning service (e.g. SMS providers in Communication only — ADR-012).
- Shared library (
backend/shared-lib) holds envelopes, JWT helpers, exceptions — not business workflows. - Register new services in service-manifest.yaml and module-registry.md.
Documentation Rules
- Update documentation in the same phase as code (documentation-template.md).
- Never overwrite accepted ADRs; supersede them.
- Update progress.md only for completed work; roadmap.md for future; next-steps.md for the immediate milestone.
- Keep module-registry.md and provider-registry.md current.
- Use glossary terms from glossary.md.
- Cross-link architecture, ADR, registries, development standards, and reference docs.
- No undocumented public API, event, permission tree, or migration for the phase.
- Framework permanent rules live under
docs/ai-framework/— do not duplicate them elsewhere.
Coding Rules
- Follow coding-standards.md.
- Python 3.11+ with type hints on public functions; English names.
- Pydantic DTOs for request/response — never return ORM models from APIs.
- Feature keys:
{service}.{resource}.{action}; permissions:{service}.*trees. - Events:
{aggregate}.{past_tense}(or service-prefixed where already established, e.g.crm.*,loyalty.*). - Migrations: reviewed Alembic revisions; no silent destructive changes without phase scope.
- No wildcard imports; raise shared exceptions with stable error codes.
- Optimistic locking / audit actors where the domain requires them (follow sibling services).
Quality Rules
- Pass all gates in quality-gates.md.
- Mandatory tests per testing-template.md and testing-strategy.md.
- Architecture, tenant isolation, permission, security, and documentation validation are required for service/module phases.
- Automatic repair loop until gates are green (development-loop.md).
- Self-audit before claiming completion (phase-handover.md).
AI Implementation Rules
- Read framework + architecture + phase docs before writing code (cursor-guidelines.md).
- Implement only the current phase scope — no speculative features.
- Do not weaken security, tenancy, or boundaries to “make it work.”
- Prefer contracts/protocols for platform dependencies; do not implement foreign platforms inside a business module.
- When blocked by missing architecture: create/update ADR and docs first.
- Never invent permanent global rules inside a phase prompt — extend this framework instead.
- On inconsistency: repair automatically and re-validate.
Dependency Rules
- Depend on Core entitlement and Identity/JWT patterns as documented.
- Call other services only via versioned HTTP APIs or events.
- External providers go behind adapters registered in the owning service and provider-registry.md.
- Do not add heavy dependencies without documenting them in the service README and requirements.
- Circular service dependencies are forbidden; use events for inverse flows.
- Frontend depends on APIs only — never on backend packages.
Platform Principles
Mirror of project-principles.md:
- Tenant-aware · Auditable · Service-layer logic · Thin API · Tests required · Docs required · No TODO in completed phases · No cross-tenant query · Posting Engine only for journals · Compliance independent · AI independent · Event-ready · API-first · Documented · Database-per-service · FE/BE separation · No hardcoded brand/secrets · Docs before conflicting code · Phase completion gate.
Rules for Adding New Services
- Follow service-template.md.
- Create
backend/services/<name>/with independent DB, Alembic, health endpoint, permissions, events. - Register in Core service/module registry (when wiring), service-manifest.yaml, module-registry.md.
- Document public APIs in reference/ as contracts stabilize.
- Add compose/env samples only when the phase scopes runtime wiring.
- Create ADR when the service introduces a platform-level ownership decision (see Loyalty ADR-011, Communication ADR-012).
- UI belongs in
frontend/only.
Rules for Adding New Modules
- Prefer a module inside an existing owning service when the domain clearly belongs there (module-template.md).
- If the capability is shared across many business domains, create an independent service instead (Loyalty, Communication pattern).
- Update module registry, phase docs, permissions, events, and tests.
- Do not expand a Sales CRM module into Customer360, Marketing, or Messaging ownership.
Rules for Extending Existing Services
- Stay within published boundaries; do not absorb foreign aggregates.
- Additive migrations preferred; breaking API changes require versioning strategy (api-template.md).
- Preserve tenant isolation and audit trails.
- Update events/catalog, permissions, tests, progress, next-steps, and handover.
- Do not “drive-by” refactor unrelated packages.
- Backward compatibility is a quality gate unless the phase explicitly documents a breaking change with migration notes.