archforge-x 1.0.0
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/LICENSE +21 -0
- package/README.md +90 -0
- package/bin/archforge.js +3 -0
- package/dist/analyzers/dependency.js +184 -0
- package/dist/cli/init.js +74 -0
- package/dist/cli/interactive.js +119 -0
- package/dist/core/architecture/model.js +3 -0
- package/dist/core/architecture/parser.js +97 -0
- package/dist/core/architecture/schema.js +32 -0
- package/dist/generators/generator.js +342 -0
- package/dist/generators/professional.js +509 -0
- package/dist/generators/templates/base.js +10 -0
- package/dist/index.js +115 -0
- package/dist/rules/engine.js +76 -0
- package/dist/sample-app/application/application.js +8 -0
- package/dist/sample-app/domain/domain.js +2 -0
- package/dist/sample-app/domain/domain.spec.js +2 -0
- package/dist/sample-app/infrastructure/infrastructure.js +8 -0
- package/dist/utils/template.js +32 -0
- package/dist/visualization/graph.js +76 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Henok
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# š”ļø ArchForge X
|
|
2
|
+
|
|
3
|
+
**Enterprise Architecture Engine** for scaffolding, analyzing, and visualizing software architecture.
|
|
4
|
+
|
|
5
|
+
ArchForge X helps development teams maintain clean, consistent, and scalable codebases by enforcing architectural boundaries and providing intelligent scaffolding.
|
|
6
|
+
|
|
7
|
+
## š Features
|
|
8
|
+
|
|
9
|
+
- **šļø Intelligent Scaffolding**: Generate project structures for TypeScript, JavaScript, Python, and Go using patterns like Clean Architecture, DDD, and Hexagonal Architecture.
|
|
10
|
+
- **š Dependency Analysis**: Detect architectural violations and circular dependencies between layers.
|
|
11
|
+
- **š Visual Graphs**: Generate high-resolution SVG dependency graphs to visualize your architecture.
|
|
12
|
+
- **š”ļø Rule Enforcement**: Define custom architectural rules in `archforge.yaml` to ensure your team follows the intended design.
|
|
13
|
+
- **⨠Interactive CLI**: A user-friendly wizard to get you started in seconds.
|
|
14
|
+
|
|
15
|
+
## š¦ Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g archforge-x
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## š ļø Usage
|
|
22
|
+
|
|
23
|
+
### 1. Initialize a Project
|
|
24
|
+
Create a new architecture configuration file:
|
|
25
|
+
```bash
|
|
26
|
+
archforge init
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Interactive Wizard (Recommended)
|
|
30
|
+
Scaffold a new project with a guided setup:
|
|
31
|
+
```bash
|
|
32
|
+
archforge interactive
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Analyze Dependencies
|
|
36
|
+
Check your project for architectural violations:
|
|
37
|
+
```bash
|
|
38
|
+
archforge analyze
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 4. Visualize Architecture
|
|
42
|
+
Generate an SVG graph of your project's layers:
|
|
43
|
+
```bash
|
|
44
|
+
archforge visualize -o architecture.svg
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 5. Deep Audit
|
|
48
|
+
Get intelligent fix suggestions based on architectural principles:
|
|
49
|
+
```bash
|
|
50
|
+
archforge audit
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## āļø Configuration (`archforge.yaml`)
|
|
54
|
+
|
|
55
|
+
Define your layers and dependency rules:
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
version: "1.0"
|
|
59
|
+
name: "My Project Architecture"
|
|
60
|
+
project:
|
|
61
|
+
name: "my-app"
|
|
62
|
+
root: "."
|
|
63
|
+
|
|
64
|
+
metadata:
|
|
65
|
+
type: "clean"
|
|
66
|
+
language: "ts"
|
|
67
|
+
framework: "express"
|
|
68
|
+
|
|
69
|
+
layers:
|
|
70
|
+
- name: "domain"
|
|
71
|
+
path: "src/domain"
|
|
72
|
+
description: "Core business logic"
|
|
73
|
+
forbiddenImports: ["infrastructure", "application"]
|
|
74
|
+
|
|
75
|
+
- name: "application"
|
|
76
|
+
path: "src/application"
|
|
77
|
+
allowedImports: ["domain"]
|
|
78
|
+
|
|
79
|
+
- name: "infrastructure"
|
|
80
|
+
path: "src/infrastructure"
|
|
81
|
+
allowedImports: ["domain", "application"]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## š¤ Contributing
|
|
85
|
+
|
|
86
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
87
|
+
|
|
88
|
+
## š License
|
|
89
|
+
|
|
90
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/bin/archforge.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.analyzeDependencies = analyzeDependencies;
|
|
7
|
+
exports.reportViolations = reportViolations;
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
// --- LANGUAGE PARSERS ---
|
|
13
|
+
const parseImportsTS = (content, filePath) => {
|
|
14
|
+
const imports = [];
|
|
15
|
+
const sourceFile = typescript_1.default.createSourceFile(filePath, content, typescript_1.default.ScriptTarget.Latest, true);
|
|
16
|
+
sourceFile.forEachChild((node) => {
|
|
17
|
+
if (typescript_1.default.isImportDeclaration(node) && node.moduleSpecifier) {
|
|
18
|
+
const importPath = node.moduleSpecifier.text;
|
|
19
|
+
imports.push(importPath);
|
|
20
|
+
}
|
|
21
|
+
if (typescript_1.default.isVariableStatement(node)) {
|
|
22
|
+
const text = node.getText();
|
|
23
|
+
const match = text.match(/require\(['"](.+)['"]\)/);
|
|
24
|
+
if (match)
|
|
25
|
+
imports.push(match[1]);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return imports;
|
|
29
|
+
};
|
|
30
|
+
const parseImportsPython = (content) => {
|
|
31
|
+
const imports = [];
|
|
32
|
+
const lines = content.split("\n");
|
|
33
|
+
for (const line of lines) {
|
|
34
|
+
const trimmed = line.trim();
|
|
35
|
+
const fromMatch = trimmed.match(/^from\s+([\w\.]+)\s+import/);
|
|
36
|
+
if (fromMatch)
|
|
37
|
+
imports.push(fromMatch[1].replace(/\./g, "/"));
|
|
38
|
+
const importMatch = trimmed.match(/^import\s+([\w\.]+)/);
|
|
39
|
+
if (importMatch)
|
|
40
|
+
imports.push(importMatch[1].replace(/\./g, "/"));
|
|
41
|
+
}
|
|
42
|
+
return imports;
|
|
43
|
+
};
|
|
44
|
+
const parseImportsGo = (content) => {
|
|
45
|
+
const imports = [];
|
|
46
|
+
const singleMatch = content.matchAll(/import\s+"(.+)"/g);
|
|
47
|
+
for (const m of singleMatch)
|
|
48
|
+
imports.push(m[1]);
|
|
49
|
+
const multiBlock = content.match(/import\s+\(([\s\S]*?)\)/);
|
|
50
|
+
if (multiBlock) {
|
|
51
|
+
const lines = multiBlock[1].split("\n");
|
|
52
|
+
for (const line of lines) {
|
|
53
|
+
const clean = line.trim().replace(/"/g, "");
|
|
54
|
+
if (clean)
|
|
55
|
+
imports.push(clean);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return imports;
|
|
59
|
+
};
|
|
60
|
+
// --- CORE ANALYZER ---
|
|
61
|
+
function analyzeDependencies(arch, options = {}) {
|
|
62
|
+
const violations = [];
|
|
63
|
+
const projectRoot = path_1.default.resolve(arch.project.root || ".");
|
|
64
|
+
function getLayerByPath(filePath) {
|
|
65
|
+
const absoluteFile = path_1.default.resolve(filePath);
|
|
66
|
+
const sortedLayers = [...arch.layers].sort((a, b) => b.path.length - a.path.length);
|
|
67
|
+
return sortedLayers.find((layer) => {
|
|
68
|
+
const layerPath = path_1.default.resolve(projectRoot, layer.path);
|
|
69
|
+
return absoluteFile.startsWith(layerPath);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function resolveImportedLayer(currentFilePath, importPath) {
|
|
73
|
+
let absoluteImportPath = "";
|
|
74
|
+
if (importPath.startsWith(".")) {
|
|
75
|
+
absoluteImportPath = path_1.default.resolve(path_1.default.dirname(currentFilePath), importPath);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// Check if the import string starts with any layer path (alias/absolute)
|
|
79
|
+
for (const layer of arch.layers) {
|
|
80
|
+
const normLayer = layer.path.replace(/\\/g, "/");
|
|
81
|
+
const normImport = importPath.replace(/\\/g, "/");
|
|
82
|
+
if (normImport.startsWith(normLayer)) {
|
|
83
|
+
return layer;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return getLayerByPath(absoluteImportPath);
|
|
89
|
+
}
|
|
90
|
+
function scanFolder(folderPath) {
|
|
91
|
+
const absoluteFolderPath = path_1.default.resolve(projectRoot, folderPath);
|
|
92
|
+
if (!fs_extra_1.default.existsSync(absoluteFolderPath))
|
|
93
|
+
return;
|
|
94
|
+
const entries = fs_extra_1.default.readdirSync(absoluteFolderPath);
|
|
95
|
+
for (const entry of entries) {
|
|
96
|
+
const fullPath = path_1.default.join(absoluteFolderPath, entry);
|
|
97
|
+
const stat = fs_extra_1.default.statSync(fullPath);
|
|
98
|
+
if (stat.isDirectory()) {
|
|
99
|
+
if (["node_modules", "__pycache__", ".git", "dist"].includes(entry))
|
|
100
|
+
continue;
|
|
101
|
+
scanFolder(fullPath);
|
|
102
|
+
}
|
|
103
|
+
else if (stat.isFile()) {
|
|
104
|
+
if (options.ignoreTests && (entry.includes(".spec") || entry.includes("_test")))
|
|
105
|
+
continue;
|
|
106
|
+
const ext = path_1.default.extname(entry);
|
|
107
|
+
if ([".ts", ".js", ".py", ".go", ".tsx", ".jsx"].includes(ext)) {
|
|
108
|
+
checkFileImports(fullPath, ext);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function checkFileImports(filePath, ext) {
|
|
114
|
+
const currentLayer = getLayerByPath(filePath);
|
|
115
|
+
if (!currentLayer)
|
|
116
|
+
return;
|
|
117
|
+
const content = fs_extra_1.default.readFileSync(filePath, "utf-8");
|
|
118
|
+
let imports = [];
|
|
119
|
+
if ([".ts", ".tsx", ".js", ".jsx"].includes(ext))
|
|
120
|
+
imports = parseImportsTS(content, filePath);
|
|
121
|
+
else if (ext === ".py")
|
|
122
|
+
imports = parseImportsPython(content);
|
|
123
|
+
else if (ext === ".go")
|
|
124
|
+
imports = parseImportsGo(content);
|
|
125
|
+
for (const importStr of imports) {
|
|
126
|
+
const importedLayer = resolveImportedLayer(filePath, importStr);
|
|
127
|
+
if (!importedLayer || importedLayer.name === currentLayer.name)
|
|
128
|
+
continue;
|
|
129
|
+
if (currentLayer.forbiddenImports?.includes(importedLayer.name)) {
|
|
130
|
+
violations.push({
|
|
131
|
+
file: path_1.default.relative(projectRoot, filePath),
|
|
132
|
+
fromLayer: currentLayer.name,
|
|
133
|
+
importedLayer: importedLayer.name,
|
|
134
|
+
importPath: importStr,
|
|
135
|
+
type: "forbidden",
|
|
136
|
+
severity: "error"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (currentLayer.allowedImports && !currentLayer.allowedImports.includes(importedLayer.name)) {
|
|
140
|
+
violations.push({
|
|
141
|
+
file: path_1.default.relative(projectRoot, filePath),
|
|
142
|
+
fromLayer: currentLayer.name,
|
|
143
|
+
importedLayer: importedLayer.name,
|
|
144
|
+
importPath: importStr,
|
|
145
|
+
type: "allowed",
|
|
146
|
+
severity: "warning"
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
arch.layers.forEach((layer) => scanFolder(layer.path));
|
|
152
|
+
return violations;
|
|
153
|
+
}
|
|
154
|
+
function reportViolations(violations, options = {}) {
|
|
155
|
+
if (violations.length === 0) {
|
|
156
|
+
console.log(chalk_1.default.green("ā
No architectural violations found. Architecture is clean."));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
console.log(chalk_1.default.red.bold(`ā Found ${violations.length} Architecture Violations:`));
|
|
160
|
+
const grouped = violations.reduce((acc, v) => {
|
|
161
|
+
const key = `${v.fromLayer} -> ${v.importedLayer}`;
|
|
162
|
+
if (!acc[key])
|
|
163
|
+
acc[key] = [];
|
|
164
|
+
acc[key].push(v);
|
|
165
|
+
return acc;
|
|
166
|
+
}, {});
|
|
167
|
+
Object.keys(grouped).forEach(key => {
|
|
168
|
+
const group = grouped[key];
|
|
169
|
+
const v = group[0];
|
|
170
|
+
const color = v.severity === "error" ? chalk_1.default.red : chalk_1.default.yellow;
|
|
171
|
+
console.log(color.bold(`\n[${v.type.toUpperCase()}] ${v.fromLayer} depends on ${v.importedLayer}`));
|
|
172
|
+
group.forEach(item => {
|
|
173
|
+
console.log(chalk_1.default.gray(` - ${item.file} imports '${item.importPath}'`));
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
if (options.outputFile) {
|
|
177
|
+
const absoluteOutput = path_1.default.resolve(options.outputFile);
|
|
178
|
+
const ext = path_1.default.extname(absoluteOutput).toLowerCase();
|
|
179
|
+
const content = ext === ".json" ? JSON.stringify(violations, null, 2) :
|
|
180
|
+
violations.map(v => `[${v.severity.toUpperCase()}] ${v.fromLayer} -> ${v.importedLayer} in ${v.file}`).join("\n");
|
|
181
|
+
fs_extra_1.default.writeFileSync(absoluteOutput, content, "utf-8");
|
|
182
|
+
console.log(chalk_1.default.blueBright(`\nš Detailed report saved to ${absoluteOutput}`));
|
|
183
|
+
}
|
|
184
|
+
}
|
package/dist/cli/init.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.initCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
exports.initCommand = new commander_1.Command("init")
|
|
12
|
+
.description("Initialize a new architecture configuration file (archforge.yaml)")
|
|
13
|
+
.action(() => {
|
|
14
|
+
const configPath = path_1.default.resolve(process.cwd(), "archforge.yaml");
|
|
15
|
+
// 1. Safety Check: Don't overwrite existing config
|
|
16
|
+
if (fs_1.default.existsSync(configPath)) {
|
|
17
|
+
console.log(chalk_1.default.yellow("ā ļø Configuration file 'archforge.yaml' already exists."));
|
|
18
|
+
console.log(chalk_1.default.gray(` Path: ${configPath}`));
|
|
19
|
+
console.log(chalk_1.default.blue(" Run 'archforge analyze' or 'archforge generate' to use it."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const template = `
|
|
23
|
+
version: "1.0"
|
|
24
|
+
name: "Enterprise Architecture Config"
|
|
25
|
+
project:
|
|
26
|
+
name: "my-awesome-project"
|
|
27
|
+
root: "."
|
|
28
|
+
|
|
29
|
+
metadata:
|
|
30
|
+
type: "clean" # Options: clean, ddd, hexagonal, layered
|
|
31
|
+
language: "ts" # Options: ts, js, py, go
|
|
32
|
+
framework: "nestjs" # Options: nestjs, express, django, flask, gin
|
|
33
|
+
version: "1.0.0"
|
|
34
|
+
modules: # Optional modules to scaffold
|
|
35
|
+
- "auth"
|
|
36
|
+
- "docker"
|
|
37
|
+
|
|
38
|
+
# Define your architecture layers and dependency rules here
|
|
39
|
+
layers:
|
|
40
|
+
- name: "domain"
|
|
41
|
+
path: "src/domain"
|
|
42
|
+
description: "Core business logic and entities (Enterprise Rules)"
|
|
43
|
+
strict: true
|
|
44
|
+
forbiddenImports: ["infrastructure", "interface", "application"]
|
|
45
|
+
|
|
46
|
+
- name: "application"
|
|
47
|
+
path: "src/application"
|
|
48
|
+
description: "Use cases and application logic"
|
|
49
|
+
allowedImports: ["domain"]
|
|
50
|
+
|
|
51
|
+
- name: "infrastructure"
|
|
52
|
+
path: "src/infrastructure"
|
|
53
|
+
description: "External tools, databases, and third-party services"
|
|
54
|
+
allowedImports: ["domain", "application"]
|
|
55
|
+
|
|
56
|
+
- name: "interface"
|
|
57
|
+
path: "src/interface"
|
|
58
|
+
description: "Controllers, API endpoints, and Presenters"
|
|
59
|
+
allowedImports: ["application"]
|
|
60
|
+
`.trim();
|
|
61
|
+
// 3. Write the file
|
|
62
|
+
try {
|
|
63
|
+
fs_1.default.writeFileSync(configPath, template, "utf-8");
|
|
64
|
+
console.log(chalk_1.default.green.bold("ā
Successfully initialized 'archforge.yaml'"));
|
|
65
|
+
console.log(chalk_1.default.white(" You can now customize the layers in the file."));
|
|
66
|
+
console.log(chalk_1.default.gray("\nNext steps:"));
|
|
67
|
+
console.log(chalk_1.default.cyan(" 1. archforge generate"));
|
|
68
|
+
console.log(chalk_1.default.cyan(" 2. archforge analyze"));
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error(chalk_1.default.red("ā Failed to create configuration file:"), err.message);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.interactiveCLI = interactiveCLI;
|
|
7
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const generator_1 = require("../generators/generator");
|
|
10
|
+
async function interactiveCLI() {
|
|
11
|
+
console.clear();
|
|
12
|
+
console.log(chalk_1.default.blue.bold("š Welcome to ArchForge X Interactive CLI"));
|
|
13
|
+
console.log(chalk_1.default.gray("-----------------------------------------"));
|
|
14
|
+
const langResponse = await (0, prompts_1.default)({
|
|
15
|
+
type: "select",
|
|
16
|
+
name: "language",
|
|
17
|
+
message: "Select programming language:",
|
|
18
|
+
choices: [
|
|
19
|
+
{ title: "TypeScript (Recommended)", value: "ts" },
|
|
20
|
+
{ title: "JavaScript", value: "js" },
|
|
21
|
+
{ title: "Python", value: "py" },
|
|
22
|
+
{ title: "Go", value: "go" },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
const frameworkResponse = await (0, prompts_1.default)({
|
|
26
|
+
type: "select",
|
|
27
|
+
name: "framework",
|
|
28
|
+
message: "Select framework:",
|
|
29
|
+
choices: langResponse.language === "ts" || langResponse.language === "js"
|
|
30
|
+
? [
|
|
31
|
+
{ title: "NestJS", value: "nestjs" },
|
|
32
|
+
{ title: "Express", value: "express" },
|
|
33
|
+
]
|
|
34
|
+
: langResponse.language === "py"
|
|
35
|
+
? [
|
|
36
|
+
{ title: "Django", value: "django" },
|
|
37
|
+
{ title: "Flask", value: "flask" },
|
|
38
|
+
]
|
|
39
|
+
: [
|
|
40
|
+
{ title: "Gin", value: "gin" },
|
|
41
|
+
{ title: "Standard Lib", value: "go" },
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
const archResponse = await (0, prompts_1.default)({
|
|
45
|
+
type: "select",
|
|
46
|
+
name: "architecture",
|
|
47
|
+
message: "Select architecture style:",
|
|
48
|
+
choices: [
|
|
49
|
+
{ title: "Clean Architecture (Recommended)", value: "clean" },
|
|
50
|
+
{ title: "Domain Driven Design", value: "ddd" },
|
|
51
|
+
{ title: "Layered Architecture", value: "layered" },
|
|
52
|
+
{ title: "Hexagonal Architecture", value: "hexagonal" },
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
const modulesResponse = await (0, prompts_1.default)({
|
|
56
|
+
type: "multiselect",
|
|
57
|
+
name: "modules",
|
|
58
|
+
message: "Select optional modules:",
|
|
59
|
+
choices: [
|
|
60
|
+
{ title: "Authentication (JWT)", value: "auth" },
|
|
61
|
+
{ title: "Database (ORM setup)", value: "db" },
|
|
62
|
+
{ title: "Caching (Redis)", value: "cache" },
|
|
63
|
+
{ title: "Docker Support", value: "docker" },
|
|
64
|
+
{ title: "CI/CD (GitHub Actions)", value: "ci" },
|
|
65
|
+
],
|
|
66
|
+
hint: "- Space to select, Enter to confirm",
|
|
67
|
+
});
|
|
68
|
+
const projectNameResp = await (0, prompts_1.default)({
|
|
69
|
+
type: "text",
|
|
70
|
+
name: "projectName",
|
|
71
|
+
message: "Enter project name:",
|
|
72
|
+
initial: "my-app",
|
|
73
|
+
});
|
|
74
|
+
console.log(chalk_1.default.yellow("\nš§ Generating project..."));
|
|
75
|
+
const options = {
|
|
76
|
+
mode: 'professional',
|
|
77
|
+
language: langResponse.language,
|
|
78
|
+
framework: frameworkResponse.framework,
|
|
79
|
+
architecture: archResponse.architecture,
|
|
80
|
+
modules: modulesResponse.modules,
|
|
81
|
+
projectName: projectNameResp.projectName,
|
|
82
|
+
};
|
|
83
|
+
// Create a dummy arch definition for the generator
|
|
84
|
+
const dummyArch = {
|
|
85
|
+
version: "1.0",
|
|
86
|
+
name: "Interactive Project",
|
|
87
|
+
project: {
|
|
88
|
+
name: projectNameResp.projectName,
|
|
89
|
+
root: "."
|
|
90
|
+
},
|
|
91
|
+
metadata: {
|
|
92
|
+
type: archResponse.architecture,
|
|
93
|
+
language: langResponse.language,
|
|
94
|
+
framework: frameworkResponse.framework,
|
|
95
|
+
modules: modulesResponse.modules
|
|
96
|
+
},
|
|
97
|
+
layers: []
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
await (0, generator_1.generateProject)(dummyArch, options);
|
|
101
|
+
console.log(chalk_1.default.blue(`\nš Next steps:`));
|
|
102
|
+
console.log(` cd ${options.projectName}`);
|
|
103
|
+
if (options.language === 'ts' || options.language === 'js') {
|
|
104
|
+
console.log(` npm install`);
|
|
105
|
+
console.log(` npm run start:dev`);
|
|
106
|
+
}
|
|
107
|
+
else if (options.language === 'py') {
|
|
108
|
+
console.log(` pip install -r requirements.txt`);
|
|
109
|
+
console.log(` python run.py`);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.log(` go mod tidy`);
|
|
113
|
+
console.log(` go run cmd/server/main.go`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error(chalk_1.default.red("\nā Error generating project:"), error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadArchitecture = loadArchitecture;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const schema_1 = require("./schema");
|
|
13
|
+
const template_1 = require("../../utils/template");
|
|
14
|
+
// --- HELPERS ---
|
|
15
|
+
/**
|
|
16
|
+
* Recursively merges two architecture definitions.
|
|
17
|
+
* Layers are merged by name: Child overrides Parent.
|
|
18
|
+
*/
|
|
19
|
+
function mergeArchitectures(base, child) {
|
|
20
|
+
const layerMap = new Map();
|
|
21
|
+
// Add base layers
|
|
22
|
+
base.layers.forEach((l) => layerMap.set(l.name, l));
|
|
23
|
+
// Override/Add child layers
|
|
24
|
+
child.layers.forEach((l) => {
|
|
25
|
+
if (layerMap.has(l.name)) {
|
|
26
|
+
const baseLayer = layerMap.get(l.name);
|
|
27
|
+
layerMap.set(l.name, {
|
|
28
|
+
...baseLayer,
|
|
29
|
+
...l,
|
|
30
|
+
allowedImports: l.allowedImports ?? baseLayer.allowedImports,
|
|
31
|
+
forbiddenImports: l.forbiddenImports ?? baseLayer.forbiddenImports,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
layerMap.set(l.name, l);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
...base,
|
|
40
|
+
...child,
|
|
41
|
+
project: { ...base.project, ...child.project },
|
|
42
|
+
metadata: { ...base.metadata, ...child.metadata },
|
|
43
|
+
layers: Array.from(layerMap.values()),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// --- MAIN FUNCTIONS ---
|
|
47
|
+
function loadArchitecture(filePath) {
|
|
48
|
+
const absolutePath = path_1.default.resolve(filePath);
|
|
49
|
+
if (!fs_1.default.existsSync(absolutePath)) {
|
|
50
|
+
throw new Error(`Architecture configuration file not found: ${absolutePath}`);
|
|
51
|
+
}
|
|
52
|
+
// 1. Read & Env Substitution
|
|
53
|
+
let rawContent = fs_1.default.readFileSync(absolutePath, "utf-8");
|
|
54
|
+
rawContent = (0, template_1.substituteEnvVars)(rawContent);
|
|
55
|
+
// 2. Parse YAML
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = yaml_1.default.parse(rawContent);
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
throw new Error(`YAML syntax error in ${filePath}: ${e.message}`);
|
|
62
|
+
}
|
|
63
|
+
// 3. Handle Inheritance (Extends)
|
|
64
|
+
if (parsed.extends) {
|
|
65
|
+
const parentPath = path_1.default.resolve(path_1.default.dirname(absolutePath), parsed.extends);
|
|
66
|
+
console.log(chalk_1.default.gray(` ā³ Extending configuration from: ${parsed.extends}`));
|
|
67
|
+
const parentArch = loadArchitecture(parentPath);
|
|
68
|
+
const { extends: _, ...childConfig } = parsed;
|
|
69
|
+
parsed = mergeArchitectures(parentArch, childConfig);
|
|
70
|
+
}
|
|
71
|
+
// 4. Validate Schema
|
|
72
|
+
try {
|
|
73
|
+
const validated = schema_1.architectureSchema.parse(parsed);
|
|
74
|
+
return processArchitecturePlaceholders(validated);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err instanceof zod_1.z.ZodError) {
|
|
78
|
+
const issues = err.issues.map(i => ` - ${i.path.join('.')}: ${i.message}`).join('\n');
|
|
79
|
+
throw new Error(`Invalid architecture configuration:\n${issues}`);
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function processArchitecturePlaceholders(arch) {
|
|
85
|
+
const placeholders = {
|
|
86
|
+
projectName: arch.project.name || "unnamed-project",
|
|
87
|
+
root: arch.project.root || ".",
|
|
88
|
+
};
|
|
89
|
+
const newLayers = arch.layers.map((layer) => ({
|
|
90
|
+
...layer,
|
|
91
|
+
path: (0, template_1.replacePlaceholders)(layer.path, placeholders),
|
|
92
|
+
}));
|
|
93
|
+
return {
|
|
94
|
+
...arch,
|
|
95
|
+
layers: newLayers,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.architectureSchema = exports.metadataSchema = exports.layerSchema = void 0;
|
|
4
|
+
// src/core/architecture/schema.ts
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.layerSchema = zod_1.z.object({
|
|
7
|
+
name: zod_1.z.string().min(1),
|
|
8
|
+
path: zod_1.z.string().min(1),
|
|
9
|
+
description: zod_1.z.string().optional(),
|
|
10
|
+
allowedImports: zod_1.z.array(zod_1.z.string()).optional(),
|
|
11
|
+
forbiddenImports: zod_1.z.array(zod_1.z.string()).optional(),
|
|
12
|
+
strict: zod_1.z.boolean().optional(),
|
|
13
|
+
});
|
|
14
|
+
exports.metadataSchema = zod_1.z.object({
|
|
15
|
+
type: zod_1.z.enum(['clean', 'ddd', 'layered', 'hexagonal', 'microservices']),
|
|
16
|
+
language: zod_1.z.enum(['ts', 'js', 'py', 'go']),
|
|
17
|
+
framework: zod_1.z.string().optional(),
|
|
18
|
+
modules: zod_1.z.array(zod_1.z.string()).optional(),
|
|
19
|
+
version: zod_1.z.string().optional(),
|
|
20
|
+
});
|
|
21
|
+
exports.architectureSchema = zod_1.z.object({
|
|
22
|
+
version: zod_1.z.string().default("1.0"),
|
|
23
|
+
name: zod_1.z.string(),
|
|
24
|
+
extends: zod_1.z.string().optional(),
|
|
25
|
+
project: zod_1.z.object({
|
|
26
|
+
name: zod_1.z.string(),
|
|
27
|
+
root: zod_1.z.string().optional(),
|
|
28
|
+
}),
|
|
29
|
+
metadata: exports.metadataSchema,
|
|
30
|
+
layers: zod_1.z.array(exports.layerSchema),
|
|
31
|
+
strict: zod_1.z.boolean().optional(),
|
|
32
|
+
});
|