codeninja 3.2.0 → 4.0.1
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 +15 -4
- package/agent/database-agent.md +24 -1
- package/agent/nodejs-agent.md +79 -0
- package/cli.js +27 -7
- package/commands/audit.workflow.md +4 -1
- package/commands/db-create-table.workflow.md +1 -1
- package/commands/initialize-project.workflow.md +21 -0
- package/ide/antigravity/.agents/personas/database-architect.md +431 -153
- package/ide/antigravity/.agents/personas/global-orchestrator.md +202 -85
- package/ide/antigravity/.agents/personas/nodejs-backend.md +368 -133
- package/ide/antigravity/.agents/personas/reactjs-frontend.md +182 -101
- package/ide/antigravity/.agents/skills/api-builder/SKILL.md +58 -0
- package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +22 -0
- package/ide/antigravity/.agents/skills/database/SKILL.md +32 -0
- package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +76 -82
- package/ide/antigravity/.agents/skills/reactjs/SKILL.md +36 -0
- package/ide/antigravity/.agents/workflows/codeninja-api.md +76 -83
- package/ide/antigravity/.agents/workflows/codeninja-audit.md +82 -44
- package/ide/antigravity/.agents/workflows/codeninja-db-create.md +107 -94
- package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +89 -67
- package/ide/antigravity/.agents/workflows/codeninja-db-index.md +86 -54
- package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +126 -68
- package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +87 -59
- package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +77 -41
- package/ide/antigravity/.agents/workflows/codeninja-debug.md +35 -21
- package/ide/antigravity/.agents/workflows/codeninja-design.md +49 -35
- package/ide/antigravity/.agents/workflows/codeninja-explain.md +41 -20
- package/ide/antigravity/.agents/workflows/codeninja-init.md +479 -289
- package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +253 -136
- package/ide/antigravity/.agents/workflows/codeninja-modularize.md +250 -132
- package/ide/antigravity/.agents/workflows/codeninja-optimize.md +71 -29
- package/ide/antigravity/.agents/workflows/codeninja-refactor.md +50 -42
- package/ide/antigravity/.agents/workflows/codeninja-review.md +38 -21
- package/ide/antigravity/.agents/workflows/codeninja-sync.md +922 -141
- package/ide/antigravity/.agents/workflows/codeninja-test.md +34 -49
- package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +449 -151
- package/ide/claude-code/.claude/CLAUDE.md +99 -0
- package/ide/claude-code/.claude/agents/database-agent.md +535 -0
- package/ide/claude-code/.claude/agents/nodejs-agent.md +493 -0
- package/ide/claude-code/.claude/agents/reactjs-agent.md +267 -0
- package/ide/claude-code/.claude/commands/codeninja-api.md +104 -0
- package/ide/claude-code/.claude/commands/codeninja-audit.md +119 -0
- package/ide/claude-code/.claude/commands/codeninja-db-create.md +138 -0
- package/ide/claude-code/.claude/commands/codeninja-db-drop.md +109 -0
- package/ide/claude-code/.claude/commands/codeninja-db-index.md +103 -0
- package/ide/claude-code/.claude/commands/codeninja-db-modify.md +165 -0
- package/ide/claude-code/.claude/commands/codeninja-db-seed.md +104 -0
- package/ide/claude-code/.claude/commands/codeninja-db-sync.md +106 -0
- package/ide/claude-code/.claude/commands/codeninja-debug.md +99 -0
- package/ide/claude-code/.claude/commands/codeninja-design.md +68 -0
- package/ide/claude-code/.claude/commands/codeninja-explain.md +61 -0
- package/ide/claude-code/.claude/commands/codeninja-init.md +529 -0
- package/ide/claude-code/.claude/commands/codeninja-integrate-api.md +453 -0
- package/ide/claude-code/.claude/commands/codeninja-modularize.md +334 -0
- package/ide/claude-code/.claude/commands/codeninja-optimize.md +129 -0
- package/ide/claude-code/.claude/commands/codeninja-refactor.md +76 -0
- package/ide/claude-code/.claude/commands/codeninja-review.md +87 -0
- package/ide/claude-code/.claude/commands/codeninja-sync.md +964 -0
- package/ide/claude-code/.claude/commands/codeninja-test.md +45 -0
- package/ide/claude-code/.claude/commands/codeninja-validate-page.md +548 -0
- package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +12 -13
- package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
- package/ide/cursor/.cursor/rules/03-api-builder.mdc +32 -110
- package/ide/cursor/.cursor/rules/04-nodejs-generation.mdc +58 -0
- package/ide/cursor/.cursor/rules/05-database.mdc +54 -0
- package/ide/cursor/.cursor/rules/06-reactjs.mdc +36 -0
- package/ide/cursor/.cursor/rules/07-reactjs-generation.mdc +49 -0
- package/ide/cursor/.cursor/rules/08-code-intelligence.mdc +56 -0
- package/ide/cursor/.cursor/rules/09-workflow-steps.mdc +53 -0
- package/ide/vscode/.github/copilot-instructions.md +67 -382
- package/ide/vscode/.vscode/instructions/code-intelligence.instructions.md +58 -0
- package/ide/vscode/.vscode/instructions/database.instructions.md +55 -0
- package/ide/vscode/.vscode/instructions/nodejs.instructions.md +77 -0
- package/ide/vscode/.vscode/instructions/reactjs.instructions.md +42 -0
- package/package.json +2 -2
- package/tasks/ask-hashing-library.task.md +31 -0
- package/tasks/ask-language-type.task.md +26 -0
- package/tasks/ask-new-module-name.task.md +13 -0
- package/tasks/ask-new-service-name.task.md +13 -0
- package/tasks/ask-old-module-name.task.md +15 -0
- package/tasks/ask-old-service-name.task.md +13 -0
- package/tasks/ask-orm-type.task.md +26 -0
- package/tasks/collect-seed-data.task.md +19 -0
- package/tasks/generate-app.task.md +42 -0
- package/tasks/generate-common.task.md +13 -0
- package/tasks/generate-constants.task.md +13 -0
- package/tasks/generate-database.task.md +32 -0
- package/tasks/generate-encryption.task.md +28 -0
- package/tasks/generate-fast-defaults.task.md +7 -0
- package/tasks/generate-hashing.task.md +180 -0
- package/tasks/generate-headerValidator.task.md +13 -0
- package/tasks/generate-ioRedis.task.md +20 -0
- package/tasks/generate-language-en.task.md +12 -0
- package/tasks/generate-logging.task.md +12 -0
- package/tasks/generate-model.task.md +74 -6
- package/tasks/generate-notification.task.md +12 -0
- package/tasks/generate-package-json.task.md +69 -0
- package/tasks/generate-prisma-client.task.md +56 -0
- package/tasks/generate-prisma-schema.task.md +71 -0
- package/tasks/generate-rateLimiter.task.md +20 -0
- package/tasks/generate-readme.task.md +24 -0
- package/tasks/generate-response.task.md +27 -0
- package/tasks/generate-route-manager.task.md +32 -0
- package/tasks/generate-route.task.md +37 -0
- package/tasks/generate-swagger.task.md +8 -0
- package/tasks/generate-template.task.md +12 -0
- package/tasks/generate-tsconfig.task.md +38 -0
- package/tasks/generate-validator.task.md +31 -0
- package/ide/cursor/.cursor/rules/04-database.mdc +0 -90
- package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -147
- package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
|
@@ -1,38 +1,54 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: codeninja MCP tools and context
|
|
2
|
+
description: codeninja MCP tools and context.json schema (v4.0). Always applied.
|
|
3
3
|
globs: ["**/*"]
|
|
4
4
|
alwaysApply: true
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
# codeninja — MCP and Context
|
|
7
|
+
# codeninja — MCP Tools and Context (v4.0)
|
|
8
8
|
|
|
9
|
-
## MCP Tools Reference
|
|
10
|
-
| Tool |
|
|
11
|
-
|
|
12
|
-
| `context_read` | Load
|
|
13
|
-
| `context_write` |
|
|
14
|
-
| `context_clear_scratchpad` | Clear current_* key
|
|
15
|
-
| `context_check_stale` | Detect unresolved
|
|
16
|
-
| `service_scan` | Discover services on disk |
|
|
17
|
-
| `migration_next_number` | Before any migration file
|
|
18
|
-
| `fs_read` | Read file
|
|
19
|
-
| `fs_list` | List directory
|
|
20
|
-
| `fs_exists` | Check existence
|
|
21
|
-
| `file_insert_after` | Surgical
|
|
22
|
-
| `file_contains` | Check
|
|
23
|
-
| `run_drift_check` | Context vs disk
|
|
24
|
-
| `lint_file` | Lint
|
|
25
|
-
| `analyze_middleware_order` | Check middleware chain
|
|
26
|
-
| `analyze_encryption_library` | Verify encryption
|
|
27
|
-
| `analyze_language_keys` | Check i18n
|
|
28
|
-
| `analyze_dependencies` | Scan package.json during @audit |
|
|
29
|
-
| `analyze_env_file` | Check .env completeness during @audit |
|
|
30
|
-
| `validate_redis_connection` | Test Redis during init |
|
|
31
|
-
| `validate_postgres_connection` | Test DB during init |
|
|
9
|
+
## MCP Tools Quick Reference
|
|
10
|
+
| Tool | Purpose | When |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| `context_read` | Load context.json | First on every activation |
|
|
13
|
+
| `context_write` | Deep-merge updates | After every completed operation |
|
|
14
|
+
| `context_clear_scratchpad` | Clear current_* key | After writing context |
|
|
15
|
+
| `context_check_stale` | Detect unresolved ops | Step 0 of activation |
|
|
16
|
+
| `service_scan` | Discover services on disk | Step 2 of activation |
|
|
17
|
+
| `migration_next_number` | Next sequential migration # | Before any migration file |
|
|
18
|
+
| `fs_read` | Read file from disk | Before modifying any file |
|
|
19
|
+
| `fs_list` | List directory | When scanning structure |
|
|
20
|
+
| `fs_exists` | Check file existence | Before conditional ops |
|
|
21
|
+
| `file_insert_after` | Surgical insert | route_manager, swagger — never rewrite |
|
|
22
|
+
| `file_contains` | Check for string | Before appending |
|
|
23
|
+
| `run_drift_check` | Context vs disk | During /codeninja:sync |
|
|
24
|
+
| `lint_file` | Lint generated JS/TS | After JS/TS generation |
|
|
25
|
+
| `analyze_middleware_order` | Check middleware chain | During audit |
|
|
26
|
+
| `analyze_encryption_library` | Verify encryption | During audit |
|
|
27
|
+
| `analyze_language_keys` | Check i18n keys | During audit |
|
|
32
28
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
## Context Schema (v4.0)
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"db": {
|
|
33
|
+
"type": "postgres|mysql|mongodb",
|
|
34
|
+
"orm": "none|prisma"
|
|
35
|
+
},
|
|
36
|
+
"services": {
|
|
37
|
+
"<name>": {
|
|
38
|
+
"type": "nodejs|reactjs",
|
|
39
|
+
"language": "javascript|typescript",
|
|
40
|
+
"hashing_library": "bcryptjs|argon2",
|
|
41
|
+
"port": 0,
|
|
42
|
+
"encryption_key": "", "encryption_iv": "", "api_key": ""
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**v4.0 new fields:** `db.orm`, `services[name].language`, `services[name].hashing_library`
|
|
49
|
+
|
|
50
|
+
## Stale Scratchpad Recovery
|
|
51
|
+
If `context_check_stale` returns stale keys:
|
|
52
|
+
1. Surface to user: "Unfinished [operation] detected"
|
|
53
|
+
2. Ask: continue or discard?
|
|
54
|
+
3. If discard: call `context_clear_scratchpad`, then proceed
|
|
@@ -1,124 +1,46 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
3
|
-
globs: ["
|
|
2
|
+
description: NodeJS API architecture standards — 2-layer rule, SOP, middleware order. Applied to JS/TS files.
|
|
3
|
+
globs: ["**/*.js", "**/*.ts"]
|
|
4
4
|
alwaysApply: false
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
# codeninja —
|
|
7
|
+
# codeninja — API Builder Standards (v4.0)
|
|
8
8
|
|
|
9
|
-
## 2-Layer
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
├── route.js ← HTTP only: validation, middleware, res.json()
|
|
13
|
-
└── <module>_model.js ← DB only: queries, business logic
|
|
14
|
-
```
|
|
15
|
-
Never SQL in `route.js`. Never `res.json()` in `_model.js`.
|
|
16
|
-
|
|
17
|
-
## /codeninja:init — NodeJS Service Scaffolding
|
|
18
|
-
|
|
19
|
-
### Phase 0 — Project Info (runs ONCE per repo, skip if context.project_info populated)
|
|
20
|
-
- Ask for project info doc (URL or paste) — store in context.project_info
|
|
21
|
-
- Ask for scope of work doc — store in context.project_info
|
|
22
|
-
- Ask for Figma URL — store in context.project_info
|
|
23
|
-
- Synthesize project summary and detected_entities[] from all provided docs
|
|
24
|
-
|
|
25
|
-
### Phase 1 — Mode and Type
|
|
26
|
-
- Ask: Fast setup (9 questions, auto-generate secure values) OR Manual setup (22 questions)
|
|
27
|
-
- Ask: NodeJS service | ReactJS app | Database only
|
|
28
|
-
- For NodeJS: ask client_type (reactjs|app), encrypted_transport, supported_languages[]
|
|
29
|
-
|
|
30
|
-
### Phase 2 — Database
|
|
31
|
-
- Ask: database type (postgresql|mysql|mongodb)
|
|
32
|
-
- Fast mode: ask db name and user only; auto-set host/port
|
|
33
|
-
- Manual mode: ask name, host, port, user individually
|
|
34
|
-
- Generate database folder at REPOSITORY ROOT (never inside service folder):
|
|
35
|
-
`database/<db_type>/migrations/`, `create-schema.sql`, `setup-database.sh`,
|
|
36
|
-
`setup-database.ps1`, `reset-database.sh`, `seeds/`, `database/README.md`
|
|
37
|
-
- Only if folder doesn't already exist — skip if it does
|
|
38
|
-
- Generate tbl_user_deviceinfo migration for nodejs projects
|
|
39
|
-
|
|
40
|
-
### Phase 3–5 — Service Identity, Package Info, Runtime Config
|
|
41
|
-
- Ask: service_name, port (manual), description
|
|
42
|
-
- Manual mode also: package_name, author, api_key, encryption_key (32 chars), redis config
|
|
43
|
-
- Fast mode: auto-generate all above values; encryption_iv = first 16 chars of encryption_key
|
|
44
|
-
|
|
45
|
-
### Phase 6 — Single Confirmation, Then Generate ALL Files
|
|
46
|
-
|
|
47
|
-
Show summary with ALL values (auto-generated marked). Run validation:
|
|
48
|
-
- BLOCKER: service name conflict, port conflict, key/iv wrong length, required fields missing
|
|
49
|
-
Ask: "Confirm and generate all files? (yes / no / change a value)"
|
|
50
|
-
ONE confirmation only — no per-file prompts after this.
|
|
51
|
-
|
|
52
|
-
**Wave 1:** package.json, .env, .env.example, .gitignore, README.md,
|
|
53
|
-
config/constants.js, config/template.js, logger/logging.js,
|
|
54
|
-
utilities/encryption.js, languages/<lang>.js for each language,
|
|
55
|
-
enc_dec.html (reactjs client) OR enc_dec.php (app client),
|
|
56
|
-
pem/ + images/ + logger/logs/ directories
|
|
57
|
-
|
|
58
|
-
**Wave 2:** config/database.js, utilities/ioRedis.js, utilities/response.js
|
|
59
|
-
|
|
60
|
-
**Wave 3:** config/common.js, utilities/validator.js,
|
|
61
|
-
utilities/notification.js, middleware/rateLimiter.js
|
|
62
|
-
|
|
63
|
-
**Wave 4:** middleware/headerValidator.js,
|
|
64
|
-
modules/v1/<ServiceName>/route.js, modules/v1/<ServiceName>/<service>_model.js,
|
|
65
|
-
document/v1/swagger_doc.json (skeleton)
|
|
66
|
-
|
|
67
|
-
**Wave 5:** modules/v1/route_manager.js, app.js
|
|
9
|
+
## The 2-Layer Rule (absolute — no exceptions)
|
|
10
|
+
- `route.js/ts` — HTTP only: validation, middleware, `res.json()` via sendResponse
|
|
11
|
+
- `<module>_model.js/ts` — DB only: queries, business logic, no `res.json()`
|
|
68
12
|
|
|
69
|
-
|
|
13
|
+
## 5-Step SOP for Every New Endpoint
|
|
14
|
+
1. **ROUTING** — append to `route_manager.js/ts` via `file_insert_after` (never rewrite)
|
|
15
|
+
2. **VALIDATION** — validatorjs schema in `route.js/ts`
|
|
16
|
+
3. **CONTROLLER** — model call + try/catch in `route.js/ts`; call `sendResponse`
|
|
17
|
+
4. **MODEL** — parameterized query or Prisma call in `<module>_model.js/ts`
|
|
18
|
+
5. **LOCALIZE** — all strings in `languages/en.js/ts`; use `file_contains` before adding
|
|
70
19
|
|
|
71
|
-
|
|
72
|
-
generate/update docker-compose.yml at repo root.
|
|
73
|
-
|
|
74
|
-
Call `context_write` → append service to context.services. Call `context_clear_scratchpad`.
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## /codeninja:api — Add API Endpoint
|
|
79
|
-
|
|
80
|
-
1. Review 1–2 existing modules for naming/auth patterns — surface summary
|
|
81
|
-
2. Ask: which service, API version (default v1)
|
|
82
|
-
3. Ask: module name, HTTP method, route path, description
|
|
83
|
-
4. Ask: primary table (from context.db.schema.tables), requires auth (yes/no)
|
|
84
|
-
5. Confirm: "Generate [METHOD] [path] in [service]/modules/[version]/[Module]?"
|
|
85
|
-
6. Generate:
|
|
86
|
-
- `modules/<v>/<Module>/route.js` — validation, middleware, res.json()
|
|
87
|
-
- `modules/<v>/<Module>/<module>_model.js` — parameterized queries only
|
|
88
|
-
- Append to `route_manager.js` via `file_insert_after` MCP — NEVER rewrite
|
|
89
|
-
- Patch `swagger_doc.json` via `file_insert_after` MCP — add path key only
|
|
90
|
-
7. Call `context_write` — append to context.api_routes, update modules list
|
|
91
|
-
|
|
92
|
-
---
|
|
93
|
-
|
|
94
|
-
## Code Standards (every generated file)
|
|
95
|
-
|
|
96
|
-
### JSDoc (every exported function — no exceptions)
|
|
97
|
-
```javascript
|
|
98
|
-
/**
|
|
99
|
-
* One-sentence description. Active voice.
|
|
100
|
-
*
|
|
101
|
-
* @param {type} paramName - Description.
|
|
102
|
-
* @returns {Promise<Object>} Description.
|
|
103
|
-
*/
|
|
20
|
+
## Middleware Order (enforced — never change)
|
|
104
21
|
```
|
|
105
|
-
|
|
106
|
-
### Route comments
|
|
107
|
-
```javascript
|
|
108
|
-
// POST /login — Authenticates user credentials and returns a session token.
|
|
109
|
-
router.post('/login', async (req, res) => {
|
|
22
|
+
rateLimiter → extractLanguage → validateApiKey → [auth if protected] → decryptRequest → routeHandler
|
|
110
23
|
```
|
|
111
24
|
|
|
112
|
-
|
|
25
|
+
## Response Contract
|
|
113
26
|
```javascript
|
|
114
|
-
|
|
27
|
+
// Success
|
|
28
|
+
sendResponse(req, res, 1, 'success_key', resultData)
|
|
29
|
+
// Error
|
|
30
|
+
sendResponse(req, res, 0, 'error_key', [])
|
|
31
|
+
// Session expired (triggers frontend logout)
|
|
32
|
+
sendResponse(req, res, -1, 'session_expired', [])
|
|
115
33
|
```
|
|
116
34
|
|
|
117
|
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
35
|
+
## Password Handling (v4.0)
|
|
36
|
+
- NEVER use `encryption.js` for passwords — AES is reversible, not safe for storage
|
|
37
|
+
- ALWAYS use `utilities/hashing.js`: `hashPassword(plain)` / `verifyPassword(plain, hash)`
|
|
38
|
+
|
|
39
|
+
## ORM Rule (v4.0)
|
|
40
|
+
- Read `context.db.orm` before generating model files
|
|
41
|
+
- orm="none": parameterized SQL (`$1`, `$2` placeholders)
|
|
42
|
+
- orm="prisma": `prisma.users.create({...})` — import singleton from `config/prisma`, never `new PrismaClient()`
|
|
120
43
|
|
|
121
|
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
- mongodb → `mongoose`
|
|
44
|
+
## Localizify Rules
|
|
45
|
+
- ONLY `headerValidator.js/ts` and `response.js/ts` may import localizify or call `t()`
|
|
46
|
+
- All other files use `sendResponse()`, `getMessage()`, or `req.t("key")`
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: NodeJS file generation standards — exact content for each generated file. Applied when editing service internals.
|
|
3
|
+
globs: ["**/modules/**", "**/middleware/**", "**/utilities/**", "**/config/**"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# codeninja — NodeJS File Generation Standards (v4.0)
|
|
8
|
+
|
|
9
|
+
Read `.codeninja/tasks/generate-<name>.task.md` before generating each file.
|
|
10
|
+
|
|
11
|
+
## Language Branch (FIRST step before generating ANY file)
|
|
12
|
+
Read `context.services[name].language` (or `context.current_init.language`).
|
|
13
|
+
- "javascript" → `.js` files, `require()`/`module.exports`
|
|
14
|
+
- "typescript" → `.ts` files, `import`/`export`, typed parameters
|
|
15
|
+
|
|
16
|
+
## utilities/hashing.js/ts
|
|
17
|
+
- bcryptjs or argon2 — read `context.services[name].hashing_library`
|
|
18
|
+
- Exports: `hashPassword(plain)` → `Promise<string>`, `verifyPassword(plain, hash)` → `Promise<boolean>`
|
|
19
|
+
- NEVER imports from encryption.js; NEVER uses AES/KEY/IV
|
|
20
|
+
|
|
21
|
+
## utilities/encryption.js/ts
|
|
22
|
+
- AES-256-CBC transport encryption ONLY — never passwords
|
|
23
|
+
- Exports: `encrypt(data)` → string, `decrypt(ciphertext)` → original value
|
|
24
|
+
- Library: `crypto-js` (client_type=reactjs) or `cryptlib` (client_type=app)
|
|
25
|
+
|
|
26
|
+
## config/database.js/ts (orm="none" only)
|
|
27
|
+
- PostgreSQL: `pg.Pool` with env vars DB_HOST/PORT/NAME/USER/PASS
|
|
28
|
+
- MySQL: `mysql2/promise` pool
|
|
29
|
+
- MongoDB: `mongoose.connect()`
|
|
30
|
+
|
|
31
|
+
## config/prisma.js/ts (orm="prisma" only)
|
|
32
|
+
- Single `new PrismaClient()` instance exported as singleton
|
|
33
|
+
- `log: ['query','error','warn']` in development only
|
|
34
|
+
|
|
35
|
+
## middleware/headerValidator.js/ts
|
|
36
|
+
- Exports: `extractLanguage`, `validateApiKey`, `validateAuthToken`, `decryptRequest`
|
|
37
|
+
- Only file permitted to call localizify `t()` directly (along with response.js)
|
|
38
|
+
- TypeScript: all middleware typed as `(req: Request, res: Response, next: NextFunction) => void`
|
|
39
|
+
|
|
40
|
+
## utilities/response.js/ts
|
|
41
|
+
- Exports: `sendResponse(req, res, code, messageKey, data)`
|
|
42
|
+
- Checks `encrypted_transport` flag — encrypts payload if true
|
|
43
|
+
- Only other file permitted to call localizify `t()` directly
|
|
44
|
+
|
|
45
|
+
## modules/v1/<Module>/route.js/ts
|
|
46
|
+
- Imports: Router, Validator, sendResponse, model functions
|
|
47
|
+
- One route handler per endpoint — single try/catch wrapping model call
|
|
48
|
+
- Route comment above each handler: `// POST /path — description`
|
|
49
|
+
- TypeScript: `async (req: Request, res: Response) => {}`
|
|
50
|
+
|
|
51
|
+
## modules/v1/<Module>/<module>_model.js/ts
|
|
52
|
+
- Imports: db pool (orm=none) or prisma singleton (orm=prisma), hashing utilities
|
|
53
|
+
- Returns exactly: `{ responsecode: 1|0|-1, responsemsg: 'key', responsedata: data }`
|
|
54
|
+
- No `res.json()`, no Express imports
|
|
55
|
+
|
|
56
|
+
## app.js/ts
|
|
57
|
+
- Middleware chain: cors → helmet → express.json → express.urlencoded → /api/v1 router
|
|
58
|
+
- TypeScript: `const app: Application = express()`
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Database standards — naming, SQL content order, index rules, Prisma conventions.
|
|
3
|
+
globs: ["**/*.sql", "**/database/**", "**/prisma/**"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# codeninja — Database Standards (v4.0)
|
|
8
|
+
|
|
9
|
+
## Naming Quick Reference
|
|
10
|
+
| Element | Rule | Example |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| Table | `tbl_` prefix, lowercase, plural | `tbl_users` |
|
|
13
|
+
| Column | lowercase snake_case | `user_id`, `created_at` |
|
|
14
|
+
| PK | `id`, bigint identity, first | always |
|
|
15
|
+
| FK | `<ref_table_singular_no_tbl>_id` | `user_id` refs `tbl_users` |
|
|
16
|
+
| Index (per-table) | `idx_<table_no_tbl>_<cols>` | `idx_users_email` |
|
|
17
|
+
| Migration (create) | `<N>-setup-tbl-<name>.sql` | `3-setup-tbl-users.sql` |
|
|
18
|
+
| Migration (alter) | `<N>-alter-tbl-<name>-<desc>.sql` | — |
|
|
19
|
+
| Shared indexes | `111-setup-database-indexes.sql` | always last |
|
|
20
|
+
|
|
21
|
+
## Column Types
|
|
22
|
+
| Use | Type |
|
|
23
|
+
|---|---|
|
|
24
|
+
| Primary key | `bigint NOT NULL GENERATED ALWAYS AS IDENTITY (...)` |
|
|
25
|
+
| Foreign key | `BIGINT NOT NULL DEFAULT 0` |
|
|
26
|
+
| Email | `VARCHAR(132)` |
|
|
27
|
+
| Password/token | `TEXT` |
|
|
28
|
+
| Status | `INTEGER NOT NULL DEFAULT 0 CHECK (status IN (0, 1))` |
|
|
29
|
+
| Soft delete | `BOOLEAN NOT NULL DEFAULT FALSE` |
|
|
30
|
+
| Timestamp | `TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP` |
|
|
31
|
+
| Financial | `NUMERIC(18,8) NOT NULL DEFAULT 0.00000000` |
|
|
32
|
+
| JSON | `JSON NOT NULL DEFAULT '{}'` |
|
|
33
|
+
|
|
34
|
+
NEVER use PostgreSQL ENUM — always `VARCHAR + CHECK constraint`.
|
|
35
|
+
|
|
36
|
+
## SQL File Content Order (strict)
|
|
37
|
+
1. Comment: `-- Creating tbl_name for purpose`
|
|
38
|
+
2. `DROP TABLE IF EXISTS public.tbl_name CASCADE;`
|
|
39
|
+
3. `CREATE TABLE` block
|
|
40
|
+
4. `COMMENT ON COLUMN` for every enum/flag column
|
|
41
|
+
5. Per-table `CREATE INDEX` statements
|
|
42
|
+
6. `ALTER TABLE ... OWNER TO <db_user>`
|
|
43
|
+
7. `GRANT ALL ON TABLE ... TO <db_user>`
|
|
44
|
+
8. Seed `INSERT` (reference tables only)
|
|
45
|
+
|
|
46
|
+
## Index Strategy
|
|
47
|
+
Always index: every FK column, (status + is_deleted) compound, created_at DESC on log tables, email + is_deleted on user tables.
|
|
48
|
+
|
|
49
|
+
## Prisma Conventions (v4.0 — orm="prisma" only)
|
|
50
|
+
- `tbl_users` → `model Users` (strip tbl_, PascalCase) + `@@map("tbl_users")`
|
|
51
|
+
- `id` BIGINT IDENTITY → `id BigInt @id @default(autoincrement())`
|
|
52
|
+
- `created_at` → `createdAt DateTime @default(now()) @map("created_at")`
|
|
53
|
+
- `is_deleted` → `isDeleted Boolean @default(false) @map("is_deleted")`
|
|
54
|
+
- After every model addition → `npx prisma generate`
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: ReactJS architecture standards — apiClient, apiHandler, component rules.
|
|
3
|
+
globs: ["**/*.jsx", "**/src/**"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# codeninja — ReactJS Architecture Standards
|
|
8
|
+
|
|
9
|
+
## apiClient.js — 4 Responsibilities
|
|
10
|
+
1. Static headers: `api-key`, `Accept-Language`, `Content-Type: text/plain`
|
|
11
|
+
2. Request interceptor: encrypt body + attach encrypted token from localStorage
|
|
12
|
+
3. Response interceptor (success): decrypt + parse JSON; code -1 → logout redirect
|
|
13
|
+
4. Response interceptor (error): ERR_NETWORK/401 → logout redirect + error message
|
|
14
|
+
|
|
15
|
+
## apiHandler.js Standard
|
|
16
|
+
- One `async` function per backend endpoint
|
|
17
|
+
- No try/catch, no decryption, no response shaping here (interceptors handle it)
|
|
18
|
+
- All API endpoint paths defined here — never in page components
|
|
19
|
+
|
|
20
|
+
## Backend Linking Rule
|
|
21
|
+
- ReactJS service CANNOT be initialized without a linked NodeJS backend
|
|
22
|
+
- Inherits from linked backend: `encryption_key`, `encryption_iv`, `api_key`, `port`
|
|
23
|
+
- These are NEVER asked from the user — always inherited from `context.services[linked]`
|
|
24
|
+
|
|
25
|
+
## Vanilla CSS Only
|
|
26
|
+
- Per-page: `<PageName>.module.css`
|
|
27
|
+
- Global: `public/assets/css/style.css`
|
|
28
|
+
- No Tailwind, no CSS-in-JS, no styled-components
|
|
29
|
+
|
|
30
|
+
## .env Standard
|
|
31
|
+
```
|
|
32
|
+
REACT_APP_BASE_URL=http://localhost:<linked_port>/api/v1/
|
|
33
|
+
REACT_APP_API_KEY=<inherited>
|
|
34
|
+
REACT_APP_KEY=<inherited>
|
|
35
|
+
REACT_APP_IV=<inherited>
|
|
36
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: ReactJS file generation standards — exact content for each generated React file.
|
|
3
|
+
globs: ["**/src/pages/**", "**/src/components/**", "**/src/api/**"]
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# codeninja — ReactJS File Generation Standards
|
|
8
|
+
|
|
9
|
+
Read `.codeninja/tasks/generate-react-*.task.md` before generating each file.
|
|
10
|
+
|
|
11
|
+
## src/api/apiClient.js
|
|
12
|
+
- Axios instance with `baseURL: process.env.REACT_APP_BASE_URL`
|
|
13
|
+
- Static headers: `api-key`, `Accept-Language: en`, `Content-Type: text/plain`
|
|
14
|
+
- Request interceptor: `CryptoJS.AES.encrypt(JSON.stringify(data), key, {iv})` + token header
|
|
15
|
+
- Response success: decrypt + JSON.parse; responsecode -1 → `logOutRedirectCall()`
|
|
16
|
+
- Response error: 401 or ERR_NETWORK → `logOutRedirectCall()` + `showErrorMessage()`
|
|
17
|
+
|
|
18
|
+
## src/api/apiHandler.js
|
|
19
|
+
- Imports `axiosClient` from `./apiClient`
|
|
20
|
+
- One exported async function per endpoint
|
|
21
|
+
- No try/catch — interceptors handle errors
|
|
22
|
+
- Example: `export const loginUser = (data) => axiosClient.post('/login', data)`
|
|
23
|
+
|
|
24
|
+
## src/pages/Welcome/index.jsx
|
|
25
|
+
- Functional component using project name from env/context
|
|
26
|
+
- Imports `Welcome.module.css`
|
|
27
|
+
- No data fetching, no state — pure welcome UI
|
|
28
|
+
- First route in App.jsx at path `/`
|
|
29
|
+
|
|
30
|
+
## src/App.jsx
|
|
31
|
+
- React Router v6: `BrowserRouter` + `Routes` + `Route`
|
|
32
|
+
- First route: `<Route path="/" element={<Welcome />} />`
|
|
33
|
+
|
|
34
|
+
## src/index.jsx
|
|
35
|
+
- `ReactDOM.createRoot(document.getElementById('root')).render(<App />)`
|
|
36
|
+
|
|
37
|
+
## public/index.html
|
|
38
|
+
- Single HTML shell with `<div id="root"></div>`
|
|
39
|
+
- Links to `public/assets/css/style.css`
|
|
40
|
+
- No inline JS or styles
|
|
41
|
+
|
|
42
|
+
## .htaccess (both root and public/)
|
|
43
|
+
```apache
|
|
44
|
+
RewriteEngine On
|
|
45
|
+
RewriteBase /
|
|
46
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
|
47
|
+
RewriteCond %{REQUEST_FILENAME} !-d
|
|
48
|
+
RewriteRule ^ index.html [L]
|
|
49
|
+
```
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Code intelligence commands — audit, debug, review, optimize checklists.
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# codeninja — Code Intelligence Standards (v4.0)
|
|
7
|
+
|
|
8
|
+
## /codeninja:audit Checklist
|
|
9
|
+
|
|
10
|
+
### Security
|
|
11
|
+
- [ ] API key validation on all routes?
|
|
12
|
+
- [ ] Passwords HASHED using `utilities/hashing.js`? Never AES-encrypted?
|
|
13
|
+
- [ ] No direct bcrypt/argon2 imports in route/model files?
|
|
14
|
+
- [ ] Parameterized queries only — no string concatenation in SQL?
|
|
15
|
+
- [ ] No hardcoded keys/passwords in source?
|
|
16
|
+
- [ ] `.env` in `.gitignore`?
|
|
17
|
+
- [ ] Middleware order: rateLimiter→extractLanguage→validateApiKey→[auth]→decryptRequest?
|
|
18
|
+
|
|
19
|
+
### Architecture
|
|
20
|
+
- [ ] 2-layer rule: no SQL in route.js, no res.json() in model files?
|
|
21
|
+
- [ ] route_manager.js uses `file_insert_after` — never rewritten?
|
|
22
|
+
- [ ] All routes in swagger_doc.json?
|
|
23
|
+
- [ ] All routes in context.api_routes?
|
|
24
|
+
|
|
25
|
+
### v4.0 Checks
|
|
26
|
+
- [ ] If orm="prisma": no `new PrismaClient()` in model files?
|
|
27
|
+
- [ ] If language="typescript": no `require()` in .ts files?
|
|
28
|
+
|
|
29
|
+
## /codeninja:debug Trace Path
|
|
30
|
+
1. extractLanguage (headerValidator) — language set?
|
|
31
|
+
2. validateApiKey — api-key header matches .env?
|
|
32
|
+
3. validateAuthToken (if protected) — token valid?
|
|
33
|
+
4. rateLimiter — not throttled?
|
|
34
|
+
5. validatorjs rules in route.js — all required fields present?
|
|
35
|
+
6. Model function call — DB connection alive?
|
|
36
|
+
7. DB query (SQL or Prisma) — column names match context.db.schema?
|
|
37
|
+
8. sendResponse — encrypted_transport flag handled correctly?
|
|
38
|
+
|
|
39
|
+
**Common causes:** 401=middleware order or key mismatch; 400=validation rules mismatch; 500=DB connection or column name wrong.
|
|
40
|
+
|
|
41
|
+
## /codeninja:review Dimensions
|
|
42
|
+
- Security: auth middleware present, parameterized queries, no hardcoded secrets
|
|
43
|
+
- Architecture: 2-layer rule, route_manager registration, swagger coverage
|
|
44
|
+
- Code quality: JSDoc on every function, no console.log, async try/catch
|
|
45
|
+
- Database: column names match context, FK indexes present, LIMIT on list queries
|
|
46
|
+
|
|
47
|
+
## /codeninja:optimize Patterns
|
|
48
|
+
1. Missing index → `CREATE INDEX CONCURRENTLY`
|
|
49
|
+
2. `SELECT *` → explicit column list
|
|
50
|
+
3. N+1 → JOIN or IN clause
|
|
51
|
+
4. `DATE(col)` in WHERE → range filter to preserve index
|
|
52
|
+
5. `RANK()` with gaps → `DENSE_RANK()` for leaderboards
|
|
53
|
+
6. No LIMIT on unbounded list queries
|
|
54
|
+
7. Heavy middleware on lightweight routes
|
|
55
|
+
8. Redis caching opportunities (repeated identical queries)
|
|
56
|
+
9. `work_mem` session-level for sort-heavy queries
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Full workflow steps for all codeninja commands — init phases, api creation, DB operations.
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# codeninja — Workflow Steps Reference (v4.0)
|
|
7
|
+
|
|
8
|
+
Read `.codeninja/commands/<workflow>.workflow.md` for the full step-by-step execution of each command.
|
|
9
|
+
Read `.codeninja/tasks/<task>.task.md` before generating any file.
|
|
10
|
+
|
|
11
|
+
## /codeninja:init — Key Phases
|
|
12
|
+
|
|
13
|
+
**Phase 0** (once per repo): ask-project-info-doc → ask-project-scope-of-work → ask-project-figma → synthesize summary
|
|
14
|
+
|
|
15
|
+
**Phase 1** (mode + type): ask-init-mode → ask-project-type
|
|
16
|
+
- NodeJS: ask-client-type → ask-language-type → ask-encrypted-transport → ask-supported-languages
|
|
17
|
+
- ReactJS: ask-linked-service → inherit encryption/api values from linked backend
|
|
18
|
+
|
|
19
|
+
**Phase 2** (database, skip for ReactJS): ask-database-type → ask-orm-type → ask-database-config
|
|
20
|
+
- Fast mode: ask-database-name + ask-database-user only
|
|
21
|
+
|
|
22
|
+
**Phase 3–5** (service identity + config): ask-service-name → ask-service-port → ask-service-description
|
|
23
|
+
- Manual NodeJS: ask-package-name → ask-package-author → ask-api-key → ask-encryption-key → ask-redis-config → ask-hashing-library
|
|
24
|
+
- Fast NodeJS: generate-fast-defaults (auto-sets port, api_key, encryption_key, language="javascript", hashing_library="bcryptjs", orm="none")
|
|
25
|
+
|
|
26
|
+
**Phase 6** (confirm + generate): show-init-summary → single confirmation → ALL files generated silently
|
|
27
|
+
|
|
28
|
+
**NodeJS Wave 1** (Foundation): package.json, .env, .gitignore, README.md, config/constants, config/template, logger/logging, utilities/encryption, **utilities/hashing**, languages/*, enc_dec.html/php, **tsconfig.json (TS only)**
|
|
29
|
+
|
|
30
|
+
**NodeJS Wave 2** (Infrastructure): config/database (or config/prisma if orm=prisma), utilities/ioRedis, utilities/response
|
|
31
|
+
|
|
32
|
+
**NodeJS Wave 3** (Service): config/common, utilities/validator, utilities/notification, middleware/rateLimiter
|
|
33
|
+
|
|
34
|
+
**NodeJS Wave 4** (Middleware + Business): middleware/headerValidator, modules/v1/<Name>/route, modules/v1/<Name>/<name>_model, document/v1/swagger_doc.json
|
|
35
|
+
|
|
36
|
+
**NodeJS Wave 5** (Orchestration): modules/v1/route_manager, app.js/ts
|
|
37
|
+
|
|
38
|
+
**NodeJS Wave 6** (Docker): Dockerfile, .dockerignore
|
|
39
|
+
|
|
40
|
+
## /codeninja:api — Key Steps
|
|
41
|
+
1. Review existing modules (Phase 0)
|
|
42
|
+
2. ask-target-service → ask-api-version → ask-module-name → ask-http-method → ask-route-path → ask-route-description
|
|
43
|
+
3. ask-primary-table → ask-requires-auth
|
|
44
|
+
4. Confirm → generate route.js/ts + _model.js/ts + append route_manager + patch swagger
|
|
45
|
+
|
|
46
|
+
## /codeninja:db:create — Key Steps
|
|
47
|
+
1. ask-table-purpose → ask-table-name → ask-table-file-number
|
|
48
|
+
2. ask-table-needs-status → ask-table-needs-soft-delete
|
|
49
|
+
3. Column loop: ask-column-name → ask-column-type → ask-column-is-enum → repeat until done
|
|
50
|
+
4. ask-table-indexes
|
|
51
|
+
5. ask-table-seed-data → if yes: collect-seed-data
|
|
52
|
+
6. show-db-table-summary → confirm → generate SQL file + update create-schema.sql
|
|
53
|
+
7. If orm=prisma: also append model to prisma/schema.prisma + `npx prisma generate`
|