Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): frontend code generator #85

Merged
merged 87 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
9d91437
feat(backent): adding react-ts template (#56)
Sma1lboy Nov 28, 2024
5bbfdd9
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Nov 28, 2024
bfda89c
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Nov 28, 2024
da9ef45
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Nov 29, 2024
ec2bb50
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Nov 30, 2024
5bdd162
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 13, 2024
2c9ae0f
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 13, 2024
60a3098
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 15, 2024
a923bc5
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 15, 2024
fd2c639
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 16, 2024
66137f1
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 17, 2024
b7b809d
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 23, 2024
02ff300
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 29, 2024
3395501
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Dec 31, 2024
8b6646e
init frontend code generate
ZHallen122 Dec 31, 2024
2d610e9
FileGeneratorUtil
ZHallen122 Jan 4, 2025
cd4fe5f
update frontend code generator for fully generate
ZHallen122 Jan 4, 2025
09aeeea
update for code generate
ZHallen122 Jan 5, 2025
c791fcc
add code genearet to manager
ZHallen122 Jan 5, 2025
74cfffd
add esModuleInterop to support common js libarary
ZHallen122 Jan 5, 2025
98ea9c8
add op:FRONTEND:CODE step
ZHallen122 Jan 5, 2025
125576c
check if virtual dir correct at file arch
ZHallen122 Jan 5, 2025
a6d713a
fix order
ZHallen122 Jan 5, 2025
f708b9e
add css generate prompt
ZHallen122 Jan 5, 2025
a22836f
update
ZHallen122 Jan 6, 2025
e17a5ec
update
ZHallen122 Jan 6, 2025
be118f0
update to use sitemap struct
ZHallen122 Jan 7, 2025
e614d06
Merge branch 'main' of https://github.com/Sma1lboy/GeneratorAI
ZHallen122 Jan 8, 2025
fabdf32
Merge branch 'main' into feat_backend_frontend_code_generate
ZHallen122 Jan 8, 2025
580f27d
fix error
ZHallen122 Jan 8, 2025
e5cc2ed
update ux sitemap
ZHallen122 Jan 8, 2025
74d4610
improved prompt
ZHallen122 Jan 10, 2025
33f22d5
update sitemap prompt and messages
ZHallen122 Jan 10, 2025
01bfedf
update file name for sitemap
ZHallen122 Jan 10, 2025
faabb88
update sitemap prompt
ZHallen122 Jan 11, 2025
d4a1d1e
update prompts
ZHallen122 Jan 11, 2025
eebffc6
update sitemap structure: add messages
ZHallen122 Jan 11, 2025
7eecfe4
page by page update
ZHallen122 Jan 12, 2025
6f92d88
update
ZHallen122 Jan 13, 2025
1cb1dda
update UXSMD and S
ZHallen122 Jan 15, 2025
5cda996
update SMS
ZHallen122 Jan 16, 2025
45895c8
update prompt
ZHallen122 Jan 17, 2025
4b1bab6
update nameing
ZHallen122 Jan 17, 2025
f42e486
Fix Update import
ZHallen122 Jan 17, 2025
2452140
update import
ZHallen122 Jan 17, 2025
a8a402b
Merge branch 'main' into feat_backend_frontend_code_generate
ZHallen122 Jan 17, 2025
9e63a90
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 17, 2025
9669af3
Fix ssr and csr issue (#99)
NarwhalChen Jan 17, 2025
a4886ab
Delete unuse code
ZHallen122 Jan 18, 2025
be2aa22
refactor: sequence executing with polling rather then steps (#100)
Sma1lboy Jan 18, 2025
940119c
Concurrent frontend code generate
ZHallen122 Jan 19, 2025
707d779
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 19, 2025
ba87f34
fix currentFullFilePath
ZHallen122 Jan 20, 2025
027765d
specify <generate>tag and remove logger
ZHallen122 Jan 20, 2025
b5fb1a8
Ensure consistent handling by always requiring 'src' prefix
ZHallen122 Jan 20, 2025
12f285a
Ensure consistent handling by always requiring 'src' prefix
ZHallen122 Jan 20, 2025
7d3c56f
use retryable error
ZHallen122 Jan 20, 2025
77fa4f3
use retryable error
ZHallen122 Jan 20, 2025
67903f0
change node return string about file structure not json result
ZHallen122 Jan 20, 2025
7a21de5
file arch using messages
ZHallen122 Jan 20, 2025
a8cc115
update system prompt
ZHallen122 Jan 20, 2025
4cfb5b6
ResponseTagError change to RetryableError
ZHallen122 Jan 20, 2025
d2a57b7
add read file retry
ZHallen122 Jan 21, 2025
6f3ede5
fix(frontend): fix some ui issue and chat message thread issues (#101)
NarwhalChen Jan 22, 2025
4a80f03
add retry to the frontend code generate
ZHallen122 Jan 22, 2025
c475dc6
pass json
ZHallen122 Jan 22, 2025
57737e6
fix: fixing bug of cannot delete chat history (#102)
NarwhalChen Jan 23, 2025
55deed8
frontend generate test
ZHallen122 Jan 24, 2025
19af1ec
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 24, 2025
7bdfba9
update prompt to correct add router depencies
ZHallen122 Jan 24, 2025
b97e552
update prompt
ZHallen122 Jan 26, 2025
d632f10
add s for folders
ZHallen122 Jan 27, 2025
407230d
Feat adding collapseable sidebar (#103)
NarwhalChen Jan 27, 2025
dd0881c
remove index.tsx in folder
ZHallen122 Jan 27, 2025
c245b8c
update
ZHallen122 Jan 28, 2025
67e2f83
update frontend code prompt
ZHallen122 Jan 28, 2025
e043c83
add tailwindcss to template
ZHallen122 Jan 28, 2025
4fa4e0f
[autofix.ci] apply automated fixes
autofix-ci[bot] Jan 28, 2025
7345d6f
update file struct
ZHallen122 Jan 28, 2025
38bdf47
fix(backend): Fix frontend template (#104)
Sma1lboy Jan 28, 2025
7aaf98e
chore(backend): adding log inside of context (#105)
Sma1lboy Jan 30, 2025
46e13e2
refactor(backedn): adjusting prompt to reduce parsing error (#106)
ZHallen122 Jan 30, 2025
4449b09
chore(backend): Chore more fix on prompt (#107)
Sma1lboy Jan 30, 2025
1fa9f47
Feat adding profilepage (#108)
NarwhalChen Jan 31, 2025
1a0a2d7
add comment
ZHallen122 Jan 31, 2025
42d9525
Comment whole file and unuse delete file
ZHallen122 Jan 31, 2025
ce478e4
fix incorrect logic and add platform
ZHallen122 Jan 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 69 additions & 119 deletions backend/src/build-system/__tests__/fullstack-gen.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { isIntegrationTest } from 'src/common/utils';
import { BuildSequence } from '../types';
import { executeBuildSequence } from './utils';
import { Logger } from '@nestjs/common';
import { ProjectInitHandler } from '../handlers/project-init';
import { PRDHandler } from '../handlers/product-manager/product-requirements-document/prd';
import { UXSMDHandler } from '../handlers/ux/sitemap-document';
import { UXSMSHandler } from '../handlers/ux/sitemap-structure';
import { DBRequirementHandler } from '../handlers/database/requirements-document';
import { FileStructureHandler } from '../handlers/file-manager/file-structure';
import { UXSMSPageByPageHandler } from '../handlers/ux/sitemap-structure/sms-page';
import { DBSchemaHandler } from '../handlers/database/schemas/schemas';
import { FileFAHandler } from '../handlers/file-manager/file-arch';
import { BackendRequirementHandler } from '../handlers/backend/requirements-document';
import { BackendCodeHandler } from '../handlers/backend/code-generate';
import { BackendFileReviewHandler } from '../handlers/backend/file-review/file-review';
import { UXDMDHandler } from '../handlers/ux/datamap';
import { BuilderContext } from '../context';
import { FrontendCodeHandler } from '../handlers/frontend-code-generate';

(isIntegrationTest ? describe : describe.skip)('Build Sequence Test', () => {
it('should execute build sequence successfully', async () => {
const sequence: BuildSequence = {
Expand All @@ -10,140 +24,76 @@ import { Logger } from '@nestjs/common';
name: 'Spotify-like Music Web',
description: 'Users can play music',
databaseType: 'SQLite',
steps: [
nodes: [
{
handler: ProjectInitHandler,
name: 'Project Folders Setup',
},
{
handler: PRDHandler,
name: 'Project Requirements Document Node',
},
{
handler: UXSMDHandler,
name: 'UX Sitemap Document Node',
},
{
id: 'step-0',
name: 'Project Initialization',
parallel: false,
nodes: [
{
id: 'op:PROJECT::STATE:SETUP',
name: 'Project Folders Setup',
},
],
handler: UXSMSHandler,
name: 'UX Sitemap Structure Node',
// requires: ['op:UX:SMD'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Uncomment dependencies to enforce build sequence validation.

The dependencies are commented out but appear to be necessary for proper build sequence validation.

Uncomment all the dependencies to ensure proper dependency checking:

-          // requires: ['op:UX:SMD'],
+          requires: ['op:UX:SMD'],

-          // requires: ['op:UX:DATAMAP:DOC'],
+          requires: ['op:UX:DATAMAP:DOC'],

-          // requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],
+          requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],

-          // requires: ['op:UX:SMS'],
+          requires: ['op:UX:SMS'],

-          // requires: ['op:DATABASE_REQ'],
+          requires: ['op:DATABASE_REQ'],

-          // requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],
+          requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],

-          // requires: ['op:DATABASE_REQ', 'op:UX:DATAMAP:DOC', 'op:UX:SMD'],
+          requires: ['op:DATABASE_REQ', 'op:UX:DATAMAP:DOC', 'op:UX:SMD'],

Also applies to: 52-52, 57-58, 65-65, 70-70, 75-75, 80-80

},
{
id: 'step-1',
name: 'Initial Analysis',
parallel: false,
nodes: [
{
id: 'op:PRD',
name: 'Project Requirements Document Node',
},
],
handler: UXDMDHandler,
name: 'UX DataMap Document Node',
},
{
id: 'step-2',
name: 'UX Base Document Generation',
parallel: false,
nodes: [
{
id: 'op:UX:SMD',
name: 'UX Sitemap Document Node',
requires: ['op:PRD'],
},
],
handler: DBRequirementHandler,
name: 'Database Requirements Node',
// requires: ['op:UX:DATAMAP:DOC'],
},
{
id: 'step-3',
name: 'Parallel UX Processing',
parallel: true,
nodes: [
{
id: 'op:UX:SMS',
name: 'UX Sitemap Structure Node',
requires: ['op:UX:SMD'],
},
{
id: 'op:UX:DATAMAP:DOC',
name: 'UX DataMap Document Node',
requires: ['op:UX:SMD'],
},
],
handler: FileStructureHandler,
name: 'File Structure Generation',
// requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],
options: {
projectPart: 'frontend',
},
},
{
id: 'step-4',
name: 'Parallel Project Structure',
parallel: true,
nodes: [
{
id: 'op:DATABASE_REQ',
name: 'Database Requirements Node',
requires: ['op:UX:DATAMAP:DOC'],
},
{
id: 'op:FILE:STRUCT',
name: 'File Structure Generation',
requires: ['op:UX:SMD', 'op:UX:DATAMAP:DOC'],
options: {
projectPart: 'frontend',
},
},
{
id: 'op:UX:SMS:LEVEL2',
name: 'Level 2 UX Sitemap Structure Node details',
requires: ['op:UX:SMS'],
},
],
handler: UXSMSPageByPageHandler,
name: 'Level 2 UX Sitemap Structure Node details',
// requires: ['op:UX:SMS'],
},
{
id: 'step-5',
name: 'Parallel Implementation',
parallel: true,
nodes: [
{
id: 'op:DATABASE:SCHEMAS',
name: 'Database Schemas Node',
requires: ['op:DATABASE_REQ'],
},
{
id: 'op:FILE:ARCH',
name: 'File Arch',
requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],
},
{
id: 'op:BACKEND:REQ',
name: 'Backend Requirements Node',
requires: ['op:DATABASE_REQ', 'op:UX:DATAMAP:DOC', 'op:UX:SMD'],
},
],
handler: DBSchemaHandler,
name: 'Database Schemas Node',
// requires: ['op:DATABASE_REQ'],
},
{
id: 'step-6',
name: 'Final Code Generation',
parallel: false,
nodes: [
{
id: 'op:BACKEND:CODE',
name: 'Backend Code Generator Node',
requires: [
'op:DATABASE:SCHEMAS',
'op:UX:DATAMAP:DOC',
'op:BACKEND:REQ',
],
},
],
handler: FileFAHandler,
name: 'File Arch',
// requires: ['op:FILE:STRUCT', 'op:UX:DATAMAP:DOC'],
},
// TODO: code reviewer
{
id: 'step-7',
name: 'Backend Code Review',
parallel: false,
nodes: [
{
id: 'op:BACKEND:FILE:REVIEW',
name: 'Backend File Review Node',
requires: ['op:BACKEND:CODE', 'op:BACKEND:REQ'],
},
],
handler: BackendRequirementHandler,
name: 'Backend Requirements Node',
// requires: ['op:DATABASE_REQ', 'op:UX:DATAMAP:DOC', 'op:UX:SMD'],
},
{
handler: BackendCodeHandler,
name: 'Backend Code Generator Node',
},
{
handler: BackendFileReviewHandler,
name: 'Backend File Review Node',
},
{
handler: FrontendCodeHandler,
name: 'Frontend Code Generator Node',
},
],
};

const result = await executeBuildSequence('fullstack-code-gen', sequence);
expect(result.success).toBe(true);
expect(result.metrics).toBeDefined();
Logger.log(`Logs saved to: ${result.logFolderPath}`);
const context = new BuilderContext(sequence, 'fullstack-code-gen');
await context.execute();
}, 300000);
});
112 changes: 112 additions & 0 deletions backend/src/build-system/__tests__/mock/MockBuilderContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { VirtualDirectory } from '../../virtual-dir';
import { readFileSync } from 'fs';
import { resolve } from 'path';
import * as path from 'path';
import { UXSMSHandler } from 'src/build-system/handlers/ux/sitemap-structure';
import { UXDMDHandler } from 'src/build-system/handlers/ux/datamap';
import { BackendRequirementHandler } from 'src/build-system/handlers/backend/requirements-document';
import { FileFAHandler } from 'src/build-system/handlers/file-manager/file-arch';
import { BuilderContext, GlobalDataKeys } from 'src/build-system/context';
import { v4 as uuidv4 } from 'uuid'; // UUID generator for unique identifiers
import {
BuildExecutionState,
BuildHandlerConstructor,
BuildSequence,
ExtractHandlerReturnType,
} from 'src/build-system/types';
import { buildProjectPath, copyProjectTemplate } from '../../utils/files';

export class MockBuilderContext extends BuilderContext {
private mockNodeData: Map<BuildHandlerConstructor, any> = new Map();
private mockGlobalContext: Map<GlobalDataKeys | string, any> = new Map();
virtualDirectory: VirtualDirectory;

constructor(sequence: BuildSequence, id: string) {
super(sequence, id); // Call the parent constructor to initialize inherited properties
this.virtualDirectory = new VirtualDirectory(); // Initialize the mock virtual directory
const uuid =
new Date().toISOString().slice(0, 10).replace(/:/g, '-') + '-' + uuidv4();

// Read mock data from files
const uxSitemapStructure = this.readMockFile(
path.join(__dirname, 'test_files', 'UX_Sitemap_Structure_Node.md'),
);
const uxDataMapDocument = this.readMockFile(
path.join(__dirname, 'test_files', 'UX_DataMap_Document_Node.md'),
);
const backendRequirements = this.readMockFile(
path.join(__dirname, 'test_files', 'Backend_Requirements_Node.md'),
);
const fileStructure = this.readMockFile(
path.join(__dirname, 'test_files', 'File_Structure_Generation.md'),
);
const fileArchitecture = this.readMockFile(
path.join(__dirname, 'test_files', 'File_Arch.md'),
);

this.mockNodeData.set(UXSMSHandler, uxSitemapStructure);
this.mockNodeData.set(UXDMDHandler, uxDataMapDocument);
this.mockNodeData.set(BackendRequirementHandler, backendRequirements);
this.mockNodeData.set(FileFAHandler, fileArchitecture);
this.buildVirtualDirectory(fileStructure);

copyProjectTemplate(
path.join(__dirname, '..', '..', '..', '..', 'template', 'react-ts'),
uuid,
'frontend',
);

// Set up mock data for globalContext
this.mockGlobalContext.set(
'frontendPath',
buildProjectPath(uuid, 'frontend'),
);
}

setGlobalContext<Key extends GlobalDataKeys | string>(
key: Key,
value: any,
): void {
this.mockGlobalContext.set(key, value);
}

setNodeData<T extends BuildHandlerConstructor>(
handlerClass: T,
data: ExtractHandlerReturnType<T>,
): void {
this.mockNodeData.set(handlerClass, data);
}

getExecutionState(): BuildExecutionState {
return {} as BuildExecutionState; // Return a mock execution state
}

buildVirtualDirectory(jsonContent: string): boolean {
return this.virtualDirectory.parseJsonStructure(jsonContent);
}

execute(): Promise<void> {
return Promise.resolve(); // Mock a resolved promise for execution
}

getNodeData(handler: any): any {
return this.mockNodeData.get(handler) || null;
}

getGlobalContext(key: string): any {
return this.mockGlobalContext.get(key) || null;
}

// Helper method to read files
private readMockFile(filePath: string): string {
try {
const absolutePath = resolve(filePath); // Resolve the file path
return readFileSync(absolutePath, 'utf-8'); // Read the file content
} catch (err) {
console.error(`Error reading file at ${filePath}:`, err);

Check warning on line 106 in backend/src/build-system/__tests__/mock/MockBuilderContext.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected console statement
return ''; // Return an empty string if file read fails
}
}

// Add other methods as necessary for mocking
}
Loading
Loading