Skip to main content

The prompt

title: "Scaffold the folder module and its resources"
context: |
  Build a `folder` domain: users organize content into folders they own; admins
  manage any. Folders self-nest (parent + children) into a per-user tree. Auth
  is owner-or-admin on every mutation. If `modules/folder/` already exists, this
  work is void — do not run.
goal: |
  Create the `folder` module + needed resources, wired owner-or-admin on mutations.

  ## Notes
  - If `modules/folder/` exists, STOP and report. Else `/module:create` folder,
    then build each resource via its `*:create` skill (`--module=folder`),
    respecting controllers → services → repositories → entities, registering all.
  - Judge each resource; create the justified, skip the rest with a reason.
    Defaults: entity + repository always; service + controller per use case;
    permission always (owner-or-admin on update/delete, reuse the permission
    service); migration/seed/event/translation/queue only if applicable;
    storage only if folders carry uploaded files; workflow only if there is a
    genuine reversible lifecycle (rarely; default skip).
  - A child must share its parent's owner; reject re-parenting under another
    user's folder.
  - Guard against cycles: a folder may not be its own ancestor.
  - Throw typed exceptions (e.g. `FolderNotFoundException`), never return null.

  ### Data Model
  - `Folder.owner` ↔ `User.folders` — ManyToOne / OneToMany
  - `Folder.parent` ↔ `Folder.children` — self-referential ManyToOne / OneToMany
dod: |
  - [ ] Aborts with a report if `modules/folder/` exists
  - [ ] `folder` module created and registered into the app and `SharedModule`
  - [ ] `Folder` entity with fields: `name`, `slug` (unique), `description`,
    `icon`, `color` (`SimpleColorType`), `position`, `lang` (`LocaleType`),
    `parent` (nullable), `children`, `owner`, `createdAt`, `updatedAt`
  - [ ] Full CRUD; user mutates only their own, admin any; non-owner/non-admin
    rejected
  - [ ] Cannot re-parent under another user's folder
  - [ ] Tree-cycle updates rejected
  - [ ] If queues are used, folder mutations run through a queue
  - [ ] Unneeded resources skipped and reported with a reason
  - [ ] `bun run fmt`, `bun run lint`, `bun run test` pass from the root