pixelcrew 0.2.3 → 0.2.6
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 +389 -315
- package/bin/pixel-agents.js +306 -149
- package/package.json +3 -1
- package/skill/SKILL.md +185 -0
- package/skill/references/anti-ai-rubric.md +30 -0
- package/skill/references/anti-ai-slop-encyclopedia.md +181 -0
- package/skill/references/commands-reference.md +135 -0
- package/skill/references/testing-and-qa-strategy.md +25 -0
- package/skill/references/token-efficiency.md +20 -0
- package/src/adapters/adapter.interface.js +77 -0
- package/src/adapters/antigravity.js +138 -0
- package/src/adapters/claude-code.js +149 -0
- package/src/adapters/codex.js +131 -0
- package/src/adapters/cursor.js +133 -0
- package/src/adapters/generic.js +63 -0
- package/src/adapters/index.js +15 -0
- package/src/adapters/kiro.js +134 -0
- package/src/adapters/registry.js +150 -0
- package/src/backend/analyzer/complexity-analyzer.js +104 -0
- package/src/backend/analyzer/requirement-analyzer.js +213 -0
- package/src/backend/analyzer/threat-analyzer.js +122 -0
- package/src/backend/api/api-designer.js +90 -0
- package/src/backend/api/error-contract.js +132 -0
- package/src/backend/api/route-generator.js +92 -0
- package/src/backend/api/schema-generator.js +64 -0
- package/src/backend/architecture/adr-generator.js +62 -0
- package/src/backend/architecture/architecture-reasoner.js +119 -0
- package/src/backend/architecture/architecture-selector.js +57 -0
- package/src/backend/architecture/tradeoff-analyzer.js +92 -0
- package/src/backend/data/data-modeler.js +114 -0
- package/src/backend/data/index-analyzer.js +93 -0
- package/src/backend/data/query-analyzer.js +41 -0
- package/src/backend/data/schema-generator.js +92 -0
- package/src/backend/data/transaction-analyzer.js +49 -0
- package/src/backend/index.js +67 -0
- package/src/backend/observability/logging-engine.js +80 -0
- package/src/backend/observability/metrics-engine.js +31 -0
- package/src/backend/observability/tracing-engine.js +16 -0
- package/src/backend/patterns/pattern-registry.js +74 -0
- package/src/backend/patterns/pattern-selector.js +39 -0
- package/src/backend/patterns/tradeoff-engine.js +17 -0
- package/src/backend/performance/cache-analyzer.js +31 -0
- package/src/backend/performance/concurrency-analyzer.js +34 -0
- package/src/backend/performance/performance-engine.js +98 -0
- package/src/backend/performance/query-optimizer.js +16 -0
- package/src/backend/reliability/failure-analyzer.js +22 -0
- package/src/backend/reliability/idempotency-engine.js +56 -0
- package/src/backend/reliability/resilience-engine.js +141 -0
- package/src/backend/reliability/retry-analyzer.js +15 -0
- package/src/backend/security/auth-selector.js +33 -0
- package/src/backend/security/authorization-engine.js +90 -0
- package/src/backend/security/policy-engine.js +49 -0
- package/src/backend/security/secret-analyzer.js +39 -0
- package/src/backend/security/security-engine.js +122 -0
- package/src/backend/security/threat-model.js +59 -0
- package/src/backend/synthesis/backend-synthesizer.js +98 -0
- package/src/backend/synthesis/infrastructure-synthesizer.js +108 -0
- package/src/backend/synthesis/module-synthesizer.js +262 -0
- package/src/backend/validation/architecture-validator.js +70 -0
- package/src/backend/validation/backend-quality-validator.js +71 -0
- package/src/backend/validation/dependency-validator.js +20 -0
- package/src/backend/validation/performance-validator.js +38 -0
- package/src/backend/validation/security-validator.js +73 -0
- package/src/commands/adapt.js +105 -0
- package/src/commands/add.js +78 -0
- package/src/commands/animate.js +48 -0
- package/src/commands/assemble.js +57 -0
- package/src/commands/audit.js +93 -0
- package/src/commands/backend.js +125 -0
- package/src/commands/bento.js +25 -0
- package/src/commands/blueprint.js +65 -0
- package/src/commands/bolder.js +48 -0
- package/src/commands/boss-fight.js +60 -0
- package/src/commands/build.js +39 -0
- package/src/commands/calibrate.js +25 -0
- package/src/commands/chromatic.js +25 -0
- package/src/commands/clarify.js +52 -0
- package/src/commands/colorize.js +57 -0
- package/src/commands/command.interface.js +28 -0
- package/src/commands/commands.js +84 -0
- package/src/commands/craft.js +57 -0
- package/src/commands/crew.js +66 -0
- package/src/commands/critique.js +25 -0
- package/src/commands/de-slop.js +25 -0
- package/src/commands/delight.js +46 -0
- package/src/commands/deploy.js +42 -0
- package/src/commands/distill.js +48 -0
- package/src/commands/doctor.js +89 -0
- package/src/commands/document.js +83 -0
- package/src/commands/eight-bit.js +25 -0
- package/src/commands/extract.js +75 -0
- package/src/commands/fix.js +46 -0
- package/src/commands/harden.js +85 -0
- package/src/commands/index.js +67 -0
- package/src/commands/install.js +75 -0
- package/src/commands/layout.js +48 -0
- package/src/commands/live.js +44 -0
- package/src/commands/manifest.js +25 -0
- package/src/commands/office.js +25 -0
- package/src/commands/onboard.js +46 -0
- package/src/commands/oneshot.js +60 -0
- package/src/commands/optimize.js +46 -0
- package/src/commands/overdrive.js +46 -0
- package/src/commands/parser.js +143 -0
- package/src/commands/pixelcrew.js +96 -0
- package/src/commands/plan.js +66 -0
- package/src/commands/polish.js +45 -0
- package/src/commands/quieter.js +48 -0
- package/src/commands/recap.js +358 -0
- package/src/commands/registry.js +353 -0
- package/src/commands/render.js +26 -0
- package/src/commands/retrofit.js +25 -0
- package/src/commands/review.js +118 -0
- package/src/commands/roster.js +25 -0
- package/src/commands/sentinel.js +25 -0
- package/src/commands/shape.js +66 -0
- package/src/commands/skills.js +57 -0
- package/src/commands/status.js +48 -0
- package/src/commands/stop.js +50 -0
- package/src/commands/sync.js +58 -0
- package/src/commands/typeset.js +58 -0
- package/src/commands/warp.js +25 -0
- package/src/core/agent-runtime.js +94 -0
- package/src/core/event-bus.js +98 -0
- package/src/core/index.js +9 -0
- package/src/core/orchestrator.js +234 -0
- package/src/core/scheduler.js +124 -0
- package/src/core/task-graph.js +185 -0
- package/src/dashboard/app.js +1172 -30
- package/src/dashboard/index.html +223 -23
- package/src/dashboard/styles.css +870 -0
- package/src/index.js +16 -0
- package/src/orchestrator/artifact-graph.js +104 -0
- package/src/orchestrator/ast-normalizer.js +147 -0
- package/src/orchestrator/code-generator.js +632 -780
- package/src/orchestrator/design-engine.js +203 -0
- package/src/orchestrator/engine.js +307 -38
- package/src/orchestrator/oneshot.js +367 -380
- package/src/orchestrator/ontology.js +394 -0
- package/src/orchestrator/planner.js +231 -258
- package/src/orchestrator/repair-planner.js +67 -0
- package/src/orchestrator/requirement-contract.js +177 -0
- package/src/orchestrator/requirement-validator.js +39 -0
- package/src/orchestrator/semantic-engine.js +582 -0
- package/src/orchestrator/semantic-reviewer.js +179 -0
- package/src/orchestrator/task-planner.js +111 -0
- package/src/orchestrator/telemetry.js +209 -0
- package/src/orchestrator/ui-synthesizer.js +245 -0
- package/src/orchestrator/visual-critic.js +106 -0
- package/src/policies/architecture/layering.policy.js +14 -0
- package/src/policies/performance/indexing.policy.js +13 -0
- package/src/policies/reliability/resilience.policy.js +13 -0
- package/src/policies/security/auth.policy.js +31 -0
- package/src/protocol/agent.js +124 -0
- package/src/protocol/event.js +78 -0
- package/src/protocol/index.js +8 -0
- package/src/protocol/skill.js +54 -0
- package/src/protocol/task.js +100 -0
- package/src/scaffold/claude-generator.js +60 -0
- package/src/scaffold/commands-catalog.js +321 -0
- package/src/scaffold/cursor-generator.js +74 -0
- package/src/scaffold/ide-rules.js +133 -0
- package/src/scaffold/init.js +415 -91
- package/src/scaffold/installer.js +571 -0
- package/src/scaffold/kiro-generator.js +86 -0
- package/src/scaffold/skills-bundle.js +520 -0
- package/src/scaffold/templates.js +57 -4
- package/src/scaffold/workstations.js +364 -0
- package/src/server/server.js +283 -40
- package/src/utils/fs-safe.js +168 -0
- package/src/utils/markdown-report.js +175 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Technology & Architecture Selector
|
|
3
|
+
*
|
|
4
|
+
* Evaluates candidate technologies across criteria:
|
|
5
|
+
* Compatibility, Performance, Operational Complexity, Security, and Ecosystem Support.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class ArchitectureSelector {
|
|
9
|
+
/**
|
|
10
|
+
* Select optimal technologies for a given architecture specification
|
|
11
|
+
* @param {object} spec - ArchitectureSpecification
|
|
12
|
+
* @returns {object} Technology Stack Selection
|
|
13
|
+
*/
|
|
14
|
+
static selectStack(spec = {}) {
|
|
15
|
+
const complexity = spec.complexity || {};
|
|
16
|
+
const reqs = spec.requirements || {};
|
|
17
|
+
|
|
18
|
+
const runtime = {
|
|
19
|
+
name: 'Node.js (TypeScript)',
|
|
20
|
+
version: '>=20.0.0',
|
|
21
|
+
framework: 'Next.js 14/15 App Router + Route Handlers',
|
|
22
|
+
rationale: 'Unified full-stack TypeScript ecosystem with server-rendered React and isolated backend route handlers.'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const database = {
|
|
26
|
+
engine: 'PostgreSQL',
|
|
27
|
+
orm: 'Prisma ORM',
|
|
28
|
+
rationale: 'Type-safe relational database with robust ACID transactions, compound index support, and declarative migrations.'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const validation = {
|
|
32
|
+
library: 'Zod',
|
|
33
|
+
rationale: 'Runtime schema validation and static TypeScript inference for request/response payloads.'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const auth = spec.authentication?.required ? {
|
|
37
|
+
mechanism: 'Iron Session / Encrypted Session Cookies + Argon2id',
|
|
38
|
+
rationale: 'Stateless encrypted server-side session cookies preventing XSS token theft, with Argon2id for secure password hashing.'
|
|
39
|
+
} : { mechanism: 'None', rationale: 'No authentication required.' };
|
|
40
|
+
|
|
41
|
+
const cache = spec.cache?.required ? {
|
|
42
|
+
mechanism: spec.cache.technology === 'redis' ? 'IORedis / BullMQ' : 'In-Memory LRU Cache',
|
|
43
|
+
rationale: spec.cache.technology === 'redis'
|
|
44
|
+
? 'Distributed caching and resilient background worker queue across multi-instance deployments.'
|
|
45
|
+
: 'Zero-infrastructure in-process LRU cache for read optimization without external dependencies.'
|
|
46
|
+
} : { mechanism: 'None', rationale: 'Caching not justified by current traffic requirements.' };
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
runtime,
|
|
50
|
+
database,
|
|
51
|
+
validation,
|
|
52
|
+
auth,
|
|
53
|
+
cache,
|
|
54
|
+
selectionDate: new Date().toISOString()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Architectural Tradeoff Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Analyzes architectural choices and documents explicit benefits, costs, risks, and mitigations.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export class TradeoffAnalyzer {
|
|
8
|
+
/**
|
|
9
|
+
* Produce comprehensive tradeoff analysis for an architecture spec
|
|
10
|
+
* @param {object} spec - ArchitectureSpecification
|
|
11
|
+
* @returns {Array<object>} Tradeoff Decisions
|
|
12
|
+
*/
|
|
13
|
+
static analyzeTradeoffs(spec = {}) {
|
|
14
|
+
const decisions = [];
|
|
15
|
+
|
|
16
|
+
// 1. Architecture Topology Tradeoff
|
|
17
|
+
decisions.push({
|
|
18
|
+
decision: `Selected architecture style: ${spec.style}`,
|
|
19
|
+
reason: `Complexity score is ${spec.complexityScore}/100 (${spec.tier} tier).`,
|
|
20
|
+
benefits: [
|
|
21
|
+
'Clear separation of domain modules with controller/service/repository layers',
|
|
22
|
+
'Eliminates distributed network latency and operational overhead of microservices',
|
|
23
|
+
'Easy local development, testing, and continuous deployment'
|
|
24
|
+
],
|
|
25
|
+
costs: [
|
|
26
|
+
'Shared runtime resources across all modules'
|
|
27
|
+
],
|
|
28
|
+
alternatives: ['Microservices architecture', 'Serverless-only lambdas'],
|
|
29
|
+
risk: 'Module coupling over time if boundaries are not strictly enforced',
|
|
30
|
+
mitigation: 'Automated architectural linting ensuring domain services never cross-import internal repositories directly'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// 2. Database Tradeoff
|
|
34
|
+
const dbDisplay = (spec.database?.type || '').toLowerCase() === 'postgresql' ? 'PostgreSQL' : (spec.database?.type || 'PostgreSQL');
|
|
35
|
+
const ormDisplay = (spec.database?.orm || '').toLowerCase() === 'prisma' ? 'Prisma' : (spec.database?.orm || 'Prisma');
|
|
36
|
+
decisions.push({
|
|
37
|
+
decision: `Selected Database: ${dbDisplay} with ${ormDisplay}`,
|
|
38
|
+
reason: 'Application requires relational data modeling, strong consistency, and compound query indexing.',
|
|
39
|
+
benefits: [
|
|
40
|
+
'Compile-time type safety with autogenerated client bindings',
|
|
41
|
+
'Declarative migration tracking and schema constraints',
|
|
42
|
+
'ACID transaction guarantees for critical workflows'
|
|
43
|
+
],
|
|
44
|
+
costs: [
|
|
45
|
+
'Slight performance overhead compared to raw SQL queries',
|
|
46
|
+
'Requires managed database instance or Docker in production'
|
|
47
|
+
],
|
|
48
|
+
alternatives: ['Raw SQL with pg-promise', 'MongoDB / Document Store', 'Drizzle ORM'],
|
|
49
|
+
risk: 'N+1 query issues on deeply nested relations if not properly loaded',
|
|
50
|
+
mitigation: 'Explicit relation queries with select/include clauses and query performance validation'
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 3. Caching & Queue Tradeoff
|
|
54
|
+
if (spec.cache?.required) {
|
|
55
|
+
decisions.push({
|
|
56
|
+
decision: `Caching Strategy: ${spec.cache.technology}`,
|
|
57
|
+
reason: 'Read-heavy query patterns and repetitive domain computations.',
|
|
58
|
+
benefits: [
|
|
59
|
+
'Sub-millisecond response latency for hot entity reads',
|
|
60
|
+
'Significant reduction in database connection and query load'
|
|
61
|
+
],
|
|
62
|
+
costs: [
|
|
63
|
+
'Cache invalidation complexity on write mutations',
|
|
64
|
+
spec.cache.technology === 'redis' ? 'Additional Redis infrastructure to maintain' : 'Memory usage in application process'
|
|
65
|
+
],
|
|
66
|
+
alternatives: ['Direct database reads with optimized indexing only', 'HTTP CDN Edge Caching'],
|
|
67
|
+
risk: 'Serving stale data to users after updates',
|
|
68
|
+
mitigation: 'Short TTL (300s) coupled with explicit cache-key invalidation in domain repository mutating methods'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 4. Authentication Tradeoff
|
|
73
|
+
if (spec.authentication?.required) {
|
|
74
|
+
decisions.push({
|
|
75
|
+
decision: `Authentication Strategy: ${spec.authentication.strategy}`,
|
|
76
|
+
reason: 'Secure session management for web and API consumers.',
|
|
77
|
+
benefits: [
|
|
78
|
+
'Immunity to client-side JavaScript XSS token theft via HTTP-only cookies',
|
|
79
|
+
'Instant server-side session revocation capability upon logout or security events'
|
|
80
|
+
],
|
|
81
|
+
costs: [
|
|
82
|
+
'Requires state verification per authenticated request'
|
|
83
|
+
],
|
|
84
|
+
alternatives: ['Stateless Bearer JWTs in localStorage', 'Third-party Auth0/Clerk'],
|
|
85
|
+
risk: 'CSRF vulnerability if SameSite cookies and origin validation are omitted',
|
|
86
|
+
mitigation: 'SameSite=Lax/Strict cookie flags, encrypted payload seals, and Origin/Referer verification'
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return decisions;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Data Modeler Engine
|
|
3
|
+
*
|
|
4
|
+
* Infers entities, relationships (1:1, 1:N, M:N), primary keys (UUID/CUID),
|
|
5
|
+
* foreign keys, unique constraints, and transaction boundaries.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class DataModeler {
|
|
9
|
+
/**
|
|
10
|
+
* Refine and enrich entity models with backend database invariants
|
|
11
|
+
* @param {Array<object>} rawEntities - Entities from AST
|
|
12
|
+
* @param {object} architecture - ArchitectureSpecification
|
|
13
|
+
* @returns {Array<object>} Enriched Entities
|
|
14
|
+
*/
|
|
15
|
+
static model(rawEntities = [], architecture = {}) {
|
|
16
|
+
const isMultiTenant = Boolean(architecture.database?.tenantIsolation);
|
|
17
|
+
const softDelete = Boolean(architecture.database?.softDelete);
|
|
18
|
+
|
|
19
|
+
const entities = rawEntities.map(ent => {
|
|
20
|
+
const name = ent.name;
|
|
21
|
+
const fields = [...(ent.fields || [])];
|
|
22
|
+
const fieldNames = new Set(fields.map(f => f.name));
|
|
23
|
+
|
|
24
|
+
// 1. Primary Key: Ensure id is UUID / string
|
|
25
|
+
if (!fieldNames.has('id')) {
|
|
26
|
+
fields.unshift({
|
|
27
|
+
name: 'id',
|
|
28
|
+
type: 'string',
|
|
29
|
+
isPrimaryKey: true,
|
|
30
|
+
required: true,
|
|
31
|
+
default: 'cuid()'
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
const idField = fields.find(f => f.name === 'id');
|
|
35
|
+
idField.isPrimaryKey = true;
|
|
36
|
+
idField.default = 'cuid()';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 2. Tenant Isolation Field
|
|
40
|
+
if (isMultiTenant && !['Organization', 'Tenant', 'User'].includes(name)) {
|
|
41
|
+
if (!fieldNames.has('organizationId')) {
|
|
42
|
+
fields.push({
|
|
43
|
+
name: 'organizationId',
|
|
44
|
+
type: 'string',
|
|
45
|
+
required: true,
|
|
46
|
+
isIndexed: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 3. Timestamps & Soft Deletion
|
|
52
|
+
if (!fieldNames.has('createdAt')) {
|
|
53
|
+
fields.push({ name: 'createdAt', type: 'datetime', required: true, default: 'now()' });
|
|
54
|
+
}
|
|
55
|
+
if (!fieldNames.has('updatedAt')) {
|
|
56
|
+
fields.push({ name: 'updatedAt', type: 'datetime', required: true, isUpdatedAt: true });
|
|
57
|
+
}
|
|
58
|
+
if (softDelete && !fieldNames.has('deletedAt')) {
|
|
59
|
+
fields.push({ name: 'deletedAt', type: 'datetime', required: false });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 4. Identify unique fields
|
|
63
|
+
const uniqueFields = [];
|
|
64
|
+
if (name.toLowerCase() === 'user' || fieldNames.has('email')) {
|
|
65
|
+
uniqueFields.push('email');
|
|
66
|
+
}
|
|
67
|
+
if (fieldNames.has('slug')) {
|
|
68
|
+
uniqueFields.push('slug');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 5. Inferred foreign keys
|
|
72
|
+
const relationships = (ent.relationships || []).map(rel => {
|
|
73
|
+
const target = rel.targetEntity || rel.target || 'Item';
|
|
74
|
+
const type = rel.type || 'hasMany';
|
|
75
|
+
const foreignKey = rel.foreignKey || (type === 'belongsTo' ? `${target.toLowerCase()}Id` : undefined);
|
|
76
|
+
return {
|
|
77
|
+
type,
|
|
78
|
+
targetEntity: target,
|
|
79
|
+
foreignKey,
|
|
80
|
+
cascade: 'Cascade'
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...ent,
|
|
86
|
+
fields,
|
|
87
|
+
uniqueFields,
|
|
88
|
+
relationships
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// If multi-tenant and Organization entity is missing, synthesize Organization
|
|
93
|
+
if (isMultiTenant && !entities.some(e => e.name === 'Organization')) {
|
|
94
|
+
entities.unshift({
|
|
95
|
+
id: 'entity-organization',
|
|
96
|
+
name: 'Organization',
|
|
97
|
+
title: 'Organization',
|
|
98
|
+
plural: 'Organizations',
|
|
99
|
+
description: 'Multi-tenant organization account boundary',
|
|
100
|
+
fields: [
|
|
101
|
+
{ name: 'id', type: 'string', isPrimaryKey: true, required: true, default: 'cuid()' },
|
|
102
|
+
{ name: 'name', type: 'string', required: true },
|
|
103
|
+
{ name: 'slug', type: 'string', required: true, unique: true },
|
|
104
|
+
{ name: 'createdAt', type: 'datetime', required: true, default: 'now()' },
|
|
105
|
+
{ name: 'updatedAt', type: 'datetime', required: true, isUpdatedAt: true }
|
|
106
|
+
],
|
|
107
|
+
uniqueFields: ['slug'],
|
|
108
|
+
relationships: []
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return entities;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Dynamic Database Index Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Inspects entity relationships, expected query filters, sorting, and tenant boundaries
|
|
5
|
+
* to synthesize optimal single, compound, and covering database indexes.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class IndexAnalyzer {
|
|
9
|
+
/**
|
|
10
|
+
* Derive index definitions for entities
|
|
11
|
+
* @param {Array<object>} entities
|
|
12
|
+
* @param {object} architecture
|
|
13
|
+
* @returns {object} Map of entityName -> Array<IndexDefinition>
|
|
14
|
+
*/
|
|
15
|
+
static deriveIndexes(entities = [], architecture = {}) {
|
|
16
|
+
const isMultiTenant = Boolean(architecture.database?.tenantIsolation);
|
|
17
|
+
const indexMap = {};
|
|
18
|
+
|
|
19
|
+
entities.forEach(ent => {
|
|
20
|
+
const indexes = [];
|
|
21
|
+
const fields = ent.fields || [];
|
|
22
|
+
const fieldNames = new Set(fields.map(f => f.name));
|
|
23
|
+
|
|
24
|
+
// 1. Foreign Keys MUST be indexed to prevent table scans on JOINs
|
|
25
|
+
fields.forEach(f => {
|
|
26
|
+
if (f.name.endsWith('Id') && f.name !== 'id') {
|
|
27
|
+
indexes.push({
|
|
28
|
+
name: `idx_${ent.name.toLowerCase()}_${f.name.toLowerCase()}`,
|
|
29
|
+
fields: [f.name],
|
|
30
|
+
type: 'btree',
|
|
31
|
+
rationale: `Foreign key index for ${f.name} lookups and joins`
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 2. Multi-Tenant Compound Indexes: (organizationId, createdAt DESC) or (organizationId, status)
|
|
37
|
+
if (isMultiTenant && fieldNames.has('organizationId')) {
|
|
38
|
+
if (fieldNames.has('createdAt')) {
|
|
39
|
+
indexes.push({
|
|
40
|
+
name: `idx_${ent.name.toLowerCase()}_org_created`,
|
|
41
|
+
fields: ['organizationId', 'createdAt'],
|
|
42
|
+
type: 'btree',
|
|
43
|
+
rationale: 'Optimizes tenant-scoped temporal ordering and cursor pagination'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (fieldNames.has('status')) {
|
|
47
|
+
indexes.push({
|
|
48
|
+
name: `idx_${ent.name.toLowerCase()}_org_status`,
|
|
49
|
+
fields: ['organizationId', 'status'],
|
|
50
|
+
type: 'btree',
|
|
51
|
+
rationale: 'Optimizes tenant-scoped status filtering'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// Single-tenant temporal index
|
|
56
|
+
if (fieldNames.has('status') && fieldNames.has('createdAt')) {
|
|
57
|
+
indexes.push({
|
|
58
|
+
name: `idx_${ent.name.toLowerCase()}_status_created`,
|
|
59
|
+
fields: ['status', 'createdAt'],
|
|
60
|
+
type: 'btree',
|
|
61
|
+
rationale: 'Optimizes filtering by status with created_at sorting'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 3. Search / Slug Indexes
|
|
67
|
+
if (fieldNames.has('slug') && !indexes.some(i => i.fields.includes('slug'))) {
|
|
68
|
+
indexes.push({
|
|
69
|
+
name: `idx_${ent.name.toLowerCase()}_slug`,
|
|
70
|
+
fields: ['slug'],
|
|
71
|
+
type: 'btree',
|
|
72
|
+
unique: true,
|
|
73
|
+
rationale: 'Fast unique lookup by URL slug'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Deduplicate indexes by field sequence
|
|
78
|
+
const seen = new Set();
|
|
79
|
+
const uniqueIndexes = [];
|
|
80
|
+
indexes.forEach(idx => {
|
|
81
|
+
const key = idx.fields.join(',');
|
|
82
|
+
if (!seen.has(key)) {
|
|
83
|
+
seen.add(key);
|
|
84
|
+
uniqueIndexes.push(idx);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
indexMap[ent.name] = uniqueIndexes;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return indexMap;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Query Analyzer Engine
|
|
3
|
+
*
|
|
4
|
+
* Inspects access patterns across entity relations to detect N+1 queries,
|
|
5
|
+
* unnecessary full table scans, and advises on eager loading / select projections.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class QueryAnalyzer {
|
|
9
|
+
/**
|
|
10
|
+
* Analyze entity relations and generate query optimization strategies
|
|
11
|
+
* @param {Array<object>} entities
|
|
12
|
+
* @returns {object} Query Optimization Strategies
|
|
13
|
+
*/
|
|
14
|
+
static analyzeQueries(entities = []) {
|
|
15
|
+
const strategies = {};
|
|
16
|
+
|
|
17
|
+
entities.forEach(ent => {
|
|
18
|
+
const relations = ent.relationships || [];
|
|
19
|
+
const includeClauses = {};
|
|
20
|
+
const warnings = [];
|
|
21
|
+
|
|
22
|
+
relations.forEach(rel => {
|
|
23
|
+
const target = rel.targetEntity;
|
|
24
|
+
if (rel.type === 'belongsTo') {
|
|
25
|
+
includeClauses[target.toLowerCase()] = true;
|
|
26
|
+
} else if (rel.type === 'hasMany') {
|
|
27
|
+
warnings.push(`Potential N+1 query when listing ${ent.name} and traversing ${target}. Use explicit 'include' or DataLoader.`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
strategies[ent.name] = {
|
|
32
|
+
defaultSelect: ent.fields.map(f => f.name),
|
|
33
|
+
safeInclude: includeClauses,
|
|
34
|
+
warnings,
|
|
35
|
+
batchingRecommended: relations.some(r => r.type === 'hasMany')
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return strategies;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Database Schema Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates complete, production-grade Prisma schemas (prisma/schema.prisma) and SQL DDL
|
|
5
|
+
* with primary keys, foreign key cascades, unique constraints, and query-derived composite indexes.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { IndexAnalyzer } from './index-analyzer.js';
|
|
9
|
+
|
|
10
|
+
export class SchemaGenerator {
|
|
11
|
+
/**
|
|
12
|
+
* Generate complete Prisma schema file
|
|
13
|
+
* @param {Array<object>} entities
|
|
14
|
+
* @param {object} architecture
|
|
15
|
+
* @returns {string} Prisma Schema content
|
|
16
|
+
*/
|
|
17
|
+
static generatePrismaSchema(entities = [], architecture = {}) {
|
|
18
|
+
const dbType = architecture.database?.type === 'postgresql' ? 'postgresql' : 'sqlite';
|
|
19
|
+
const indexMap = IndexAnalyzer.deriveIndexes(entities, architecture);
|
|
20
|
+
|
|
21
|
+
let schema = `// Auto-generated by Pixel Crew Universal Backend Engineering Engine
|
|
22
|
+
// Architecture: ${architecture.style || 'modular-monolith'}
|
|
23
|
+
// Engine: ${dbType.toUpperCase()}
|
|
24
|
+
|
|
25
|
+
generator client {
|
|
26
|
+
provider = "prisma-client-js"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
datasource db {
|
|
30
|
+
provider = "${dbType}"
|
|
31
|
+
url = env("DATABASE_URL")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
entities.forEach(ent => {
|
|
37
|
+
schema += `model ${ent.name} {\n`;
|
|
38
|
+
const fields = ent.fields || [];
|
|
39
|
+
|
|
40
|
+
// 1. Render Fields
|
|
41
|
+
fields.forEach(f => {
|
|
42
|
+
let prismaType = 'String';
|
|
43
|
+
if (f.type === 'number') prismaType = 'Int';
|
|
44
|
+
else if (f.type === 'float') prismaType = 'Float';
|
|
45
|
+
else if (f.type === 'boolean') prismaType = 'Boolean';
|
|
46
|
+
else if (f.type === 'datetime') prismaType = 'DateTime';
|
|
47
|
+
else if (f.type === 'json') prismaType = 'Json';
|
|
48
|
+
|
|
49
|
+
let line = ` ${f.name.padEnd(16)} ${prismaType}${f.required ? '' : '?'}`;
|
|
50
|
+
|
|
51
|
+
if (f.isPrimaryKey) {
|
|
52
|
+
line += ` @id @default(cuid())`;
|
|
53
|
+
} else if (f.default === 'now()') {
|
|
54
|
+
line += ` @default(now())`;
|
|
55
|
+
} else if (f.isUpdatedAt) {
|
|
56
|
+
line += ` @updatedAt`;
|
|
57
|
+
} else if (f.unique || (ent.uniqueFields && ent.uniqueFields.includes(f.name))) {
|
|
58
|
+
line += ` @unique`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
schema += `${line}\n`;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// 2. Render Relationships
|
|
65
|
+
const relationships = ent.relationships || [];
|
|
66
|
+
relationships.forEach(rel => {
|
|
67
|
+
const target = rel.targetEntity;
|
|
68
|
+
if (rel.type === 'belongsTo') {
|
|
69
|
+
const fk = rel.foreignKey || `${target.toLowerCase()}Id`;
|
|
70
|
+
schema += ` ${target.toLowerCase().padEnd(16)} ${target} @relation(fields: [${fk}], references: [id], onDelete: Cascade)\n`;
|
|
71
|
+
} else if (rel.type === 'hasMany') {
|
|
72
|
+
schema += ` ${(rel.name || `${target.toLowerCase()}s`).padEnd(16)} ${target}[]\n`;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// 3. Render Inferred Indexes (Compound & Single)
|
|
77
|
+
const indexes = indexMap[ent.name] || [];
|
|
78
|
+
const nonUniqueIndexes = indexes.filter(idx => !idx.unique && !(idx.fields.length === 1 && idx.fields[0] === 'id'));
|
|
79
|
+
|
|
80
|
+
if (nonUniqueIndexes.length > 0) {
|
|
81
|
+
schema += `\n`;
|
|
82
|
+
nonUniqueIndexes.forEach(idx => {
|
|
83
|
+
schema += ` @@index([${idx.fields.join(', ')}])\n`;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
schema += `}\n\n`;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return schema;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Transaction Boundary Analyzer
|
|
3
|
+
*
|
|
4
|
+
* Identifies multi-entity mutating workflows that require atomic transaction guarantees ($transaction),
|
|
5
|
+
* rollback handling, and concurrency locks.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class TransactionAnalyzer {
|
|
9
|
+
/**
|
|
10
|
+
* Determine transaction boundaries across workflows
|
|
11
|
+
* @param {Array<object>} workflows
|
|
12
|
+
* @param {Array<object>} entities
|
|
13
|
+
* @returns {Array<object>} Transaction Boundaries
|
|
14
|
+
*/
|
|
15
|
+
static identifyBoundaries(workflows = [], entities = []) {
|
|
16
|
+
const boundaries = [];
|
|
17
|
+
|
|
18
|
+
workflows.forEach(wf => {
|
|
19
|
+
const name = wf.name || 'Workflow';
|
|
20
|
+
const isTransactional = /order|payment|transfer|booking|reserve|checkout|register|create|delete/i.test(name);
|
|
21
|
+
|
|
22
|
+
if (isTransactional) {
|
|
23
|
+
boundaries.push({
|
|
24
|
+
workflowId: wf.id,
|
|
25
|
+
workflowName: name,
|
|
26
|
+
requiresTransaction: true,
|
|
27
|
+
isolationLevel: 'ReadCommitted',
|
|
28
|
+
timeoutMs: 5000,
|
|
29
|
+
steps: wf.steps || ['Validate inputs', 'Mutate primary entity', 'Update related records', 'Audit log'],
|
|
30
|
+
rollbackStrategy: 'Automatic ORM rollback on unhandled error or constraint violation'
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (boundaries.length === 0) {
|
|
36
|
+
boundaries.push({
|
|
37
|
+
workflowId: 'wf-default-atomic',
|
|
38
|
+
workflowName: 'Default Atomic Mutation',
|
|
39
|
+
requiresTransaction: true,
|
|
40
|
+
isolationLevel: 'ReadCommitted',
|
|
41
|
+
timeoutMs: 5000,
|
|
42
|
+
steps: ['Input validation', 'Database write', 'Event emission'],
|
|
43
|
+
rollbackStrategy: 'Rollback on error'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return boundaries;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PIXEL CREW — Universal Backend Engineering Engine
|
|
3
|
+
*
|
|
4
|
+
* Public API Surface:
|
|
5
|
+
* - Requirement & Complexity Analysis
|
|
6
|
+
* - Architecture Reasoning & Technology Selection
|
|
7
|
+
* - Data Modeling, Schema Generation & Index Optimization
|
|
8
|
+
* - API Design & Route Generation (RFC 7807, Zod)
|
|
9
|
+
* - Security Engine & Threat Modeling
|
|
10
|
+
* - Performance, Resilience & Observability Suites
|
|
11
|
+
* - Backend Synthesizer & Quality Validator
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export { RequirementAnalyzer } from './analyzer/requirement-analyzer.js';
|
|
15
|
+
export { ComplexityAnalyzer } from './analyzer/complexity-analyzer.js';
|
|
16
|
+
export { ThreatAnalyzer } from './analyzer/threat-analyzer.js';
|
|
17
|
+
|
|
18
|
+
export { ArchitectureReasoner } from './architecture/architecture-reasoner.js';
|
|
19
|
+
export { ArchitectureSelector } from './architecture/architecture-selector.js';
|
|
20
|
+
export { TradeoffAnalyzer } from './architecture/tradeoff-analyzer.js';
|
|
21
|
+
export { ADRGenerator } from './architecture/adr-generator.js';
|
|
22
|
+
|
|
23
|
+
export { DataModeler } from './data/data-modeler.js';
|
|
24
|
+
export { SchemaGenerator as PrismaSchemaGenerator } from './data/schema-generator.js';
|
|
25
|
+
export { IndexAnalyzer } from './data/index-analyzer.js';
|
|
26
|
+
export { QueryAnalyzer } from './data/query-analyzer.js';
|
|
27
|
+
export { TransactionAnalyzer } from './data/transaction-analyzer.js';
|
|
28
|
+
|
|
29
|
+
export { APIDesigner } from './api/api-designer.js';
|
|
30
|
+
export { RouteGenerator } from './api/route-generator.js';
|
|
31
|
+
export { SchemaGenerator as ZodSchemaGenerator } from './api/schema-generator.js';
|
|
32
|
+
export { ErrorContract } from './api/error-contract.js';
|
|
33
|
+
|
|
34
|
+
export { SecurityEngine } from './security/security-engine.js';
|
|
35
|
+
export { AuthSelector } from './security/auth-selector.js';
|
|
36
|
+
export { AuthorizationEngine } from './security/authorization-engine.js';
|
|
37
|
+
export { ThreatModelDocumenter } from './security/threat-model.js';
|
|
38
|
+
export { PolicyEngine } from './security/policy-engine.js';
|
|
39
|
+
export { SecretAnalyzer } from './security/secret-analyzer.js';
|
|
40
|
+
|
|
41
|
+
export { PerformanceEngine } from './performance/performance-engine.js';
|
|
42
|
+
export { CacheAnalyzer } from './performance/cache-analyzer.js';
|
|
43
|
+
export { QueryOptimizer } from './performance/query-optimizer.js';
|
|
44
|
+
export { ConcurrencyAnalyzer } from './performance/concurrency-analyzer.js';
|
|
45
|
+
|
|
46
|
+
export { ResilienceEngine } from './reliability/resilience-engine.js';
|
|
47
|
+
export { RetryAnalyzer } from './reliability/retry-analyzer.js';
|
|
48
|
+
export { IdempotencyEngine } from './reliability/idempotency-engine.js';
|
|
49
|
+
export { FailureAnalyzer } from './reliability/failure-analyzer.js';
|
|
50
|
+
|
|
51
|
+
export { LoggingEngine } from './observability/logging-engine.js';
|
|
52
|
+
export { MetricsEngine } from './observability/metrics-engine.js';
|
|
53
|
+
export { TracingEngine } from './observability/tracing-engine.js';
|
|
54
|
+
|
|
55
|
+
export { PatternRegistry } from './patterns/pattern-registry.js';
|
|
56
|
+
export { PatternSelector } from './patterns/pattern-selector.js';
|
|
57
|
+
export { TradeoffEngine } from './patterns/tradeoff-engine.js';
|
|
58
|
+
|
|
59
|
+
export { BackendSynthesizer } from './synthesis/backend-synthesizer.js';
|
|
60
|
+
export { ModuleSynthesizer } from './synthesis/module-synthesizer.js';
|
|
61
|
+
export { InfrastructureSynthesizer } from './synthesis/infrastructure-synthesizer.js';
|
|
62
|
+
|
|
63
|
+
export { ArchitectureValidator } from './validation/architecture-validator.js';
|
|
64
|
+
export { SecurityValidator } from './validation/security-validator.js';
|
|
65
|
+
export { PerformanceValidator } from './validation/performance-validator.js';
|
|
66
|
+
export { DependencyValidator } from './validation/dependency-validator.js';
|
|
67
|
+
export { BackendQualityValidator } from './validation/backend-quality-validator.js';
|