@cubocicloide/stack-frappe 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +37 -0
  3. package/dist/commands/lint/checks/APP/001.d.ts +13 -0
  4. package/dist/commands/lint/checks/APP/001.js +73 -0
  5. package/dist/commands/lint/checks/APP/001.js.map +1 -0
  6. package/dist/commands/lint/checks/APP/002.d.ts +12 -0
  7. package/dist/commands/lint/checks/APP/002.js +94 -0
  8. package/dist/commands/lint/checks/APP/002.js.map +1 -0
  9. package/dist/commands/lint/checks/APP/003.d.ts +12 -0
  10. package/dist/commands/lint/checks/APP/003.js +94 -0
  11. package/dist/commands/lint/checks/APP/003.js.map +1 -0
  12. package/dist/commands/lint/checks/APP/004.d.ts +12 -0
  13. package/dist/commands/lint/checks/APP/004.js +117 -0
  14. package/dist/commands/lint/checks/APP/004.js.map +1 -0
  15. package/dist/commands/lint/checks/DT/001.d.ts +11 -0
  16. package/dist/commands/lint/checks/DT/001.js +57 -0
  17. package/dist/commands/lint/checks/DT/001.js.map +1 -0
  18. package/dist/commands/lint/checks/DT/002.d.ts +12 -0
  19. package/dist/commands/lint/checks/DT/002.js +74 -0
  20. package/dist/commands/lint/checks/DT/002.js.map +1 -0
  21. package/dist/commands/lint/checks/DT/003.d.ts +13 -0
  22. package/dist/commands/lint/checks/DT/003.js +96 -0
  23. package/dist/commands/lint/checks/DT/003.js.map +1 -0
  24. package/dist/commands/lint/checks/DT/004.d.ts +12 -0
  25. package/dist/commands/lint/checks/DT/004.js +101 -0
  26. package/dist/commands/lint/checks/DT/004.js.map +1 -0
  27. package/dist/commands/lint/checks/PY/001.d.ts +12 -0
  28. package/dist/commands/lint/checks/PY/001.js +87 -0
  29. package/dist/commands/lint/checks/PY/001.js.map +1 -0
  30. package/dist/commands/lint/checks/PY/002.d.ts +12 -0
  31. package/dist/commands/lint/checks/PY/002.js +80 -0
  32. package/dist/commands/lint/checks/PY/002.js.map +1 -0
  33. package/dist/commands/lint/checks/PY/003.d.ts +11 -0
  34. package/dist/commands/lint/checks/PY/003.js +56 -0
  35. package/dist/commands/lint/checks/PY/003.js.map +1 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +1987 -0
  38. package/dist/index.js.map +1 -0
  39. package/dude.stack.json +12 -0
  40. package/package.json +41 -0
  41. package/templates/aws-ecs/_dockerignore +11 -0
  42. package/templates/aws-ecs/docker/Dockerfile.prod.hbs +80 -0
  43. package/templates/aws-ecs/docker/nginx-entrypoint.sh +17 -0
  44. package/templates/aws-ecs/docker/nginx-template.conf +95 -0
  45. package/templates/aws-ecs/docs/docs/deploy.md.hbs +53 -0
  46. package/templates/aws-ecs/iac/README.md.hbs +113 -0
  47. package/templates/aws-ecs/iac/_gitignore +14 -0
  48. package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
  49. package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +93 -0
  50. package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +14 -0
  51. package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
  52. package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
  53. package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
  54. package/templates/aws-ecs/iac/terraform/main.tf.hbs +1205 -0
  55. package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +103 -0
  56. package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
  57. package/templates/aws-ecs/iac/terraform/variables.tf.hbs +139 -0
  58. package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
  59. package/templates/base/.claude/rules/APP/001.md +26 -0
  60. package/templates/base/.claude/rules/APP/002.md +26 -0
  61. package/templates/base/.claude/rules/APP/003.md +25 -0
  62. package/templates/base/.claude/rules/APP/004.md +27 -0
  63. package/templates/base/.claude/rules/DT/001.md +25 -0
  64. package/templates/base/.claude/rules/DT/002.md +25 -0
  65. package/templates/base/.claude/rules/DT/003.md +24 -0
  66. package/templates/base/.claude/rules/DT/004.md +22 -0
  67. package/templates/base/.claude/rules/PY/001.md +30 -0
  68. package/templates/base/.claude/rules/PY/002.md +31 -0
  69. package/templates/base/.claude/rules/PY/003.md +29 -0
  70. package/templates/base/.claude/settings.json +42 -0
  71. package/templates/base/.claude/skills/create-doctype/SKILL.md +99 -0
  72. package/templates/base/.dude/commands/README.md +85 -0
  73. package/templates/base/.dude/commands/hello.ts +34 -0
  74. package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
  75. package/templates/base/.dude/lint/checks/README.md +69 -0
  76. package/templates/base/.vscode/tasks.json +44 -0
  77. package/templates/base/CLAUDE.md.hbs +49 -0
  78. package/templates/base/README.md.hbs +68 -0
  79. package/templates/base/_env.example.hbs +5 -0
  80. package/templates/base/_env.hbs +12 -0
  81. package/templates/base/_gitignore +26 -0
  82. package/templates/base/_npmrc +2 -0
  83. package/templates/base/apps/README.md +24 -0
  84. package/templates/base/apps/ticketing/README.md +43 -0
  85. package/templates/base/apps/ticketing/pyproject.toml +34 -0
  86. package/templates/base/apps/ticketing/ticketing/__init__.py +1 -0
  87. package/templates/base/apps/ticketing/ticketing/api.py +35 -0
  88. package/templates/base/apps/ticketing/ticketing/events/__init__.py +0 -0
  89. package/templates/base/apps/ticketing/ticketing/events/hd_ticket.py +32 -0
  90. package/templates/base/apps/ticketing/ticketing/fixtures/workflow.json +55 -0
  91. package/templates/base/apps/ticketing/ticketing/fixtures/workflow_action_master.json +12 -0
  92. package/templates/base/apps/ticketing/ticketing/fixtures/workflow_state.json +20 -0
  93. package/templates/base/apps/ticketing/ticketing/hooks.py +54 -0
  94. package/templates/base/apps/ticketing/ticketing/modules.txt +1 -0
  95. package/templates/base/apps/ticketing/ticketing/patches/__init__.py +0 -0
  96. package/templates/base/apps/ticketing/ticketing/patches/v1_0/__init__.py +0 -0
  97. package/templates/base/apps/ticketing/ticketing/patches/v1_0/set_default_branding.py +26 -0
  98. package/templates/base/apps/ticketing/ticketing/patches.txt +5 -0
  99. package/templates/base/apps/ticketing/ticketing/public/images/favicon.png +0 -0
  100. package/templates/base/apps/ticketing/ticketing/public/images/logo.png +0 -0
  101. package/templates/base/apps/ticketing/ticketing/tasks.py +99 -0
  102. package/templates/base/apps/ticketing/ticketing/templates/__init__.py +0 -0
  103. package/templates/base/apps/ticketing/ticketing/templates/pages/__init__.py +0 -0
  104. package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.html +30 -0
  105. package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.py +14 -0
  106. package/templates/base/apps/ticketing/ticketing/ticketing/__init__.py +0 -0
  107. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/__init__.py +0 -0
  108. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py +0 -0
  109. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/test_ticket_escalation_rule.py +32 -0
  110. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.js +23 -0
  111. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.json +99 -0
  112. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.py +18 -0
  113. package/templates/base/docker/init.sh +114 -0
  114. package/templates/base/docker-compose.yml.hbs +62 -0
  115. package/templates/base/docs/docs/api.md +21 -0
  116. package/templates/base/docs/docs/dude.md.hbs +220 -0
  117. package/templates/base/docs/docs/extending.md +238 -0
  118. package/templates/base/docs/docs/frappe.md.hbs +223 -0
  119. package/templates/base/docs/docs/index.md.hbs +101 -0
  120. package/templates/base/docs/docs/mkdocs.md +235 -0
  121. package/templates/base/docs/mkdocs.yml.hbs +54 -0
  122. package/templates/base/package.json.hbs +11 -0
@@ -0,0 +1,103 @@
1
+ # Outputs consumed by the `dude iac` commands (build/push/deploy/status/
2
+ # create-site/migrate read them with `terraform output -json`) — keep the
3
+ # names stable.
4
+
5
+ output "region" {
6
+ description = "AWS region of this environment."
7
+ value = var.region
8
+ }
9
+
10
+ output "app_url" {
11
+ description = "Public URL of the app."
12
+ value = local.app_url
13
+ }
14
+
15
+ output "site_name" {
16
+ description = "Frappe site served by this environment."
17
+ value = local.site_name
18
+ }
19
+
20
+ output "alb_dns_name" {
21
+ description = "DNS name of the load balancer."
22
+ value = aws_lb.this.dns_name
23
+ }
24
+
25
+ output "ecr_app_repository_url" {
26
+ description = "ECR repository for the production Frappe image."
27
+ value = data.aws_ecr_repository.app.repository_url
28
+ }
29
+
30
+ output "cluster_name" {
31
+ description = "ECS cluster name."
32
+ value = aws_ecs_cluster.this.name
33
+ }
34
+
35
+ output "frontend_service_name" {
36
+ description = "ECS service running nginx."
37
+ value = aws_ecs_service.frontend.name
38
+ }
39
+
40
+ output "backend_service_name" {
41
+ description = "ECS service running gunicorn."
42
+ value = aws_ecs_service.backend.name
43
+ }
44
+
45
+ output "websocket_service_name" {
46
+ description = "ECS service running socketio."
47
+ value = aws_ecs_service.websocket.name
48
+ }
49
+
50
+ output "worker_service_name" {
51
+ description = "ECS service running the queue worker."
52
+ value = aws_ecs_service.worker.name
53
+ }
54
+
55
+ output "scheduler_service_name" {
56
+ description = "ECS service running bench schedule."
57
+ value = aws_ecs_service.scheduler.name
58
+ }
59
+
60
+ output "public_subnet_ids" {
61
+ description = "Subnets the one-off tasks run in."
62
+ value = aws_subnet.public[*].id
63
+ }
64
+
65
+ output "app_security_group_id" {
66
+ description = "Security group shared by every Frappe task (used by the one-off tasks)."
67
+ value = aws_security_group.app.id
68
+ }
69
+
70
+ output "configurator_task_definition" {
71
+ description = "Task definition ARN for the configurator one-off task."
72
+ value = aws_ecs_task_definition.configurator.arn
73
+ }
74
+
75
+ output "create_site_task_definition" {
76
+ description = "Task definition ARN for the create-site one-off task."
77
+ value = aws_ecs_task_definition.create_site.arn
78
+ }
79
+
80
+ output "migrate_task_definition" {
81
+ description = "Task definition ARN for the migrate one-off task."
82
+ value = aws_ecs_task_definition.migrate.arn
83
+ }
84
+
85
+ output "db_endpoint" {
86
+ description = "RDS MariaDB endpoint."
87
+ value = aws_db_instance.this.address
88
+ }
89
+
90
+ output "redis_endpoint" {
91
+ description = "ElastiCache Redis endpoint."
92
+ value = local.redis_host
93
+ }
94
+
95
+ output "efs_id" {
96
+ description = "EFS file system holding the frappe sites/ volume."
97
+ value = aws_efs_file_system.sites.id
98
+ }
99
+
100
+ output "admin_password_secret_arn" {
101
+ description = "Secrets Manager secret holding the site's Administrator password."
102
+ value = aws_secretsmanager_secret.admin_password.arn
103
+ }
@@ -0,0 +1,19 @@
1
+ provider "aws" {
2
+ region = var.region
3
+
4
+ # Pin to the standard public endpoints — the AWS provider 5.x enables
5
+ # endpoint discovery by default and can return VPC-endpoint-scoped URLs
6
+ # that don't resolve from a local machine.
7
+ endpoints {
8
+ dynamodb = "https://dynamodb.${var.region}.amazonaws.com"
9
+ s3 = "https://s3.${var.region}.amazonaws.com"
10
+ }
11
+
12
+ default_tags {
13
+ tags = {
14
+ Project = var.project_name
15
+ Environment = var.environment
16
+ ManagedBy = "terraform"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,139 @@
1
+ variable "project_name" {
2
+ description = "Project slug — prefixes every resource name."
3
+ type = string
4
+ default = "{{projectName}}"
5
+ }
6
+
7
+ variable "environment" {
8
+ description = "Environment name (dev, staging, prod, …)."
9
+ type = string
10
+ }
11
+
12
+ variable "region" {
13
+ description = "AWS region to deploy into."
14
+ type = string
15
+ }
16
+
17
+ variable "image_tag" {
18
+ description = "Tag of the production Frappe image to run (written by `dude iac deploy`)."
19
+ type = string
20
+ default = "latest"
21
+ }
22
+
23
+ variable "site_name" {
24
+ description = "Frappe site name served by this environment (default: the project name). nginx pins it via FRAPPE_SITE_NAME_HEADER, so it is independent of the public domain."
25
+ type = string
26
+ default = ""
27
+ }
28
+
29
+ variable "allowed_cidrs" {
30
+ description = "CIDRs allowed to reach the ALB (tighten for non-public environments)."
31
+ type = list(string)
32
+ default = ["0.0.0.0/0"]
33
+ }
34
+
35
+ variable "domain_name" {
36
+ description = "Public domain for the app (e.g. helpdesk.example.com). Empty = serve on the ALB DNS name over plain HTTP."
37
+ type = string
38
+ default = ""
39
+ }
40
+
41
+ variable "route53_zone_name" {
42
+ description = "Route53 hosted zone that owns domain_name (e.g. example.com). Required when domain_name is set."
43
+ type = string
44
+ default = ""
45
+ }
46
+
47
+ variable "log_retention_days" {
48
+ description = "CloudWatch log retention for every service."
49
+ type = number
50
+ default = 30
51
+ }
52
+
53
+ # ── Database / cache ─────────────────────────────────────────────────────────
54
+
55
+ variable "db_instance_class" {
56
+ description = "RDS MariaDB instance class."
57
+ type = string
58
+ default = "db.t4g.micro"
59
+ }
60
+
61
+ variable "db_allocated_storage" {
62
+ description = "RDS storage (GiB)."
63
+ type = number
64
+ default = 20
65
+ }
66
+
67
+ variable "redis_node_type" {
68
+ description = "ElastiCache Redis node type."
69
+ type = string
70
+ default = "cache.t4g.micro"
71
+ }
72
+
73
+ # ── Task sizing ──────────────────────────────────────────────────────────────
74
+
75
+ variable "frontend_cpu" {
76
+ description = "Fargate CPU units for the nginx frontend."
77
+ type = number
78
+ default = 256
79
+ }
80
+
81
+ variable "frontend_memory" {
82
+ description = "Fargate memory (MiB) for the nginx frontend."
83
+ type = number
84
+ default = 512
85
+ }
86
+
87
+ variable "frontend_desired_count" {
88
+ description = "Number of frontend tasks."
89
+ type = number
90
+ default = 1
91
+ }
92
+
93
+ variable "backend_cpu" {
94
+ description = "Fargate CPU units for the gunicorn backend (also used by the one-off tasks)."
95
+ type = number
96
+ default = 512
97
+ }
98
+
99
+ variable "backend_memory" {
100
+ description = "Fargate memory (MiB) for the gunicorn backend (also used by the one-off tasks)."
101
+ type = number
102
+ default = 1024
103
+ }
104
+
105
+ variable "backend_desired_count" {
106
+ description = "Number of backend tasks."
107
+ type = number
108
+ default = 1
109
+ }
110
+
111
+ variable "websocket_cpu" {
112
+ description = "Fargate CPU units for the socketio websocket service."
113
+ type = number
114
+ default = 256
115
+ }
116
+
117
+ variable "websocket_memory" {
118
+ description = "Fargate memory (MiB) for the socketio websocket service."
119
+ type = number
120
+ default = 512
121
+ }
122
+
123
+ variable "worker_cpu" {
124
+ description = "Fargate CPU units for the queue worker."
125
+ type = number
126
+ default = 512
127
+ }
128
+
129
+ variable "worker_memory" {
130
+ description = "Fargate memory (MiB) for the queue worker."
131
+ type = number
132
+ default = 1024
133
+ }
134
+
135
+ variable "worker_desired_count" {
136
+ description = "Number of queue-worker tasks."
137
+ type = number
138
+ default = 1
139
+ }
@@ -0,0 +1,19 @@
1
+ terraform {
2
+ required_version = ">= 1.6.0"
3
+
4
+ required_providers {
5
+ aws = {
6
+ source = "hashicorp/aws"
7
+ version = "~> 5.60"
8
+ }
9
+ random = {
10
+ source = "hashicorp/random"
11
+ version = "~> 3.6"
12
+ }
13
+ }
14
+
15
+ # Partial backend: the concrete bucket/key/table are supplied per environment
16
+ # via `-backend-config=environments/<env>/backend.hcl` at `terraform init`.
17
+ # This keeps a single root usable both locally and from CI/CD.
18
+ backend "s3" {}
19
+ }
@@ -0,0 +1,26 @@
1
+ # APP001 — Frappe app layout integrity (error)
2
+
3
+ Every directory under `apps/` that ships a `pyproject.toml` must be a complete
4
+ Frappe app: a Python package `apps/<app>/<app>/` containing `hooks.py`,
5
+ `modules.txt`, `patches.txt` and `__init__.py`. A directory with Python files
6
+ but no `pyproject.toml` gets a warning — `docker/init.sh` only links
7
+ directories that look like real apps, so it would silently be ignored.
8
+
9
+ These four files are the app's contract with the framework: `bench install`
10
+ reads `hooks.py` and `modules.txt`, `bench migrate` reads `patches.txt`.
11
+ A missing file doesn't fail loudly — the app just half-works.
12
+
13
+ ```text
14
+ ✅ apps/ticketing/
15
+ pyproject.toml
16
+ ticketing/
17
+ __init__.py
18
+ hooks.py
19
+ modules.txt
20
+ patches.txt
21
+
22
+ ❌ apps/my_app/ # has my_app/tasks.py but no pyproject.toml
23
+ ```
24
+
25
+ **Fix**: scaffold apps with `dude app new --name <app>` (wraps `bench
26
+ new-app`), or add the missing file(s) by copying them from `apps/ticketing/`.
@@ -0,0 +1,26 @@
1
+ # APP002 — scheduler_events handlers must resolve (error)
2
+
3
+ Every dotted path declared in the `scheduler_events` dict of `hooks.py`
4
+ (e.g. `"ticketing.tasks.escalate_overdue_tickets"`) must resolve to an
5
+ existing module file inside the app with a matching `def <function>(`.
6
+
7
+ The scheduler resolves these paths at **runtime**, per tick: a typo doesn't
8
+ fail on install or on boot — the job just never runs, and the only trace is a
9
+ Scheduled Job Log entry most people never read. This check makes the failure
10
+ visible at lint time.
11
+
12
+ ```python
13
+ # ✅ hooks.py
14
+ scheduler_events = {
15
+ "hourly": ["ticketing.tasks.escalate_overdue_tickets"], # tasks.py defines it
16
+ }
17
+
18
+ # ❌ hooks.py
19
+ scheduler_events = {
20
+ "hourly": ["ticketing.tasks.escalate_overdue_ticket"], # typo — silently dead
21
+ }
22
+ ```
23
+
24
+ **Fix**: correct the dotted path, or create the function in the module the
25
+ path points at. Test a job by hand with
26
+ `dude bench --site <site> execute ticketing.tasks.escalate_overdue_tickets`.
@@ -0,0 +1,25 @@
1
+ # APP003 — doc_events handlers must resolve (error)
2
+
3
+ Every handler declared in the `doc_events` dict of `hooks.py`
4
+ (e.g. `"ticketing.events.hd_ticket.after_insert"`) must resolve to an existing
5
+ module file inside the app with a matching `def <function>(`.
6
+
7
+ `doc_events` is how an app extends DocTypes owned by *other* apps (e.g.
8
+ Helpdesk's `HD Ticket`) without forking them. Like scheduler events, the
9
+ paths are resolved at runtime on every document save — a broken path either
10
+ throws on every save of that DocType or (depending on the frappe version)
11
+ silently skips your logic.
12
+
13
+ ```python
14
+ # ✅ hooks.py
15
+ doc_events = {
16
+ "HD Ticket": {
17
+ "after_insert": "ticketing.events.hd_ticket.after_insert",
18
+ },
19
+ }
20
+ # with apps/ticketing/ticketing/events/hd_ticket.py defining
21
+ # def after_insert(doc, method=None): ...
22
+ ```
23
+
24
+ **Fix**: correct the dotted path or create the handler function. Handlers
25
+ take `(doc, method)` — see `apps/ticketing/ticketing/events/hd_ticket.py`.
@@ -0,0 +1,27 @@
1
+ # APP004 — Fixtures declared ↔ shipped (error)
2
+
3
+ The `fixtures` list in `hooks.py` and the JSON files in
4
+ `apps/<app>/<app>/fixtures/` must match in both directions:
5
+
6
+ - every declared fixture DocType (`{"dt": "Workflow"}` or plain `"Workflow"`)
7
+ needs a `fixtures/<scrubbed_name>.json` file (`Workflow State` →
8
+ `workflow_state.json`);
9
+ - every `fixtures/*.json` file must be declared in `hooks.py`.
10
+
11
+ `bench migrate` imports fixtures **from the declaration list**: a declared-
12
+ but-missing file breaks installs on a fresh site, while an undeclared file is
13
+ dead weight that everyone assumes is being imported — the worst kind of
14
+ config drift.
15
+
16
+ ```python
17
+ # ✅ hooks.py — masters first, then the docs that link to them
18
+ fixtures = [
19
+ {"dt": "Workflow State", "filters": [["name", "in", ["Draft", "Approved", "Rejected"]]]},
20
+ {"dt": "Workflow Action Master", "filters": [["name", "in", ["Approve", "Reject"]]]},
21
+ {"dt": "Workflow", "filters": [["name", "in", ["Ticket Escalation Rule Approval"]]]},
22
+ ]
23
+ ```
24
+
25
+ **Fix**: after changing fixture records in the Desk UI, export them with
26
+ `dude bench --site <site> export-fixtures` (writes the JSON files), and keep
27
+ the `fixtures` list in `hooks.py` in sync. Remove stale files/declarations.
@@ -0,0 +1,25 @@
1
+ # DT001 — DocType bundle completeness (error)
2
+
3
+ Every DocType directory
4
+ `apps/<app>/<app>/<module>/doctype/<doctype_name>/` must contain the full
5
+ bundle: `<doctype_name>.json` (the schema), `<doctype_name>.py` (the
6
+ controller) and `__init__.py`. The form script (`.js`) and tests are optional
7
+ (tests are nudged separately by PY003).
8
+
9
+ Frappe loads DocTypes by convention from exactly these paths. A missing
10
+ controller means `frappe.get_doc(...)` falls back to a generic `Document`
11
+ with none of your validation; a missing `__init__.py` breaks imports; a
12
+ missing JSON means the DocType simply doesn't exist on migrate.
13
+
14
+ ```text
15
+ ✅ apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/
16
+ __init__.py
17
+ ticket_escalation_rule.json
18
+ ticket_escalation_rule.py
19
+ ticket_escalation_rule.js # optional
20
+ test_ticket_escalation_rule.py # optional (see PY003)
21
+ ```
22
+
23
+ **Fix**: add the missing file. For a new DocType, copy the
24
+ `ticket_escalation_rule` bundle as a starting point, or create it in the Desk
25
+ UI with developer mode on (frappe writes the bundle into the app for you).
@@ -0,0 +1,25 @@
1
+ # DT002 — DocTypes must declare permissions (error)
2
+
3
+ Every DocType JSON must have a non-empty `permissions` array in which at
4
+ least one entry names a `role`.
5
+
6
+ Frappe's permission model is **deny-by-default**: a DocType with no
7
+ permission rules is invisible and unusable for every user except
8
+ `Administrator`. That "works" in development (you are Administrator) and then
9
+ fails for the first real user — the classic Frappe rookie trap.
10
+
11
+ ```json
12
+ // ✅ ticket_escalation_rule.json
13
+ "permissions": [
14
+ {
15
+ "role": "System Manager",
16
+ "read": 1, "write": 1, "create": 1, "delete": 1,
17
+ "email": 1, "export": 1, "print": 1, "report": 1, "share": 1
18
+ }
19
+ ]
20
+ ```
21
+
22
+ **Fix**: add a permissions entry per role that needs access (start with
23
+ `System Manager`, add end-user roles deliberately). Prefer editing the JSON in
24
+ the app (or Desk UI with developer mode on) over site-local Custom
25
+ Permissions, so the rules ship with the code.
@@ -0,0 +1,24 @@
1
+ # DT003 — DocType naming and module registration (error)
2
+
3
+ Three naming invariants tie a DocType to its place on disk:
4
+
5
+ 1. `scrub(name)` (lowercase, spaces → underscores) must equal the doctype
6
+ directory name: `"Ticket Escalation Rule"` → `ticket_escalation_rule/`;
7
+ 2. the JSON's `module` must be listed in the app's `modules.txt`;
8
+ 3. `scrub(module)` must equal the module directory the doctype lives under:
9
+ module `"Ticketing"` → `ticketing/doctype/<name>/`.
10
+
11
+ Frappe locates a DocType's code purely from these conventions (`module` +
12
+ scrubbed name → path). Break any of them and `bench migrate` either fails or
13
+ — worse — imports the schema while never finding your controller.
14
+
15
+ ```text
16
+ ✅ modules.txt: Ticketing
17
+ JSON: "name": "Ticket Escalation Rule", "module": "Ticketing"
18
+ Path: ticketing/ticketing/doctype/ticket_escalation_rule/
19
+ ```
20
+
21
+ **Fix**: rename the directory to the scrubbed DocType name, add the module to
22
+ `modules.txt`, or move the bundle under the right module directory. When you
23
+ add a new module, remember every module in `modules.txt` needs a matching
24
+ `<scrubbed_module>/` package directory in the app.
@@ -0,0 +1,22 @@
1
+ # DT004 — Field hygiene: snake_case, unique fieldnames (error)
2
+
3
+ In every DocType JSON, each `fields[]` entry (layout breaks included) must
4
+ have a `fieldname` matching `^[a-z][a-z0-9_]*$`, unique within the DocType.
5
+
6
+ Fieldnames are not labels: they become **database columns**, **API keys**
7
+ (`/api/resource/...`), Jinja/JS attribute names and filter keys. A camelCase
8
+ or duplicated fieldname works just well enough to spread through client
9
+ scripts and integrations before it breaks something that is painful to
10
+ rename (renaming a fieldname later means a patch + data migration).
11
+
12
+ ```json
13
+ // ✅
14
+ { "fieldname": "hours_until_escalation", "fieldtype": "Int", "label": "Hours Until Escalation" }
15
+
16
+ // ❌ camelCase / duplicate
17
+ { "fieldname": "hoursUntilEscalation", ... }
18
+ ```
19
+
20
+ **Fix**: rename the fieldname to snake_case (before the DocType carries data;
21
+ afterwards use `frappe.reload_doc` + a rename patch), and deduplicate
22
+ conflicting entries — keep the one with the intended `fieldtype`.
@@ -0,0 +1,30 @@
1
+ # PY001 — No unjustified `allow_guest=True` (error)
2
+
3
+ A whitelisted method with `@frappe.whitelist(allow_guest=True)` is callable by
4
+ **unauthenticated** visitors — it bypasses login entirely and becomes part of
5
+ your public attack surface. The linter flags every occurrence unless a
6
+ justification comment `# guest-ok: <reason>` sits on the same line or the
7
+ line directly above.
8
+
9
+ Most methods never need guest access; the common legitimate cases are public
10
+ webforms, health probes and truly public read-only data. Even then: validate
11
+ inputs defensively and return the minimum.
12
+
13
+ ```python
14
+ # ✅ authenticated (the default)
15
+ @frappe.whitelist()
16
+ def ticket_stats(): ...
17
+
18
+ # ✅ deliberate, documented public endpoint
19
+ # guest-ok: public status page, returns only aggregate counts
20
+ @frappe.whitelist(allow_guest=True)
21
+ def public_status(): ...
22
+
23
+ # ❌ unjustified guest exposure
24
+ @frappe.whitelist(allow_guest=True)
25
+ def delete_ticket(name): ...
26
+ ```
27
+
28
+ **Fix**: drop `allow_guest=True` (callers authenticate via session or API
29
+ key), or add a `# guest-ok:` comment explaining why the method is safe to
30
+ expose — and make sure it actually is.
@@ -0,0 +1,31 @@
1
+ # PY002 — SQL safety (error for interpolation, warning for raw SQL)
2
+
3
+ Two tiers:
4
+
5
+ - **Error** — `frappe.db.sql()` whose query is built dynamically (f-string,
6
+ `%` formatting, `.format(...)`, string concatenation). That is a SQL
7
+ injection waiting for user input to reach it.
8
+ - **Warning** — any other raw `frappe.db.sql()`. Prefer `frappe.get_all` /
9
+ `frappe.get_list` or `frappe.qb` (the query builder): they respect the
10
+ permission model, escape everything, and survive schema/engine changes.
11
+ Raw SQL is legitimate for what the ORM genuinely cannot express — keep it
12
+ parameterized.
13
+
14
+ ```python
15
+ # ❌ error — injectable
16
+ frappe.db.sql(f"select name from `tabHD Ticket` where status = '{status}'")
17
+
18
+ # ✅ raw but parameterized (warning still nudges toward the ORM)
19
+ frappe.db.sql(
20
+ "select status, count(*) from `tabHD Ticket` where opening_date < %(cutoff)s group by status",
21
+ {"cutoff": cutoff},
22
+ )
23
+
24
+ # ✅ preferred
25
+ frappe.get_all("HD Ticket", filters={"opening_date": ("<", cutoff)},
26
+ fields=["status", "count(name) as total"], group_by="status")
27
+ ```
28
+
29
+ **Fix**: rewrite with `frappe.get_all`/`frappe.qb`; where raw SQL must stay,
30
+ pass values via the second argument with `%(name)s` placeholders — never
31
+ interpolate them into the query string.
@@ -0,0 +1,29 @@
1
+ # PY003 — Every DocType should ship tests (warning)
2
+
3
+ Every DocType bundle should include a `test_<doctype_name>.py` next to its
4
+ controller. `bench run-tests --app <app>` (wrapped by `dude test`) discovers
5
+ tests from exactly that convention.
6
+
7
+ Controller logic (`validate`, `on_update`, …) is where business rules live,
8
+ and it only runs inside a full frappe context — an untested controller is
9
+ effectively unexercised until production. `FrappeTestCase` makes this cheap:
10
+ each test runs in a transaction that is rolled back, so tests never leak data
11
+ into the site.
12
+
13
+ ```python
14
+ # ✅ test_ticket_escalation_rule.py
15
+ import frappe
16
+ from frappe.tests.utils import FrappeTestCase
17
+
18
+ class TestTicketEscalationRule(FrappeTestCase):
19
+ def test_non_positive_hours_are_rejected(self):
20
+ rule = frappe.get_doc({
21
+ "doctype": "Ticket Escalation Rule",
22
+ "rule_name": "x", "priority": "High", "hours_until_escalation": 0,
23
+ })
24
+ self.assertRaises(frappe.ValidationError, rule.insert)
25
+ ```
26
+
27
+ **Fix**: add a `test_<name>.py` covering at least the validation paths of the
28
+ controller. Run it with `dude test --app <app>` (or a single module via
29
+ `dude test --module <dotted.path>`).
@@ -0,0 +1,42 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git *)",
5
+ "Bash(docker *)",
6
+ "Bash(dude *)",
7
+ "Bash(node *)",
8
+ "Bash(pnpm *)",
9
+ "Bash(npm *)",
10
+ "Bash(pip *)",
11
+ "Bash(pip3 *)",
12
+ "Bash(python *)",
13
+ "Bash(python3 *)",
14
+ "Bash(rm *)",
15
+ "Bash(mkdir *)",
16
+ "Bash(cp *)",
17
+ "Bash(mv *)",
18
+ "Bash(sed *)",
19
+ "Bash(find *)",
20
+ "Bash(cat *)",
21
+ "Read(*)",
22
+ "Write(*)",
23
+ "Edit(*)",
24
+ "Glob(*)",
25
+ "Grep(*)",
26
+ "PushNotification"
27
+ ]
28
+ },
29
+ "hooks": {
30
+ "SubagentStop": [
31
+ {
32
+ "hooks": [
33
+ {
34
+ "type": "command",
35
+ "command": "osascript -e 'display notification \"Agent completed\" with title \"Claude Code\"' 2>/dev/null || true",
36
+ "async": true
37
+ }
38
+ ]
39
+ }
40
+ ]
41
+ }
42
+ }