@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.
- package/LICENSE +33 -0
- package/README.md +37 -0
- package/dist/commands/lint/checks/APP/001.d.ts +13 -0
- package/dist/commands/lint/checks/APP/001.js +73 -0
- package/dist/commands/lint/checks/APP/001.js.map +1 -0
- package/dist/commands/lint/checks/APP/002.d.ts +12 -0
- package/dist/commands/lint/checks/APP/002.js +94 -0
- package/dist/commands/lint/checks/APP/002.js.map +1 -0
- package/dist/commands/lint/checks/APP/003.d.ts +12 -0
- package/dist/commands/lint/checks/APP/003.js +94 -0
- package/dist/commands/lint/checks/APP/003.js.map +1 -0
- package/dist/commands/lint/checks/APP/004.d.ts +12 -0
- package/dist/commands/lint/checks/APP/004.js +117 -0
- package/dist/commands/lint/checks/APP/004.js.map +1 -0
- package/dist/commands/lint/checks/DT/001.d.ts +11 -0
- package/dist/commands/lint/checks/DT/001.js +57 -0
- package/dist/commands/lint/checks/DT/001.js.map +1 -0
- package/dist/commands/lint/checks/DT/002.d.ts +12 -0
- package/dist/commands/lint/checks/DT/002.js +74 -0
- package/dist/commands/lint/checks/DT/002.js.map +1 -0
- package/dist/commands/lint/checks/DT/003.d.ts +13 -0
- package/dist/commands/lint/checks/DT/003.js +96 -0
- package/dist/commands/lint/checks/DT/003.js.map +1 -0
- package/dist/commands/lint/checks/DT/004.d.ts +12 -0
- package/dist/commands/lint/checks/DT/004.js +101 -0
- package/dist/commands/lint/checks/DT/004.js.map +1 -0
- package/dist/commands/lint/checks/PY/001.d.ts +12 -0
- package/dist/commands/lint/checks/PY/001.js +87 -0
- package/dist/commands/lint/checks/PY/001.js.map +1 -0
- package/dist/commands/lint/checks/PY/002.d.ts +12 -0
- package/dist/commands/lint/checks/PY/002.js +80 -0
- package/dist/commands/lint/checks/PY/002.js.map +1 -0
- package/dist/commands/lint/checks/PY/003.d.ts +11 -0
- package/dist/commands/lint/checks/PY/003.js +56 -0
- package/dist/commands/lint/checks/PY/003.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1987 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +12 -0
- package/package.json +41 -0
- package/templates/aws-ecs/_dockerignore +11 -0
- package/templates/aws-ecs/docker/Dockerfile.prod.hbs +80 -0
- package/templates/aws-ecs/docker/nginx-entrypoint.sh +17 -0
- package/templates/aws-ecs/docker/nginx-template.conf +95 -0
- package/templates/aws-ecs/docs/docs/deploy.md.hbs +53 -0
- package/templates/aws-ecs/iac/README.md.hbs +113 -0
- package/templates/aws-ecs/iac/_gitignore +14 -0
- package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +93 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +14 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
- package/templates/aws-ecs/iac/terraform/main.tf.hbs +1205 -0
- package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +103 -0
- package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
- package/templates/aws-ecs/iac/terraform/variables.tf.hbs +139 -0
- package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
- package/templates/base/.claude/rules/APP/001.md +26 -0
- package/templates/base/.claude/rules/APP/002.md +26 -0
- package/templates/base/.claude/rules/APP/003.md +25 -0
- package/templates/base/.claude/rules/APP/004.md +27 -0
- package/templates/base/.claude/rules/DT/001.md +25 -0
- package/templates/base/.claude/rules/DT/002.md +25 -0
- package/templates/base/.claude/rules/DT/003.md +24 -0
- package/templates/base/.claude/rules/DT/004.md +22 -0
- package/templates/base/.claude/rules/PY/001.md +30 -0
- package/templates/base/.claude/rules/PY/002.md +31 -0
- package/templates/base/.claude/rules/PY/003.md +29 -0
- package/templates/base/.claude/settings.json +42 -0
- package/templates/base/.claude/skills/create-doctype/SKILL.md +99 -0
- package/templates/base/.dude/commands/README.md +85 -0
- package/templates/base/.dude/commands/hello.ts +34 -0
- package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
- package/templates/base/.dude/lint/checks/README.md +69 -0
- package/templates/base/.vscode/tasks.json +44 -0
- package/templates/base/CLAUDE.md.hbs +49 -0
- package/templates/base/README.md.hbs +68 -0
- package/templates/base/_env.example.hbs +5 -0
- package/templates/base/_env.hbs +12 -0
- package/templates/base/_gitignore +26 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/apps/README.md +24 -0
- package/templates/base/apps/ticketing/README.md +43 -0
- package/templates/base/apps/ticketing/pyproject.toml +34 -0
- package/templates/base/apps/ticketing/ticketing/__init__.py +1 -0
- package/templates/base/apps/ticketing/ticketing/api.py +35 -0
- package/templates/base/apps/ticketing/ticketing/events/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/events/hd_ticket.py +32 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow.json +55 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow_action_master.json +12 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow_state.json +20 -0
- package/templates/base/apps/ticketing/ticketing/hooks.py +54 -0
- package/templates/base/apps/ticketing/ticketing/modules.txt +1 -0
- package/templates/base/apps/ticketing/ticketing/patches/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/patches/v1_0/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/patches/v1_0/set_default_branding.py +26 -0
- package/templates/base/apps/ticketing/ticketing/patches.txt +5 -0
- package/templates/base/apps/ticketing/ticketing/public/images/favicon.png +0 -0
- package/templates/base/apps/ticketing/ticketing/public/images/logo.png +0 -0
- package/templates/base/apps/ticketing/ticketing/tasks.py +99 -0
- package/templates/base/apps/ticketing/ticketing/templates/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.html +30 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.py +14 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/test_ticket_escalation_rule.py +32 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.js +23 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.json +99 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.py +18 -0
- package/templates/base/docker/init.sh +114 -0
- package/templates/base/docker-compose.yml.hbs +62 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +220 -0
- package/templates/base/docs/docs/extending.md +238 -0
- package/templates/base/docs/docs/frappe.md.hbs +223 -0
- package/templates/base/docs/docs/index.md.hbs +101 -0
- package/templates/base/docs/docs/mkdocs.md +235 -0
- package/templates/base/docs/mkdocs.yml.hbs +54 -0
- package/templates/base/package.json.hbs +11 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: create-doctype
|
|
3
|
+
description: Scaffold a new Frappe DocType in a custom app. Asks for the target app, DocType name, module, fields and role permissions, then creates the full bundle (JSON schema, controller, tests) by following the ticket_escalation_rule example, applies it with dude site migrate, and verifies with dude lint and dude test.
|
|
4
|
+
disable-model-invocation: false
|
|
5
|
+
allowed-tools: "Read Write Edit Glob Grep Bash(dude *) Bash(find *) Bash(cat *) Bash(grep *) Bash(ls *)"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Create DocType
|
|
9
|
+
|
|
10
|
+
Guided creation of a DocType that satisfies the DT/PY rules in
|
|
11
|
+
`.claude/rules/`. The reference bundle is
|
|
12
|
+
`apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/` — copy
|
|
13
|
+
its patterns, don't invent new ones.
|
|
14
|
+
|
|
15
|
+
> Read `.claude/rules/DT/*.md` and `.claude/rules/PY/003.md` once at the
|
|
16
|
+
> start — they are the source of truth.
|
|
17
|
+
|
|
18
|
+
**The UI alternative** — the site runs with `developer_mode = 1`, so a DocType
|
|
19
|
+
created in the Desk UI (`/app/doctype/new`) is written back into the app's
|
|
20
|
+
source tree automatically. Prefer the UI when the user wants to explore field
|
|
21
|
+
types interactively or the schema is large; use this skill's manual path when
|
|
22
|
+
working headless, from a spec, or when the Desk UI isn't running. Either way
|
|
23
|
+
the result is the same committed bundle — and the UI path still needs the test
|
|
24
|
+
file added by hand.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Step 1 — Gather requirements
|
|
29
|
+
|
|
30
|
+
Ask only for what the user hasn't already provided:
|
|
31
|
+
|
|
32
|
+
1. **Target app** — default `ticketing`. Must exist under `apps/`.
|
|
33
|
+
2. **DocType name** — Title Case, singular (e.g. `Support Contract`). Derive
|
|
34
|
+
`scrub_name` = lowercase with underscores (`support_contract`).
|
|
35
|
+
3. **Module** — must be listed in `apps/<app>/<app>/modules.txt` (check it;
|
|
36
|
+
`ticketing` has one module: `Ticketing`). The module's scrubbed name is the
|
|
37
|
+
directory the bundle lives under.
|
|
38
|
+
4. **Fields** — for each: `fieldname` (snake_case — DT004), `fieldtype`
|
|
39
|
+
(`Data`, `Int`, `Select` + `options`, `Link` + `options`, `Check`,
|
|
40
|
+
`Small Text`, `Date`, …), `label`, `reqd` yes/no.
|
|
41
|
+
5. **Permissions** — which roles get which rights (read/write/create/delete).
|
|
42
|
+
At least one role — an empty `permissions` array violates DT002.
|
|
43
|
+
6. **Naming** — autoname by a unique field (`field:<fieldname>`), a series
|
|
44
|
+
(`PREF-.####`), or default hash.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Step 2 — Create the bundle
|
|
49
|
+
|
|
50
|
+
Create `apps/<app>/<app>/<scrub_module>/doctype/<scrub_name>/` with **all** of
|
|
51
|
+
these files (DT001), modelling each on the `ticket_escalation_rule` file of
|
|
52
|
+
the same role:
|
|
53
|
+
|
|
54
|
+
| File | Content |
|
|
55
|
+
|------|---------|
|
|
56
|
+
| `__init__.py` | empty |
|
|
57
|
+
| `<scrub_name>.json` | the schema — copy `ticket_escalation_rule.json`, replace `name`, `module`, `autoname`, `field_order`, `fields`, `permissions`; keep `"doctype": "DocType"`, engine, sort settings |
|
|
58
|
+
| `<scrub_name>.py` | controller: `class <CamelCaseName>(Document)` with a `validate(self)` stub enforcing any invariant the user described (`frappe.throw(_("…"))`) |
|
|
59
|
+
| `test_<scrub_name>.py` | `FrappeTestCase` subclass with at least one insert test and one validation-failure test (PY003) — mirror `test_ticket_escalation_rule.py` |
|
|
60
|
+
|
|
61
|
+
Checks while writing:
|
|
62
|
+
|
|
63
|
+
- Every `fieldname` snake_case (DT004); layout pseudo-fields
|
|
64
|
+
(`column_break_*`, `*_section`) count too.
|
|
65
|
+
- `permissions` non-empty (DT002); grant only what the user asked for.
|
|
66
|
+
- `"module"` matches an entry in `modules.txt` (DT003).
|
|
67
|
+
- No raw SQL anywhere (PY002); query via `frappe.get_all`/`frappe.get_doc`.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Step 3 — Apply + validate
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
dude site migrate # creates the table from the new JSON
|
|
75
|
+
dude lint # must pass — fix any DT/PY violation and re-run
|
|
76
|
+
dude test --app <app> # the new tests must pass
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
If `dude site migrate` fails on the JSON, compare it field-by-field with
|
|
80
|
+
`ticket_escalation_rule.json` — missing framework keys are the usual cause.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Step 4 — Report
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
DocType created
|
|
88
|
+
═════════════════════════════════════════
|
|
89
|
+
DocType <Name> (module <Module>, app <app>)
|
|
90
|
+
Bundle apps/<app>/<app>/<scrub_module>/doctype/<scrub_name>/
|
|
91
|
+
Fields <n> (+ naming: <autoname>)
|
|
92
|
+
Permissions <roles>
|
|
93
|
+
Tests test_<scrub_name>.py
|
|
94
|
+
─────────────────────────────────────────
|
|
95
|
+
dude site migrate: ✓
|
|
96
|
+
dude lint: ✓
|
|
97
|
+
dude test: ✓
|
|
98
|
+
Open it: /app/<scrub_name with hyphens>
|
|
99
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Custom `dude` commands
|
|
2
|
+
|
|
3
|
+
Drop a file in this directory and it becomes a `dude` command. The command name
|
|
4
|
+
is the file's base name:
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
.dude/commands/reset.ts → dude reset
|
|
8
|
+
.dude/commands/seed.ts → dude seed
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
No registration step — this directory **is** the registry.
|
|
12
|
+
|
|
13
|
+
## Writing a command
|
|
14
|
+
|
|
15
|
+
Each file must `export default` a command object. Use the `defineCommand` helper
|
|
16
|
+
from `@cubocicloide/dude` (already a dev dependency of this project) for full
|
|
17
|
+
type-checking and autocomplete:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineCommand } from '@cubocicloide/dude'
|
|
21
|
+
|
|
22
|
+
export default defineCommand({
|
|
23
|
+
description: 'Seed the site with demo tickets.',
|
|
24
|
+
args: {
|
|
25
|
+
count: { type: 'string', description: 'How many tickets to create.', default: '10' },
|
|
26
|
+
},
|
|
27
|
+
async run({ projectRoot, args }) {
|
|
28
|
+
// your logic here
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### The command context
|
|
34
|
+
|
|
35
|
+
`run()` receives:
|
|
36
|
+
|
|
37
|
+
| Field | Description |
|
|
38
|
+
| ------------- | -------------------------------------------------------- |
|
|
39
|
+
| `projectRoot` | Absolute path to this project (where `dude.json` lives). |
|
|
40
|
+
| `stackRoot` | Absolute path to the installed stack package. |
|
|
41
|
+
| `args` | Parsed flags, keyed by the names you declare in `args`. |
|
|
42
|
+
|
|
43
|
+
### Arguments
|
|
44
|
+
|
|
45
|
+
Each entry in `args` declares a flag of `type: 'string'` or `type: 'boolean'`,
|
|
46
|
+
with an optional `description` and `default`. They show up in `dude help <cmd>`.
|
|
47
|
+
|
|
48
|
+
## TypeScript & extra packages
|
|
49
|
+
|
|
50
|
+
Commands are loaded with [jiti](https://github.com/unjs/jiti), so you can write
|
|
51
|
+
real TypeScript and `import` any package you add to the project:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pnpm add -D execa
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { defineCommand } from '@cubocicloide/dude'
|
|
59
|
+
import { execa } from 'execa'
|
|
60
|
+
|
|
61
|
+
export default defineCommand({
|
|
62
|
+
description: 'Tail the bench logs.',
|
|
63
|
+
async run() {
|
|
64
|
+
await execa('docker', ['compose', 'logs', '-f', 'bench'], { stdio: 'inherit' })
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`.mjs` and `.js` files work too.
|
|
70
|
+
|
|
71
|
+
## Overriding built-in commands
|
|
72
|
+
|
|
73
|
+
A custom command overrides a stack command of the same name. For example, a
|
|
74
|
+
`.dude/commands/up.ts` replaces the default `dude up`. Overrides are marked in
|
|
75
|
+
`dude help`.
|
|
76
|
+
|
|
77
|
+
The core commands `init`, `upgrade`, `version`, and `help` are reserved and
|
|
78
|
+
cannot be overridden.
|
|
79
|
+
|
|
80
|
+
## Listing your commands
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
dude help # shows a "PROJECT COMMANDS" section
|
|
84
|
+
dude help <command> # shows a command's flags
|
|
85
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example custom command — `dude hello`.
|
|
3
|
+
*
|
|
4
|
+
* This file is a starting point: rename it, edit it, or delete it. Every file
|
|
5
|
+
* under `.dude/commands/` becomes a `dude` command named after the file
|
|
6
|
+
* (`hello.ts` → `dude hello`). See `.dude/commands/README.md` for the full
|
|
7
|
+
* contract.
|
|
8
|
+
*/
|
|
9
|
+
import { defineCommand } from '@cubocicloide/dude'
|
|
10
|
+
|
|
11
|
+
export default defineCommand({
|
|
12
|
+
description: 'Example custom command — prints a greeting.',
|
|
13
|
+
args: {
|
|
14
|
+
name: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'Who to greet.',
|
|
17
|
+
default: 'world',
|
|
18
|
+
},
|
|
19
|
+
shout: {
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
description: 'Greet in uppercase.',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
// `projectRoot` is the absolute path to this project; `args` holds the parsed
|
|
25
|
+
// flags above. You can import any package you add to the project here.
|
|
26
|
+
async run({ projectRoot, args }) {
|
|
27
|
+
const name = typeof args.name === 'string' ? args.name : 'world'
|
|
28
|
+
let message = `Hello, ${name}! 👋`
|
|
29
|
+
if (args.shout) message = message.toUpperCase()
|
|
30
|
+
|
|
31
|
+
process.stdout.write(message + '\n')
|
|
32
|
+
process.stdout.write(`(running in ${projectRoot})\n`)
|
|
33
|
+
},
|
|
34
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example project lint check — PRJ001.
|
|
3
|
+
*
|
|
4
|
+
* This file is a starting point: rename it, edit it, or delete it. Every
|
|
5
|
+
* module under `.dude/lint/checks/<GROUP>/<id>.ts` becomes a lint rule coded
|
|
6
|
+
* `<GROUP><id>` (this one is `PRJ001`) and runs on every `dude lint`, right
|
|
7
|
+
* after the stack's built-in checks. See `.dude/lint/checks/README.md` for
|
|
8
|
+
* the full contract.
|
|
9
|
+
*/
|
|
10
|
+
import type { RawDiagnostic } from '@cubocicloide/dude'
|
|
11
|
+
|
|
12
|
+
export default function check(root: string): RawDiagnostic[] {
|
|
13
|
+
const diagnostics: RawDiagnostic[] = []
|
|
14
|
+
|
|
15
|
+
// Emit a diagnostic for each violation you find under `root`, e.g.:
|
|
16
|
+
//
|
|
17
|
+
// diagnostics.push({
|
|
18
|
+
// file: 'backend/app/main.py', // path relative to the project root
|
|
19
|
+
// line: 1,
|
|
20
|
+
// col: 1,
|
|
21
|
+
// severity: 'error', // 'error' fails `dude lint`; 'warning' doesn't
|
|
22
|
+
// message: 'What is wrong and how to fix it.',
|
|
23
|
+
// })
|
|
24
|
+
|
|
25
|
+
return diagnostics
|
|
26
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Project lint checks
|
|
2
|
+
|
|
3
|
+
Drop a file in this directory and it becomes a lint rule that `dude lint` runs
|
|
4
|
+
alongside the stack's built-in checks. The rule's code is derived from the
|
|
5
|
+
path:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
.dude/lint/checks/PRJ/001.ts → PRJ001
|
|
9
|
+
.dude/lint/checks/SEC/002.ts → SEC002
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
No registration step — this directory **is** the registry (groups are the
|
|
13
|
+
sub-directories, ids are the file names).
|
|
14
|
+
|
|
15
|
+
## Writing a check
|
|
16
|
+
|
|
17
|
+
Each file must `export default` a function that receives the project root and
|
|
18
|
+
returns diagnostics (synchronously or as a Promise). Use the types from
|
|
19
|
+
`@cubocicloide/dude` (already a dev dependency of this project):
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// .dude/lint/checks/PRJ/001.ts
|
|
23
|
+
import type { RawDiagnostic } from '@cubocicloide/dude'
|
|
24
|
+
|
|
25
|
+
export default function check(root: string): RawDiagnostic[] {
|
|
26
|
+
return [
|
|
27
|
+
// {
|
|
28
|
+
// file: 'backend/app/main.py', // path relative to the project root
|
|
29
|
+
// line: 1,
|
|
30
|
+
// col: 1,
|
|
31
|
+
// severity: 'error', // 'error' fails the build; 'warning' doesn't
|
|
32
|
+
// message: 'What is wrong and how to fix it.',
|
|
33
|
+
// },
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Checks are loaded with [jiti](https://github.com/unjs/jiti), so you can write
|
|
39
|
+
real TypeScript and `import` any package you add to the project.
|
|
40
|
+
|
|
41
|
+
You can document a rule with a Markdown file next to it
|
|
42
|
+
(`PRJ/001.md`) — `dude lint` ignores non-module files. Co-located tests
|
|
43
|
+
(`001.test.ts`) are ignored too.
|
|
44
|
+
|
|
45
|
+
## Choosing codes
|
|
46
|
+
|
|
47
|
+
Use your own groups (e.g. `PRJ`, `SEC`, your project's initials). A code
|
|
48
|
+
already claimed by the stack (e.g. `BE001`) is a **hard error** — project
|
|
49
|
+
checks extend the stack's rule set, they never shadow it.
|
|
50
|
+
|
|
51
|
+
## Disabling a stack rule
|
|
52
|
+
|
|
53
|
+
To drop a built-in rule, list its code in `dude.json`:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"lint": { "disable": ["BE003"] }
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
To *replace* a stack rule, disable it and add your adapted version under a
|
|
62
|
+
project-owned code (e.g. `PRJ/001.ts`).
|
|
63
|
+
|
|
64
|
+
## Running
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
dude lint # stack checks + project checks, minus disabled codes
|
|
68
|
+
dude lint --quiet # errors only
|
|
69
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"label": "dude lint (watch)",
|
|
6
|
+
"type": "shell",
|
|
7
|
+
"command": "echo 'Lint started'; dude lint 2>&1; fswatch -r --exclude '\\.git' --exclude 'node_modules' --exclude '__pycache__' --exclude '\\.venv' --exclude '\\.mypy_cache' . | while read -r _; do echo 'Lint started'; dude lint 2>&1; done",
|
|
8
|
+
"options": {
|
|
9
|
+
"cwd": "${workspaceFolder}"
|
|
10
|
+
},
|
|
11
|
+
"isBackground": true,
|
|
12
|
+
"group": {
|
|
13
|
+
"kind": "build",
|
|
14
|
+
"isDefault": true
|
|
15
|
+
},
|
|
16
|
+
"runOptions": {
|
|
17
|
+
"runOn": "folderOpen"
|
|
18
|
+
},
|
|
19
|
+
"presentation": {
|
|
20
|
+
"reveal": "silent",
|
|
21
|
+
"panel": "dedicated",
|
|
22
|
+
"clear": false
|
|
23
|
+
},
|
|
24
|
+
"problemMatcher": {
|
|
25
|
+
"owner": "dude",
|
|
26
|
+
"fileLocation": ["relative", "${workspaceFolder}"],
|
|
27
|
+
"background": {
|
|
28
|
+
"activeOnStart": true,
|
|
29
|
+
"beginsPattern": "^Lint started$",
|
|
30
|
+
"endsPattern": "^(No issues found\\.|(\\d+ errors?(, \\d+ warnings?)?|\\d+ warnings?))$"
|
|
31
|
+
},
|
|
32
|
+
"pattern": {
|
|
33
|
+
"regexp": "^(.+?)\\((\\d+),(\\d+)\\):\\s+(error|warning)\\s+([\\w-]+):\\s+(.+)$",
|
|
34
|
+
"file": 1,
|
|
35
|
+
"line": 2,
|
|
36
|
+
"column": 3,
|
|
37
|
+
"severity": 4,
|
|
38
|
+
"code": 5,
|
|
39
|
+
"message": 6
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# CLAUDE.md — {{projectName}}
|
|
2
|
+
|
|
3
|
+
Frappe Framework ticketing project scaffolded by `dude` (stack: `frappe`).
|
|
4
|
+
{{#if withHelpdesk}}Frappe Helpdesk provides the ticketing UI; the custom app
|
|
5
|
+
`apps/ticketing/` extends it.{{/if}}
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
- **Local runtime** — Docker Compose: `mariadb`, `redis-cache`, `redis-queue`
|
|
10
|
+
and a `bench` container. On first boot `docker/init.sh` creates the bench
|
|
11
|
+
(`frappe-bench/`, persisted in the `bench_home` volume), the site
|
|
12
|
+
(`$SITE_NAME` from `.env`), installs {{#if withHelpdesk}}Helpdesk and {{/if}}every
|
|
13
|
+
custom app found under `apps/`, then runs `bench start`.
|
|
14
|
+
- **Custom apps** — live in `apps/` in this repo and are symlinked into the
|
|
15
|
+
bench in editable mode. Edit on the host; the dev server reloads.
|
|
16
|
+
- **`apps/ticketing/`** — the example app. Its README maps every Frappe
|
|
17
|
+
concept (DocType, controller, hooks, tasks, workflow, portal page, API) to
|
|
18
|
+
a concrete file. Follow its patterns when adding features.
|
|
19
|
+
|
|
20
|
+
## Rules that matter here
|
|
21
|
+
|
|
22
|
+
- `dude lint` enforces the structural conventions described in
|
|
23
|
+
`.claude/rules/{APP,DT,PY}/` — read the matching rule before fixing a
|
|
24
|
+
violation, and keep new code compliant:
|
|
25
|
+
- **APP** — app layout and `hooks.py` integrity (dotted paths must resolve,
|
|
26
|
+
fixtures declared ↔ shipped).
|
|
27
|
+
- **DT** — DocType conventions (controller + tests present, permissions
|
|
28
|
+
declared, snake_case fieldnames).
|
|
29
|
+
- **PY** — Python safety (no guest-exposed whitelisted methods, no
|
|
30
|
+
interpolated SQL).
|
|
31
|
+
- New DocTypes: create them via the Desk UI with developer mode on (the JSON
|
|
32
|
+
is written back into the app), or copy
|
|
33
|
+
`apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/` as a
|
|
34
|
+
starting point. Always keep `<name>.json`, `<name>.py`, `__init__.py` and a
|
|
35
|
+
`test_<name>.py` together.
|
|
36
|
+
- Anything that changes the schema or fixtures needs `dude site migrate`
|
|
37
|
+
(or restart: `docker/init.sh` migrates on boot).
|
|
38
|
+
- Python in `apps/` is formatted with **ruff** (tabs, Frappe style) —
|
|
39
|
+
`dude format`.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
`dude help` prints the live catalog. Highlights: `dude up/down/logs/shell`,
|
|
44
|
+
`dude bench <raw args>`, `dude site migrate/console/backup/clear-cache/mariadb`,
|
|
45
|
+
`dude app new/install`, `dude test`, `dude lint`, `dude format`, `dude docs`{{#if withIac}},
|
|
46
|
+
`dude iac …` (Terraform / AWS ECS Fargate — see `iac/README.md`){{/if}}.
|
|
47
|
+
|
|
48
|
+
Custom project commands can be added under `.dude/commands/` (one file = one
|
|
49
|
+
command; see `.dude/commands/README.md`).
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
A minimal-but-functional **ticketing system** built on the
|
|
4
|
+
[Frappe Framework](https://frappeframework.com){{#if withHelpdesk}} and
|
|
5
|
+
[Frappe Helpdesk](https://github.com/frappe/helpdesk){{/if}}, scaffolded by
|
|
6
|
+
[`dude`](https://github.com/cubocicloide/dude) (stack: `frappe`).
|
|
7
|
+
|
|
8
|
+
Beyond running out of the box, this project is a **worked example of Frappe's
|
|
9
|
+
core building blocks**: the custom app in [`apps/ticketing/`](apps/ticketing/)
|
|
10
|
+
demonstrates DocTypes (models), controllers, form scripts and portal pages
|
|
11
|
+
(views), whitelisted API methods, scheduled tasks, document-event hooks,
|
|
12
|
+
workflows and fixtures — so you can copy the patterns into your own apps.
|
|
13
|
+
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# One-time: the global launcher + project toolchain
|
|
18
|
+
npm install -g @cubocicloide/dude-launcher
|
|
19
|
+
pnpm install
|
|
20
|
+
|
|
21
|
+
# Start everything (first boot provisions the bench + site: several minutes)
|
|
22
|
+
dude up
|
|
23
|
+
dude logs --service bench # watch the provisioning progress
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
When `bench start` is up:
|
|
27
|
+
|
|
28
|
+
| What | Where |
|
|
29
|
+
| ---- | ----- |
|
|
30
|
+
| Desk (admin UI) | http://{{projectName}}.localhost:8000/app — `Administrator` / `admin` |
|
|
31
|
+
{{#if withHelpdesk}}| Helpdesk (agent UI) | http://{{projectName}}.localhost:8000/helpdesk |
|
|
32
|
+
{{/if}}| Example portal page | http://{{projectName}}.localhost:8000/ticket_stats |
|
|
33
|
+
| Example API method | http://{{projectName}}.localhost:8000/api/method/ticketing.api.ticket_stats |
|
|
34
|
+
|
|
35
|
+
> `*.localhost` resolves to 127.0.0.1 in modern browsers. If your tooling
|
|
36
|
+
> can't resolve it, add `127.0.0.1 {{projectName}}.localhost` to `/etc/hosts`.
|
|
37
|
+
|
|
38
|
+
## Everyday commands
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
dude up [--build] # start the stack
|
|
42
|
+
dude down [--volumes] # stop it (--volumes wipes bench + database!)
|
|
43
|
+
dude logs [--service s] # follow logs
|
|
44
|
+
dude shell [--service s] # shell into a container (default: bench)
|
|
45
|
+
dude bench <anything> # raw bench passthrough, e.g. `dude bench --site all migrate`
|
|
46
|
+
dude site migrate # bench migrate on the default site
|
|
47
|
+
dude site console # IPython with the site loaded
|
|
48
|
+
dude site backup # backup database + files
|
|
49
|
+
dude app new --name x # scaffold a new custom app into apps/
|
|
50
|
+
dude test # run the ticketing app's tests
|
|
51
|
+
dude lint # Frappe best-practice structural checks
|
|
52
|
+
dude format # ruff format + autofix over apps/
|
|
53
|
+
dude docs # serve the project docs (MkDocs)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Run `dude help` for the full, live catalog{{#if withIac}} — including the
|
|
57
|
+
`dude iac …` group that deploys this project to AWS ECS Fargate (see
|
|
58
|
+
`iac/README.md`){{/if}}.
|
|
59
|
+
|
|
60
|
+
## Learn Frappe with this repo
|
|
61
|
+
|
|
62
|
+
Start with [`apps/ticketing/README.md`](apps/ticketing/README.md) — it maps
|
|
63
|
+
each Frappe concept to a concrete file. The project docs (`dude docs`) include
|
|
64
|
+
a guided tour and a "how do I add a new DocType / task / workflow?" cookbook.
|
|
65
|
+
|
|
66
|
+
The structural conventions the linter enforces are described in
|
|
67
|
+
[`.claude/rules/`](.claude/rules/) — useful reading even if you never open
|
|
68
|
+
the linter.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# ── Frappe site ───────────────────────────────────────────────────────────────
|
|
2
|
+
# The bench serves this site by default. `*.localhost` resolves to 127.0.0.1 in
|
|
3
|
+
# modern browsers; add an /etc/hosts entry if your tooling can't resolve it.
|
|
4
|
+
SITE_NAME={{projectName}}.localhost
|
|
5
|
+
ADMIN_PASSWORD=admin
|
|
6
|
+
|
|
7
|
+
# ── Database (MariaDB) ────────────────────────────────────────────────────────
|
|
8
|
+
MARIADB_ROOT_PASSWORD=admin
|
|
9
|
+
|
|
10
|
+
# ── Apps ──────────────────────────────────────────────────────────────────────
|
|
11
|
+
# Install Frappe Helpdesk (the ticketing UI) on first boot.
|
|
12
|
+
INSTALL_HELPDESK={{#if withHelpdesk}}true{{else}}false{{/if}}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
.venv/
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.pyc
|
|
6
|
+
*.egg-info/
|
|
7
|
+
|
|
8
|
+
# Env
|
|
9
|
+
.env
|
|
10
|
+
.env.local
|
|
11
|
+
|
|
12
|
+
# Editor / OS
|
|
13
|
+
.DS_Store
|
|
14
|
+
.idea/
|
|
15
|
+
|
|
16
|
+
# Logs
|
|
17
|
+
*.log
|
|
18
|
+
|
|
19
|
+
# Site backups pulled out of the bench container
|
|
20
|
+
backups/
|
|
21
|
+
|
|
22
|
+
# Private / ephemeral workspace (reports, local overrides, scratch files)
|
|
23
|
+
private/
|
|
24
|
+
|
|
25
|
+
# Generated API reference — rebuilt from the live command catalog by `dude docs`
|
|
26
|
+
docs/docs/api.md
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# apps/ — your custom Frappe apps
|
|
2
|
+
|
|
3
|
+
Every directory in here that looks like a Frappe app (has a `pyproject.toml`
|
|
4
|
+
and a `<app>/hooks.py`) is automatically linked into the bench container in
|
|
5
|
+
**editable mode** on boot (see `docker/init.sh`): code changes on the host
|
|
6
|
+
reload live inside the container.
|
|
7
|
+
|
|
8
|
+
The scaffold ships one example app, **`ticketing/`**, that demonstrates each
|
|
9
|
+
core Frappe building block:
|
|
10
|
+
|
|
11
|
+
| Building block | Where to look |
|
|
12
|
+
| ------------------------- | -------------------------------------------------------------------- |
|
|
13
|
+
| DocType (model) | `ticketing/ticketing/doctype/ticket_escalation_rule/*.json` |
|
|
14
|
+
| Controller (server logic) | `ticketing/ticketing/doctype/ticket_escalation_rule/*.py` |
|
|
15
|
+
| Form script (desk view) | `ticketing/ticketing/doctype/ticket_escalation_rule/*.js` |
|
|
16
|
+
| Whitelisted API method | `ticketing/ticketing/api.py` |
|
|
17
|
+
| Scheduled tasks | `ticketing/ticketing/tasks.py` + `scheduler_events` in `hooks.py` |
|
|
18
|
+
| Document event hooks | `ticketing/ticketing/events/hd_ticket.py` + `doc_events` in `hooks.py` |
|
|
19
|
+
| Workflow (flow) | `ticketing/ticketing/fixtures/workflow.json` |
|
|
20
|
+
| Portal web page (view) | `ticketing/ticketing/templates/pages/ticket_stats.*` |
|
|
21
|
+
| Tests | `ticketing/ticketing/doctype/ticket_escalation_rule/test_*.py` |
|
|
22
|
+
|
|
23
|
+
To add a new app: `dude app new --name my_app` (wraps `bench new-app` and
|
|
24
|
+
moves the result here), then restart with `dude up`.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# ticketing — example custom Frappe app
|
|
2
|
+
|
|
3
|
+
This app extends Frappe Helpdesk with a minimal escalation feature, and doubles
|
|
4
|
+
as a **worked example of every core Frappe building block**. Read it top-down
|
|
5
|
+
to learn how a Frappe app is put together, then copy the patterns into your
|
|
6
|
+
own apps.
|
|
7
|
+
|
|
8
|
+
## Tour
|
|
9
|
+
|
|
10
|
+
- `ticketing/hooks.py` — the app's contract with the framework: document event
|
|
11
|
+
hooks, scheduler events, fixtures. Start here.
|
|
12
|
+
- `ticketing/ticketing/doctype/ticket_escalation_rule/` — a complete DocType:
|
|
13
|
+
- `ticket_escalation_rule.json` — the model (fields, permissions, naming)
|
|
14
|
+
- `ticket_escalation_rule.py` — the controller (`validate` lifecycle hook)
|
|
15
|
+
- `ticket_escalation_rule.js` — the desk form script (client-side view logic)
|
|
16
|
+
- `test_ticket_escalation_rule.py` — unit tests (`dude test`)
|
|
17
|
+
- `ticketing/api.py` — whitelisted methods, callable at
|
|
18
|
+
`/api/method/ticketing.api.ticket_stats`.
|
|
19
|
+
- `ticketing/tasks.py` — background jobs wired via `scheduler_events`.
|
|
20
|
+
- `ticketing/events/hd_ticket.py` — handlers for `doc_events` on Helpdesk's
|
|
21
|
+
`HD Ticket` DocType (extend another app without forking it).
|
|
22
|
+
- `ticketing/fixtures/` — records shipped with the app (a Workflow that gates
|
|
23
|
+
escalation rules behind an approval flow) and synced on `bench migrate`.
|
|
24
|
+
- `ticketing/templates/pages/ticket_stats.*` — a public portal page at
|
|
25
|
+
`/ticket-stats` (Jinja template + Python context).
|
|
26
|
+
- `ticketing/public/images/logo.png`, `favicon.png` — branding. Referenced by
|
|
27
|
+
`app_logo_url` / `website_context` in `hooks.py` (Desk + portal) and, via
|
|
28
|
+
the `set_default_branding` patch, by Helpdesk's own `HD Settings`. **To
|
|
29
|
+
rebrand: replace these two files with your own, keeping the same
|
|
30
|
+
filenames** — no code or database change needed.
|
|
31
|
+
- `ticketing/patches/` — one-off data migrations run once per site on
|
|
32
|
+
`bench migrate` (registered in `patches.txt`), for changes fixtures can't
|
|
33
|
+
express (e.g. seeding a Single doctype like `HD Settings`).
|
|
34
|
+
|
|
35
|
+
## Everyday commands
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
dude shell # shell into the bench container
|
|
39
|
+
dude bench --site all migrate
|
|
40
|
+
dude site console # IPython with the site loaded
|
|
41
|
+
dude test # run this app's tests
|
|
42
|
+
dude lint # Frappe best-practice structural checks
|
|
43
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "ticketing"
|
|
3
|
+
authors = [{ name = "Your Team" }]
|
|
4
|
+
description = "Custom ticketing extensions for Frappe Helpdesk — example app"
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
|
|
9
|
+
[build-system]
|
|
10
|
+
requires = ["flit_core >=3.4,<4"]
|
|
11
|
+
build-backend = "flit_core.buildapi"
|
|
12
|
+
|
|
13
|
+
# Frappe-style formatting/linting defaults (mirrors the frappe codebase).
|
|
14
|
+
[tool.ruff]
|
|
15
|
+
line-length = 110
|
|
16
|
+
target-version = "py310"
|
|
17
|
+
|
|
18
|
+
[tool.ruff.lint]
|
|
19
|
+
select = [
|
|
20
|
+
"F", # pyflakes
|
|
21
|
+
"E", # pycodestyle errors
|
|
22
|
+
"W", # pycodestyle warnings
|
|
23
|
+
"I", # isort
|
|
24
|
+
"UP", # pyupgrade
|
|
25
|
+
"B", # bugbear
|
|
26
|
+
]
|
|
27
|
+
ignore = [
|
|
28
|
+
"E501", # line length is enforced by the formatter
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[tool.ruff.format]
|
|
32
|
+
quote-style = "double"
|
|
33
|
+
indent-style = "tab"
|
|
34
|
+
docstring-code-format = true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Whitelisted API methods.
|
|
2
|
+
|
|
3
|
+
Any function decorated with @frappe.whitelist() becomes an RPC endpoint at
|
|
4
|
+
/api/method/<dotted.path>, e.g.:
|
|
5
|
+
|
|
6
|
+
GET /api/method/ticketing.api.ticket_stats
|
|
7
|
+
|
|
8
|
+
Only expose what you must; never add allow_guest=True unless the data is
|
|
9
|
+
truly public (see lint rule PY001).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import frappe
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@frappe.whitelist()
|
|
16
|
+
def ticket_stats() -> dict:
|
|
17
|
+
"""Return HD Ticket counts grouped by status.
|
|
18
|
+
|
|
19
|
+
Used by the /ticket-stats portal page; also handy from the browser
|
|
20
|
+
console or any HTTP client authenticated against the site.
|
|
21
|
+
"""
|
|
22
|
+
if not frappe.db.table_exists("HD Ticket"):
|
|
23
|
+
return {"helpdesk_installed": False, "by_status": {}, "total": 0}
|
|
24
|
+
|
|
25
|
+
rows = frappe.get_all(
|
|
26
|
+
"HD Ticket",
|
|
27
|
+
fields=["status", "count(name) as total"],
|
|
28
|
+
group_by="status",
|
|
29
|
+
)
|
|
30
|
+
by_status = {row.status: row.total for row in rows}
|
|
31
|
+
return {
|
|
32
|
+
"helpdesk_installed": True,
|
|
33
|
+
"by_status": by_status,
|
|
34
|
+
"total": sum(by_status.values()),
|
|
35
|
+
}
|