Phase 10: ERP Enterprise Features
Objective: Implement scalable ERP features using CQRS for Reporting, Analytics, and Integrations. Ensure "Zero Cliff" scalability from startup to enterprise.
1. Analytics & Read Models (CQRS)
Concept: Separate the "Write Model" (Transactional DB) from the "Read Model" (Reporting DB / Analytics Engine).
1.1 Read Model Protocol
- Create
src/framework_m/core/interfaces/read_model.py: - Define
ReadModelProtocol:-
async def project(event: Event) -> None -
async def query(filters: dict) -> list[dict] -
async def rebuild() -> None
-
1.2 Enterprise Projectors
- Implement
Projector(Event Handler):- Subscribe to
doc.created,doc.updated - Transform transactional data into "Read Optimized" format
- Upsert into Read Store (Postgres Read Replica, ClickHouse, Elastic)
- Subscribe to
1.3 Report Engine (Scalable)
- Create
ReportDocType:-
report_type:-
Code Report(SQL file in repo or Python Class - Indie Mode) -
Analytics Report(Queries Read Model / OLAP - Enterprise Mode)
-
-
data_source: SQL / Elastic / ClickHouse adapter
-
2. Webhook System (Integration)
Objective: Zero-code integration with 3rd party tools (Slack, Zapier).
2.1 Webhook DocType
- Create
src/framework_m/public/webhook.py - Define
WebhookDocType:-
doctype: str- Trigger DocType -
event: str- Event name (after_save, on_submit) -
url: str- Target Endpoint -
headers: dict- Auth/Custom Headers -
condition: str | None- JMESPath or SimpleEval expression (Noeval()) -
payload_transform: str | None- Jinja2 template for JSON payload
-
2.2 Webhook Dispatcher
- Implement
WebhookListener:- Subscribe to
doc.*events - Queue background job
fire_webhook - Resilience: Exponential Backoff (handled by Job Queue)
- Subscribe to
2.3 Webhook Visualization (Native UI)
- Webhook Log DocType (defined in Phase 04):
- Stores Request/Response/Error.
- Status:
Success(Green),Failed(Red).
- Desk Integration:
- Add "Recent Logs" table to
WebhookForm View. - Action: "Retry Now" button (re-queues the job).
- Add "Recent Logs" table to
3. Data Import / Export (Bulk)
- Defined in Phase 05 CLI (See
m import --bypass-controllers)