@compilr-dev/factory 0.1.9 → 0.1.11
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/dist/factory/registry.js +4 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/toolkits/react-fastapi/api.d.ts +9 -0
- package/dist/toolkits/react-fastapi/api.js +378 -0
- package/dist/toolkits/react-fastapi/config.d.ts +9 -0
- package/dist/toolkits/react-fastapi/config.js +128 -0
- package/dist/toolkits/react-fastapi/helpers.d.ts +13 -0
- package/dist/toolkits/react-fastapi/helpers.js +54 -0
- package/dist/toolkits/react-fastapi/index.d.ts +11 -0
- package/dist/toolkits/react-fastapi/index.js +55 -0
- package/dist/toolkits/react-fastapi/seed.d.ts +12 -0
- package/dist/toolkits/react-fastapi/seed.js +54 -0
- package/dist/toolkits/react-fastapi/shared.d.ts +6 -0
- package/dist/toolkits/react-fastapi/shared.js +6 -0
- package/dist/toolkits/react-fastapi/static.d.ts +8 -0
- package/dist/toolkits/react-fastapi/static.js +123 -0
- package/dist/toolkits/react-go/api.d.ts +12 -0
- package/dist/toolkits/react-go/api.js +523 -0
- package/dist/toolkits/react-go/config.d.ts +9 -0
- package/dist/toolkits/react-go/config.js +129 -0
- package/dist/toolkits/react-go/helpers.d.ts +13 -0
- package/dist/toolkits/react-go/helpers.js +49 -0
- package/dist/toolkits/react-go/index.d.ts +11 -0
- package/dist/toolkits/react-go/index.js +55 -0
- package/dist/toolkits/react-go/seed.d.ts +12 -0
- package/dist/toolkits/react-go/seed.js +55 -0
- package/dist/toolkits/react-go/shared.d.ts +6 -0
- package/dist/toolkits/react-go/shared.js +6 -0
- package/dist/toolkits/react-go/static.d.ts +8 -0
- package/dist/toolkits/react-go/static.js +122 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React+FastAPI Toolkit
|
|
3
|
+
*
|
|
4
|
+
* Generates a full-stack MVP: React 18 + Vite + Tailwind + FastAPI (Python).
|
|
5
|
+
* Deterministic: same ApplicationModel -> same output files.
|
|
6
|
+
*
|
|
7
|
+
* Frontend is identical to react-node (same React components, Vite config, Tailwind).
|
|
8
|
+
* Backend is Python FastAPI with in-memory data stores.
|
|
9
|
+
*/
|
|
10
|
+
import { generateConfigFiles } from './config.js';
|
|
11
|
+
import { generateStaticFiles } from './static.js';
|
|
12
|
+
import { generateShellFiles } from '../react-node/shell.js';
|
|
13
|
+
import { generateSharedComponents } from './shared.js';
|
|
14
|
+
import { generateDashboard } from '../react-node/dashboard.js';
|
|
15
|
+
import { generateEntityFiles } from '../react-node/entity.js';
|
|
16
|
+
import { generateRouter } from '../react-node/router.js';
|
|
17
|
+
import { generateApiFiles } from './api.js';
|
|
18
|
+
import { generateTypesFile } from '../react-node/types-gen.js';
|
|
19
|
+
export const reactFastapiToolkit = {
|
|
20
|
+
id: 'react-fastapi',
|
|
21
|
+
name: 'React + FastAPI',
|
|
22
|
+
description: 'React 18 + Vite + Tailwind CSS + FastAPI — full-stack MVP with Python backend',
|
|
23
|
+
requiredSections: ['identity', 'entities', 'layout', 'features', 'theme'],
|
|
24
|
+
generate(model) {
|
|
25
|
+
const warnings = [];
|
|
26
|
+
const allFiles = [];
|
|
27
|
+
// Collect files from all generators
|
|
28
|
+
const generators = [
|
|
29
|
+
generateConfigFiles(model),
|
|
30
|
+
generateStaticFiles(model),
|
|
31
|
+
generateTypesFile(model),
|
|
32
|
+
generateShellFiles(model),
|
|
33
|
+
generateSharedComponents(),
|
|
34
|
+
generateDashboard(model),
|
|
35
|
+
generateEntityFiles(model),
|
|
36
|
+
generateRouter(model),
|
|
37
|
+
generateApiFiles(model),
|
|
38
|
+
];
|
|
39
|
+
for (const files of generators) {
|
|
40
|
+
allFiles.push(...files);
|
|
41
|
+
}
|
|
42
|
+
// Check for potential issues
|
|
43
|
+
if (model.entities.length === 0) {
|
|
44
|
+
warnings.push('No entities defined — generated app will have minimal functionality.');
|
|
45
|
+
}
|
|
46
|
+
if (model.entities.length > 10) {
|
|
47
|
+
warnings.push('Large number of entities — generated sidebar may be crowded.');
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
files: allFiles,
|
|
51
|
+
toolkit: 'react-fastapi',
|
|
52
|
+
warnings,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React+FastAPI Toolkit — Seed Data Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates realistic mock data in Python dict format.
|
|
5
|
+
* Uses shared generateFieldValue for deterministic values,
|
|
6
|
+
* wraps them in Python list-of-dicts format for FastAPI data stores.
|
|
7
|
+
*/
|
|
8
|
+
import type { ApplicationModel, Entity } from '../../model/types.js';
|
|
9
|
+
import { SEED_COUNT } from '../shared/seed-data.js';
|
|
10
|
+
/** Generate seed data items for a single entity (Python list format). */
|
|
11
|
+
export declare function generateSeedData(model: ApplicationModel, entity: Entity): string;
|
|
12
|
+
export { SEED_COUNT };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React+FastAPI Toolkit — Seed Data Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates realistic mock data in Python dict format.
|
|
5
|
+
* Uses shared generateFieldValue for deterministic values,
|
|
6
|
+
* wraps them in Python list-of-dicts format for FastAPI data stores.
|
|
7
|
+
*/
|
|
8
|
+
import { belongsToRels, fkFieldName } from './helpers.js';
|
|
9
|
+
import { generateFieldValue, SEED_COUNT } from '../shared/seed-data.js';
|
|
10
|
+
/** Generate seed data items for a single entity (Python list format). */
|
|
11
|
+
export function generateSeedData(model, entity) {
|
|
12
|
+
const rels = belongsToRels(entity);
|
|
13
|
+
const lines = [];
|
|
14
|
+
lines.push('SEED_DATA = [');
|
|
15
|
+
for (let i = 0; i < SEED_COUNT; i++) {
|
|
16
|
+
lines.push(' {');
|
|
17
|
+
lines.push(` "id": ${String(i + 1)},`);
|
|
18
|
+
for (const field of entity.fields) {
|
|
19
|
+
const jsValue = generateFieldValue(field, i, entity.name);
|
|
20
|
+
const pyValue = jsToPyValue(jsValue, field.type);
|
|
21
|
+
lines.push(` "${field.name}": ${pyValue},`);
|
|
22
|
+
}
|
|
23
|
+
// FK fields from belongsTo relationships
|
|
24
|
+
for (const rel of rels) {
|
|
25
|
+
const fk = fkFieldName(rel);
|
|
26
|
+
const targetEntity = model.entities.find((e) => e.name === rel.target);
|
|
27
|
+
const targetCount = targetEntity ? SEED_COUNT : SEED_COUNT;
|
|
28
|
+
lines.push(` "${fk}": ${String((i % targetCount) + 1)},`);
|
|
29
|
+
}
|
|
30
|
+
// Implicit timestamps (deterministic)
|
|
31
|
+
const createdDate = new Date('2025-06-01T10:00:00Z');
|
|
32
|
+
createdDate.setDate(createdDate.getDate() + i * 2);
|
|
33
|
+
const updatedDate = new Date(createdDate);
|
|
34
|
+
updatedDate.setDate(updatedDate.getDate() + i);
|
|
35
|
+
lines.push(` "createdAt": "${createdDate.toISOString()}",`);
|
|
36
|
+
lines.push(` "updatedAt": "${updatedDate.toISOString()}",`);
|
|
37
|
+
lines.push(' },');
|
|
38
|
+
}
|
|
39
|
+
lines.push(']');
|
|
40
|
+
return lines.join('\n');
|
|
41
|
+
}
|
|
42
|
+
/** Convert a JS seed value string to Python format. */
|
|
43
|
+
function jsToPyValue(jsValue, fieldType) {
|
|
44
|
+
if (fieldType === 'boolean') {
|
|
45
|
+
return jsValue === 'true' ? 'True' : 'False';
|
|
46
|
+
}
|
|
47
|
+
// String/enum/date values come wrapped in single quotes — convert to double quotes
|
|
48
|
+
if (jsValue.startsWith("'") && jsValue.endsWith("'")) {
|
|
49
|
+
return `"${jsValue.slice(1, -1)}"`;
|
|
50
|
+
}
|
|
51
|
+
// Numbers pass through unchanged
|
|
52
|
+
return jsValue;
|
|
53
|
+
}
|
|
54
|
+
export { SEED_COUNT };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React+FastAPI Toolkit — Static Files Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates: .gitignore, .env.example, README.md, index.html, src/main.tsx, src/index.css
|
|
5
|
+
*/
|
|
6
|
+
import type { ApplicationModel } from '../../model/types.js';
|
|
7
|
+
import type { FactoryFile } from '../types.js';
|
|
8
|
+
export declare function generateStaticFiles(model: ApplicationModel): FactoryFile[];
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React+FastAPI Toolkit — Static Files Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates: .gitignore, .env.example, README.md, index.html, src/main.tsx, src/index.css
|
|
5
|
+
*/
|
|
6
|
+
export function generateStaticFiles(model) {
|
|
7
|
+
return [
|
|
8
|
+
generateGitignore(),
|
|
9
|
+
generateEnvExample(),
|
|
10
|
+
generateReadme(model),
|
|
11
|
+
generateIndexHtml(model),
|
|
12
|
+
generateMainTsx(),
|
|
13
|
+
generateIndexCss(),
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
function generateGitignore() {
|
|
17
|
+
return {
|
|
18
|
+
path: '.gitignore',
|
|
19
|
+
content: `node_modules
|
|
20
|
+
dist
|
|
21
|
+
.env
|
|
22
|
+
*.local
|
|
23
|
+
__pycache__
|
|
24
|
+
.venv
|
|
25
|
+
*.pyc
|
|
26
|
+
`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function generateEnvExample() {
|
|
30
|
+
return {
|
|
31
|
+
path: '.env.example',
|
|
32
|
+
content: `PORT=8000
|
|
33
|
+
VITE_API_URL=http://localhost:8000
|
|
34
|
+
`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function generateReadme(model) {
|
|
38
|
+
let entitiesSection = '';
|
|
39
|
+
if (model.entities.length > 0) {
|
|
40
|
+
const entityLines = model.entities
|
|
41
|
+
.map((e) => {
|
|
42
|
+
const relCount = e.relationships.length;
|
|
43
|
+
const parts = [`${String(e.fields.length)} fields`];
|
|
44
|
+
if (relCount > 0) {
|
|
45
|
+
parts.push(`${String(relCount)} relationship${relCount > 1 ? 's' : ''}`);
|
|
46
|
+
}
|
|
47
|
+
return `- **${e.name}** (${e.icon}) — ${parts.join(', ')}`;
|
|
48
|
+
})
|
|
49
|
+
.join('\n');
|
|
50
|
+
entitiesSection = `\n## Entities\n\n${entityLines}\n`;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
path: 'README.md',
|
|
54
|
+
content: `# ${model.identity.name}
|
|
55
|
+
|
|
56
|
+
${model.identity.description}
|
|
57
|
+
${entitiesSection}
|
|
58
|
+
## Getting Started
|
|
59
|
+
|
|
60
|
+
\`\`\`bash
|
|
61
|
+
npm install
|
|
62
|
+
pip install -r requirements.txt
|
|
63
|
+
npm run dev
|
|
64
|
+
\`\`\`
|
|
65
|
+
|
|
66
|
+
This starts both the Vite dev server and the FastAPI server.
|
|
67
|
+
|
|
68
|
+
- **Frontend:** http://localhost:5173
|
|
69
|
+
- **API:** http://localhost:8000
|
|
70
|
+
|
|
71
|
+
## Tech Stack
|
|
72
|
+
|
|
73
|
+
- React 18 + TypeScript
|
|
74
|
+
- Vite
|
|
75
|
+
- Tailwind CSS
|
|
76
|
+
- FastAPI (Python)
|
|
77
|
+
- React Router v6
|
|
78
|
+
`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function generateIndexHtml(model) {
|
|
82
|
+
return {
|
|
83
|
+
path: 'index.html',
|
|
84
|
+
content: `<!doctype html>
|
|
85
|
+
<html lang="en">
|
|
86
|
+
<head>
|
|
87
|
+
<meta charset="UTF-8" />
|
|
88
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
89
|
+
<title>${model.identity.name}</title>
|
|
90
|
+
</head>
|
|
91
|
+
<body>
|
|
92
|
+
<div id="root"></div>
|
|
93
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
94
|
+
</body>
|
|
95
|
+
</html>
|
|
96
|
+
`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function generateMainTsx() {
|
|
100
|
+
return {
|
|
101
|
+
path: 'src/main.tsx',
|
|
102
|
+
content: `import React from 'react';
|
|
103
|
+
import ReactDOM from 'react-dom/client';
|
|
104
|
+
import App from './App';
|
|
105
|
+
import './index.css';
|
|
106
|
+
|
|
107
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
108
|
+
<React.StrictMode>
|
|
109
|
+
<App />
|
|
110
|
+
</React.StrictMode>,
|
|
111
|
+
);
|
|
112
|
+
`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function generateIndexCss() {
|
|
116
|
+
return {
|
|
117
|
+
path: 'src/index.css',
|
|
118
|
+
content: `@tailwind base;
|
|
119
|
+
@tailwind components;
|
|
120
|
+
@tailwind utilities;
|
|
121
|
+
`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React+Go Toolkit — API Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates: server/main.go, server/models.go,
|
|
5
|
+
* server/data/{entity}.go, server/handlers/{entity}.go
|
|
6
|
+
*
|
|
7
|
+
* All files use `package main` so `go run ./server` compiles everything.
|
|
8
|
+
* Go 1.22+ net/http stdlib with method-based routing.
|
|
9
|
+
*/
|
|
10
|
+
import type { ApplicationModel } from '../../model/types.js';
|
|
11
|
+
import type { FactoryFile } from '../types.js';
|
|
12
|
+
export declare function generateApiFiles(model: ApplicationModel): FactoryFile[];
|