system-prompts-and-models-o.../salesflow-saas/docs/ARCHITECTURE.md
Claude 84762f08ab
Add complete launch infrastructure: models, APIs, agents, compliance, docs, knowledge base
Phase 1 - Repo Hardening:
- README.md, LICENSE, SECURITY.md, CONTRIBUTING.md
- GitHub Actions repo-hygiene workflow
- docs/: ARCHITECTURE, DATA-MODEL, API-MAP, AGENT-MAP, DEPLOYMENT-NOTES

Phase 2 - Database Models (7 new):
- Company, Contact, Call, Commission, Payout, Dispute, GuaranteeClaim
- Consent, Complaint, Policy, KnowledgeArticle, SectorAsset
- Updated models/__init__.py with all 32+ models

Phase 3 - API Surfaces (16 new route files):
- companies, contacts, calls, meetings, commissions, payouts
- disputes, guarantees, consents, complaints, knowledge
- sectors, presentations, supervisor, admin, health
- Updated router.py with all 24 route groups

Phase 4 - AI Prompt Registry (18 agent contracts):
- Lead Qualification, Affiliate Recruitment Evaluator, Onboarding Coach
- Outreach Writer, Arabic WhatsApp, English Conversation, Voice Call
- Meeting Booking, Sector Strategist, Objection Handler
- Proposal Drafter, QA Reviewer, Compliance Reviewer
- Knowledge Retrieval, Revenue Attribution, Fraud Reviewer
- Guarantee Claim Reviewer, Management Summary

Phase 5 - Communication Templates:
- 15 production templates (WhatsApp, email, voice, internal)
- Arabic + English variants with variable interpolation

Phase 6 - Compliance Center (7 legal docs):
- Privacy policy, Terms of service, Refund policy
- Commission policy, Affiliate rules, Consent policy, Data protection
- All PDPL-compliant, Arabic

Phase 7 - Celery Workers (fully implemented):
- follow_up_tasks: automated lead follow-ups with workflow execution
- message_tasks: WhatsApp/email/SMS with retry logic
- notification_tasks: daily reports, meeting reminders, in-app notifications
- affiliate_tasks: target checking, commission calculation, weekly reports, AI outreach

Phase 8 - Knowledge Base OS (8 files):
- Services overview, Pricing policy, Channel policy, Meeting policy
- Identity rules, Escalation rules, Hiring path, Internal SOPs

https://claude.ai/code/session_01KnJgK7RwyeCvRZTRThHtfU
2026-03-31 07:57:48 +00:00

124 lines
4.8 KiB
Markdown

# Architecture Overview
## System Diagram
```
+------------------+
| Client / App |
| (Browser/Mobile) |
+--------+---------+
|
HTTPS (443)
|
+--------+---------+
| Nginx |
| (Reverse Proxy) |
+---+---------+----+
| |
/api/* | | /*
| |
+-------------+ +----+-----------+
| FastAPI | | Next.js |
| Backend | | Frontend |
| :8000 | | :3000 |
+--+-----+----+ +----------------+
| |
+--------+ +--------+
| |
+-------+--------+ +--------+-------+
| PostgreSQL 15 | | Redis 7 |
| (Primary DB) | | (Cache/Broker) |
+----------------+ +-------+--------+
|
+-------+--------+
| Celery Workers |
| + Celery Beat |
+----------------+
```
## Multi-Tenant Model
```
Request --> Auth Middleware --> Extract tenant_id from JWT
|
v
Query scoping: WHERE tenant_id = :tid
|
v
All reads/writes isolated per tenant
```
- Every database table with tenant-scoped data includes a `tenant_id` foreign key.
- Middleware extracts `tenant_id` from the authenticated JWT on every request.
- Database queries are automatically scoped. Cross-tenant access is blocked at the ORM layer.
- Superadmin role can query across tenants for platform-level reporting.
## AI Agent Layer
```
Incoming Event (lead, message, call, meeting request)
|
v
+------------------+
| Agent Router | --> selects agent(s) based on event type
+------------------+
|
v
+------------------+ +------------------+
| Agent Executor | --> | LLM Provider |
| (Celery Task) | | (OpenAI / etc) |
+------------------+ +------------------+
|
v
+------------------+
| Action Handler | --> update DB, send message, book meeting, escalate
+------------------+
```
- 18 specialized agents (see `docs/AGENT-MAP.md`)
- Each agent has a defined role, input schema, output schema, and escalation rules
- Agents execute as Celery tasks for async processing
- Outputs are logged to `ai_conversations` for audit
## Integration Layer
```
+------------------+ +------------------+ +------------------+
| WhatsApp | | Email | | SMS |
| Business API | | (SMTP/Provider) | | (Gateway) |
+--------+---------+ +--------+---------+ +--------+---------+
| | |
+------------------------+------------------------+
|
+-------+--------+
| Message Bus |
| (Redis Queue) |
+-------+--------+
|
+-------+--------+
| Celery Worker |
+----------------+
```
- WhatsApp Business API for Arabic-first automated conversations
- Email for proposals, notifications, and follow-ups
- SMS for OTP and urgent alerts
- All outbound messages queued through Redis for rate limiting and retry
## Major Modules
| Module | Location | Purpose |
|--------|----------|---------|
| Auth & Tenancy | `backend/auth/` | JWT, RBAC, tenant isolation |
| Lead Management | `backend/leads/` | Capture, scoring, qualification, assignment |
| Deal Pipeline | `backend/deals/` | Stage tracking, revenue forecasting |
| Affiliate System | `affiliate-system/` | Recruitment, onboarding, performance, commissions |
| AI Agents | `ai-agents/` | 18 specialized agents with prompt definitions |
| Knowledge Base | `knowledge-base/` | RAG articles, sector data, FAQ |
| Guarantee | `guarantee/` | Gold guarantee claims, disputes, refunds |
| Presentations | `presentations/` | Proposal and pitch deck generation |
| Meetings | `backend/meetings/` | AI-driven booking, calendar sync |
| Commissions | `backend/commissions/` | Calculation, payouts, dispute resolution |
| Notifications | `backend/notifications/` | Multi-channel delivery (WhatsApp, email, SMS, in-app) |
| Dashboard | `frontend/` | Analytics, pipeline views, admin panels |