Skip to content

Commit 7cdff89

Browse files
Sma1lboyZHallen122
andcommitted
fix(backend): fix a lot small issue in backend (#127)
- Optimized the success rate of generation - Added overall theme analysis - Added project size analysis - Increase support for single-page projects and distinguish multi-page projects <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced project build and document generation with dynamic configuration for tailored code, architecture, and UX outputs. - Improved Docker integration with updated file mounting for better file access. - Introduced new handlers and updated configurations for generating file structures and architecture documents. - Added new properties for project size and model selection in build configurations. - Expanded prompt generation for UX Sitemap and Product Requirement Document (PRD) with detailed guidelines. - **Bug Fixes** - Resolved issues with file handling and asynchronous processes, ensuring smoother performance and more reliable error reporting. - Improved error messaging for model-related issues to aid debugging. These updates contribute to a more stable and responsive experience. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: ZHallen122 <zhallen12261@gmail.com>
1 parent 9617407 commit 7cdff89

File tree

30 files changed

+1100
-986
lines changed

30 files changed

+1100
-986
lines changed

backend/src/build-system/__tests__/fullstack-gen.spec.ts

+10-40
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ import { PRDHandler } from '../handlers/product-manager/product-requirements-doc
55
import { UXSMDHandler } from '../handlers/ux/sitemap-document';
66
import { UXSMSHandler } from '../handlers/ux/sitemap-structure';
77
import { DBRequirementHandler } from '../handlers/database/requirements-document';
8-
import { FileStructureHandler } from '../handlers/file-manager/file-structure';
9-
import { UXSMSPageByPageHandler } from '../handlers/ux/sitemap-structure/sms-page';
10-
import { DBSchemaHandler } from '../handlers/database/schemas/schemas';
11-
import { FileFAHandler } from '../handlers/file-manager/file-arch';
12-
import { BackendRequirementHandler } from '../handlers/backend/requirements-document';
13-
import { BackendCodeHandler } from '../handlers/backend/code-generate';
14-
import { BackendFileReviewHandler } from '../handlers/backend/file-review/file-review';
158
import { UXDMDHandler } from '../handlers/ux/datamap';
169
import { BuilderContext } from '../context';
1710
import { FrontendCodeHandler } from '../handlers/frontend-code-generate';
11+
import { FileStructureAndArchitectureHandler } from '../handlers/file-manager/file-struct';
12+
import { BackendRequirementHandler } from '../handlers/backend/requirements-document';
1813

1914
(isIntegrationTest ? describe : describe.skip)('Build Sequence Test', () => {
2015
it('should execute build sequence successfully', async () => {
@@ -23,8 +18,10 @@ import { FrontendCodeHandler } from '../handlers/frontend-code-generate';
2318
version: '1.0.0',
2419
name: 'Wrtie a Cool personal website',
2520
description:
26-
'A personal blog website. I am a cybersecurity engineer so i want it to show i am a really cool hacker',
21+
'A personal blog website. I am a cybersecurity engineer so i want it to show i am a really cool hacker, with cool terminal functionality',
2722
databaseType: 'SQLite',
23+
model: 'gpt-4o-mini',
24+
projectSize: 'medium', // limit for fun
2825
nodes: [
2926
{
3027
handler: ProjectInitHandler,
@@ -47,47 +44,20 @@ import { FrontendCodeHandler } from '../handlers/frontend-code-generate';
4744
handler: UXDMDHandler,
4845
name: 'UX DataMap Document Node',
4946
},
47+
{
48+
handler: FileStructureAndArchitectureHandler,
49+
name: 'File Structure and Architecture',
50+
},
5051
{
5152
handler: DBRequirementHandler,
5253
name: 'Database Requirements Node',
5354
// requires: ['op:UX:DATAMAP:DOC'],
5455
},
55-
{
56-
handler: FileStructureHandler,
57-
name: 'File Structure Generation',
58-
// requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],
59-
options: {
60-
projectPart: 'frontend',
61-
},
62-
},
63-
{
64-
handler: UXSMSPageByPageHandler,
65-
name: 'Level 2 UX Sitemap Structure Node details',
66-
// requires: ['op:UX:SMS'],
67-
},
68-
{
69-
handler: DBSchemaHandler,
70-
name: 'Database Schemas Node',
71-
// requires: ['op:DATABASE_REQ'],
72-
},
73-
{
74-
handler: FileFAHandler,
75-
name: 'File Arch',
76-
// requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],
77-
},
7856
{
7957
handler: BackendRequirementHandler,
8058
name: 'Backend Requirements Node',
8159
// requires: ['op:DATABASE_REQ', 'op:UX:DATAMAP:DOC', 'op:UX:SMD'],
8260
},
83-
{
84-
handler: BackendCodeHandler,
85-
name: 'Backend Code Generator Node',
86-
},
87-
{
88-
handler: BackendFileReviewHandler,
89-
name: 'Backend File Review Node',
90-
},
9161
{
9262
handler: FrontendCodeHandler,
9363
name: 'Frontend Code Generator Node',
@@ -97,5 +67,5 @@ import { FrontendCodeHandler } from '../handlers/frontend-code-generate';
9767
};
9868
const context = new BuilderContext(sequence, 'fullstack-code-gen');
9969
await context.execute();
100-
}, 300000);
70+
}, 2000000);
10171
});

backend/src/build-system/__tests__/mock/MockBuilderContext.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as path from 'path';
55
import { UXSMSHandler } from 'src/build-system/handlers/ux/sitemap-structure';
66
import { UXDMDHandler } from 'src/build-system/handlers/ux/datamap';
77
import { BackendRequirementHandler } from 'src/build-system/handlers/backend/requirements-document';
8-
import { FileFAHandler } from 'src/build-system/handlers/file-manager/file-arch';
98
import { BuilderContext, GlobalDataKeys } from 'src/build-system/context';
109
import { v4 as uuidv4 } from 'uuid'; // UUID generator for unique identifiers
1110
import {
@@ -37,18 +36,20 @@ export class MockBuilderContext extends BuilderContext {
3736
const backendRequirements = this.readMockFile(
3837
path.join(__dirname, 'test_files', 'Backend_Requirements_Node.md'),
3938
);
40-
const fileStructure = this.readMockFile(
41-
path.join(__dirname, 'test_files', 'File_Structure_Generation.md'),
42-
);
43-
const fileArchitecture = this.readMockFile(
44-
path.join(__dirname, 'test_files', 'File_Arch.md'),
45-
);
4639

40+
//To do integrate FileStructureAndArchitectureHandler
41+
const fileStructureAndArchitectureHandler = this.readMockFile(
42+
path.join(__dirname, 'test_files', 'File_Structure_Architecture_Node.md'),
43+
);
4744
this.mockNodeData.set(UXSMSHandler, uxSitemapStructure);
4845
this.mockNodeData.set(UXDMDHandler, uxDataMapDocument);
4946
this.mockNodeData.set(BackendRequirementHandler, backendRequirements);
50-
this.mockNodeData.set(FileFAHandler, fileArchitecture);
51-
this.buildVirtualDirectory(fileStructure);
47+
// this.mockNodeData.set(
48+
// fileStructureAndArchitectureHandler,
49+
// FileStructureAndArchitectureHandler,
50+
// );
51+
52+
// this.buildVirtualDirectory(fileStructure);
5253

5354
copyProjectTemplate(
5455
path.join(__dirname, '..', '..', '..', '..', 'template', 'react-ts'),

backend/src/build-system/__tests__/test.frontend-code-generate.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ describe('FrontendCodeHandler', () => {
1212
name: 'Spotify-like Music Web',
1313
description: 'Users can play music',
1414
databaseType: 'SQLite',
15+
model: 'o3-mini-high',
1516
nodes: [
1617
{
1718
handler: FrontendCodeHandler,
1819
name: 'Frontend Code Handler',
1920
// requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],
2021
},
2122
],
23+
packages: [],
2224
};
2325

2426
beforeEach(() => {
2527
handler = new FrontendCodeHandler();
26-
context = new MockBuilderContext(sequence, 'test');
28+
context = new MockBuilderContext(sequence, 'frontend-only');
2729
});
2830

2931
//rember to comment requirement in FrontendCodeHandler
@@ -32,5 +34,5 @@ describe('FrontendCodeHandler', () => {
3234
const result = await handler.run(context);
3335

3436
expect(result.success).toBe(true);
35-
});
37+
}, 6000000);
3638
});

backend/src/build-system/context.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export class BuilderContext {
8181

8282
private logFolder: string | null = null;
8383

84+
public defaultModel: string;
8485
/**
8586
* Constructor to initialize the BuilderContext.
8687
* Sets up the handler manager, retry handler, model provider, logger, and virtual directory.
@@ -99,21 +100,41 @@ export class BuilderContext {
99100
this.monitor = BuildMonitor.getInstance();
100101
this.logger = new Logger(`builder-context-${id ?? sequence.id}`);
101102
this.virtualDirectory = new VirtualDirectory();
103+
this.defaultModel = this.sequence.model;
102104

103-
// Initialize global context with default project values
104105
this.globalContext.set('projectName', sequence.name);
105106
this.globalContext.set('description', sequence.description || '');
106107
this.globalContext.set('platform', 'web'); // Default platform is 'web'
107108
this.globalContext.set('databaseType', sequence.databaseType || 'SQLite');
108109

110+
if (sequence.projectSize) {
111+
this.globalContext.set('projectSize', sequence.projectSize);
112+
} else {
113+
switch (sequence.model) {
114+
case 'gpt-4o-mini':
115+
this.globalContext.set('projectSize', 'small');
116+
break;
117+
case 'gpt-4o':
118+
case 'o3-mini-high':
119+
this.globalContext.set('projectSize', 'medium');
120+
break;
121+
default:
122+
this.globalContext.set('projectSize', 'small');
123+
break;
124+
}
125+
}
126+
const now = new Date();
109127
const projectUUIDPath =
110-
new Date().toISOString().slice(0, 18).replaceAll(/:/g, '-') +
128+
`${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}` +
129+
`-${String(now.getHours()).padStart(2, '0')}-${String(now.getMinutes()).padStart(2, '0')}-${String(now.getSeconds()).padStart(2, '0')}-${String(now.getMilliseconds()).padStart(3, '0')}` +
111130
'-' +
112131
uuidv4();
113132
this.globalContext.set('projectUUID', projectUUIDPath);
114133

115134
if (process.env.DEBUG) {
116-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
135+
const timestamp =
136+
`${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}` +
137+
`-${String(now.getHours()).padStart(2, '0')}-${String(now.getMinutes()).padStart(2, '0')}-${String(now.getSeconds()).padStart(2, '0')}-${String(now.getMilliseconds()).padStart(3, '0')}`;
117138
this.logFolder = path.join(
118139
process.cwd(),
119140
'logs',

backend/src/build-system/handlers/file-manager/file-arch/index.ts

-182
This file was deleted.

0 commit comments

Comments
 (0)