create-backlist 6.2.2 → 7.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/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "create-backlist",
3
- "version": "6.2.2",
4
- "description": "An advanced, multi-language backend generator based on frontend analysis.",
5
- "type": "commonjs",
3
+ "version": "7.0.1",
4
+ "description": "An advanced, multi-language backend generator based on frontend analysis. Smart Freemium SaaS CLI.",
5
+ "type": "module",
6
6
  "bin": {
7
7
  "create-backlist": "bin/index.js"
8
8
  },
9
9
  "files": [
10
10
  "bin",
11
- "src"
11
+ "src",
12
+ "AiModuls"
12
13
  ],
13
14
  "scripts": {
14
15
  "start": "node bin/index.js"
@@ -19,12 +20,14 @@
19
20
  "@babel/parser": "^7.22.7",
20
21
  "@babel/traverse": "^7.22.8",
21
22
  "axios": "^1.13.1",
22
- "chalk": "^4.1.2",
23
+ "chalk": "^5.3.0",
23
24
  "ejs": "^3.1.9",
24
- "execa": "^6.1.0",
25
+ "execa": "^8.0.1",
25
26
  "fs-extra": "^11.1.1",
26
27
  "glob": "^10.3.3",
27
- "inquirer": "^8.2.4",
28
+ "inquirer": "^9.2.12",
29
+ "ora": "^7.0.1",
30
+ "together-ai": "^0.39.0",
28
31
  "unzipper": "^0.12.3"
29
32
  }
30
- }
33
+ }
@@ -0,0 +1,171 @@
1
+ import Together from "together-ai";
2
+ import fs from 'fs-extra';
3
+ import path from 'node:path';
4
+
5
+ export class BacklistAIAgent {
6
+ constructor(apiKey, onThought) {
7
+ this.apiKey = apiKey;
8
+ this.onThought = onThought || (() => {});
9
+ this.together = null;
10
+ this.modelName = "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8";
11
+ }
12
+
13
+ async init() {
14
+ this.onThought('[THOUGHT] Initializing Together AI runtime...');
15
+ try {
16
+ this.together = new Together({ apiKey: this.apiKey });
17
+ this.onThought('[THOUGHT] Connected to Together AI cloud service successfully.');
18
+ } catch (err) {
19
+ throw new Error(`Together AI initialization failed: ${err.message}`);
20
+ }
21
+ }
22
+
23
+ async promptModel(systemPrompt, userPrompt) {
24
+ const response = await this.together.chat.completions.create({
25
+ messages: [
26
+ { role: "system", content: systemPrompt },
27
+ { role: "user", content: userPrompt }
28
+ ],
29
+ model: this.modelName
30
+ });
31
+ return response.choices[0].message.content;
32
+ }
33
+
34
+ // --- PASS 1: Generate Code Blocks ---
35
+ async generateBackendBlocks(astJsonData, existingSchemaContent = null) {
36
+ this.onThought(`[THOUGHT] Commencing Pass 1 Analysis on ${astJsonData.length} AST endpoints via Cloud AI...`);
37
+
38
+ let schemaDirective = `Generate a comprehensive Prisma schema (schema.prisma). Deduce many-to-many relationships and apply optimal indexing.`;
39
+ if (existingSchemaContent) {
40
+ this.onThought('[THOUGHT] Detected existing schema.prisma. Generating Schema Migration Scripts instead of full overwrite.');
41
+ schemaDirective = `An existing schema exists. Output an SQL Migration Script instead of a full schema rewrite, along with the updated prisma schema models.`;
42
+ }
43
+
44
+ const systemPrompt = `You are an expert backend architect and Domain-Driven Design (DDD) specialist.
45
+ Follow Hexagonal Architecture (Ports and Adapters) principles.
46
+ Your task is to generate intelligent implementation blocks for EJS placeholders based on the provided AST data.
47
+
48
+ 1. ${schemaDirective}
49
+ 2. Generate <%- aiSecurityConfig %>: Define complex JWT filters, rate limiting, and CORS based on the sensitivity of the endpoints.
50
+ 3. Generate <%- aiDbRelations %>: Code for Repositories connecting defined Prisma models.
51
+ 4. Generate <%- aiValidationLogic %>: Input validation middleware (Zod, Joi) tailored precisely to the data shapes extracted from the frontend.
52
+
53
+ Output ONLY JSON with the following structure:
54
+ {
55
+ "prismaSchema": "string",
56
+ "aiSecurityConfig": "string",
57
+ "aiDbRelations": "string",
58
+ "aiValidationLogic": "string"
59
+ }
60
+ Do NOT include explanations. Output raw JSON only.`;
61
+
62
+ const userPrompt = `AST Frontend Extracted Data:\n${JSON.stringify(astJsonData, null, 2)}`;
63
+
64
+ this.onThought('[THOUGHT] Prompting Together AI (Llama-4-Maverick) with Hexagonal architecture rules...');
65
+ let result = await this.promptModel(systemPrompt, userPrompt);
66
+
67
+ // Clean JSON response
68
+ try {
69
+ if (result.includes('```json')) {
70
+ result = result.split('```json')[1].split('```')[0].trim();
71
+ } else if (result.includes('```')) {
72
+ result = result.split('```')[1].split('```')[0].trim();
73
+ }
74
+ return JSON.parse(result);
75
+ } catch (e) {
76
+ this.onThought(`[WARNING] Failed to parse Pass 1 JSON. Attempting heuristic extraction...`);
77
+ return {
78
+ prismaSchema: "// Fallback schema\n" + result,
79
+ aiSecurityConfig: "// Security fallback",
80
+ aiDbRelations: "// Db Relations fallback",
81
+ aiValidationLogic: "// Validation fallback"
82
+ };
83
+ }
84
+ }
85
+
86
+ // --- PASS 2: Verification Loop (Dry-Run & DOM Sync) ---
87
+ async verifyDryRun(generatedBlocks, astJsonData) {
88
+ this.onThought('[THOUGHT] Commencing Pass 2 Verification Loop (Virtual Dry Run)...');
89
+
90
+ let issueFound = false;
91
+
92
+ // DOM Sync Level 2 (Data-type matching check)
93
+ this.onThought('[THOUGHT] Simulating frontend component tree data injection against generated validation logic...');
94
+
95
+ const systemPrompt = `You are a strict QA Engine.
96
+ Review the following generated Validation Logic and DB Relations against the Frontend AST data shapes.
97
+ Check for:
98
+ 1. Missing DB relations (e.g., User -> Post).
99
+ 2. Data-type mismatches (DOM Sync Level 2: if AST expects 'Date' string but DB expects 'DateTime', inject a transformation middleware).
100
+
101
+ Output JSON:
102
+ {
103
+ "issuesFound": boolean,
104
+ "fixedValidationLogic": "string (original or fixed)",
105
+ "fixedDbRelations": "string (original or fixed)",
106
+ "reasonings": ["string"]
107
+ }`;
108
+
109
+ const userPrompt = `Data:
110
+ Generated Validation: ${generatedBlocks.aiValidationLogic}
111
+ Generated DB Rel: ${generatedBlocks.aiDbRelations}
112
+ AST Shapes: ${JSON.stringify(astJsonData.map(e => e.schemaFields), null, 2)}`;
113
+
114
+ let result = await this.promptModel(systemPrompt, userPrompt);
115
+
116
+ try {
117
+ if (result.includes('```json')) result = result.split('```json')[1].split('```')[0].trim();
118
+ else if (result.includes('```')) result = result.split('```')[1].split('```')[0].trim();
119
+ const verified = JSON.parse(result);
120
+
121
+ if (verified.issuesFound) {
122
+ this.onThought(`[THOUGHT] Verification caught issues! Self-healing triggered...`);
123
+ verified.reasonings.forEach(r => this.onThought(`[THOUGHT] -> Fix applied: ${r}`));
124
+ return {
125
+ ...generatedBlocks,
126
+ aiValidationLogic: verified.fixedValidationLogic,
127
+ aiDbRelations: verified.fixedDbRelations
128
+ };
129
+ } else {
130
+ this.onThought('[THOUGHT] Virtual Dry Run passed perfectly. Zero data mismatches found.');
131
+ return generatedBlocks;
132
+ }
133
+ } catch (e) {
134
+ this.onThought('[WARNING] Verification parsing failed. Using Pass 1 results.');
135
+ return generatedBlocks;
136
+ }
137
+ }
138
+
139
+ // --- Autonomous Deployment Engine ---
140
+ async generateDeploymentConfig(stack, astJsonData) {
141
+ this.onThought(`[THOUGHT] Generating Autonomous Deployment workflows for [${stack}]...`);
142
+
143
+ const systemPrompt = `Generate a highly optimized docker-compose.yml and a .github/workflows/deploy.yml for a production ${stack} backend.
144
+ Include PostgreSQL, Redis, and best-practice health checks.
145
+ Output JSON:
146
+ {
147
+ "dockerCompose": "string",
148
+ "githubWorkflow": "string"
149
+ }`;
150
+
151
+ const userPrompt = `Target Stack: ${stack}\nAST Endpoints Count: ${astJsonData ? astJsonData.length : 0}`;
152
+
153
+ const res = await this.promptModel(systemPrompt, userPrompt);
154
+
155
+ try {
156
+ let clean = res;
157
+ if (clean.includes('```json')) clean = clean.split('```json')[1].split('```')[0].trim();
158
+ else if (clean.includes('```')) clean = clean.split('```')[1].split('```')[0].trim();
159
+ const parsed = JSON.parse(clean);
160
+ this.onThought('[THOUGHT] Deployment workflows synthesized successfully.');
161
+ return parsed;
162
+ } catch (e) {
163
+ return { dockerCompose: "# Fallback Config", githubWorkflow: "# Fallback Workflow" };
164
+ }
165
+ }
166
+
167
+ async dispose() {
168
+ this.onThought('[THOUGHT] Shutting down AI context...');
169
+ // Together AI doesn't hold local VRAM or contexts to dispose, doing nothing.
170
+ }
171
+ }