@ronaldjdevfs/forge 1.1.0 → 1.3.0-beta
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/README.md +38 -23
- package/package.json +11 -3
- package/skills/forge/SKILL.md +11 -6
- package/skills/forge/scripts/forgeSentinel-lib.mjs +86 -0
- package/skills/forge/scripts/forgeSentinel.mjs +184 -0
- package/skills/forge/scripts/forgeSmith-admin.mjs +104 -0
- package/skills/forge/scripts/forgeSmith.mjs +164 -0
- package/skills/forge/scripts/pin.mjs +10 -3
- package/skills/forge/scripts/posttool.mjs +17 -211
- package/skills/forge/templates/agents/SKILL.md.template +283 -0
- package/skills/forge/templates/agents/agents/hooks.json +18 -0
- package/skills/forge/templates/agents/claude/CLAUDE.md +99 -0
- package/skills/forge/templates/agents/claude/settings.local.json +18 -0
- package/skills/forge/templates/agents/codex/hooks.json +18 -0
- package/skills/forge/templates/agents/cursor/.cursorrules +97 -0
- package/skills/forge/templates/agents/cursor/hooks.json +11 -0
- package/skills/forge/templates/agents/gemini/SKILL.md +13 -0
- package/skills/forge/tests/core.test.mjs +4 -4
- package/src/agents.mjs +88 -0
- package/src/cli.js +187 -54
- package/src/wizard.mjs +526 -0
- package/logo.png +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: forge
|
|
3
|
+
description: >
|
|
4
|
+
Architecture Operating System especializado en diseñar, construir, auditar,
|
|
5
|
+
proteger y evolucionar arquitecturas backend escalables basadas en features
|
|
6
|
+
(vertical slices), hexagonal architecture y DDD pragmático. Triggers:
|
|
7
|
+
"arquitectura", "migrar", "refactorizar", "features", "hexagonal",
|
|
8
|
+
"puertos y adaptadores", "clean architecture", "cast", "inspect",
|
|
9
|
+
"quench", "chain", "grafo", "graph", "nodo", "architecture graph",
|
|
10
|
+
"violaciones", "ownership", "platform", "infraestructura". Excluye
|
|
11
|
+
infraestructura (Docker, CI/CD), optimización de queries y cambios de
|
|
12
|
+
lógica de negocio sin reestructuración.
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# Forge — Backend Architecture Operating System
|
|
16
|
+
|
|
17
|
+
Forge es un **sistema operativo arquitectónico**. Diseña, construye, audita, protege y evoluciona arquitecturas backend completas. Opera sobre cualquier stack moderno modelando **cuatro dominios arquitectónicos**: **Platform**, **Features**, **Shared** e **Infrastructure**.
|
|
18
|
+
|
|
19
|
+
No es un template ni una guía. Es un orquestador.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Modelo Arquitectónico
|
|
24
|
+
|
|
25
|
+
Todo backend se modela en cuatro dominios:
|
|
26
|
+
|
|
27
|
+
| Layer | Propósito | Ejemplos |
|
|
28
|
+
|-------|-----------|----------|
|
|
29
|
+
| **Platform** | Backbone técnico global | config, database, http, server, logger, cache, security, events, di |
|
|
30
|
+
| **Features** | Capacidades de negocio | auth, users, payments |
|
|
31
|
+
| **Shared** | Componentes reutilizables puros | errors, contracts, types, utils |
|
|
32
|
+
| **Infrastructure** | Implementaciones concretas | prisma, mongodb, redis, mail |
|
|
33
|
+
|
|
34
|
+
### Dependency Rules
|
|
35
|
+
|
|
36
|
+
Permitido:
|
|
37
|
+
- `feature → platform`
|
|
38
|
+
- `feature → shared`
|
|
39
|
+
- `platform → infra`
|
|
40
|
+
- `adapter → infra`
|
|
41
|
+
- `feature → domain`
|
|
42
|
+
|
|
43
|
+
Prohibido:
|
|
44
|
+
- `feature → infra`
|
|
45
|
+
- `platform → feature`
|
|
46
|
+
- `shared → feature`
|
|
47
|
+
- `shared → infra`
|
|
48
|
+
- `domain → infra`
|
|
49
|
+
- `domain → platform`
|
|
50
|
+
- `infra → feature`
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Architecture Guidance
|
|
55
|
+
|
|
56
|
+
Ver `reference/principles.md` para el manifiesto completo y los 12 principios inquebrantables.
|
|
57
|
+
Ver `reference/patterns.md` para las convenciones de nomenclatura (PascalCase.artifact, kebab dirs, etc.).
|
|
58
|
+
En esencia:
|
|
59
|
+
|
|
60
|
+
| Principio | Regla |
|
|
61
|
+
|---|---|
|
|
62
|
+
| Cuatro dominios arquitectónicos | Platform, Features, Shared, Infrastructure con ownership estricto |
|
|
63
|
+
| Unidades autónomas | Cada feature es dueño de su dominio, aplicación y adapters |
|
|
64
|
+
| Dependencias unidireccionales | adapters → application → domain → (nada) |
|
|
65
|
+
| Cero lógica en controllers | El controller parsea, delega y responde |
|
|
66
|
+
| Cero BD fuera de repositorios | Los repositories son la única puerta a datos |
|
|
67
|
+
| DI disciplinada | Constructor injection, sin service locators |
|
|
68
|
+
| Cero acoplamiento directo entre features | Siempre vía interfaces inyectadas |
|
|
69
|
+
| Ownership obligatorio | Cada componente tiene un único propietario arquitectónico |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Boot Sequence (OBLIGATORIO — ejecutar siempre antes de responder)
|
|
74
|
+
|
|
75
|
+
ANTES de cualquier acción, Forge DEBE ejecutar esta secuencia. Si no lo haces, puedes dar respuestas incorrectas:
|
|
76
|
+
|
|
77
|
+
1. **context.mjs** — Detectar stack, platform, features, shared, infra, grafo, estado
|
|
78
|
+
2. **armorer.mjs** — Detectar ownership, huérfanos, duplicados, mal ubicados
|
|
79
|
+
3. **profile.mjs** — Determinar perfil tecnológico
|
|
80
|
+
4. **graph.mjs** — Construir grafo arquitectónico global (4 capas + 9 reglas)
|
|
81
|
+
5. **chain.mjs** — Analizar dependencias multi-capa
|
|
82
|
+
6. **inspect.mjs** — Auditoría completa con ownership + platform
|
|
83
|
+
7. **architecture.mjs** — Generar/actualizar ARCHITECTURE.md
|
|
84
|
+
8. **Ejecutar comando solicitado** — cast, quench, temper, etc.
|
|
85
|
+
9. **forgeSentinel** — Verificar cambios tras escritura
|
|
86
|
+
10. **Actualizar ARCHITECTURE.md** — Reflejar nuevo estado
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Template de setup que debes ejecutar:
|
|
90
|
+
ctx=$(node {{AGENT_PATH}}/scripts/context.mjs --json 2>/dev/null)
|
|
91
|
+
armorer=$(node {{AGENT_PATH}}/scripts/armorer.mjs --json 2>/dev/null)
|
|
92
|
+
profile=$(node {{AGENT_PATH}}/scripts/profile.mjs --extended 2>/dev/null)
|
|
93
|
+
graph=$(node {{AGENT_PATH}}/scripts/graph.mjs --json 2>/dev/null)
|
|
94
|
+
deps=$(node {{AGENT_PATH}}/scripts/chain.mjs --json 2>/dev/null)
|
|
95
|
+
inspect=$(node {{AGENT_PATH}}/scripts/inspect.mjs --json 2>/dev/null)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## Command Routing
|
|
101
|
+
|
|
102
|
+
| Lenguaje natural | Comando | Archivo |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| "ayuda", "help", "comandos", "lista", "--help" | `forge --help` | `reference/help.md` |
|
|
105
|
+
| "inicializar", "setup", "empezar" | `forge` | `reference/forge.md` |
|
|
106
|
+
| "crear feature", "nuevo dominio" | `cast` | `reference/cast.md` |
|
|
107
|
+
| "inspeccionar", "diagnóstico", "evaluar" | `inspect` | `reference/inspect.md` |
|
|
108
|
+
| "trasladar", "mover", "reestructurar feature" | `relocate` | `reference/relocate.md` |
|
|
109
|
+
| "refactorizar", "rediseñar", "cambiar estructura" | `reforge` | `reference/reforge.md` |
|
|
110
|
+
| "verificar", "quench", "checklist" | `quench` | `reference/quench.md` |
|
|
111
|
+
| "templar", "endurecer", "mejorar" | `temper` | `reference/temper.md` |
|
|
112
|
+
| "cadena", "grafo", "acoplamiento" | `chain` | `scripts/chain.mjs` |
|
|
113
|
+
| "inscribir", "grabar", "ARCHITECTURE.md" | `inscribe` | `reference/inscribe.md` |
|
|
114
|
+
| "grafo", "graph", "nodo", "violaciones", "risk score" | `graph` | `scripts/graph.mjs` |
|
|
115
|
+
| "fundir", "compartir", "mover a shared" | `smelt` | `reference/smelt.md` |
|
|
116
|
+
| "ownership", "huérfanos", "armorer" | `inspect` | (incluido en auditoría) |
|
|
117
|
+
| "fijar", "pinar", "atajo", "shortcut" | `nail` | `scripts/pin.mjs` |
|
|
118
|
+
| "desfijar", "despinar", "remover atajo" | `unnail` | `scripts/pin.mjs` |
|
|
119
|
+
| "hook", "pre-commit", "githook", "validar commit" | `forge hook` | `reference/hooks.md` |
|
|
120
|
+
| "api", "contrato", "openapi", "swagger", "graphql" | `forge api` | `scripts/forge-api.mjs` |
|
|
121
|
+
| "rollback", "restaurar", "deshacer", "backup" | `forge rollback` | `scripts/rollback.mjs` |
|
|
122
|
+
| "estado", "state", "último audit" | `forge state --show` | `scripts/forge-state.mjs` |
|
|
123
|
+
| "examinar","calidad", "assay", "opinión", "personas", "critique", "evaluación cualitativa" | `assay` | `reference/assay.md` |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Execution Flow
|
|
128
|
+
|
|
129
|
+
Para cada comando, Forge sigue este flujo:
|
|
130
|
+
|
|
131
|
+
1. **Contexto**: Ejecutar `context.mjs` + `armorer.mjs` + `profile.mjs`
|
|
132
|
+
2. **Grafo**: Ejecutar `graph.mjs` + `chain.mjs`
|
|
133
|
+
3. **Auditoría**: Ejecutar `inspect.mjs`
|
|
134
|
+
4. **Referencia**: Cargar `reference/<command>.md`
|
|
135
|
+
5. **Ejecutar**: Aplicar el flujo definido en la referencia, usando los scripts según corresponda
|
|
136
|
+
6. **Verificar**: Ejecutar `scripts/detect.mjs` para verificar que no se introdujeron violaciones
|
|
137
|
+
7. **forgeSentinel**: Ejecutar `scripts/forgeSentinel.mjs --reminder`
|
|
138
|
+
8. **Actualizar ARCHITECTURE.md**: Reflejar el nuevo estado (`architecture.mjs`)
|
|
139
|
+
9. **Reportar**: Mostrar resultado al usuario con severidades
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Routing Rules
|
|
144
|
+
|
|
145
|
+
- Si el lenguaje natural matchea exactamente un comando, ejecutarlo directamente.
|
|
146
|
+
- Si hay ambigüedad, preguntar al usuario: "¿Quieres decir: cast, relocate o reforge?"
|
|
147
|
+
- Si el comando requiere un perfil que no está detectado, preguntar antes de continuar.
|
|
148
|
+
- Si el proyecto no tiene `src/features/` y el comando es `cast`, sugerir `forge` primero.
|
|
149
|
+
- Si el proyecto no tiene `src/platform/`, ejecutar `bootstrapPlatform()` automáticamente.
|
|
150
|
+
- Si `ARCHITECTURE.md` está desactualizado (fecha de auditoría > 7 días), sugerir `forge inscribe`.
|
|
151
|
+
- Todos los resultados se muestran con severidades: `[CRITICAL]`, `[ERROR]`, `[WARNING]`, `[INFO]`, `[SUGGESTION]`.
|
|
152
|
+
|
|
153
|
+
### Inline Ignores
|
|
154
|
+
|
|
155
|
+
Forge soporta comentarios inline para excepcionar violaciones línea por línea:
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
// forge-ignore-next-line
|
|
159
|
+
import { something } from "../infra/prisma"; // ← esta línea no se reporta
|
|
160
|
+
|
|
161
|
+
// forge-ignore: R1
|
|
162
|
+
import { PrismaClient } from "../../infra/prisma/client"; // ← solo R1 ignorada
|
|
163
|
+
|
|
164
|
+
// forge-ignore: R1, R8
|
|
165
|
+
import { crossFeature } from "../other-feature/domain/Entity"; // ← R1 y R8 ignoradas
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## ARCHITECTURE.md
|
|
171
|
+
|
|
172
|
+
Forge mantiene un archivo `ARCHITECTURE.md` en la raíz del proyecto con el contexto persistente. Contiene:
|
|
173
|
+
|
|
174
|
+
```md
|
|
175
|
+
# Architecture State
|
|
176
|
+
|
|
177
|
+
- Project Name: <name>
|
|
178
|
+
- Framework: <detectado>
|
|
179
|
+
- Runtime: <detectado>
|
|
180
|
+
- Database: <detectado>
|
|
181
|
+
- ORM: <detectado>
|
|
182
|
+
- DI Strategy: <detectado>
|
|
183
|
+
- Profile: <detectado>
|
|
184
|
+
- Architecture: hexagonal-feature (Platform + Features + Shared + Infra)
|
|
185
|
+
- Last Audit: <fecha> (score: <puntaje>)
|
|
186
|
+
|
|
187
|
+
## Platform
|
|
188
|
+
- platform/config/
|
|
189
|
+
- platform/server/
|
|
190
|
+
...
|
|
191
|
+
|
|
192
|
+
## Features
|
|
193
|
+
- features/users/
|
|
194
|
+
...
|
|
195
|
+
|
|
196
|
+
## Shared
|
|
197
|
+
- shared/errors/
|
|
198
|
+
...
|
|
199
|
+
|
|
200
|
+
## Infrastructure
|
|
201
|
+
- infra/prisma/
|
|
202
|
+
...
|
|
203
|
+
|
|
204
|
+
## Ownership
|
|
205
|
+
- Health: healthy | degraded | critical
|
|
206
|
+
- Score: 0-100
|
|
207
|
+
- Orphans: 0
|
|
208
|
+
- Duplicates: 0
|
|
209
|
+
- Misplaced: 0
|
|
210
|
+
|
|
211
|
+
## Architecture Graph
|
|
212
|
+
...
|
|
213
|
+
|
|
214
|
+
## Dependency Health
|
|
215
|
+
...
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
El agente DEBE leer este archivo al inicio de cada interacción y actualizarlo al finalizar cada comando.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Module Index
|
|
223
|
+
|
|
224
|
+
| Módulo | Propósito |
|
|
225
|
+
|---|---|
|
|
226
|
+
| `reference/principles.md` | Manifiesto y 12 principios inquebrantables |
|
|
227
|
+
| `reference/patterns.md` | Convenciones de nomenclatura globales (PascalCase.artifact, kebab dirs, etc.) |
|
|
228
|
+
| `reference/errors.md` | Manejo de errores tipados en dominio y aplicación |
|
|
229
|
+
| `reference/di-strategies.md` | Estrategias de inyección de dependencias según tamaño |
|
|
230
|
+
| `reference/testing-patterns.md` | Pirámide de tests, unit mocks, integration tests |
|
|
231
|
+
| `reference/api-design.md` | REST / GraphQL, paginación, validación, contratos |
|
|
232
|
+
| `reference/observability.md` | Logging, tracing, métricas, health checks |
|
|
233
|
+
| `reference/data-patterns.md` | Repository, Unit of Work, CQRS, Event Sourcing |
|
|
234
|
+
| `reference/security-patterns.md` | AuthN, AuthZ, RBAC, rate limiting, validación |
|
|
235
|
+
| `reference/events.md` | Eventos de dominio, outbox pattern, sagas |
|
|
236
|
+
| `reference/hooks.md` | Git pre-commit hook para validación arquitectónica |
|
|
237
|
+
| `reference/help.md` | Lista completa de comandos y flags de Forge |
|
|
238
|
+
| `reference/assay.md` | Ensayo arquitectónico multi-persona — interpretación cualitativa del audit |
|
|
239
|
+
| `profiles/` | Perfiles tecnológicos detallados (Express, Fastify, NestJS, etc.) |
|
|
240
|
+
| `scripts/` | Scripts: context, detect, inspect, chain, profile, graph, architecture, armorer, bootstrap, forge-config, forge-signals, forge-state, forge-api, pin, update, rollback, hook, forgeSentinel, forgeSmith, forgeSentinel-lib, forgeSmith-admin, formatter, assay, registry/rules |
|
|
241
|
+
| `scripts/registry/rules.mjs` | Anti-pattern rule registry (R1-R9 + custom rules desacopladas de detect.mjs) |
|
|
242
|
+
| `scripts/formatter.mjs` | Output formatter unificado (JSON, tabla, severidad coloreada, scoreBar, formatCheck, formatViolation) |
|
|
243
|
+
| `scripts/forgeSentinel.mjs` | PostToolUse hook — analiza archivos modificados tras escritura y reporta violaciones |
|
|
244
|
+
| `scripts/forgeSentinel-lib.mjs` | Lógica compartida para hooks forgeSentinel y forgeSmith |
|
|
245
|
+
| `scripts/forgeSmith.mjs` | preToolUse gate — previene escrituras con violaciones CRITICAL/ERROR (Cursor) |
|
|
246
|
+
| `scripts/forgeSmith-admin.mjs` | Gestión de hooks (on/off/status) |
|
|
247
|
+
| `scripts/assay.mjs` | Motor de ensayo arquitectónico multi-persona (Bezos, Fowler, Hacker, PM, Arquitecta Senior) |
|
|
248
|
+
| `templates/feature/` | Templates de feature (entity, repository, uc, controller, routes, schema, mapper) |
|
|
249
|
+
| `templates/platform/` | Templates de platform (config, server, database, logger, http, di) |
|
|
250
|
+
| `templates/shared/` | Templates de shared (errors, contracts, types, utils) |
|
|
251
|
+
| `templates/infra/` | Templates de infra (prisma, mongodb, redis, mail) |
|
|
252
|
+
| `command/forge.md` | Definición del comando `/forge` para opencode |
|
|
253
|
+
|
|
254
|
+
### Tests
|
|
255
|
+
|
|
256
|
+
Forge incluye tests unitarios con `node:test` (sin dependencias externas).
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
node --test {{AGENT_PATH}}/tests/core.test.mjs
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
| Módulo | Tests | Descripción |
|
|
263
|
+
|--------|-------|-------------|
|
|
264
|
+
| `profile.mjs` | 8 | Detección de perfiles |
|
|
265
|
+
| `graph.mjs` | 1 | Grafo vacío |
|
|
266
|
+
| `armorer.mjs` | 1 | Ownership vacío |
|
|
267
|
+
| `forge-config.mjs` | 2 | Load/save state |
|
|
268
|
+
| `chain.mjs` | 1 | Grafo de dependencias vacío |
|
|
269
|
+
| `formatter.mjs` | 4 | Output format, colores, JSON |
|
|
270
|
+
| `registry/rules.mjs` | 4 | R1-R9, evaluación, custom rules |
|
|
271
|
+
| `detect.mjs` (inline ignores) | 5 | parseInlineIgnores, isIgnored |
|
|
272
|
+
| `forgeSentinel.mjs` | 1 | PostToolUse hook |
|
|
273
|
+
| `assay.mjs` | 4 | Personas, generateAssay, opiniones |
|
|
274
|
+
|
|
275
|
+
### Flags adicionales
|
|
276
|
+
|
|
277
|
+
| Flag | Comando | Descripción |
|
|
278
|
+
|---|---|---|
|
|
279
|
+
| `--fix` | `quench` | Auto-corrige violaciones WARNING/INFO (missing @injectable(), tsconfig, naming, container.resolve) |
|
|
280
|
+
| `--show-ignores` | `quench` | Muestra los inline ignores encontrados en el código |
|
|
281
|
+
| `--persona=<id>` | `assay` | Filtra ensayo por una persona (bezos, fowler, hacker, pm, senior) |
|
|
282
|
+
| `--save` | `assay` | Persiste ensayo en `.forge/assay/` |
|
|
283
|
+
| `--json` | `assay` | Salida JSON |
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Forge architecture guard: runs forgeSentinel after Edit/Write/apply_patch and surfaces architectural violations as system reminders.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PostToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "Edit|Write|apply_patch",
|
|
7
|
+
"hooks": [
|
|
8
|
+
{
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "node \"$(git rev-parse --show-toplevel)/.agents/skills/forge/scripts/forgeSentinel.mjs\" --hook",
|
|
11
|
+
"timeout": 10,
|
|
12
|
+
"statusMessage": "forgeSentinel — checking architecture"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Forge — Backend Architecture Operating System
|
|
2
|
+
|
|
3
|
+
Forge es un sistema operativo arquitectónico para backend. Diseña, construye, audita y evoluciona arquitecturas basadas en **Arquitectura Hexagonal**, **DDD pragmático** y **vertical slices**.
|
|
4
|
+
|
|
5
|
+
## Boot Sequence
|
|
6
|
+
|
|
7
|
+
Ejecutar en orden antes de cualquier acción. Todos los paths son relativos a `.claude/skills/forge/`:
|
|
8
|
+
|
|
9
|
+
1. `node .claude/skills/forge/scripts/context.mjs` — stack + layers detection
|
|
10
|
+
2. `node .claude/skills/forge/scripts/armorer.mjs` — ownership, orphans, duplicates
|
|
11
|
+
3. `node .claude/skills/forge/scripts/profile.mjs --extended` — tech profile
|
|
12
|
+
4. `node .claude/skills/forge/scripts/graph.mjs --json` — 4-layer graph
|
|
13
|
+
5. `node .claude/skills/forge/scripts/chain.mjs --json` — dependency analysis
|
|
14
|
+
6. `node .claude/skills/forge/scripts/inspect.mjs --json` — full audit
|
|
15
|
+
7. `node .claude/skills/forge/scripts/architecture.mjs` — update ARCHITECTURE.md
|
|
16
|
+
8. Execute user command (cast, quench, relocate, etc.)
|
|
17
|
+
9. Run `node .claude/skills/forge/scripts/forgeSentinel.mjs --reminder` — check changes
|
|
18
|
+
10. Run `architecture.mjs` again
|
|
19
|
+
|
|
20
|
+
## Architecture Model
|
|
21
|
+
|
|
22
|
+
Cuatro capas obligatorias:
|
|
23
|
+
|
|
24
|
+
| Layer | Propósito |
|
|
25
|
+
|-------|-----------|
|
|
26
|
+
| `src/platform/` | config, database, http, server, logger, cache, security, events, di |
|
|
27
|
+
| `src/features/<name>/` | domain/, application/use-cases/, application/mappers/, adapters/in/http/, adapters/out/persistence/ |
|
|
28
|
+
| `src/shared/` | errors/, contracts/, types/, utils/ (puro, sin lógica de negocio) |
|
|
29
|
+
| `src/infra/` | prisma/, mongodb/, redis/, mail/ (implementaciones, sin reglas de negocio) |
|
|
30
|
+
|
|
31
|
+
### Dependency Rules
|
|
32
|
+
|
|
33
|
+
**Permitido:** `feature → platform`, `feature → shared`, `platform → infra`, `adapter → infra`, `feature → domain`
|
|
34
|
+
|
|
35
|
+
**Prohibido (CRITICAL):**
|
|
36
|
+
- R1: `feature → infra`
|
|
37
|
+
- R2: `platform → feature`
|
|
38
|
+
- R3: `shared → feature`
|
|
39
|
+
- R4: `shared → infra`
|
|
40
|
+
- R5: `domain → infra`
|
|
41
|
+
- R6: `domain → platform`
|
|
42
|
+
- R7: `infra → feature`
|
|
43
|
+
- R8: cross-feature direct imports
|
|
44
|
+
- R9: cycles
|
|
45
|
+
|
|
46
|
+
## Naming Conventions
|
|
47
|
+
|
|
48
|
+
| Elemento | Formato |
|
|
49
|
+
|----------|---------|
|
|
50
|
+
| Directorios | `kebab-case/` |
|
|
51
|
+
| Archivos | `<PascalCase>.<artefacto>.ts` |
|
|
52
|
+
| Interfaces | `I<PascalCase>.<artefacto>.ts` |
|
|
53
|
+
| Use cases | `<Action>.uc.ts` |
|
|
54
|
+
| Clases | `PascalCase` |
|
|
55
|
+
| Funciones/variables | `camelCase` |
|
|
56
|
+
| Constantes | `UPPER_SNAKE_CASE` |
|
|
57
|
+
| Barrel files | `index.ts` con named exports, no `export default` |
|
|
58
|
+
| Imports ESM | con extensión `.js`: `import { X } from "./foo.js"` |
|
|
59
|
+
|
|
60
|
+
## Commands
|
|
61
|
+
|
|
62
|
+
| Comando | Acción |
|
|
63
|
+
|---------|--------|
|
|
64
|
+
| `forge` | Init project (context + bootstrap + profile + graph) |
|
|
65
|
+
| `cast` | New feature (verifica platform/shared/infra primero) |
|
|
66
|
+
| `inspect` | Full audit (6 categorías, 110pts → 0-100) |
|
|
67
|
+
| `quench` | Validate dependency rules |
|
|
68
|
+
| `chain` | Topological dependency sort |
|
|
69
|
+
| `graph` | Architecture graph con R1-R9 |
|
|
70
|
+
| `armorer` | Ownership report (orphans, duplicates, misplaced) |
|
|
71
|
+
| `smelt` | Extract code to shared/ |
|
|
72
|
+
| `relocate` | Migrate legacy to platform/, shared/, infra/ or features/ |
|
|
73
|
+
| `reforge` | Refactor considering all 4 layers |
|
|
74
|
+
| `temper` | Harden DI (constructor injection) |
|
|
75
|
+
| `inscribe` | Generate ARCHITECTURE.md |
|
|
76
|
+
|
|
77
|
+
## Architecture Principles
|
|
78
|
+
|
|
79
|
+
1. **Hexagonal basado en features** — unidad de organización = feature, no capa técnica
|
|
80
|
+
2. **DDD ligero** — sin sobreingeniería, pragmatismo sobre dogma
|
|
81
|
+
3. **Separación dominio e infraestructura** — domain/ no sabe de frameworks ni BD
|
|
82
|
+
4. **Feature autónomo** — todo lo del dominio vive dentro de `features/<name>/`
|
|
83
|
+
5. **Dependencias unidireccionales** — `adapters → application → domain → (nada)`
|
|
84
|
+
6. **Cero lógica en controllers** — parsean, delegan, responden
|
|
85
|
+
7. **Cero BD fuera de repositories** — única puerta a datos
|
|
86
|
+
8. **DI disciplinada** — constructor injection, sin service locators
|
|
87
|
+
9. **Errores tipados** — clases explícitas, no `throw Error()`
|
|
88
|
+
10. **Grafo arquitectónico vivo** — todo componente es un nodo, toda relación un edge validado
|
|
89
|
+
|
|
90
|
+
## Key Files
|
|
91
|
+
|
|
92
|
+
- `.claude/skills/forge/SKILL.md` — orchestrator principal
|
|
93
|
+
- `.claude/skills/forge/reference/principles.md` — manifiesto y 15 principios
|
|
94
|
+
- `.claude/skills/forge/reference/patterns.md` — naming conventions
|
|
95
|
+
- `.claude/skills/forge/scripts/` — context, detect, inspect, chain, profile, graph, architecture, armorer, bootstrap, forgeSentinel, forgeSmith
|
|
96
|
+
- `.claude/skills/forge/profiles/` — 10 tech profiles (express, fastify, nestjs × mongodb, postgres, prisma, drizzle)
|
|
97
|
+
- `.claude/skills/forge/templates/` — templates para feature, platform, shared, infra
|
|
98
|
+
- `AGENTS.md` — guía para agentes de IA
|
|
99
|
+
- `ARCHITECTURE.md` — estado actual de la arquitectura
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Forge architecture guard: runs forgeSentinel after Edit/Write/MultiEdit and surfaces architectural violations as system reminders.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PostToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "Edit|Write|MultiEdit",
|
|
7
|
+
"hooks": [
|
|
8
|
+
{
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "node \"${CLAUDE_PROJECT_DIR}/.claude/skills/forge/scripts/forgeSentinel.mjs\" --hook",
|
|
11
|
+
"timeout": 10,
|
|
12
|
+
"statusMessage": "forgeSentinel — checking architecture"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Forge architecture guard: runs forgeSentinel after Edit/Write/apply_patch and surfaces architectural violations as system reminders.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"PostToolUse": [
|
|
5
|
+
{
|
|
6
|
+
"matcher": "Edit|Write|apply_patch",
|
|
7
|
+
"hooks": [
|
|
8
|
+
{
|
|
9
|
+
"type": "command",
|
|
10
|
+
"command": "node \"$(git rev-parse --show-toplevel)/.agents/skills/forge/scripts/forgeSentinel.mjs\" --hook",
|
|
11
|
+
"timeout": 10,
|
|
12
|
+
"statusMessage": "forgeSentinel — checking architecture"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
You are an AI assistant for a project that uses Forge — a Backend Architecture Operating System. Tu función es ayudar a diseñar, construir, auditar y evolucionar la arquitectura usando Arquitectura Hexagonal, DDD pragmático y vertical slices.
|
|
2
|
+
|
|
3
|
+
All forge scripts are in `.cursor/skills/forge/scripts/`.
|
|
4
|
+
|
|
5
|
+
## Architecture Model
|
|
6
|
+
|
|
7
|
+
The project uses four mandatory layers:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
src/
|
|
11
|
+
├── platform/ # Config, database, http, server, logger, cache, security, events, di
|
|
12
|
+
├── features/<name>/ # domain/, application/use-cases/, application/mappers/, adapters/in/http/, adapters/out/persistence/
|
|
13
|
+
├── shared/ # errors/, contracts/, types/, utils/ (pure code, no business logic)
|
|
14
|
+
└── infra/ # prisma/, mongodb/, redis/, mail/ (implementations, no business rules)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Dependency Rules (CRITICAL — never violate)
|
|
18
|
+
|
|
19
|
+
**Allowed:** `feature → platform`, `feature → shared`, `platform → infra`, `adapter → infra`, `feature → domain`
|
|
20
|
+
|
|
21
|
+
**Prohibited:**
|
|
22
|
+
- R1: `feature → infra`
|
|
23
|
+
- R2: `platform → feature`
|
|
24
|
+
- R3: `shared → feature`
|
|
25
|
+
- R4: `shared → infra`
|
|
26
|
+
- R5: `domain → infra`
|
|
27
|
+
- R6: `domain → platform`
|
|
28
|
+
- R7: `infra → feature`
|
|
29
|
+
- R8: cross-feature direct imports
|
|
30
|
+
- R9: cycles
|
|
31
|
+
|
|
32
|
+
## Boot Sequence
|
|
33
|
+
|
|
34
|
+
Ejecutar en orden antes de cualquier acción:
|
|
35
|
+
|
|
36
|
+
1. `node .cursor/skills/forge/scripts/context.mjs` — stack + layers detection
|
|
37
|
+
2. `node .cursor/skills/forge/scripts/armorer.mjs` — ownership, orphans, duplicates
|
|
38
|
+
3. `node .cursor/skills/forge/scripts/profile.mjs --extended` — tech profile
|
|
39
|
+
4. `node .cursor/skills/forge/scripts/graph.mjs --json` — 4-layer graph
|
|
40
|
+
5. `node .cursor/skills/forge/scripts/chain.mjs --json` — dependency analysis
|
|
41
|
+
6. `node .cursor/skills/forge/scripts/inspect.mjs --json` — full audit
|
|
42
|
+
7. `node .cursor/skills/forge/scripts/architecture.mjs` — update ARCHITECTURE.md
|
|
43
|
+
8. Execute user command (cast, quench, relocate, etc.)
|
|
44
|
+
9. Run `node .cursor/skills/forge/scripts/forgeSentinel.mjs --reminder`
|
|
45
|
+
10. Run `architecture.mjs` again
|
|
46
|
+
|
|
47
|
+
## Naming Conventions
|
|
48
|
+
|
|
49
|
+
| Element | Convention | Example |
|
|
50
|
+
|---------|-----------|---------|
|
|
51
|
+
| Directories | `kebab-case/` | `credit-card/` |
|
|
52
|
+
| Files | `<PascalCase>.<artifact>.ts` | `User.entity.ts` |
|
|
53
|
+
| Interfaces | `I<PascalCase>.<artifact>.ts` | `IUser.repository.ts` |
|
|
54
|
+
| Use cases | `<Action>.uc.ts` | `CreateUser.uc.ts` |
|
|
55
|
+
| Classes | `PascalCase` | `UserController` |
|
|
56
|
+
| Functions/vars | `camelCase` | `formatDate` |
|
|
57
|
+
| Constants | `UPPER_SNAKE_CASE` | `MAX_RETRY_COUNT` |
|
|
58
|
+
| Barrels | `index.ts` | named exports only, no `export default` |
|
|
59
|
+
| ESM imports | with `.js` extension | `import { X } from "./foo.js"` |
|
|
60
|
+
|
|
61
|
+
## Code Principles
|
|
62
|
+
|
|
63
|
+
1. **Zero business logic in controllers** — parse, delegate, respond
|
|
64
|
+
2. **Zero DB access outside repositories** — only repositories touch the database
|
|
65
|
+
3. **Constructor injection only** — no service locators, no `container.resolve()` in business logic
|
|
66
|
+
4. **Typed domain errors** — explicit error classes, never generic `throw Error()`
|
|
67
|
+
5. **Unidirectional dependencies** — `adapters → application → domain → (nothing)`
|
|
68
|
+
6. **Domain knows nothing about infrastructure** — no framework, database, or external service imports in domain/
|
|
69
|
+
7. **Features are autonomous** — no direct imports between features, only via injected interfaces
|
|
70
|
+
8. **Explicit over magic** — prefer explicit imports and declared types over hidden decorators
|
|
71
|
+
|
|
72
|
+
## Available Commands
|
|
73
|
+
|
|
74
|
+
| Command | Action |
|
|
75
|
+
|---------|--------|
|
|
76
|
+
| `forge` | Initialize project |
|
|
77
|
+
| `cast` | Create new feature |
|
|
78
|
+
| `inspect` | Full architecture audit |
|
|
79
|
+
| `quench` | Validate dependency rules |
|
|
80
|
+
| `chain` | Dependency graph (topological) |
|
|
81
|
+
| `graph` | Architecture graph with rules |
|
|
82
|
+
| `armorer` | Ownership report |
|
|
83
|
+
| `smelt` | Extract to shared/ |
|
|
84
|
+
| `relocate` | Migrate legacy code |
|
|
85
|
+
| `reforge` | Refactor architecture |
|
|
86
|
+
| `temper` | Harden dependency injection |
|
|
87
|
+
| `inscribe` | Generate ARCHITECTURE.md |
|
|
88
|
+
|
|
89
|
+
## Key Files Reference
|
|
90
|
+
|
|
91
|
+
- `.cursor/skills/forge/SKILL.md` — orchestrator
|
|
92
|
+
- `.cursor/skills/forge/reference/principles.md` — 15 principles
|
|
93
|
+
- `.cursor/skills/forge/reference/patterns.md` — naming conventions
|
|
94
|
+
- `.cursor/skills/forge/scripts/` — all engine scripts
|
|
95
|
+
- `.cursor/skills/forge/profiles/` — tech profiles
|
|
96
|
+
- `AGENTS.md` — agent guide
|
|
97
|
+
- `ARCHITECTURE.md` — current architecture state
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: forge
|
|
3
|
+
description: >
|
|
4
|
+
Architecture Operating System especializado en diseñar, construir, auditar,
|
|
5
|
+
proteger y evolucionar arquitecturas backend escalables basadas en features
|
|
6
|
+
(vertical slices), hexagonal architecture y DDD pragmático.
|
|
7
|
+
allowed-tools:
|
|
8
|
+
- Bash(node .gemini/skills/forge/scripts/*)
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Forge — Backend Architecture Operating System
|
|
12
|
+
|
|
13
|
+
Ver `.gemini/skills/forge/SKILL.md` para la guía completa.
|
|
@@ -318,10 +318,10 @@ describe("detect.mjs — inline ignores", () => {
|
|
|
318
318
|
});
|
|
319
319
|
});
|
|
320
320
|
|
|
321
|
-
describe("
|
|
322
|
-
it("
|
|
323
|
-
const {
|
|
324
|
-
const result = await
|
|
321
|
+
describe("forgeSentinel.mjs", () => {
|
|
322
|
+
it("runSentinelCheck returns empty for no files", async () => {
|
|
323
|
+
const { runSentinelCheck } = await import("../scripts/forgeSentinel-lib.mjs");
|
|
324
|
+
const result = await runSentinelCheck([], {});
|
|
325
325
|
assert.equal(result.total, 0);
|
|
326
326
|
assert.ok(result.summary);
|
|
327
327
|
});
|
package/src/agents.mjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
|
|
5
|
+
const HOME = homedir();
|
|
6
|
+
|
|
7
|
+
function detect(cwd) {
|
|
8
|
+
const agents = [];
|
|
9
|
+
|
|
10
|
+
agents.push({
|
|
11
|
+
id: "claude-global",
|
|
12
|
+
label: "Claude Code",
|
|
13
|
+
scope: "Global",
|
|
14
|
+
detected: existsSync(join(HOME, ".claude")) || existsSync(join(HOME, ".config", "claude")),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
agents.push({
|
|
18
|
+
id: "claude-project",
|
|
19
|
+
label: "Claude Code",
|
|
20
|
+
scope: "Proyecto",
|
|
21
|
+
detected: existsSync(join(cwd, ".claude")) || existsSync(join(cwd, "CLAUDE.md")),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
agents.push({
|
|
25
|
+
id: "opencode-global",
|
|
26
|
+
label: "OpenCode",
|
|
27
|
+
scope: "Global",
|
|
28
|
+
detected: existsSync(join(HOME, ".config", "opencode")),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
agents.push({
|
|
32
|
+
id: "opencode-project",
|
|
33
|
+
label: "OpenCode",
|
|
34
|
+
scope: "Proyecto",
|
|
35
|
+
detected: existsSync(join(cwd, ".opencode")),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
agents.push({
|
|
39
|
+
id: "cursor-project",
|
|
40
|
+
label: "Cursor",
|
|
41
|
+
scope: "Proyecto",
|
|
42
|
+
detected: existsSync(join(cwd, ".cursor")) || existsSync(join(cwd, ".cursorrules")),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
agents.push({
|
|
46
|
+
id: "codex-project",
|
|
47
|
+
label: "Codex CLI",
|
|
48
|
+
scope: "Proyecto",
|
|
49
|
+
detected: existsSync(join(cwd, ".codex")),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
agents.push({
|
|
53
|
+
id: "gemini-project",
|
|
54
|
+
label: "Gemini Code Assist",
|
|
55
|
+
scope: "Proyecto",
|
|
56
|
+
detected: existsSync(join(cwd, ".gemini")),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
agents.push({
|
|
60
|
+
id: "agents-project",
|
|
61
|
+
label: "Agentes Genéricos",
|
|
62
|
+
scope: "Proyecto",
|
|
63
|
+
detected: existsSync(join(cwd, ".agents")),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
agents.push({
|
|
67
|
+
id: "copilot-project",
|
|
68
|
+
label: "GitHub Copilot",
|
|
69
|
+
scope: "Proyecto",
|
|
70
|
+
detected: existsSync(join(cwd, ".github", "copilot-instructions.md")),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
agents.push({
|
|
74
|
+
id: "codex-global",
|
|
75
|
+
label: "Codex CLI",
|
|
76
|
+
scope: "Global",
|
|
77
|
+
detected: existsSync(join(HOME, ".codex")),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return agents;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function detectAll(cwd) {
|
|
84
|
+
const all = detect(cwd);
|
|
85
|
+
return all.filter(a => a.detected).map(a => a.id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { detect as detectForWizard, detectAll };
|