Add the Sales CRM service through collaboration, sync architecture/registry docs, expose crm.torbatyar.ir, and include a production deploy script. Co-authored-by: Cursor <cursoragent@cursor.com>
4.1 KiB
4.1 KiB
Phase 6.0 — CRM Service Foundation
| Field | Value |
|---|---|
| Status | Complete |
| Module | crm |
| Version | 0.6.0.0 |
| Database | crm_db |
| API Port | 8003 |
| ADR | ADR-001, ADR-003, ADR-006 |
Goal
Establish the Sales CRM service foundation and architectural boundaries only. No Customer360, Automation, Marketing, Communication, Helpdesk, Analytics, or AI platforms.
CRM Responsibilities
CRM owns Sales CRM domain only:
- Lead
- Contact
- Organization (business account)
- Opportunity
- Pipeline / PipelineStage
- SalesActivity (meeting / call / task / note)
- Quote (sales quote only)
- CRM timeline event source contracts (publish)
Service Boundaries
| CRM owns | CRM does not own |
|---|---|
| Sales aggregates above | Workflow / Automation |
CRM HTTP APIs under /api/v1/* |
Customer360 |
crm.* permissions |
Marketing |
| Publish-only CRM events | Notification / Messaging / Communication |
| Platform provider interfaces | Helpdesk / Analytics / AI |
| Identity / Accounting / Inventory | |
| Restaurant / Marketplace / Files / Search |
Communication with platform services is API + Events only. No cross-DB access.
Owned Modules (aggregates)
Independent aggregates in backend/services/crm/app/models/foundation.py:
LeadContactOrganizationOpportunityPipelinePipelineStageSalesActivityQuote
Cross-aggregate links use UUID references inside crm_db only (no SQLAlchemy relationship graphs).
External Platform Dependencies (contracts only)
Defined in app/providers/contracts.py — no implementations:
AutomationProviderCustomer360ProviderNotificationProviderAnalyticsProviderAIProviderCommunicationProviderHelpdeskProvider
Published Events
| Event | Aggregate |
|---|---|
crm.lead.created |
lead |
crm.lead.updated |
lead |
crm.contact.created |
contact |
crm.opportunity.created |
opportunity |
crm.opportunity.won |
opportunity |
crm.activity.completed |
sales_activity |
crm.quote.created |
quote |
Phase 6.0 does not consume future platform events.
API Contracts
| Method | Path |
|---|---|
| CRUD | /api/v1/leads |
| CRUD | /api/v1/contacts |
| CRUD | /api/v1/organizations |
| CRUD + stages | /api/v1/pipelines |
| CRUD + win | /api/v1/opportunities |
| CRUD + complete | /api/v1/activities |
| CRUD | /api/v1/quotes |
| Health | /health |
No Automation / Customer360 / Notification APIs are exposed.
Permissions
crm.*crm.leads.*crm.contacts.*crm.organizations.*crm.opportunities.*crm.activities.*crm.quotes.*
Architecture Decisions
- Database-per-service (
crm_db) — ADR-001 - Row-level
tenant_idfrom request tenant context — ADR-003 - Event publish contracts via
EventEnvelope— ADR-006 - Layering: API → Services → Repositories → Models
- Platform capabilities stay behind provider protocols; CRM never implements them
Folder Structure
backend/services/crm/
app/
api/v1/
core/
middlewares/
models/
repositories/
services/
validators/
schemas/
events/
permissions/
providers/
tests/
alembic/versions/0001_initial.py
scripts/ensure_db.py
README.md
Future Roadmap (beyond foundation)
- Provider adapters when sibling platforms exist
- Frontend CRM module UI
- Outbox worker wiring to real message bus
Phases 6.1–6.3 completed — see crm-phase-6-3.md.
Completion Checklist
- Code completed
- Architecture / dependency / repository / migration / API / permission / tenant / docs tests
- Documentation updated
- Module registry updated
- No forbidden platform ownership
- No TODO placeholders in foundation