14 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).
The framework is the single source of truth for how phases are executed (ADR-013, ADR-018). Enterprise production quality is the default — not an optional add-on prompt.
Document loading: Start from docs/project-status.yaml (execution dashboard — execution_priority + critical_path + deployment_readiness) — then project-index.yaml, Runtime Read Policy, Context Cache Policy, service snapshot, manifests, latest handover. When project-status exists, do not full-project-scan or inspect unrelated services. Never scan repository folders for discovery. Deprecated: next_recommended_phase.
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, leftover TODOs for claimed work, or incomplete Definition of Done.
- 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, Communication, and later platform services over inventing new structures.
- CRUD is never sufficient for phase completion (definition-of-done.md).
Enterprise Completeness Rules
- Enterprise Phase Discovery is mandatory before Implementation (enterprise-phase-discovery.md, ADR-019).
- Every implementation phase automatically includes all mandatory-phase-artifacts.md applicable to its boundary.
- Satisfy definition-of-done.md before marking Complete.
- Verify enterprise-completeness.md dimensions; implement any missing current-phase requirement before Complete.
- If the roadmap describes a module only at a high level, derive every missing technical component for production readiness inside this phase — without pulling future-phase product features forward.
- Quality gates include Discovery and enterprise completeness checks (quality-gates.md).
- Never assume CRUD is sufficient; Discovery gap analysis rejects CRUD-only scope.
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), with Commands, Queries, Policies, Specifications, Validators as required. - Business logic only in Services (or command handlers); repositories are persistence-only; routers stay thin (project-principles.md).
- Respect module-boundaries.md and boundary-rules.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/).
Boundary Rules (summary)
Full text: boundary-rules.md.
- Never implement responsibilities owned by another service.
- Never duplicate business logic across services.
- Never access another service database.
- Only integrate through APIs, Events, and Provider interfaces.
- Never move functionality from future phases into the current phase.
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, project-index.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.
- Update
docs/project-status.yamlanddocs/project-status.mdafter every Complete phase (mandatory). - 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. - OpenAPI must reflect new/changed routes before Complete.
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.
- Soft delete, optimistic locking, audit actors, pagination/filter/sort/search where collections and concurrency require them (mandatory-phase-artifacts.md).
- Prefer explicit Commands, Queries, Policies, Specifications packages (or equivalent documented patterns).
- Dependency injection via constructors / FastAPI deps — no hidden globals for domain 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, performance, and documentation validation are required for service/module phases.
- Automatic repair loop until gates are green — implement missing required artifacts, do not weaken gates (development-loop.md).
- Self-audit before claiming completion (phase-handover.md).
- Enterprise Completeness sign-off required (enterprise-completeness.md).
AI Implementation Rules
- Load
docs/project-status.yamlfirst; choose work viaexecution_prioritythencritical_path; then project-index.yaml, Runtime Read Policy, Context Cache Policy, only the active service snapshot/handover, manifests; follow cursor-guidelines.md. Never scan folders or unrelated services when project-status exists. - Run Enterprise Phase Discovery before Implementation — baseline from service snapshot + latest handover; synthesize remaining inputs per policy mapping.
- Implement only the current phase scope (Discovery-promoted) — no speculative future-phase 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.
- Production readiness is automatic — do not ask whether to add health, permissions, tests, audit, events, or OpenAPI when they apply to the phase.
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 · Enterprise DoD · CRUD never sufficient · Boundary rules enforced · Enterprise Phase Discovery mandatory.
Rules for Adding New Services
- Follow service-template.md.
- Create
backend/services/<name>/with independent DB, Alembic, health, capabilities, metrics (or justified N/A), permissions, events, providers, commands/queries/policies/specs as applicable. - Register in Core service/module registry (when wiring), service-manifest.yaml, project-index.yaml, module-registry.md.
- Document public APIs in reference/ as contracts stabilize; keep OpenAPI accurate.
- Add compose/env samples only when the phase scopes runtime wiring.
- Create ADR when the service introduces a platform-level ownership decision.
- 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.
- Update module registry, phase docs, permissions, events, and tests.
- Deliver full mandatory artifacts for the module’s phase boundary — not CRUD-only.
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, handover, project-index.yaml, and regenerate service snapshot per service-snapshot-policy.md.
- Do not “drive-by” refactor unrelated packages.
- Backward compatibility is a quality gate unless the phase explicitly documents a breaking change with migration notes.
Related Documents
- Project Index
- Runtime Read Policy
- Context Cache Policy
- Service Snapshot Policy
- AI / Enterprise Framework README
- Enterprise Phase Discovery
- Definition of Done
- Mandatory Phase Artifacts
- Enterprise Completeness
- Boundary Rules
- Development Loop
- Quality Gates
- Architecture Overview
- Project Principles
- ADR Index