Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Rule Daemon Module Structure?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/geniro-io-rule-daemon-module-structure)
---
name: rule-daemon-module-structure
description: "Directory layout every daemon (NestJS) feature module must follow. A repository rule for apps/daemon/src/**; read it before editing a file there."
---
<!-- GENERATED by scripts/sync-agent-rules.mjs from .claude/rules/daemon-module-structure.md. DO NOT EDIT: edit the source, then run `pnpm sync:agent-rules`. -->
# Daemon module structure
A feature module (`apps/daemon/src/v1/<name>/`) keeps only `<name>.module.ts` and its types file at its root. Everything else goes in a kind-directory.
## Kind-directories
- `controllers/` — HTTP controllers (route + delegation only).
- `services/` — `@Injectable()` business logic, event buses, registries.
- `dao/` — extends `BaseDao`, injects `EntityManager` from `@mikro-orm/sqlite`.
- `entity/` — MikroORM entities.
- `dto/` — Zod DTOs via `createZodDto()`.
- `utils/` — pure helpers with no DI, plain kebab names (`ndjson-buffer.ts`). The `*.utils.ts` suffix is used only inside `adapters/<name>/utils/` and `adapters/utils/`.
- `adapters/` — CLI adapters (see `agent-adapters.md`); a CLI's own services live in its adapter directory, not `services/`.
- `gateways/` — Socket.IO gateways.
- `tools/` — geniro's MCP tools, `v1/mcp/` only (see `mcp-tools.md`).
- `worker/` — the entry and code of a child process the module runs, `v1/embeddings/` only (see `daemon-embeddings.md`); nothing in it is imported by the daemon's Nest graph except its types and the `node:sqlite` dialect.
- `__tests__/` — test-only helpers (below); never the specs themselves.
Rules:
- Put a new file in its kind-directory from the start; never at the module root, even temporarily. (The sibling Geniro repo parks `*.listener.ts` / `*.utils.ts` at module roots — don't copy that.)
- Create only the directories the module needs.
- A type used by one file may stay unexported in that file; once a second file imports it, it moves to the module's types file (`<name>.types.ts`; `chat.types.ts` in `v1/agents`).
- Reference layout: `apps/daemon/src/v1/agents/`.
## Layers and entities
- The flow is Controller (one `@Controller` class per file, no module-scope functions) → Service (all logic) → DAO → Entity; HTTP input uses `createZodDto()` DTOs.
- Entities use `@mikro-orm/decorators/legacy`, extend `TimestampsEntity`, and declare explicit column types (`@PrimaryKey({ type: 'string' })`, `@Property({ type: 'integer' | 'text' | … })`); swc discovery needs them. Declare dates with the `DateTimeType` class, never `'datetime'` (the string form marks every loaded entity dirty).
## `__tests__/`
- A fixture, process double or builder shared by several specs lives in a `__tests__/` directory at the level those specs share (`adapters/__tests__/fake-group-child.ts`, `v1/agents/__tests__/fake-child.ts`). Never in `utils/`.
- A helper only one spec uses is declared in that spec.
- A vendored data file a spec reads always lives in `__tests__/` (`adapters/acp/__tests__/acp-schema.v1.21.0.json`).
- The directory is what keeps test code out of `dist/`: both the swc `--ignore` globs in `package.json` and `tsconfig.build.json`'s `exclude` skip `**/__tests__/**`. Never use a filename suffix instead; a new build config must exclude the same directory.
## Sharing code
- Cross-module logic is extracted into its owning module and imported, never copied. `v1/agents` is the shared agent-execution substrate (adapters, event bus, registries, run DAOs, `utils/event-to-item`, `utils/persist-item`).
- The daemon↔renderer HTTP contract is generated, never mirrored (see root `AGENTS.md` → *The daemon API client*).
- Anything outside the typed HTTP contract (a CLI tool payload, a WS envelope, an on-disk handshake file) is a deliberate twin parser: an independent implementation on each side, each carrying a `TWIN PARSER:` doc block naming the other. A shape change on one side must be made on the other. Find them with `grep -rn "TWIN PARSER:" apps packages`.
## Daemon side of the HTTP contract (`v1/*`)
- Wire shapes are zod schemas in each module's types file; TS types are `z.infer` of them. Shared schemas carry `.meta({ id })` so they become named OpenAPI components.
- A response DTO's root schema must not carry `.meta({ id })`; `setupSwagger` fails the boot on the resulting dangling `$ref`.
- Declare responses with `@ZodResponse({ status, type })` (nestjs-zod). No `@nestjs/swagger` CLI plugin (swc cannot run it).
- Every controller has `@ApiTags`, `@ApiBearerAuth` and `@ApiOperation({ operationId })`; operationIds are globally unique (`setupSwagger` throws on duplicates).
- `TeamSchema` stays default-free so request and response collapse to one type; YAML defaults live in `TeamYamlSchema` (`parseTeamYaml` only).
- `McpController` is `@ApiExcludeController()`.