Loading...
Loading...
Production-grade architectural patterns for building enterprise Frappe apps like CRM, Helpdesk, and HRMS. Use when designing complex multi-entity systems with workflows, SLAs, and integrations.
npx skill4agent add lubusin/agent-skills frappe-enterprise-patternsTicket (parent)
├── customer (Link: Customer)
├── assigned_to (Link: User)
├── status (Select: Open, In Progress, Resolved, Closed)
├── priority (Link: Priority)
├── sla (Link: SLA)
├── activities (Table: Ticket Activity)
└── response_by, resolution_by (Datetime)| docstatus | Meaning |
|---|---|
| 0 | Draft |
| 1 | Submitted |
| 2 | Cancelled |
def validate(self):
allowed = self.get_allowed_transitions()
if self.status not in allowed:
frappe.throw(f"Cannot transition to {self.status}")@frappe.whitelist()
def update_ticket(name, status):
doc = frappe.get_doc("Ticket", name)
if not frappe.has_permission("Ticket", "write", doc):
frappe.throw("Not permitted", frappe.PermissionError)
doc.status = status
doc.save()def on_update(self):
if self.has_value_changed("status"):
self.append("activities", {
"action": "Status Change",
"old_value": self._doc_before_save.status,
"new_value": self.status,
"timestamp": frappe.utils.now()
})SLA
├── entity_type (Link: DocType)
├── response_time (Duration)
├── resolution_time (Duration)
└── escalation_rules (Table: Escalation Rule)def after_insert(self):
sla = get_applicable_sla(self)
if sla:
self.response_by = add_to_date(self.creation, hours=sla.response_time)
self.resolution_by = add_to_date(self.creation, hours=sla.resolution_time)
self.db_update()def check_sla_breaches():
tickets = frappe.get_all("Ticket",
filters={"status": ["not in", ["Resolved", "Closed"]]},
fields=["name", "resolution_by"]
)
for t in tickets:
if frappe.utils.now_datetime() > t.resolution_by:
mark_sla_breached(t.name)def assign_next_agent(queue):
agents = frappe.get_all("Queue Member",
filters={"queue": queue, "available": 1},
fields=["user", "current_load"],
order_by="current_load asc"
)
if agents:
return agents[0].user
return NoneLevel 1 (0h): Notify assigned agent
Level 2 (4h): Notify team lead
Level 3 (8h): Notify manager
Level 4 (24h): Notify department headintegrations/# my_app/integrations/email_connector.py
def sync_emails():
# Fetch from Email Account
# Create Communications
# Link to Ticketsfrappe.enqueue(
"my_app.integrations.email_connector.sync_emails",
queue="long",
timeout=600
)has_value_changedfrappe-ui-patternsfrappe-ui-patternsfrappe.log_error()| Mistake | Why It Fails | Fix |
|---|---|---|
| Over-complex workflows | Hard to maintain, user confusion | Keep workflows linear when possible; split complex flows |
| Missing error handling in integrations | Silent failures, data inconsistency | Wrap external calls in try/except; log errors; retry logic |
| Race conditions in document updates | Data corruption | Use |
| SLA without timezone handling | Wrong calculations for global users | Store and compare in UTC; use |
| Not using queues for bulk operations | Timeouts, memory issues | Use |
| Hardcoded role names | Breaks on role changes | Use constants or settings for role names |
| Custom UI patterns | Inconsistent UX, user confusion | Study and follow CRM/Helpdesk app shells |
| Using vanilla JS/jQuery for frontend | Maintenance burden, ecosystem mismatch | Always use Frappe UI with Vue 3 |