@adityum/studio 0.0.0-stage → 0.1.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/README.md +21 -2
- package/bin/adi-studio.js +2 -0
- package/dist/bin/adi-studio.d.ts +1 -0
- package/dist/bin/adi-studio.js +140 -0
- package/dist/engines/blueprints.d.ts +24 -0
- package/dist/engines/blueprints.js +724 -0
- package/dist/engines/codegen.d.ts +32 -0
- package/dist/engines/codegen.js +427 -0
- package/dist/engines/types.d.ts +114 -0
- package/dist/engines/types.js +1 -0
- package/dist/engines/validator.d.ts +7 -0
- package/dist/engines/validator.js +311 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/package.json +32 -4
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StudioDeployPayload, StudioGeneratedBundle, StudioNode, StudioTopology } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a CIS-hardened, multi-stage Dockerfile for a Studio compute service.
|
|
4
|
+
* Guaranteed to pass Adityum Tools Container Hardener (non-root UID 10001, pinned digest/tag, HEALTHCHECK).
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateServiceDockerfile(node: StudioNode): string;
|
|
7
|
+
/**
|
|
8
|
+
* Generates production-hardened docker-compose.yml from the visual Studio topology.
|
|
9
|
+
* Enforces internal network isolation, healthchecks, non-root users, and secret placeholder hygiene.
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateDockerCompose(topology: StudioTopology): string;
|
|
12
|
+
/**
|
|
13
|
+
* Generates declarative Adityum Blueprint Manifest (adityum.yaml)
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateAdityumManifest(topology: StudioTopology): string;
|
|
16
|
+
/**
|
|
17
|
+
* Generates hardened /etc/cloudflared/config.yml enforcing Contract #2 (403 catch-all).
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateTunnelIngress(topology: StudioTopology): string;
|
|
20
|
+
/**
|
|
21
|
+
* Generates secret-safe .env.example with Contract #3 AAD Vault guidance.
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateEnvExample(topology: StudioTopology): string;
|
|
24
|
+
/**
|
|
25
|
+
* Generates the complete declarative artifact bundle for the Studio topology.
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateStudioBundle(topology: StudioTopology): StudioGeneratedBundle;
|
|
28
|
+
/**
|
|
29
|
+
* Converts Studio compute nodes into ready-to-submit Adityum Deploy (/api/v1/projects) payloads
|
|
30
|
+
* sorted in topological dependency order.
|
|
31
|
+
*/
|
|
32
|
+
export declare function generateDeployPayloads(topology: StudioTopology, serverId: string): StudioDeployPayload[];
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { validateStudioTopology } from "./validator.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a CIS-hardened, multi-stage Dockerfile for a Studio compute service.
|
|
4
|
+
* Guaranteed to pass Adityum Tools Container Hardener (non-root UID 10001, pinned digest/tag, HEALTHCHECK).
|
|
5
|
+
*/
|
|
6
|
+
export function generateServiceDockerfile(node) {
|
|
7
|
+
const port = node.port || 3000;
|
|
8
|
+
const hcPath = node.healthcheckPath || "/api/v1/health";
|
|
9
|
+
const userDirective = node.nonRootUser ? "USER 10001:10001" : "# WARNING: nonRootUser disabled";
|
|
10
|
+
if (node.runtime === "python") {
|
|
11
|
+
return `# Generated by Adityum Studio V1.0 — Service: ${node.name}
|
|
12
|
+
# CIS Docker Benchmark & CERT-In Hardened Multi-Stage Python Image
|
|
13
|
+
FROM python:3.12.7-slim-bookworm@sha256:9c1d9ed7593f2552a4ea47362ec0d212924833d28070f2366475894f6215c25b AS builder
|
|
14
|
+
WORKDIR /app
|
|
15
|
+
COPY requirements.txt ./
|
|
16
|
+
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
|
17
|
+
|
|
18
|
+
FROM python:3.12.7-slim-bookworm@sha256:9c1d9ed7593f2552a4ea47362ec0d212924833d28070f2366475894f6215c25b AS runner
|
|
19
|
+
WORKDIR /app
|
|
20
|
+
ENV PYTHONDONTWRITEBYTECODE=1 \\
|
|
21
|
+
PYTHONUNBUFFERED=1 \\
|
|
22
|
+
PORT=${port}
|
|
23
|
+
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/* && useradd -u 10001 -m -s /usr/sbin/nologin adityum
|
|
24
|
+
COPY --from=builder /install /usr/local
|
|
25
|
+
COPY --chown=10001:10001 . .
|
|
26
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD curl -fsS http://127.0.0.1:${port}${hcPath} || exit 1
|
|
27
|
+
${userDirective}
|
|
28
|
+
EXPOSE ${port}
|
|
29
|
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "${port}"]
|
|
30
|
+
`;
|
|
31
|
+
}
|
|
32
|
+
if (node.runtime === "go") {
|
|
33
|
+
return `# Generated by Adityum Studio V1.0 — Service: ${node.name}
|
|
34
|
+
# CIS Docker Benchmark & CERT-In Hardened Static Go Image
|
|
35
|
+
FROM golang:1.23.2-bookworm@sha256:8c9183459d292a07a0f980e1cb1d0a1f78c47a38e6d3699e75c0d5a428c88f4c AS builder
|
|
36
|
+
WORKDIR /src
|
|
37
|
+
COPY go.mod go.sum ./
|
|
38
|
+
RUN go mod download
|
|
39
|
+
COPY . .
|
|
40
|
+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o /out/server ./cmd/server
|
|
41
|
+
|
|
42
|
+
FROM debian:bookworm-slim@sha256:562456a05a03812679735174880220c1322455a14712357792099018249123a1 AS runner
|
|
43
|
+
WORKDIR /app
|
|
44
|
+
ENV PORT=${port}
|
|
45
|
+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl && rm -rf /var/lib/apt/lists/* && useradd -u 10001 -m -s /usr/sbin/nologin adityum
|
|
46
|
+
COPY --from=builder --chown=10001:10001 /out/server /app/server
|
|
47
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 CMD curl -fsS http://127.0.0.1:${port}${hcPath} || exit 1
|
|
48
|
+
${userDirective}
|
|
49
|
+
EXPOSE ${port}
|
|
50
|
+
CMD ["/app/server"]
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
// Default: Next.js / Node.js hardened multi-stage build
|
|
54
|
+
const startCmd = node.runtime === "nextjs"
|
|
55
|
+
? `CMD ["node", "server.js"]`
|
|
56
|
+
: `CMD ["node", "dist/index.js"]`;
|
|
57
|
+
return `# Generated by Adityum Studio V1.0 — Service: ${node.name}
|
|
58
|
+
# CIS Docker Benchmark & CERT-In Hardened Multi-Stage Node.js Image
|
|
59
|
+
FROM node:20.18-bookworm-slim@sha256:773950efef5e4fb0604b684cb33cd96c3ab083073f1d5cd621375d315ef82b6d AS builder
|
|
60
|
+
WORKDIR /app
|
|
61
|
+
COPY package*.json ./
|
|
62
|
+
RUN npm ci
|
|
63
|
+
COPY . .
|
|
64
|
+
RUN npm run build
|
|
65
|
+
|
|
66
|
+
FROM node:20.18-bookworm-slim@sha256:773950efef5e4fb0604b684cb33cd96c3ab083073f1d5cd621375d315ef82b6d AS runner
|
|
67
|
+
WORKDIR /app
|
|
68
|
+
ENV NODE_ENV=production \\
|
|
69
|
+
PORT=${port}
|
|
70
|
+
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/* && useradd -u 10001 -m -s /usr/sbin/nologin adityum
|
|
71
|
+
COPY --from=builder --chown=10001:10001 /app ./
|
|
72
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD curl -fsS http://127.0.0.1:${port}${hcPath} || exit 1
|
|
73
|
+
${userDirective}
|
|
74
|
+
EXPOSE ${port}
|
|
75
|
+
${startCmd}
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Generates production-hardened docker-compose.yml from the visual Studio topology.
|
|
80
|
+
* Enforces internal network isolation, healthchecks, non-root users, and secret placeholder hygiene.
|
|
81
|
+
*/
|
|
82
|
+
export function generateDockerCompose(topology) {
|
|
83
|
+
const nodeById = new Map(topology.nodes.map((n) => [n.id, n]));
|
|
84
|
+
const lines = [
|
|
85
|
+
`# ==============================================================================`,
|
|
86
|
+
`# Adityum Studio V1.0 — Sovereign Microservice Composition`,
|
|
87
|
+
`# Stack: ${topology.name} | Region: ${topology.region} | Compliance: ${topology.complianceProfile}`,
|
|
88
|
+
`# Zero exposed raw database ports · Internal Docker bridge isolation`,
|
|
89
|
+
`# ==============================================================================`,
|
|
90
|
+
`name: ${topology.name}`,
|
|
91
|
+
``,
|
|
92
|
+
`services:`,
|
|
93
|
+
];
|
|
94
|
+
const volumes = [];
|
|
95
|
+
for (const node of topology.nodes) {
|
|
96
|
+
if (node.kind === "storage")
|
|
97
|
+
continue; // External Cloudflare R2 bucket
|
|
98
|
+
lines.push(` ${node.name}:`);
|
|
99
|
+
if (node.kind === "tunnel") {
|
|
100
|
+
lines.push(` image: cloudflare/cloudflared:2026.11.1`);
|
|
101
|
+
lines.push(` command: tunnel --no-autoupdate --config /etc/cloudflared/config.yml run`);
|
|
102
|
+
lines.push(` read_only: true`);
|
|
103
|
+
lines.push(` security_opt:`);
|
|
104
|
+
lines.push(` - no-new-privileges:true`);
|
|
105
|
+
lines.push(` volumes:`);
|
|
106
|
+
lines.push(` - ./cloudflared/config.yml:/etc/cloudflared/config.yml:ro`);
|
|
107
|
+
lines.push(` networks:`);
|
|
108
|
+
lines.push(` - adi-edge`);
|
|
109
|
+
}
|
|
110
|
+
else if (node.kind === "postgres") {
|
|
111
|
+
const volName = `${node.name.replace(/-/g, "_")}_data`;
|
|
112
|
+
volumes.push(volName);
|
|
113
|
+
lines.push(` image: postgres:16.4-alpine`);
|
|
114
|
+
lines.push(` restart: unless-stopped`);
|
|
115
|
+
lines.push(` security_opt:`);
|
|
116
|
+
lines.push(` - no-new-privileges:true`);
|
|
117
|
+
lines.push(` volumes:`);
|
|
118
|
+
lines.push(` - ${volName}:${node.volumePath || "/var/lib/postgresql/data"}`);
|
|
119
|
+
lines.push(` healthcheck:`);
|
|
120
|
+
lines.push(` test: ["CMD-SHELL", "pg_isready -U \${POSTGRES_USER:-adityum}"]`);
|
|
121
|
+
lines.push(` interval: 15s`);
|
|
122
|
+
lines.push(` timeout: 5s`);
|
|
123
|
+
lines.push(` retries: 5`);
|
|
124
|
+
lines.push(` networks:`);
|
|
125
|
+
lines.push(` - adi-internal`);
|
|
126
|
+
}
|
|
127
|
+
else if (node.kind === "redis") {
|
|
128
|
+
const volName = `${node.name.replace(/-/g, "_")}_data`;
|
|
129
|
+
volumes.push(volName);
|
|
130
|
+
lines.push(` image: redis:7.4-alpine`);
|
|
131
|
+
lines.push(` command: ["redis-server", "--appendonly", "yes"]`);
|
|
132
|
+
lines.push(` restart: unless-stopped`);
|
|
133
|
+
lines.push(` security_opt:`);
|
|
134
|
+
lines.push(` - no-new-privileges:true`);
|
|
135
|
+
lines.push(` volumes:`);
|
|
136
|
+
lines.push(` - ${volName}:${node.volumePath || "/data"}`);
|
|
137
|
+
lines.push(` healthcheck:`);
|
|
138
|
+
lines.push(` test: ["CMD", "redis-cli", "ping"]`);
|
|
139
|
+
lines.push(` interval: 15s`);
|
|
140
|
+
lines.push(` timeout: 5s`);
|
|
141
|
+
lines.push(` retries: 5`);
|
|
142
|
+
lines.push(` networks:`);
|
|
143
|
+
lines.push(` - adi-internal`);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// Compute service (web, api, worker, cron)
|
|
147
|
+
lines.push(` build:`);
|
|
148
|
+
lines.push(` context: ./services/${node.name}`);
|
|
149
|
+
lines.push(` dockerfile: Dockerfile`);
|
|
150
|
+
lines.push(` restart: unless-stopped`);
|
|
151
|
+
if (node.nonRootUser) {
|
|
152
|
+
lines.push(` user: "10001:10001"`);
|
|
153
|
+
}
|
|
154
|
+
if (node.readOnlyRootFs) {
|
|
155
|
+
lines.push(` read_only: true`);
|
|
156
|
+
lines.push(` tmpfs:`);
|
|
157
|
+
lines.push(` - /tmp:size=64M,noexec,nosuid`);
|
|
158
|
+
}
|
|
159
|
+
lines.push(` security_opt:`);
|
|
160
|
+
lines.push(` - no-new-privileges:true`);
|
|
161
|
+
lines.push(` expose:`);
|
|
162
|
+
lines.push(` - "${node.port}"`);
|
|
163
|
+
if (node.healthcheckPath) {
|
|
164
|
+
lines.push(` healthcheck:`);
|
|
165
|
+
lines.push(` test: ["CMD", "curl", "-fsS", "http://127.0.0.1:${node.port}${node.healthcheckPath}"]`);
|
|
166
|
+
lines.push(` interval: 30s`);
|
|
167
|
+
lines.push(` timeout: 5s`);
|
|
168
|
+
lines.push(` retries: 3`);
|
|
169
|
+
}
|
|
170
|
+
lines.push(` networks:`);
|
|
171
|
+
if (node.publicIngress) {
|
|
172
|
+
lines.push(` - adi-edge`);
|
|
173
|
+
}
|
|
174
|
+
lines.push(` - adi-internal`);
|
|
175
|
+
}
|
|
176
|
+
// Resource limits
|
|
177
|
+
if (node.cpuLimit > 0 || node.memoryMb > 0) {
|
|
178
|
+
lines.push(` deploy:`);
|
|
179
|
+
lines.push(` replicas: ${Math.max(1, node.replicas || 1)}`);
|
|
180
|
+
lines.push(` resources:`);
|
|
181
|
+
lines.push(` limits:`);
|
|
182
|
+
if (node.cpuLimit > 0) {
|
|
183
|
+
lines.push(` cpus: "${node.cpuLimit}"`);
|
|
184
|
+
}
|
|
185
|
+
if (node.memoryMb > 0) {
|
|
186
|
+
lines.push(` memory: ${node.memoryMb}M`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Environment variables (scrubbing secrets to ${VAR} placeholders)
|
|
190
|
+
if (node.envVars.length > 0) {
|
|
191
|
+
lines.push(` environment:`);
|
|
192
|
+
for (const env of node.envVars) {
|
|
193
|
+
const renderedVal = env.isSecret ? `\${${env.key}}` : env.value;
|
|
194
|
+
lines.push(` ${env.key}: "${renderedVal}"`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Dependencies derived directly from canvas edges
|
|
198
|
+
const deps = topology.edges
|
|
199
|
+
.filter((e) => e.sourceId === node.id)
|
|
200
|
+
.map((e) => nodeById.get(e.targetId))
|
|
201
|
+
.filter((t) => Boolean(t && t.kind !== "storage"));
|
|
202
|
+
if (deps.length > 0) {
|
|
203
|
+
lines.push(` depends_on:`);
|
|
204
|
+
for (const dep of deps) {
|
|
205
|
+
const hasHealthcheck = dep.kind === "postgres" ||
|
|
206
|
+
dep.kind === "redis" ||
|
|
207
|
+
Boolean(dep.healthcheckPath);
|
|
208
|
+
lines.push(` ${dep.name}:`);
|
|
209
|
+
lines.push(` condition: ${hasHealthcheck ? "service_healthy" : "service_started"}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
lines.push(``);
|
|
213
|
+
}
|
|
214
|
+
lines.push(`networks:`);
|
|
215
|
+
lines.push(` adi-edge:`);
|
|
216
|
+
lines.push(` driver: bridge`);
|
|
217
|
+
lines.push(` adi-internal:`);
|
|
218
|
+
lines.push(` driver: bridge`);
|
|
219
|
+
lines.push(` internal: true # Contract #2: zero direct internet egress/ingress for data tier`);
|
|
220
|
+
if (volumes.length > 0) {
|
|
221
|
+
lines.push(``);
|
|
222
|
+
lines.push(`volumes:`);
|
|
223
|
+
for (const v of volumes) {
|
|
224
|
+
lines.push(` ${v}:`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return lines.join("\n") + "\n";
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Generates declarative Adityum Blueprint Manifest (adityum.yaml)
|
|
231
|
+
*/
|
|
232
|
+
export function generateAdityumManifest(topology) {
|
|
233
|
+
const audit = validateStudioTopology(topology);
|
|
234
|
+
const nodeById = new Map(topology.nodes.map((n) => [n.id, n]));
|
|
235
|
+
const lines = [
|
|
236
|
+
`apiVersion: adityum.dev/v1`,
|
|
237
|
+
`kind: SovereignTopology`,
|
|
238
|
+
`metadata:`,
|
|
239
|
+
` name: ${topology.name}`,
|
|
240
|
+
` region: ${topology.region}`,
|
|
241
|
+
` domain: ${topology.domain}`,
|
|
242
|
+
` complianceProfile: ${topology.complianceProfile}`,
|
|
243
|
+
` securityScore: ${audit.score}`,
|
|
244
|
+
` securityGrade: "${audit.grade}"`,
|
|
245
|
+
`deployOrder:`,
|
|
246
|
+
...audit.deployOrder.map((slug) => ` - ${slug}`),
|
|
247
|
+
`services:`,
|
|
248
|
+
];
|
|
249
|
+
for (const node of topology.nodes) {
|
|
250
|
+
lines.push(` - name: ${node.name}`);
|
|
251
|
+
lines.push(` kind: ${node.kind}`);
|
|
252
|
+
lines.push(` runtime: ${node.runtime}`);
|
|
253
|
+
lines.push(` port: ${node.port}`);
|
|
254
|
+
lines.push(` publicIngress: ${node.publicIngress}`);
|
|
255
|
+
lines.push(` replicas: ${node.replicas}`);
|
|
256
|
+
lines.push(` resources:`);
|
|
257
|
+
lines.push(` cpu: "${node.cpuLimit}"`);
|
|
258
|
+
lines.push(` memoryMb: ${node.memoryMb}`);
|
|
259
|
+
lines.push(` hardening:`);
|
|
260
|
+
lines.push(` nonRootUser: ${node.nonRootUser}`);
|
|
261
|
+
lines.push(` readOnlyRootFs: ${node.readOnlyRootFs}`);
|
|
262
|
+
if (node.gitRepoUrl) {
|
|
263
|
+
lines.push(` source:`);
|
|
264
|
+
lines.push(` gitRepoUrl: ${node.gitRepoUrl}`);
|
|
265
|
+
lines.push(` gitBranch: ${node.gitBranch || "main"}`);
|
|
266
|
+
}
|
|
267
|
+
if (node.envVars.length > 0) {
|
|
268
|
+
lines.push(` env:`);
|
|
269
|
+
for (const env of node.envVars) {
|
|
270
|
+
lines.push(` - key: ${env.key}`);
|
|
271
|
+
lines.push(` vaultAadBound: ${env.isSecret}`);
|
|
272
|
+
if (!env.isSecret) {
|
|
273
|
+
lines.push(` value: "${env.value}"`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
lines.push(`edges:`);
|
|
279
|
+
for (const edge of topology.edges) {
|
|
280
|
+
const src = nodeById.get(edge.sourceId)?.name || edge.sourceId;
|
|
281
|
+
const dst = nodeById.get(edge.targetId)?.name || edge.targetId;
|
|
282
|
+
lines.push(` - from: ${src}`);
|
|
283
|
+
lines.push(` to: ${dst}`);
|
|
284
|
+
lines.push(` protocol: ${edge.protocol}`);
|
|
285
|
+
lines.push(` encrypted: ${edge.encrypted}`);
|
|
286
|
+
}
|
|
287
|
+
return lines.join("\n") + "\n";
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Generates hardened /etc/cloudflared/config.yml enforcing Contract #2 (403 catch-all).
|
|
291
|
+
*/
|
|
292
|
+
export function generateTunnelIngress(topology) {
|
|
293
|
+
const nodeById = new Map(topology.nodes.map((n) => [n.id, n]));
|
|
294
|
+
const domain = topology.domain || "app.your-domain.dev";
|
|
295
|
+
const tunnelTargets = topology.edges
|
|
296
|
+
.filter((e) => nodeById.get(e.sourceId)?.kind === "tunnel")
|
|
297
|
+
.map((e) => nodeById.get(e.targetId))
|
|
298
|
+
.filter((n) => Boolean(n));
|
|
299
|
+
const routes = tunnelTargets.length > 0
|
|
300
|
+
? tunnelTargets
|
|
301
|
+
: topology.nodes.filter((n) => (n.kind === "web" || n.kind === "api") && n.publicIngress);
|
|
302
|
+
const lines = [
|
|
303
|
+
`# ==============================================================================`,
|
|
304
|
+
`# Adityum Studio V1.0 — Hardened Cloudflare Named Tunnel Config`,
|
|
305
|
+
`# Enforces Ecosystem Contract #2: Zero Open Inbound Ports + 403 Catch-All`,
|
|
306
|
+
`# ==============================================================================`,
|
|
307
|
+
`tunnel: \${CLOUDFLARE_TUNNEL_UUID}`,
|
|
308
|
+
`credentials-file: /etc/cloudflared/\${CLOUDFLARE_TUNNEL_UUID}.json`,
|
|
309
|
+
``,
|
|
310
|
+
`ingress:`,
|
|
311
|
+
];
|
|
312
|
+
// Prioritize /api/v1/* path rules before root web catch-all
|
|
313
|
+
const apiRoutes = routes.filter((r) => r.kind === "api");
|
|
314
|
+
const webRoutes = routes.filter((r) => r.kind !== "api");
|
|
315
|
+
for (const api of apiRoutes) {
|
|
316
|
+
lines.push(` - hostname: ${domain}`);
|
|
317
|
+
lines.push(` path: ^/api/v1/.*`);
|
|
318
|
+
lines.push(` service: http://${api.name}:${api.port}`);
|
|
319
|
+
lines.push(` originRequest:`);
|
|
320
|
+
lines.push(` connectTimeout: 8s`);
|
|
321
|
+
}
|
|
322
|
+
for (const web of webRoutes) {
|
|
323
|
+
lines.push(` - hostname: ${domain}`);
|
|
324
|
+
lines.push(` service: http://${web.name}:${web.port}`);
|
|
325
|
+
lines.push(` originRequest:`);
|
|
326
|
+
lines.push(` connectTimeout: 8s`);
|
|
327
|
+
}
|
|
328
|
+
lines.push(` # Contract #2 Strict Catch-All Guard — blocks all unmapped hostnames & raw ports`);
|
|
329
|
+
lines.push(` - service: http_status:403`);
|
|
330
|
+
return lines.join("\n") + "\n";
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Generates secret-safe .env.example with Contract #3 AAD Vault guidance.
|
|
334
|
+
*/
|
|
335
|
+
export function generateEnvExample(topology) {
|
|
336
|
+
const seen = new Set();
|
|
337
|
+
const lines = [
|
|
338
|
+
`# ==============================================================================`,
|
|
339
|
+
`# Adityum Studio V1.0 — Secret-Safe Environment Template (${topology.name})`,
|
|
340
|
+
`# Contract #3: Never commit plaintext secrets. Vault via AES-256-GCM AAD in adi-console.`,
|
|
341
|
+
`# ==============================================================================`,
|
|
342
|
+
``,
|
|
343
|
+
];
|
|
344
|
+
for (const node of topology.nodes) {
|
|
345
|
+
if (node.envVars.length === 0)
|
|
346
|
+
continue;
|
|
347
|
+
lines.push(`# --- ${node.label} (${node.name}) ---`);
|
|
348
|
+
for (const env of node.envVars) {
|
|
349
|
+
if (seen.has(env.key))
|
|
350
|
+
continue;
|
|
351
|
+
seen.add(env.key);
|
|
352
|
+
if (env.isSecret) {
|
|
353
|
+
lines.push(`${env.key}=__VAULT_REQUIRED__`);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
lines.push(`${env.key}=${env.value}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
lines.push(``);
|
|
360
|
+
}
|
|
361
|
+
return lines.join("\n");
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Generates the complete declarative artifact bundle for the Studio topology.
|
|
365
|
+
*/
|
|
366
|
+
export function generateStudioBundle(topology) {
|
|
367
|
+
const dockerfiles = {};
|
|
368
|
+
for (const node of topology.nodes) {
|
|
369
|
+
if (node.kind === "web" ||
|
|
370
|
+
node.kind === "api" ||
|
|
371
|
+
node.kind === "worker" ||
|
|
372
|
+
node.kind === "cron") {
|
|
373
|
+
dockerfiles[node.name] = generateServiceDockerfile(node);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
dockerComposeYaml: generateDockerCompose(topology),
|
|
378
|
+
adityumManifestYaml: generateAdityumManifest(topology),
|
|
379
|
+
tunnelConfigYaml: generateTunnelIngress(topology),
|
|
380
|
+
envExample: generateEnvExample(topology),
|
|
381
|
+
dockerfiles,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Converts Studio compute nodes into ready-to-submit Adityum Deploy (/api/v1/projects) payloads
|
|
386
|
+
* sorted in topological dependency order.
|
|
387
|
+
*/
|
|
388
|
+
export function generateDeployPayloads(topology, serverId) {
|
|
389
|
+
const audit = validateStudioTopology(topology);
|
|
390
|
+
const nodeByName = new Map(topology.nodes.map((n) => [n.name, n]));
|
|
391
|
+
const payloads = [];
|
|
392
|
+
for (const slug of audit.deployOrder) {
|
|
393
|
+
const node = nodeByName.get(slug);
|
|
394
|
+
if (!node)
|
|
395
|
+
continue;
|
|
396
|
+
if (node.kind !== "web" &&
|
|
397
|
+
node.kind !== "api" &&
|
|
398
|
+
node.kind !== "worker" &&
|
|
399
|
+
node.kind !== "cron") {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
const mappedRuntime = node.runtime === "nextjs"
|
|
403
|
+
? "nextjs"
|
|
404
|
+
: node.runtime === "nodejs"
|
|
405
|
+
? "nodejs"
|
|
406
|
+
: node.runtime === "python"
|
|
407
|
+
? "python"
|
|
408
|
+
: "dockerfile";
|
|
409
|
+
payloads.push({
|
|
410
|
+
nodeId: node.id,
|
|
411
|
+
name: `${topology.name}-${node.name}`.slice(0, 48),
|
|
412
|
+
server_id: serverId,
|
|
413
|
+
git_repo_url: node.gitRepoUrl || "https://github.com/adityumgroups-dev/starter-app",
|
|
414
|
+
git_branch: node.gitBranch || "main",
|
|
415
|
+
runtime: mappedRuntime,
|
|
416
|
+
build_pack: mappedRuntime === "dockerfile" ? "dockerfile" : "nixpacks",
|
|
417
|
+
port: node.port || 3000,
|
|
418
|
+
custom_domain: node.publicIngress ? topology.domain : undefined,
|
|
419
|
+
envVars: node.envVars.map((e) => ({
|
|
420
|
+
key: e.key,
|
|
421
|
+
isSecret: e.isSecret,
|
|
422
|
+
placeholder: e.isSecret ? "${VAULT_SECRET}" : e.value,
|
|
423
|
+
})),
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
return payloads;
|
|
427
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type StudioServiceKind = "tunnel" | "web" | "api" | "worker" | "postgres" | "redis" | "storage" | "cron";
|
|
2
|
+
export type StudioRuntime = "cloudflared" | "nextjs" | "nodejs" | "python" | "go" | "dockerfile" | "postgres16" | "redis7" | "r2-bucket";
|
|
3
|
+
export type StudioEdgeProtocol = "https" | "http-internal" | "postgres-tls" | "redis-tls" | "s3-sigv4" | "grpc-tls";
|
|
4
|
+
export type StudioRegion = "blr1" | "bom1" | "sin1" | "fsn1" | "byoc-custom";
|
|
5
|
+
export type StudioComplianceProfile = "standard" | "cert-in-180d" | "dpdp-strict";
|
|
6
|
+
export interface StudioEnvVar {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
isSecret: boolean;
|
|
10
|
+
fromServiceId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface StudioNode {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
label: string;
|
|
16
|
+
kind: StudioServiceKind;
|
|
17
|
+
runtime: StudioRuntime;
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
port: number;
|
|
21
|
+
publicIngress: boolean;
|
|
22
|
+
replicas: number;
|
|
23
|
+
cpuLimit: number;
|
|
24
|
+
memoryMb: number;
|
|
25
|
+
gitRepoUrl?: string;
|
|
26
|
+
gitBranch?: string;
|
|
27
|
+
healthcheckPath?: string;
|
|
28
|
+
volumePath?: string;
|
|
29
|
+
nonRootUser: boolean;
|
|
30
|
+
readOnlyRootFs: boolean;
|
|
31
|
+
envVars: StudioEnvVar[];
|
|
32
|
+
}
|
|
33
|
+
export interface StudioEdge {
|
|
34
|
+
id: string;
|
|
35
|
+
sourceId: string;
|
|
36
|
+
targetId: string;
|
|
37
|
+
protocol: StudioEdgeProtocol;
|
|
38
|
+
label?: string;
|
|
39
|
+
encrypted: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface StudioTopology {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
region: StudioRegion;
|
|
46
|
+
complianceProfile: StudioComplianceProfile;
|
|
47
|
+
domain: string;
|
|
48
|
+
nodes: StudioNode[];
|
|
49
|
+
edges: StudioEdge[];
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
}
|
|
52
|
+
export interface StudioAuditFinding {
|
|
53
|
+
id: string;
|
|
54
|
+
code: string;
|
|
55
|
+
severity: "critical" | "high" | "medium" | "info";
|
|
56
|
+
nodeId?: string;
|
|
57
|
+
nodeName?: string;
|
|
58
|
+
title: string;
|
|
59
|
+
message: string;
|
|
60
|
+
remediation: string;
|
|
61
|
+
}
|
|
62
|
+
export interface StudioResourceSummary {
|
|
63
|
+
serviceCount: number;
|
|
64
|
+
computeServices: number;
|
|
65
|
+
dataServices: number;
|
|
66
|
+
totalVcpu: number;
|
|
67
|
+
totalMemoryMb: number;
|
|
68
|
+
recommendedTierName: string;
|
|
69
|
+
recommendedSpecs: string;
|
|
70
|
+
estimatedMonthlyInr: number;
|
|
71
|
+
estimatedAwsEquivalentInr: number;
|
|
72
|
+
monthlySavingsPercent: number;
|
|
73
|
+
}
|
|
74
|
+
export interface StudioAuditResult {
|
|
75
|
+
score: number;
|
|
76
|
+
grade: "A+" | "A" | "B" | "C" | "D" | "F";
|
|
77
|
+
isDeployReady: boolean;
|
|
78
|
+
hasCycle: boolean;
|
|
79
|
+
deployOrder: string[];
|
|
80
|
+
findings: StudioAuditFinding[];
|
|
81
|
+
resources: StudioResourceSummary;
|
|
82
|
+
}
|
|
83
|
+
export interface StudioDeployPayload {
|
|
84
|
+
nodeId: string;
|
|
85
|
+
name: string;
|
|
86
|
+
server_id: string;
|
|
87
|
+
git_repo_url: string;
|
|
88
|
+
git_branch: string;
|
|
89
|
+
runtime: "nextjs" | "nodejs" | "python" | "dockerfile";
|
|
90
|
+
build_pack: "nixpacks" | "dockerfile";
|
|
91
|
+
port: number;
|
|
92
|
+
custom_domain?: string;
|
|
93
|
+
envVars: Array<{
|
|
94
|
+
key: string;
|
|
95
|
+
isSecret: boolean;
|
|
96
|
+
placeholder: string;
|
|
97
|
+
}>;
|
|
98
|
+
}
|
|
99
|
+
export interface StudioGeneratedBundle {
|
|
100
|
+
dockerComposeYaml: string;
|
|
101
|
+
adityumManifestYaml: string;
|
|
102
|
+
tunnelConfigYaml: string;
|
|
103
|
+
envExample: string;
|
|
104
|
+
dockerfiles: Record<string, string>;
|
|
105
|
+
}
|
|
106
|
+
export interface StudioBlueprintMeta {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
tagline: string;
|
|
110
|
+
category: "Full-Stack SaaS" | "AI & Data" | "High-Throughput API" | "FinTech / Compliance" | "Starter";
|
|
111
|
+
complianceProfile: StudioComplianceProfile;
|
|
112
|
+
badge: string;
|
|
113
|
+
create: () => StudioTopology;
|
|
114
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { StudioAuditResult, StudioResourceSummary, StudioTopology } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Pure client-side & CLI architecture security, graph cycle, CIS hardening,
|
|
4
|
+
* topological deploy-order, and INR BYOC sizing validator.
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateStudioTopology(topology: StudioTopology): StudioAuditResult;
|
|
7
|
+
export declare function computeResourceSummary(topology: StudioTopology): StudioResourceSummary;
|