From 3e6e8abbc39f3ae69d97bf1194306d7ea0a23798 Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Fri, 13 Dec 2024 17:19:09 -0600 Subject: [PATCH 01/10] feat(backend): implement DBSchemaHandler for dynamic database schema generation --- .../node/database-schemas/schemas.ts | 168 +++++++++++++++--- .../src/build-system/utils/database-utils.ts | 94 ++++++++++ 2 files changed, 238 insertions(+), 24 deletions(-) create mode 100644 backend/src/build-system/utils/database-utils.ts diff --git a/backend/src/build-system/node/database-schemas/schemas.ts b/backend/src/build-system/node/database-schemas/schemas.ts index 44a1c7cd..9de4f423 100644 --- a/backend/src/build-system/node/database-schemas/schemas.ts +++ b/backend/src/build-system/node/database-schemas/schemas.ts @@ -1,48 +1,168 @@ import { BuildHandler, BuildResult } from 'src/build-system/types'; import { BuilderContext } from 'src/build-system/context'; -import { prompts } from './prompt'; import { Logger } from '@nestjs/common'; +import { + DatabaseType, + getSchemaFileExtension, + getSupportedDatabaseTypes, + isSupportedDatabaseType, + parseGenerateTag, +} from '../../utils/database-utils'; +import { writeFile } from 'fs-extra'; +import { prompts } from './prompt'; + +/** + * Defines the expected order and types of arguments for DBSchemaHandler. + * + * Expected argument order: + * 0 - dbRequirements: string + */ +type DBSchemaArgs = [dbRequirements: string]; +/** + * DBSchemaHandler is responsible for generating database schemas based on provided requirements. + */ export class DBSchemaHandler implements BuildHandler { - readonly id = 'OP:DATABASE:SCHEMAS'; + readonly id = 'op:DATABASE:SCHEMAS'; + private readonly logger: Logger = new Logger('DBSchemaHandler'); - readonly logger = new Logger('DBSchemaHandler'); + /** + * Executes the handler to generate database schemas. + * @param context - The builder context containing configuration and utilities. + * @param args - The variadic arguments required for generating the database schemas. + * @returns A BuildResult containing the generated schema content and related data. + */ + async run(context: BuilderContext, ...args: any[]): Promise { + this.logger.log('Generating Database Schemas...'); - async run(context: BuilderContext, args: unknown): Promise { + // Retrieve projectName and databaseType from context const projectName = context.getData('projectName') || 'Default Project Name'; const databaseType = context.getData('databaseType') || 'PostgreSQL'; + this.logger.debug(`Project Name: ${projectName}`); + this.logger.debug(`Database Type: ${databaseType}`); + + // Validate and extract args + if (!args || !Array.isArray(args)) { + throw new Error( + 'Database schema generation requires specific configuration arguments as an array.', + ); + } + + const [dbRequirements] = args as DBSchemaArgs; + this.logger.debug('Database requirements are provided.'); + + // Check if the databaseType is supported + if (!isSupportedDatabaseType(databaseType)) { + throw new Error( + `Unsupported database type: ${databaseType}. Supported types are: ${getSupportedDatabaseTypes().join( + ', ', + )}.`, + ); + } + + // Get the file extension for the schema + let fileExtension: string; + try { + fileExtension = getSchemaFileExtension(databaseType as DatabaseType); + } catch (error) { + this.logger.error('Error determining schema file extension:', error); + throw new Error( + `Failed to determine schema file extension for database type: ${databaseType}.`, + ); + } + + this.logger.debug(`Schema file extension: .${fileExtension}`); + + // Step 1: Analyze database requirements const analysisPrompt = prompts.analyzeDatabaseRequirements( projectName, - args as string, + dbRequirements, databaseType, ); - const dbAnalysis = await context.model.chatSync( - { - content: analysisPrompt, - }, - 'gpt-4o-mini', - ); + let dbAnalysis: string; + try { + // Invoke the language model to analyze database requirements + const analysisResponse = await context.model.chatSync( + { + content: analysisPrompt, + }, + 'gpt-4o-mini', // Specify the model variant as needed + ); - const schemaPrompt = prompts.generateDatabaseSchema( - dbAnalysis, - databaseType, - ); + // Parse the tag to extract DBAnalysis content + dbAnalysis = parseGenerateTag(analysisResponse); + } catch (error) { + this.logger.error('Error during database requirements analysis:', error); + return { + success: false, + error: new Error('Failed to analyze database requirements.'), + }; + } - const schemaContent = await context.model.chatSync( - { - content: schemaPrompt, - }, - 'gpt-4o-mini', - ); + this.logger.debug('Database requirements analyzed successfully.'); + + // Step 2: Generate database schema based on analysis + let schemaPrompt: string; + try { + schemaPrompt = prompts.generateDatabaseSchema( + dbAnalysis, + databaseType, + fileExtension, + ); + } catch (error) { + this.logger.error('Error during schema prompt generation:', error); + return { + success: false, + error: new Error('Failed to generate schema prompt.'), + }; + } + + let schemaContent: string; + try { + // Invoke the language model to generate the database schema + const schemaResponse = await context.model.chatSync( + { + content: schemaPrompt, + }, + 'gpt-4o-mini', // Specify the model variant as needed + ); + + // Parse the tag to extract schema content + schemaContent = parseGenerateTag(schemaResponse); + } catch (error) { + this.logger.error('Error during schema generation:', error); + return { + success: false, + error: new Error('Failed to generate database schema.'), + }; + } + + this.logger.debug('Database schema generated successfully.'); + + // Define the schema file name + const schemaFileName = `schema.${fileExtension}`; + + // Write the schemaContent to a file + try { + await writeFile(schemaFileName, schemaContent, 'utf-8'); + this.logger.log(`Schema file (${schemaFileName}) written successfully.`); + } catch (error) { + this.logger.error('Error writing schema file:', error); + return { + success: false, + error: new Error('Failed to write schema file.'), + }; + } + + this.logger.debug(`Schema file (${schemaFileName}) prepared.`); + // Return the generated schema content and file information return { success: true, - data: { - schema: schemaContent, - }, + data: schemaContent, }; } } diff --git a/backend/src/build-system/utils/database-utils.ts b/backend/src/build-system/utils/database-utils.ts new file mode 100644 index 00000000..e9bdd589 --- /dev/null +++ b/backend/src/build-system/utils/database-utils.ts @@ -0,0 +1,94 @@ +/** + * Supported database types. + */ +export enum DatabaseType { + PostgreSQL = 'PostgreSQL', + MongoDB = 'MongoDB', + SQLite = 'SQLite', + MySQL = 'MySQL', + MariaDB = 'MariaDB', + Oracle = 'Oracle', + SQLServer = 'SQLServer', +} + +/** + * Mapping of database types to their corresponding schema file extensions. + */ +const databaseSchemaExtensions: Record = { + [DatabaseType.PostgreSQL]: 'sql', + [DatabaseType.MongoDB]: 'js', + [DatabaseType.SQLite]: 'sql', + [DatabaseType.MySQL]: 'sql', + [DatabaseType.MariaDB]: 'sql', + [DatabaseType.Oracle]: 'sql', + [DatabaseType.SQLServer]: 'sql', +}; + +/** + * Retrieves the schema file extension based on the provided database type. + * @param databaseType - The type of the database. + * @returns The corresponding schema file extension. + * @throws Error if the database type is unsupported. + */ +export function getSchemaFileExtension(databaseType: DatabaseType): string { + const extension = databaseSchemaExtensions[databaseType]; + if (!extension) { + throw new Error( + `Unsupported database type: ${databaseType}. Supported types are: ${Object.values( + DatabaseType, + ).join(', ')}.`, + ); + } + return extension; +} + +/** + * Validates whether the provided database type is supported. + * @param databaseType - The type of the database. + * @returns True if supported, false otherwise. + */ +export function isSupportedDatabaseType( + databaseType: string, +): databaseType is DatabaseType { + return Object.values(DatabaseType).includes(databaseType as DatabaseType); +} + +/** + * Retrieves the list of supported database types. + * @returns An array of supported database type strings. + */ +export function getSupportedDatabaseTypes(): string[] { + return Object.values(DatabaseType); +} + +/** + * Extracts content within tags from a given string. + * @param input - The input string containing tags. + * @returns The content within the tags. + * @throws Error if the tags are missing or improperly formatted. + */ +export function parseGenerateTag(input: string): string { + const generateTagRegex = /([\s\S]*?)<\/GENERATE>/; + const match = input.match(generateTagRegex); + if (!match || match.length < 2) { + throw new Error( + 'Invalid format: tags are missing or improperly formatted.', + ); + } + return match[1].trim(); +} + +/** + * Removes Markdown code block fences (e.g. ``` or ```javascript) from the given string. + * This function will remove lines that contain triple backticks, leaving only the actual code content. + * + * @param input - The input string potentially containing Markdown code fences. + * @returns The input string without Markdown code block fences. + */ +export function removeCodeBlockFences(input: string): string { + return input + .split('\n') + .filter((line) => !line.trim().startsWith('```')) + .join('\n') + .trim(); +} From 30d1fba04168d5d5abcc0803a7fe2036e3946f80 Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Fri, 13 Dec 2024 17:19:25 -0600 Subject: [PATCH 02/10] feat(backend): add BackendCodeHandler for dynamic backend code generation with enhanced prompt structure --- .../node/backend-code-generate/index.ts | 106 +++++++++++++++ .../node/backend-code-generate/prompt.ts | 124 ++++++++++-------- 2 files changed, 178 insertions(+), 52 deletions(-) create mode 100644 backend/src/build-system/node/backend-code-generate/index.ts diff --git a/backend/src/build-system/node/backend-code-generate/index.ts b/backend/src/build-system/node/backend-code-generate/index.ts new file mode 100644 index 00000000..f2815cf4 --- /dev/null +++ b/backend/src/build-system/node/backend-code-generate/index.ts @@ -0,0 +1,106 @@ +import { BuildHandler, BuildResult } from 'src/build-system/types'; +import { BuilderContext } from 'src/build-system/context'; +import { generateBackendCodePrompt } from './prompt'; +import { Logger } from '@nestjs/common'; +import { + parseGenerateTag, + removeCodeBlockFences, +} from 'src/build-system/utils/database-utils'; + +/** + * Defines the expected order and types of arguments for BackendCodeHandler. + * + * @param sitemapDoc - The sitemap documentation as a string. + * @param DatamapDoc - The data analysis document as a string. + * @param currentFile - (Optional) The name of the current file. Defaults to 'backend.js'. + * @param dependencyFile - (Optional) The name of the dependency file. Defaults to 'dependencies.json'. + */ +type BackendCodeArgs = [ + sitemapDoc: string, + DatamapDoc: string, + currentFile?: string, + dependencyFile?: string, +]; + +/** + * BackendCodeHandler is responsible for generating the backend codebase + * based on the provided sitemap and data mapping documents. + */ +export class BackendCodeHandler implements BuildHandler { + readonly id = 'op:BACKEND_CODE::STATE:GENERATE'; + readonly logger: Logger = new Logger('BackendCodeHandler'); + + /** + * Executes the handler to generate backend code. + * @param context - The builder context containing configuration and utilities. + * @param args - The variadic arguments required for generating the backend code. + * @returns A BuildResult containing the generated code and related data. + */ + async run(context: BuilderContext, ...args: any[]): Promise { + this.logger.log('Generating Backend Codebase...'); + + // Retrieve projectName from context + const projectName = + context.getData('projectName') || 'Default Project Name'; + this.logger.debug(`Project Name: ${projectName}`); + + // Validate and extract args + if (!args || !Array.isArray(args)) { + throw new Error( + 'Backend code generation requires specific configuration arguments as an array.', + ); + } + + // Destructure arguments with default values for optional parameters + const [ + sitemapDoc, + DatamapDoc, + currentFile = 'backend.js', + dependencyFile = 'dependencies.json', + ] = args as BackendCodeArgs; + + this.logger.debug( + 'Sitemap Documentation and Data Analysis Document are provided.', + ); + + // Generate the prompt using the provided documents and project name + const backendCodePrompt = generateBackendCodePrompt( + projectName, + sitemapDoc, + DatamapDoc, + currentFile, + dependencyFile, + ); + + // Log the prompt generation + this.logger.debug('Generated backend code prompt.'); + + try { + // Invoke the language model to generate the backend code + const modelResponse = await context.model.chatSync( + { + content: backendCodePrompt, + }, + 'gpt-4o-mini', // Specify the model variant as needed + ); + + const generatedCode = removeCodeBlockFences( + parseGenerateTag(modelResponse), + ); + + // Optionally, you can process or validate the generated code here + this.logger.debug('Backend code generated and parsed successfully.'); + + return { + success: true, + data: generatedCode, + }; + } catch (error) { + this.logger.error('Error during backend code generation:', error); + return { + success: false, + error: new Error('Failed to generate backend code.'), + }; + } + } +} diff --git a/backend/src/build-system/node/backend-code-generate/prompt.ts b/backend/src/build-system/node/backend-code-generate/prompt.ts index afe76a2a..0c700a6e 100644 --- a/backend/src/build-system/node/backend-code-generate/prompt.ts +++ b/backend/src/build-system/node/backend-code-generate/prompt.ts @@ -5,56 +5,76 @@ export const generateBackendCodePrompt = ( currentFile: string, dependencyFile: string, ): string => { - return `You are an expert backend developer. Your task is to generate a complete backend codebase within a single file for a project named "AwesomeApp". The code should be written using the Express framework and should include all necessary functionalities to cover essential backend operations while ensuring scalability and maintainability. - -### Based on the following input: - -- **Project Name:** ${projectName} -- **Sitemap Documentation:** ${sitemapDoc} -- **Data Analysis Document:** ${DatamapDoc} - -### Instructions and Rules: - -**Include:** -1. **Server Setup:** - - Initialize the server using the Express framework. - - Configure middleware for JSON parsing and CORS. - -2. **Route Definitions:** - - Define RESTful API endpoints based on the sitemap documentation. - - Implement at least two example routes (e.g., GET /api/users, POST /api/users). - -3. Include all controllers, model, and service in one file. - -4. **Error Handling:** - - Implement basic error handling middleware. - - Ensure that meaningful error messages are returned for invalid requests. - -5. **Comments and Documentation:** - - Add comments explaining the purpose of each section and major code blocks. - - Ensure the code is readable and follows best practices. - -**Do Not Include:** -- Database connections or ORM integrations. -- External service integrations. -- Complex business logic beyond basic CRUD operations. - -**File Naming and Structure:** -- Since all code is to be included in a single file, organize the code with clear sections using comments. -- Follow consistent coding conventions and formatting as per the Express standards. - -### Ask Yourself: -1. Are you covering all the necessary routes based on the sitemap documentation? If not, add the missing routes. -2. Are the controller functions adequately handling the requests and responses? If not, enhance them. -3. Is the error handling comprehensive enough for basic testing? If not, improve it. -4. Are the comments clear and descriptive to aid understanding and maintenance? - -### Output Format: - -Provide the backend code within markdown code blocks as follows: - -\`\`\`javascript -\`\`\` - - `; + return `You are an expert backend developer. Your task is to generate a complete backend codebase within a single file for a project named "${projectName}". The code should be written using the Express framework with ES Module syntax (using \`import\` statements) and should include all necessary functionalities to cover essential backend operations while ensuring scalability and maintainability. + + ### Based on the following input: + + - **Project Name:** ${projectName} + - **Sitemap Documentation:** ${sitemapDoc} + - **Data Analysis Document:** ${DatamapDoc} + + ### Instructions and Rules: + + **Include:** + 1. **Server Setup:** + - Initialize the server using the Express framework with ES Module syntax (use \`import\` instead of \`require\`). + - Configure middleware for JSON parsing and CORS. + + 2. **Database Connection:** + - Implement a separate section for database connection handling. + - Determine the database type (e.g., SQLite, PostgreSQL, MySQL) based on provided configuration. + - Use the appropriate connection method for the specified database type. + - Load and execute a schema script file (e.g., \`schema.sql\`) to initialize the database structure. + - Ensure that all CRUD operations interact with the database instead of using in-memory data structures. + + 3. **Route Definitions:** + - Define RESTful API endpoints based on the sitemap documentation. + - Implement at least two example routes (e.g., GET /api/users, POST /api/users) that perform CRUD operations using the database. + + 4. **Controllers, Models, and Services:** + - Include all controllers, models, and services within the single file, organized into clear sections using comments. + - Ensure that database interactions are encapsulated within appropriate service functions. + + 5. **Error Handling:** + - Implement basic error handling middleware. + - Ensure that meaningful error messages are returned for invalid requests. + + 6. **Comments and Documentation:** + - Add comments explaining the purpose of each section and major code blocks. + - Ensure the code is readable and follows best practices. + + **Do Not Include:** + - External service integrations beyond the specified database setup. + - Complex business logic beyond basic CRUD operations. + + **File Naming and Structure:** + - Since all code is to be included in a single file, organize the code with clear sections using comments. + - Follow consistent coding conventions and formatting as per the Express standards. + + **Special Requirements:** + - **ES Module Syntax:** Use \`import\` statements instead of \`require\`. + - **Database Handling:** + - Use the specified database type for database operations. + - Initialize the database connection using a schema script file (e.g., \`schema.sql\`). + - Avoid using in-memory data structures like arrays; all data should be persisted in the database. + + - **Environment Variables:** Utilize environment variables for configuration settings such as database connection details and server port. + + ### Ask Yourself: + 1. Are you covering all the necessary routes based on the sitemap documentation? If not, add the missing routes. + 2. Are the controller functions adequately handling the requests and responses using the database? If not, enhance them. + 3. Is the error handling comprehensive enough for basic testing? If not, improve it. + 4. Are the comments clear and descriptive to aid understanding and maintenance? + 5. Are you using ES Module syntax correctly throughout the code? + 6. Is the database connection handled appropriately based on the specified database type? + 7. Are you loading and executing the schema script file to initialize the database? + + ### Output Format: + + Provide the backend code within \`\` tags as follows: + + + // Your generated backend code goes here + + `; }; From e3e09e7bdfec8a84114b672a20790060c2e69c0a Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Fri, 13 Dec 2024 17:19:34 -0600 Subject: [PATCH 03/10] feat(backend): replace FileStructureHandler with enhanced version for improved file structure generation --- .../build-system/node/file-structure/index.ts | 178 ++++++++++++++++++ .../prompt.ts | 140 +++++--------- .../node/frontend-file-structure/index.ts | 79 -------- 3 files changed, 221 insertions(+), 176 deletions(-) create mode 100644 backend/src/build-system/node/file-structure/index.ts rename backend/src/build-system/node/{frontend-file-structure => file-structure}/prompt.ts (56%) delete mode 100644 backend/src/build-system/node/frontend-file-structure/index.ts diff --git a/backend/src/build-system/node/file-structure/index.ts b/backend/src/build-system/node/file-structure/index.ts new file mode 100644 index 00000000..9d17d06e --- /dev/null +++ b/backend/src/build-system/node/file-structure/index.ts @@ -0,0 +1,178 @@ +import { BuildHandler, BuildResult } from 'src/build-system/types'; +import { BuilderContext } from 'src/build-system/context'; +import { prompts } from './prompt'; +import { Logger } from '@nestjs/common'; + +/** + * Defines the expected order and types of arguments for FileStructureHandler. + * + * Expected argument order: + * 0 - sitemapDoc: string + * 1 - dataAnalysisDoc: string + * 2 - framework: string + * 3 - projectPart: 'frontend' | 'backend' + */ +type FileStructureArgs = [ + sitemapDoc: string, + dataAnalysisDoc: string, + framework: string, + projectPart: 'frontend' | 'backend', +]; + +/** + * FileStructureHandler is responsible for generating the project's file and folder structure + * based on the provided documentation. + */ +export class FileStructureHandler implements BuildHandler { + readonly id = 'op:FSTRUCT::STATE:GENERATE'; + private readonly logger: Logger = new Logger('FileStructureHandler'); + + /** + * Executes the handler to generate the file structure. + * @param context - The builder context containing configuration and utilities. + * @param args - The variadic arguments required for generating the file structure. + * @returns A BuildResult containing the generated file structure JSON and related data. + */ + async run(context: BuilderContext, ...args: any[]): Promise { + this.logger.log('Generating File Structure Document...'); + + // Retrieve projectName from context + const projectName = + context.getData('projectName') || 'Default Project Name'; + this.logger.debug(`Project Name: ${projectName}`); + + // Validate and extract args + if (!args || !Array.isArray(args)) { + throw new Error( + 'File structure generation requires specific configuration arguments as an array.', + ); + } + + // Destructure arguments with type assertion + const [sitemapDoc, dataAnalysisDoc, framework, projectPart] = + args as FileStructureArgs; + + // Validate required arguments + if (!sitemapDoc || typeof sitemapDoc !== 'string') { + throw new Error( + 'The first argument (sitemapDoc) is required and must be a string.', + ); + } + if (!dataAnalysisDoc || typeof dataAnalysisDoc !== 'string') { + throw new Error( + 'The second argument (dataAnalysisDoc) is required and must be a string.', + ); + } + if (!framework || typeof framework !== 'string') { + throw new Error( + 'The third argument (framework) is required and must be a string.', + ); + } + if ( + !projectPart || + (projectPart !== 'frontend' && projectPart !== 'backend') + ) { + throw new Error( + 'The fourth argument (projectPart) is required and must be either "frontend" or "backend".', + ); + } + + this.logger.debug(`Project Part: ${projectPart}`); + this.logger.debug( + 'Sitemap Documentation and Data Analysis Document are provided.', + ); + + // Generate the common file structure prompt + const prompt = prompts.generateCommonFileStructurePrompt( + projectName, + sitemapDoc, + dataAnalysisDoc, + framework, + projectPart, + ); + + let fileStructureContent: string; + try { + // Invoke the language model to generate the file structure content + fileStructureContent = await context.model.chatSync( + { + content: prompt, + }, + 'gpt-4o-mini', // Specify the model variant as needed + ); + } catch (error) { + this.logger.error('Error during file structure generation:', error); + return { + success: false, + error: new Error('Failed to generate file structure.'), + }; + } + + this.logger.debug('Generated file structure content.'); + + // Convert the tree structure to JSON using the appropriate prompt + const convertToJsonPrompt = + prompts.convertTreeToJsonPrompt(fileStructureContent); + + let fileStructureJsonContent: string | null = null; + let successBuild = false; + let retry = 0; + const retryChances = 2; + + while (!successBuild) { + if (retry > retryChances) { + this.logger.error( + 'Failed to build virtual directory after multiple attempts.', + ); + return { + success: false, + error: new Error( + 'Failed to build virtual directory after multiple attempts.', + ), + }; + } + + try { + // Invoke the language model to convert tree structure to JSON + fileStructureJsonContent = await context.model.chatSync( + { + content: convertToJsonPrompt, + }, + 'gpt-4o-mini', // Specify the model variant as needed + ); + } catch (error) { + this.logger.error('Error during tree to JSON conversion:', error); + return { + success: false, + error: new Error('Failed to convert file structure to JSON.'), + }; + } + + this.logger.debug('Converted file structure to JSON.'); + + // Attempt to build the virtual directory from the JSON structure + try { + successBuild = context.buildVirtualDirectory(fileStructureJsonContent); + } catch (error) { + this.logger.error('Error during virtual directory build:', error); + successBuild = false; + } + + if (!successBuild) { + this.logger.warn( + `Retrying to build virtual directory (${retry + 1}/${retryChances})...`, + ); + retry += 1; + } + } + + this.logger.log( + 'File structure JSON content and virtual directory built successfully.', + ); + + return { + success: true, + data: fileStructureJsonContent, + }; + } +} diff --git a/backend/src/build-system/node/frontend-file-structure/prompt.ts b/backend/src/build-system/node/file-structure/prompt.ts similarity index 56% rename from backend/src/build-system/node/frontend-file-structure/prompt.ts rename to backend/src/build-system/node/file-structure/prompt.ts index 0f6a1a42..0e36596f 100644 --- a/backend/src/build-system/node/frontend-file-structure/prompt.ts +++ b/backend/src/build-system/node/file-structure/prompt.ts @@ -1,67 +1,18 @@ +// src/build-system/prompts.ts + export const prompts = { + // 已被通用的 generateCommonFileStructurePrompt 取代 + /* generateFileStructurePrompt: ( projectName: string, sitemapDoc: string, DataAnalysisDoc: string, framework: string, ): string => { - return `You are an expert frontend developer. Your task is to generate a complete folder and file structure for the src directory of a frontend project. Include all necessary files and folders to cover UI, API calls, and local state management while ensuring scalability and maintainability. - Based on following input - - - Project name: ${projectName} - - Sitemap Documentation: ${sitemapDoc} - - Data Analysis Doc ${DataAnalysisDoc} - - ### Instructions and Rules: - -Include: - Folder Structure: - components: Reusable UI elements grouped by category (e.g., common, layout, specific). - contexts: Global state management (e.g., auth, theme, player). - hooks: Custom hooks for data fetching and state management. - pages: Route-specific views (e.g., Home, Search, Playlist). - utils: Utility functions (e.g., constants, helpers, validators). - api: Organized API logic (e.g., auth, music, user). - router.ts: Central routing configuration. - index.ts: Application entry point. - - Files: - Include placeholder files in each folder to illustrate their purpose. - Add example filenames for components, hooks, APIs, etc. - -Do Not Include: - Asset folders (e.g., images, icons, fonts). - Test folders or files. - Service folders unrelated to API logic. - -File Naming Guidelines: - Use meaningful and descriptive file names. - For components, include an index.tsx file in each folder to simplify imports. - Each component should have its own folder named after the component (e.g., Button/). - Use index.tsx as the main file inside the component folder. - Component-specific styles must be in index.css within the same folder as the component. - -File Comments: - Include comments describing the purpose of each file or folder to improve readability. - -Ask yourself: - 1, Are you consider all the cases based on the sitemap doc? If not add new folder or file - 2, Are you consider all the components based on the sitemap doc? If not add new folder or file - 3, Are you consider all the hooks based on the sitemap doc? If not add new folder or file - 4, Are you consider all the api based on the sitemap doc? If not add new folder or file - 5, Are you consider all the pages based on the sitemap doc? If not add new folder or file - -This final result must be 100% complete. Will be directly use in the production - -Output Format: - - Start with: "\`\`\`FolderStructure" - Tree format: - Include folder names with placeholder files inside. - Add comments to describe the purpose of each file/folder. - End with: "\`\`\`" - `; + // 原有的 generateFileStructurePrompt 内容 }, + */ + convertTreeToJsonPrompt: (treeMarkdown: string): string => { return `You are a highly skilled developer. Your task is to convert the given file and folder structure, currently represented in an ASCII tree format, into a JSON structure. The JSON structure must: @@ -115,6 +66,7 @@ Output Format: Return only the JSON structure (no explanations, no additional comments). This JSON will be used directly in the application. `; }, + generateCommonFileStructurePrompt: ( projectName: string, sitemapDoc: string, @@ -122,13 +74,12 @@ Output Format: framework: string, projectPart: string, ): string => { - // Define role and specific instructions based on project part let roleDescription = ''; let includeSections = ''; let excludeSections = ''; let fileNamingGuidelines = ''; - switch (projectPart) { + switch (projectPart.toLowerCase()) { case 'frontend': roleDescription = 'an expert frontend developer'; includeSections = ` @@ -141,10 +92,6 @@ Output Format: api: Organized API logic (e.g., auth, music, user). router.ts: Central routing configuration. index.ts: Application entry point. - - Files: - Include placeholder files in each folder to illustrate their purpose. - Add example filenames for components, hooks, APIs, etc. `; excludeSections = ` Do Not Include: @@ -192,45 +139,44 @@ Output Format: break; default: - throw new Error('Invalid project part specified.'); + throw new Error( + 'Invalid project part specified. Must be "frontend" or "backend".', + ); } return `You are ${roleDescription}. Your task is to generate a complete folder and file structure for the ${projectPart} of a project named "${projectName}". Include all necessary files and folders to cover the essential aspects while ensuring scalability and maintainability. - Based on the following input: - - - Project name: ${projectName} - - Sitemap Documentation: ${sitemapDoc} - - Data Analysis Doc: ${dataAnalysisDoc} - - ### Instructions and Rules: - - Include: - ${includeSections} - - ${fileNamingGuidelines} - - ${excludeSections} - - File Comments: - Include comments describing the purpose of each file or folder to improve readability. - - Ask yourself: - 1. Are you considering all the cases based on the sitemap doc? If not, add new folder or file. - 2. Are you considering all the components based on the sitemap doc? If not, add new folder or file. - 3. Are you considering all the hooks/services based on the sitemap doc? If not, add new folder or file. - 4. Are you considering all the APIs/routes based on the sitemap doc? If not, add new folder or file. - 5. Are you considering all the pages/controllers based on the sitemap doc? If not, add new folder or file. - - This final result must be 100% complete and ready for direct use in production. + Based on the following input: + + - Project name: ${projectName} + - Sitemap Documentation: ${sitemapDoc} + - Data Analysis Doc: ${dataAnalysisDoc} + + ### Instructions and Rules: + + Include: + ${includeSections} + + ${fileNamingGuidelines} + + ${excludeSections} + + File Comments: + Include comments describing the purpose of each file or folder to improve readability. + + Ask yourself: + 1. Are you considering all the cases based on the sitemap doc? If not, add new folder or file. + 2. Are you considering all the components/hooks/services/APIs/routes based on the sitemap doc? If not, add new folder or file. + + This final result must be 100% complete and ready for direct use in production. + + Output Format: - Output Format: - - Start with: "\`\`\`FolderStructure" - Tree format: - Include folder names with placeholder files inside. - Add comments to describe the purpose of each file/folder. - End with: "\`\`\`" - `; + Start with: "\`\`\`FolderStructure" + Tree format: + Include folder names with placeholder files inside. + Add comments to describe the purpose of each file/folder. + End with: "\`\`\`" + `; }, }; diff --git a/backend/src/build-system/node/frontend-file-structure/index.ts b/backend/src/build-system/node/frontend-file-structure/index.ts deleted file mode 100644 index 63fa13b0..00000000 --- a/backend/src/build-system/node/frontend-file-structure/index.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { BuildHandler, BuildResult } from 'src/build-system/types'; -import { BuilderContext } from 'src/build-system/context'; -import { ModelProvider } from 'src/common/model-provider'; -import { prompts } from './prompt'; -import { Logger } from '@nestjs/common'; - -export class FileStructureHandler implements BuildHandler { - readonly id = 'op:FSTRUCT::STATE:GENERATE'; - private readonly logger: Logger = new Logger('FileStructureHandler'); - - async run(context: BuilderContext, args: unknown): Promise { - this.logger.log('Generating File Structure Document...'); - - // extract relevant data from the context - const projectName = - context.getData('projectName') || 'Default Project Name'; - - const sitemapDoc = args[0] as string; - const dataMap = args[1] as string; - - if (!dataMap || !sitemapDoc) { - return { - success: false, - error: new Error('Missing required parameters: sitemapDoc or dataMap'), - }; - } - - const prompt = prompts.generateFileStructurePrompt( - projectName, - JSON.stringify(sitemapDoc, null, 2), - JSON.stringify(dataMap, null, 2), - 'FrameWork Holder', - ); - - // Call the chatSync function to get the file structure content. - const fileStructureContent = await context.model.chatSync( - { - content: prompt, - }, - 'gpt-4o-mini', - ); - - this.logger.log('For fileStructureContent debug: ' + fileStructureContent); - - const ToJsonPrompt = prompts.convertTreeToJsonPrompt(fileStructureContent); - - // Try to build the virtual directory from the JSON structure. - let successBuild = false; - let fileStructureJsonContent = null; - let retry = 0; - const retryChances = 2; - while (!successBuild) { - if (retry > retryChances) { - throw new Error( - 'Failed to build virtual directory after multiple attempts', - ); - } - fileStructureJsonContent = await context.model.chatSync( - { - content: ToJsonPrompt, - }, - 'gpt-4o-mini', - ); - - this.logger.log('fileStructureJsonContent: ' + fileStructureJsonContent); - - successBuild = context.buildVirtualDirectory(fileStructureJsonContent); - retry += 1; - } - - this.logger.log('fileStructureJsonContent success'); - this.logger.log('buildVirtualDirectory success'); - - return { - success: true, - data: fileStructureJsonContent, - }; - } -} From 1a6d05f78fdfaa513881730c7cb0733a3eb65e0a Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Fri, 13 Dec 2024 17:19:45 -0600 Subject: [PATCH 04/10] feat(backend): enhance database prompt functions for improved analysis and schema generation --- .../node/database-schemas/prompt.ts | 106 +++++++----------- 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/backend/src/build-system/node/database-schemas/prompt.ts b/backend/src/build-system/node/database-schemas/prompt.ts index 98411fc7..8949664a 100644 --- a/backend/src/build-system/node/database-schemas/prompt.ts +++ b/backend/src/build-system/node/database-schemas/prompt.ts @@ -1,25 +1,37 @@ +// src/build-system/prompts.ts + +/** + * Collection of prompt functions used for various build system operations. + */ + export const prompts = { - // Step 1: Analyze requirements and generate database tasks + /** + * Analyzes database requirements and generates a structured analysis. + * @param projectName - The name of the project. + * @param dbRequirements - The database requirements as a string. + * @param databaseType - The type of the database (e.g., PostgreSQL, MongoDB, SQLite). + * @returns A prompt string for the language model to perform the analysis. + */ analyzeDatabaseRequirements: ( projectName: string, dbRequirements: string, databaseType: string = 'PostgreSQL', ): string => { return `You are a Database Architect specializing in ${databaseType}. Your task is to analyze the provided database requirements document and create a clear plan for schema generation. Use the following requirements as input: - + ${dbRequirements} - -Generate a structured analysis describing what needs to be created for each database entity. Your reply must start with "\`\`\`DBAnalysis" and end with "\`\`\`". - + +Generate a structured analysis describing what needs to be created for each database entity. Your reply must start with "DBAnalysis" and end with "". + For each entity in the requirements: 1. What tables/collections need to be created 2. What indexes are necessary 3. What constraints must be enforced 4. What relationships need to be established - + Example output format: - -\`\`\`DBAnalysis + +DBAnalysis Database: ${projectName} Type: ${databaseType} @@ -54,68 +66,36 @@ Performance Considerations: 1. User table needs hash indexes on email and username 2. Playlist_songs needs index on position for queue management 3. Songs table needs full text search capability -\`\`\``; +`; }, - // Step 2: Generate actual schema based on analysis + /** + * Generates the database schema based on the analysis. + * @param dbAnalysis - The database analysis as a string. + * @param databaseType - The type of the database (e.g., PostgreSQL, MongoDB, SQLite). + * @param fileExtension - The file extension to use for the schema file. + * @returns A prompt string for the language model to generate the schema. + */ generateDatabaseSchema: ( dbAnalysis: string, databaseType: string = 'PostgreSQL', + fileExtension: string, ): string => { return `You are a Database Engineer specializing in ${databaseType}. Generate the complete database schema based on the following analysis, using appropriate ${databaseType} syntax and features: - - Here is dbAnalysis content {${dbAnalysis}} - + +Here is dbAnalysis content: + +${dbAnalysis} + + Rules for generation: -1. Use ${databaseType}-specific data types and features -2. Do not include any comments in the output -3. Use standardized naming conventions -4. Include all necessary constraints and indexes -5. Generate schema in the correct creation order for dependencies - -Your reply must start with "\`\`\`${databaseType}" and end with "\`\`\`". - -For PostgreSQL, output format should be like: -\`\`\`sql -CREATE TYPE subscription_type_enum AS ENUM ('FREE', 'PREMIUM', 'FAMILY'); - -CREATE TABLE users ( - id UUID DEFAULT gen_random_uuid(), - email VARCHAR(255) NOT NULL, - username VARCHAR(50) NOT NULL, - password_hash VARCHAR(255) NOT NULL, - subscription_type subscription_type_enum NOT NULL DEFAULT 'FREE', - preferences JSONB DEFAULT '{"theme":"light","audioQuality":"high"}', - created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (id), - UNIQUE (email), - UNIQUE (username) -); - -CREATE INDEX idx_users_email ON users(email); -[Continue with other tables...] -\`\`\` - -For MongoDB, output format should be like: -\`\`\`javascript -db.createCollection("users", { - validator: { - $jsonSchema: { - bsonType: "object", - required: ["email", "username", "password_hash", "subscription_type"], - properties: { - email: { bsonType: "string" }, - username: { bsonType: "string" }, - password_hash: { bsonType: "string" }, - subscription_type: { enum: ["FREE", "PREMIUM", "FAMILY"] } - } - } - } -}); - -db.users.createIndex({ "email": 1 }, { unique: true }); -[Continue with other collections...] -\`\`\``; +1. Use ${databaseType}-specific data types and features. +2. Do not include any comments in the output. +3. Use standardized naming conventions. +4. Include all necessary constraints and indexes. +5. Generate schema in the correct creation order for dependencies. + +Your reply must start with "" and end with "". +`; }, }; From 8c11e9cfb44798a925bf1decd4443c2595df9d09 Mon Sep 17 00:00:00 2001 From: Jackson Chen <541898146chen@gmail.com> Date: Fri, 13 Dec 2024 17:20:07 -0600 Subject: [PATCH 05/10] feat(backend): add BackendCodeHandler and DBSchemaHandler; update package.json and enhance virtual directory path normalization --- backend/package.json | 2 + .../test.backend-code-generator.spec.ts | 160 ++++++++++++++++++ backend/src/build-system/hanlder-manager.ts | 6 +- .../database-requirements-document/index.ts | 2 - backend/src/build-system/virtual-dir.ts | 8 +- 5 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 backend/src/build-system/__tests__/test.backend-code-generator.spec.ts diff --git a/backend/package.json b/backend/package.json index 418c0a38..7e412f37 100644 --- a/backend/package.json +++ b/backend/package.json @@ -37,6 +37,7 @@ "@nestjs/typeorm": "^10.0.2", "@types/bcrypt": "^5.0.2", "@types/fs-extra": "^11.0.4", + "@types/normalize-path": "^3.0.2", "bcrypt": "^5.1.1", "class-validator": "^0.14.1", "fs-extra": "^11.2.0", @@ -44,6 +45,7 @@ "graphql-subscriptions": "^2.0.0", "graphql-ws": "^5.16.0", "markdown-to-txt": "^2.0.1", + "normalize-path": "^3.0.0", "reflect-metadata": "^0.2.2", "rxjs": "^7.8.1", "sqlite3": "^5.1.7", diff --git a/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts b/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts new file mode 100644 index 00000000..71d4596d --- /dev/null +++ b/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts @@ -0,0 +1,160 @@ +/* eslint-disable no-console */ +import { BuilderContext } from 'src/build-system/context'; +import { BuildResult, BuildSequence } from '../types'; +import { BuildSequenceExecutor } from '../executor'; +import * as fs from 'fs'; +import * as path from 'path'; + +describe('Sequence: PRD -> UXSD -> UXDD -> UXSS -> DBSchemas -> BackendCodeGenerator', () => { + // Generate a unique folder with a timestamp + const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); + const logFolderPath = `./logs/backend_code_generator-${timestamp}`; + fs.mkdirSync(logFolderPath, { recursive: true }); + + /** + * Utility function to extract content within tags and write to .md files. + * @param handlerName - The name of the handler/node. + * @param data - The data returned by the handler/node. + */ + const writeMarkdownToFile = (handlerName: string, data: BuildResult) => { + try { + // Extract "data" field and ensure it's a string + const content: string = data?.data; + if (typeof content !== 'string') { + throw new Error(`Invalid data format for handler: ${handlerName}`); + } + + const sanitizedHandlerName = handlerName.replace(/[^a-zA-Z0-9_-]/g, '_'); + const filePath = path.join(logFolderPath, `${sanitizedHandlerName}.md`); + fs.writeFileSync(filePath, content, 'utf8'); + console.log(`Logged ${handlerName} result data to ${filePath}`); + } catch (error) { + console.error(`Failed to write markdown for ${handlerName}:`, error); + throw error; + } + }; + + it('should execute the backend code generation sequence and log results to individual files', async () => { + // Define the build sequence up to Backend Code Generator + const sequence: BuildSequence = { + id: 'test-backend-sequence', + version: '1.0.0', + name: 'Test PRD to Backend Code Generation Sequence', + description: + 'Testing sequence execution from PRD to Backend Code Generation', + steps: [ + { + id: 'step-1', + name: 'Generate PRD', + nodes: [ + { + id: 'op:PRD::STATE:GENERATE', + name: 'PRD Generation Node', + type: 'ANALYSIS', + subType: 'PRD', + }, + ], + }, + { + id: 'step-2', + name: 'Generate UX Sitemap Document', + nodes: [ + { + id: 'op:UXSMD::STATE:GENERATE', + name: 'UX Sitemap Document Node', + type: 'UX', + subType: 'SITEMAP', + requires: ['op:PRD::STATE:GENERATE'], + }, + ], + }, + { + id: 'step-3', + name: 'Generate UX Data Map Document', + nodes: [ + { + id: 'op:UX_DATAMAP::STATE:GENERATE', + name: 'UX Data Map Document Node', + type: 'UX', + subType: 'DATAMAP', + requires: ['op:UXSMD::STATE:GENERATE'], + }, + ], + }, + { + id: 'step-4', + name: 'Generate Database Schemas', + nodes: [ + { + id: 'op:DATABASE:SCHEMAS', + name: 'Database Schemas Node', + type: 'DATABASE', + subType: 'SCHEMAS', + requires: ['op:UX_DATAMAP::STATE:GENERATE'], + }, + ], + }, + { + id: 'step-5', + name: 'Generate Backend Code', + nodes: [ + { + id: 'op:BACKEND_CODE::STATE:GENERATE', + name: 'Backend Code Generator Node', + type: 'BACKEND', + requires: [ + 'op:DATABASE:SCHEMAS', + 'op:UX_DATAMAP::STATE:GENERATE', + ], + }, + ], + }, + ], + }; + + // Initialize the BuilderContext with the defined sequence and environment + const context = new BuilderContext(sequence, 'test-env'); + + // Set input data for context + context.setData('projectName', 'Spotify-like Music Web'); + context.setData('description', 'Users can play music'); + context.setData('platform', 'web'); + context.setData('databaseType', 'SQLite'); // Can be 'PostgreSQL', 'MongoDB', etc., based on your needs + + try { + // Execute the build sequence + await BuildSequenceExecutor.executeSequence(sequence, context); + + // Iterate through each step and node to retrieve and log results + for (const step of sequence.steps) { + for (const node of step.nodes) { + const resultData = await context.getResult(node.id); + console.log(`Result for ${node.name}:`, resultData); + + if (resultData && resultData.success) { + writeMarkdownToFile(node.name, resultData); + } else if (resultData && !resultData.success) { + console.error( + `Handler ${node.name} failed with error:`, + resultData.error, + ); + // Optionally, you can log this to a separate file or handle it as needed + } + } + } + + console.log( + 'Sequence executed successfully. Logs stored in:', + logFolderPath, + ); + } catch (error) { + console.error('Error during sequence execution:', error); + fs.writeFileSync( + path.join(logFolderPath, 'error.txt'), + `Error: ${error.message}\n${error.stack}`, + 'utf8', + ); + throw new Error('Sequence execution failed.'); + } + }, 600000); // Timeout set to 10 minutes +}); diff --git a/backend/src/build-system/hanlder-manager.ts b/backend/src/build-system/hanlder-manager.ts index 4760a77d..b02a5851 100644 --- a/backend/src/build-system/hanlder-manager.ts +++ b/backend/src/build-system/hanlder-manager.ts @@ -4,8 +4,10 @@ import { PRDHandler } from './node/product-requirements-document/prd'; import { UXSitemapStructureHandler } from './node/ux-sitemap-structure'; import { UXDatamapHandler } from './node/ux-datamap'; import { UXSMDHandler } from './node/ux-sitemap-document/uxsmd'; -import { FileStructureHandler } from './node/frontend-file-structure'; +import { FileStructureHandler } from './node/file-structure'; import { FileArchGenerateHandler } from './node/file-arch'; +import { BackendCodeHandler } from './node/backend-code-generate'; +import { DBSchemaHandler } from './node/database-schemas/schemas'; export class BuildHandlerManager { private static instance: BuildHandlerManager; @@ -24,6 +26,8 @@ export class BuildHandlerManager { new UXSMDHandler(), new FileStructureHandler(), new FileArchGenerateHandler(), + new BackendCodeHandler(), + new DBSchemaHandler(), ]; for (const handler of builtInHandlers) { diff --git a/backend/src/build-system/node/database-requirements-document/index.ts b/backend/src/build-system/node/database-requirements-document/index.ts index 9219df74..7141b310 100644 --- a/backend/src/build-system/node/database-requirements-document/index.ts +++ b/backend/src/build-system/node/database-requirements-document/index.ts @@ -1,8 +1,6 @@ import { BuildHandler, BuildResult } from 'src/build-system/types'; import { BuilderContext } from 'src/build-system/context'; import { ModelProvider } from 'src/common/model-provider'; -import * as fs from 'fs'; -import * as path from 'path'; import { prompts } from './prompt'; import { Logger } from '@nestjs/common'; diff --git a/backend/src/build-system/virtual-dir.ts b/backend/src/build-system/virtual-dir.ts index d9d568c4..aa33ee02 100644 --- a/backend/src/build-system/virtual-dir.ts +++ b/backend/src/build-system/virtual-dir.ts @@ -1,5 +1,5 @@ +import normalizePath from 'normalize-path'; import * as path from 'path'; -import * as normalizePath from 'normalize-path'; interface VirtualNode { name: string; @@ -70,7 +70,7 @@ export class VirtualDirectory { } private findNode(inputPath: string): VirtualNode | null { - const normalizedPath = this.normalize_Path(inputPath); + const normalizedPath = this.normalizePath(inputPath); const parts = normalizedPath.split('/').filter(Boolean); if (parts[0] !== 'src') { @@ -86,14 +86,14 @@ export class VirtualDirectory { return current; } - private normalize_Path(inputPath: string): string { + private normalizePath(inputPath: string): string { return normalizePath(inputPath); } resolveRelativePath(fromFile: string, toPath: string): string { const fromDir = path.dirname(fromFile); const resolvedPath = path.join(fromDir, toPath).replace(/\\/g, '/'); - return this.normalize_Path(resolvedPath); + return this.normalizePath(resolvedPath); } getAllFiles(): string[] { From 9ed8053110811b052ea19579ee203973af18ded5 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:21:36 +0000 Subject: [PATCH 06/10] [autofix.ci] apply automated fixes --- pnpm-lock.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a1e0dd72..bf955169 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,9 @@ importers: '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4 + '@types/normalize-path': + specifier: ^3.0.2 + version: 3.0.2 bcrypt: specifier: ^5.1.1 version: 5.1.1 @@ -90,6 +93,9 @@ importers: markdown-to-txt: specifier: ^2.0.1 version: 2.0.1 + normalize-path: + specifier: ^3.0.0 + version: 3.0.0 reflect-metadata: specifier: ^0.2.2 version: 0.2.2 @@ -5642,6 +5648,10 @@ packages: dependencies: undici-types: 6.20.0 + /@types/normalize-path@3.0.2: + resolution: {integrity: sha512-DO++toKYPaFn0Z8hQ7Tx+3iT9t77IJo/nDiqTXilgEP+kPNIYdpS9kh3fXuc53ugqwp9pxC1PVjCpV1tQDyqMA==} + dev: false + /@types/parse-json@4.0.2: resolution: {integrity: sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==} dev: true @@ -6404,6 +6414,7 @@ packages: resolution: {integrity: sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==} engines: {node: ^12.13.0 || ^14.15.0 || >=16.0.0} deprecated: This package is no longer supported. + requiresBuild: true dependencies: delegates: 1.0.0 readable-stream: 3.6.2 @@ -6611,7 +6622,7 @@ packages: resolution: {integrity: sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==} dependencies: follow-redirects: 1.15.9(debug@4.3.7) - form-data: 4.0.0 + form-data: 4.0.1 proxy-from-env: 1.1.0 transitivePeerDependencies: - debug @@ -9022,6 +9033,7 @@ packages: resolution: {integrity: sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==} engines: {node: ^12.13.0 || ^14.15.0 || >=16.0.0} deprecated: This package is no longer supported. + requiresBuild: true dependencies: aproba: 2.0.0 color-support: 1.1.3 From 744530d16c0a2f40d8bfa8dea56d2b3b824c7cdc Mon Sep 17 00:00:00 2001 From: ZHallen122 Date: Sat, 14 Dec 2024 11:28:50 -0500 Subject: [PATCH 07/10] update --- .../build-system/node/backend-code-generate/index.ts | 4 ++++ .../build-system/node/backend-code-generate/prompt.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/src/build-system/node/backend-code-generate/index.ts b/backend/src/build-system/node/backend-code-generate/index.ts index f2815cf4..f1dec055 100644 --- a/backend/src/build-system/node/backend-code-generate/index.ts +++ b/backend/src/build-system/node/backend-code-generate/index.ts @@ -43,6 +43,9 @@ export class BackendCodeHandler implements BuildHandler { const projectName = context.getData('projectName') || 'Default Project Name'; this.logger.debug(`Project Name: ${projectName}`); + const databaseType = + context.getData('databaseType') || 'Default database type'; + this.logger.debug(`Database Type: ${databaseType}`); // Validate and extract args if (!args || !Array.isArray(args)) { @@ -68,6 +71,7 @@ export class BackendCodeHandler implements BuildHandler { projectName, sitemapDoc, DatamapDoc, + databaseType, currentFile, dependencyFile, ); diff --git a/backend/src/build-system/node/backend-code-generate/prompt.ts b/backend/src/build-system/node/backend-code-generate/prompt.ts index 0c700a6e..2d13b873 100644 --- a/backend/src/build-system/node/backend-code-generate/prompt.ts +++ b/backend/src/build-system/node/backend-code-generate/prompt.ts @@ -2,13 +2,15 @@ export const generateBackendCodePrompt = ( projectName: string, sitemapDoc: string, DatamapDoc: string, + databaseType: string, currentFile: string, dependencyFile: string, ): string => { - return `You are an expert backend developer. Your task is to generate a complete backend codebase within a single file for a project named "${projectName}". The code should be written using the Express framework with ES Module syntax (using \`import\` statements) and should include all necessary functionalities to cover essential backend operations while ensuring scalability and maintainability. - - ### Based on the following input: - + return `You are an expert backend developer. + Your task is to generate a complete backend codebase within a single file for a project named "${projectName}". The code should be written using the Express framework with ES Module syntax (using \`import\` statements), and database is ${databaseType}. Ensure the code include all necessary functionalities to cover essential backend operations while ensuring scalability and maintainability. + + ### Based on the following input: + - **Project Name:** ${projectName} - **Sitemap Documentation:** ${sitemapDoc} - **Data Analysis Document:** ${DatamapDoc} From 799a093f277a935ef0b843da71fc85568e7fa1cd Mon Sep 17 00:00:00 2001 From: ZHallen122 Date: Sat, 14 Dec 2024 11:29:03 -0500 Subject: [PATCH 08/10] disable strict mode --- backend/template/template-backend/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/template/template-backend/tsconfig.json b/backend/template/template-backend/tsconfig.json index 02fe3b16..c7781fb5 100644 --- a/backend/template/template-backend/tsconfig.json +++ b/backend/template/template-backend/tsconfig.json @@ -83,7 +83,7 @@ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, /* Type Checking */ - "strict": true /* Enable all strict type-checking options. */, + "strict": false /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ From 10c4a3f6e77f9b6da830673457bb94bfccd1ae0a Mon Sep 17 00:00:00 2001 From: Jackson Chen <90215880+Sma1lboy@users.noreply.github.com> Date: Sat, 14 Dec 2024 12:16:10 -0600 Subject: [PATCH 09/10] =?UTF-8?q?refactor(backend):=20reorganize=20handler?= =?UTF-8?q?=20imports=20and=20update=20paths=20for=20co=E2=80=A6=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …nsistency --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: ZHallen122 --- .../__tests__/test-database-schemas.spec.ts | 2 +- .../__tests__/test-file-create.spec.ts | 2 +- .../__tests__/test.file-arch.spec.ts | 2 +- .../src/build-system/__tests__/test.spec.ts | 2 +- .../backend/code-generate}/index.ts | 0 .../backend/code-generate}/prompt.ts | 0 .../backend/requirements-document}/index.ts | 0 .../backend/requirements-document}/prompt.ts | 0 .../database/requirements-document}/index.ts | 0 .../database/requirements-document}/prompt.ts | 0 .../database/schemas}/prompt.ts | 2 -- .../database/schemas}/schemas.ts | 2 +- .../file-manager}/file-arch/index.ts | 2 +- .../file-manager}/file-arch/prompt.ts | 0 .../file-manager}/file-generate/index.ts | 4 ++-- .../file-manager}/file-structure/index.ts | 0 .../file-manager}/file-structure/prompt.ts | 0 .../frontend-code-generate/prompt.ts | 0 .../product-requirements-document/prd.ts | 2 +- .../product-requirements-document}/prompt.ts | 0 .../{node => handlers}/project-init.ts | 0 .../ux/datamap}/index.ts | 0 .../ux/datamap}/prompt.ts | 0 .../ux/sitemap-document}/prompt/prompt.ts | 0 .../ux/sitemap-document}/uxsmd.ts | 0 .../ux/sitemap-structure}/index.ts | 0 .../ux/sitemap-structure}/prompt.ts | 0 backend/src/build-system/hanlder-manager.ts | 18 +++++++++--------- backend/src/build-system/{ => utils}/util.ts | 0 .../{virtual-dir.ts => virtual-dir/index.ts} | 0 30 files changed, 18 insertions(+), 20 deletions(-) rename backend/src/build-system/{node/backend-code-generate => handlers/backend/code-generate}/index.ts (100%) rename backend/src/build-system/{node/backend-code-generate => handlers/backend/code-generate}/prompt.ts (100%) rename backend/src/build-system/{node/backend-requirements-document => handlers/backend/requirements-document}/index.ts (100%) rename backend/src/build-system/{node/backend-requirements-document => handlers/backend/requirements-document}/prompt.ts (100%) rename backend/src/build-system/{node/database-requirements-document => handlers/database/requirements-document}/index.ts (100%) rename backend/src/build-system/{node/database-requirements-document => handlers/database/requirements-document}/prompt.ts (100%) rename backend/src/build-system/{node/database-schemas => handlers/database/schemas}/prompt.ts (99%) rename backend/src/build-system/{node/database-schemas => handlers/database/schemas}/schemas.ts (99%) rename backend/src/build-system/{node => handlers/file-manager}/file-arch/index.ts (98%) rename backend/src/build-system/{node => handlers/file-manager}/file-arch/prompt.ts (100%) rename backend/src/build-system/{node => handlers/file-manager}/file-generate/index.ts (98%) rename backend/src/build-system/{node => handlers/file-manager}/file-structure/index.ts (100%) rename backend/src/build-system/{node => handlers/file-manager}/file-structure/prompt.ts (100%) rename backend/src/build-system/{node => handlers}/frontend-code-generate/prompt.ts (100%) rename backend/src/build-system/{node => handlers/product-manager}/product-requirements-document/prd.ts (97%) rename backend/src/build-system/{node/product-requirements-document/prompt => handlers/product-manager/product-requirements-document}/prompt.ts (100%) rename backend/src/build-system/{node => handlers}/project-init.ts (100%) rename backend/src/build-system/{node/ux-datamap => handlers/ux/datamap}/index.ts (100%) rename backend/src/build-system/{node/ux-datamap => handlers/ux/datamap}/prompt.ts (100%) rename backend/src/build-system/{node/ux-sitemap-document => handlers/ux/sitemap-document}/prompt/prompt.ts (100%) rename backend/src/build-system/{node/ux-sitemap-document => handlers/ux/sitemap-document}/uxsmd.ts (100%) rename backend/src/build-system/{node/ux-sitemap-structure => handlers/ux/sitemap-structure}/index.ts (100%) rename backend/src/build-system/{node/ux-sitemap-structure => handlers/ux/sitemap-structure}/prompt.ts (100%) rename backend/src/build-system/{ => utils}/util.ts (100%) rename backend/src/build-system/{virtual-dir.ts => virtual-dir/index.ts} (100%) diff --git a/backend/src/build-system/__tests__/test-database-schemas.spec.ts b/backend/src/build-system/__tests__/test-database-schemas.spec.ts index a7224af9..b95108f8 100644 --- a/backend/src/build-system/__tests__/test-database-schemas.spec.ts +++ b/backend/src/build-system/__tests__/test-database-schemas.spec.ts @@ -1,5 +1,5 @@ import { BuilderContext } from 'src/build-system/context'; -import { DBSchemaHandler } from '../node/database-schemas/schemas'; +import { DBSchemaHandler } from '../handlers/database/schemas/schemas'; import { readFileSync } from 'fs'; import markdownToTxt from 'markdown-to-txt'; diff --git a/backend/src/build-system/__tests__/test-file-create.spec.ts b/backend/src/build-system/__tests__/test-file-create.spec.ts index 5c195c25..f2ca5cde 100644 --- a/backend/src/build-system/__tests__/test-file-create.spec.ts +++ b/backend/src/build-system/__tests__/test-file-create.spec.ts @@ -1,6 +1,6 @@ import * as fs from 'fs-extra'; import * as path from 'path'; -import { FileGeneratorHandler } from '../node/file-generate'; // Update with actual file path to the handler +import { FileGeneratorHandler } from '../handlers/file-generate'; // Update with actual file path to the handler describe('FileGeneratorHandler', () => { const projectSrcPath = 'src\\build-system\\__tests__\\test-project\\'; diff --git a/backend/src/build-system/__tests__/test.file-arch.spec.ts b/backend/src/build-system/__tests__/test.file-arch.spec.ts index 4aab1e9b..7627185d 100644 --- a/backend/src/build-system/__tests__/test.file-arch.spec.ts +++ b/backend/src/build-system/__tests__/test.file-arch.spec.ts @@ -1,5 +1,5 @@ import { BuilderContext } from 'src/build-system/context'; -import { FileArchGenerateHandler } from '../node/file-arch'; +import { FileArchGenerateHandler } from '../handlers/file-arch'; import markdownToTxt from 'markdown-to-txt'; import { readFileSync } from 'fs-extra'; diff --git a/backend/src/build-system/__tests__/test.spec.ts b/backend/src/build-system/__tests__/test.spec.ts index 40ea0e69..7e132c6a 100644 --- a/backend/src/build-system/__tests__/test.spec.ts +++ b/backend/src/build-system/__tests__/test.spec.ts @@ -2,7 +2,7 @@ import { BuilderContext } from '../context'; import { BuildSequenceExecutor } from '../executor'; import { BuildHandlerManager } from '../hanlder-manager'; -import { ProjectInitHandler } from '../node/project-init'; +import { ProjectInitHandler } from '../handlers/project-init'; import { BuildSequence } from '../types'; describe('Project Init Handler Test', () => { let context: BuilderContext; diff --git a/backend/src/build-system/node/backend-code-generate/index.ts b/backend/src/build-system/handlers/backend/code-generate/index.ts similarity index 100% rename from backend/src/build-system/node/backend-code-generate/index.ts rename to backend/src/build-system/handlers/backend/code-generate/index.ts diff --git a/backend/src/build-system/node/backend-code-generate/prompt.ts b/backend/src/build-system/handlers/backend/code-generate/prompt.ts similarity index 100% rename from backend/src/build-system/node/backend-code-generate/prompt.ts rename to backend/src/build-system/handlers/backend/code-generate/prompt.ts diff --git a/backend/src/build-system/node/backend-requirements-document/index.ts b/backend/src/build-system/handlers/backend/requirements-document/index.ts similarity index 100% rename from backend/src/build-system/node/backend-requirements-document/index.ts rename to backend/src/build-system/handlers/backend/requirements-document/index.ts diff --git a/backend/src/build-system/node/backend-requirements-document/prompt.ts b/backend/src/build-system/handlers/backend/requirements-document/prompt.ts similarity index 100% rename from backend/src/build-system/node/backend-requirements-document/prompt.ts rename to backend/src/build-system/handlers/backend/requirements-document/prompt.ts diff --git a/backend/src/build-system/node/database-requirements-document/index.ts b/backend/src/build-system/handlers/database/requirements-document/index.ts similarity index 100% rename from backend/src/build-system/node/database-requirements-document/index.ts rename to backend/src/build-system/handlers/database/requirements-document/index.ts diff --git a/backend/src/build-system/node/database-requirements-document/prompt.ts b/backend/src/build-system/handlers/database/requirements-document/prompt.ts similarity index 100% rename from backend/src/build-system/node/database-requirements-document/prompt.ts rename to backend/src/build-system/handlers/database/requirements-document/prompt.ts diff --git a/backend/src/build-system/node/database-schemas/prompt.ts b/backend/src/build-system/handlers/database/schemas/prompt.ts similarity index 99% rename from backend/src/build-system/node/database-schemas/prompt.ts rename to backend/src/build-system/handlers/database/schemas/prompt.ts index 8949664a..caed72d9 100644 --- a/backend/src/build-system/node/database-schemas/prompt.ts +++ b/backend/src/build-system/handlers/database/schemas/prompt.ts @@ -1,5 +1,3 @@ -// src/build-system/prompts.ts - /** * Collection of prompt functions used for various build system operations. */ diff --git a/backend/src/build-system/node/database-schemas/schemas.ts b/backend/src/build-system/handlers/database/schemas/schemas.ts similarity index 99% rename from backend/src/build-system/node/database-schemas/schemas.ts rename to backend/src/build-system/handlers/database/schemas/schemas.ts index 9de4f423..e0b44244 100644 --- a/backend/src/build-system/node/database-schemas/schemas.ts +++ b/backend/src/build-system/handlers/database/schemas/schemas.ts @@ -7,7 +7,7 @@ import { getSupportedDatabaseTypes, isSupportedDatabaseType, parseGenerateTag, -} from '../../utils/database-utils'; +} from '../../../utils/database-utils'; import { writeFile } from 'fs-extra'; import { prompts } from './prompt'; diff --git a/backend/src/build-system/node/file-arch/index.ts b/backend/src/build-system/handlers/file-manager/file-arch/index.ts similarity index 98% rename from backend/src/build-system/node/file-arch/index.ts rename to backend/src/build-system/handlers/file-manager/file-arch/index.ts index 280251b2..840b1fc8 100644 --- a/backend/src/build-system/node/file-arch/index.ts +++ b/backend/src/build-system/handlers/file-manager/file-arch/index.ts @@ -2,7 +2,7 @@ import { BuildHandler, BuildResult } from 'src/build-system/types'; import { BuilderContext } from 'src/build-system/context'; import { generateFileArchPrompt } from './prompt'; import { Logger } from '@nestjs/common'; -import { FileUtil } from 'src/build-system/util'; +import { FileUtil } from 'src/build-system/utils/util'; export class FileArchGenerateHandler implements BuildHandler { readonly id = 'op:FILE_ARCH::STATE:GENERATE'; diff --git a/backend/src/build-system/node/file-arch/prompt.ts b/backend/src/build-system/handlers/file-manager/file-arch/prompt.ts similarity index 100% rename from backend/src/build-system/node/file-arch/prompt.ts rename to backend/src/build-system/handlers/file-manager/file-arch/prompt.ts diff --git a/backend/src/build-system/node/file-generate/index.ts b/backend/src/build-system/handlers/file-manager/file-generate/index.ts similarity index 98% rename from backend/src/build-system/node/file-generate/index.ts rename to backend/src/build-system/handlers/file-manager/file-generate/index.ts index 446084f7..8a5a34ed 100644 --- a/backend/src/build-system/node/file-generate/index.ts +++ b/backend/src/build-system/handlers/file-manager/file-generate/index.ts @@ -2,10 +2,10 @@ import * as fs from 'fs/promises'; import * as path from 'path'; import { Logger } from '@nestjs/common'; import * as toposort from 'toposort'; -import { VirtualDirectory } from '../../virtual-dir'; +import { VirtualDirectory } from '../../../virtual-dir'; import { BuilderContext } from 'src/build-system/context'; import { BuildHandler, BuildResult } from 'src/build-system/types'; -import { FileUtil } from 'src/build-system/util'; +import { FileUtil } from 'src/build-system/utils/util'; export class FileGeneratorHandler { private readonly logger = new Logger('FileGeneratorHandler'); diff --git a/backend/src/build-system/node/file-structure/index.ts b/backend/src/build-system/handlers/file-manager/file-structure/index.ts similarity index 100% rename from backend/src/build-system/node/file-structure/index.ts rename to backend/src/build-system/handlers/file-manager/file-structure/index.ts diff --git a/backend/src/build-system/node/file-structure/prompt.ts b/backend/src/build-system/handlers/file-manager/file-structure/prompt.ts similarity index 100% rename from backend/src/build-system/node/file-structure/prompt.ts rename to backend/src/build-system/handlers/file-manager/file-structure/prompt.ts diff --git a/backend/src/build-system/node/frontend-code-generate/prompt.ts b/backend/src/build-system/handlers/frontend-code-generate/prompt.ts similarity index 100% rename from backend/src/build-system/node/frontend-code-generate/prompt.ts rename to backend/src/build-system/handlers/frontend-code-generate/prompt.ts diff --git a/backend/src/build-system/node/product-requirements-document/prd.ts b/backend/src/build-system/handlers/product-manager/product-requirements-document/prd.ts similarity index 97% rename from backend/src/build-system/node/product-requirements-document/prd.ts rename to backend/src/build-system/handlers/product-manager/product-requirements-document/prd.ts index fc386f0c..bd65555c 100644 --- a/backend/src/build-system/node/product-requirements-document/prd.ts +++ b/backend/src/build-system/handlers/product-manager/product-requirements-document/prd.ts @@ -1,6 +1,6 @@ import { BuildHandler, BuildResult } from 'src/build-system/types'; import { BuilderContext } from 'src/build-system/context'; -import { prompts } from './prompt/prompt'; +import { prompts } from './prompt'; import { ModelProvider } from 'src/common/model-provider'; import { Logger } from '@nestjs/common'; diff --git a/backend/src/build-system/node/product-requirements-document/prompt/prompt.ts b/backend/src/build-system/handlers/product-manager/product-requirements-document/prompt.ts similarity index 100% rename from backend/src/build-system/node/product-requirements-document/prompt/prompt.ts rename to backend/src/build-system/handlers/product-manager/product-requirements-document/prompt.ts diff --git a/backend/src/build-system/node/project-init.ts b/backend/src/build-system/handlers/project-init.ts similarity index 100% rename from backend/src/build-system/node/project-init.ts rename to backend/src/build-system/handlers/project-init.ts diff --git a/backend/src/build-system/node/ux-datamap/index.ts b/backend/src/build-system/handlers/ux/datamap/index.ts similarity index 100% rename from backend/src/build-system/node/ux-datamap/index.ts rename to backend/src/build-system/handlers/ux/datamap/index.ts diff --git a/backend/src/build-system/node/ux-datamap/prompt.ts b/backend/src/build-system/handlers/ux/datamap/prompt.ts similarity index 100% rename from backend/src/build-system/node/ux-datamap/prompt.ts rename to backend/src/build-system/handlers/ux/datamap/prompt.ts diff --git a/backend/src/build-system/node/ux-sitemap-document/prompt/prompt.ts b/backend/src/build-system/handlers/ux/sitemap-document/prompt/prompt.ts similarity index 100% rename from backend/src/build-system/node/ux-sitemap-document/prompt/prompt.ts rename to backend/src/build-system/handlers/ux/sitemap-document/prompt/prompt.ts diff --git a/backend/src/build-system/node/ux-sitemap-document/uxsmd.ts b/backend/src/build-system/handlers/ux/sitemap-document/uxsmd.ts similarity index 100% rename from backend/src/build-system/node/ux-sitemap-document/uxsmd.ts rename to backend/src/build-system/handlers/ux/sitemap-document/uxsmd.ts diff --git a/backend/src/build-system/node/ux-sitemap-structure/index.ts b/backend/src/build-system/handlers/ux/sitemap-structure/index.ts similarity index 100% rename from backend/src/build-system/node/ux-sitemap-structure/index.ts rename to backend/src/build-system/handlers/ux/sitemap-structure/index.ts diff --git a/backend/src/build-system/node/ux-sitemap-structure/prompt.ts b/backend/src/build-system/handlers/ux/sitemap-structure/prompt.ts similarity index 100% rename from backend/src/build-system/node/ux-sitemap-structure/prompt.ts rename to backend/src/build-system/handlers/ux/sitemap-structure/prompt.ts diff --git a/backend/src/build-system/hanlder-manager.ts b/backend/src/build-system/hanlder-manager.ts index b02a5851..1e5bd567 100644 --- a/backend/src/build-system/hanlder-manager.ts +++ b/backend/src/build-system/hanlder-manager.ts @@ -1,13 +1,13 @@ -import { ProjectInitHandler } from './node/project-init'; +import { ProjectInitHandler } from './handlers/project-init'; import { BuildHandler } from './types'; -import { PRDHandler } from './node/product-requirements-document/prd'; -import { UXSitemapStructureHandler } from './node/ux-sitemap-structure'; -import { UXDatamapHandler } from './node/ux-datamap'; -import { UXSMDHandler } from './node/ux-sitemap-document/uxsmd'; -import { FileStructureHandler } from './node/file-structure'; -import { FileArchGenerateHandler } from './node/file-arch'; -import { BackendCodeHandler } from './node/backend-code-generate'; -import { DBSchemaHandler } from './node/database-schemas/schemas'; +import { PRDHandler } from './handlers/product-manager/product-requirements-document/prd'; +import { UXSitemapStructureHandler } from './handlers/ux/sitemap-structure'; +import { UXDatamapHandler } from './handlers/ux/datamap'; +import { UXSMDHandler } from './handlers/ux/sitemap-document/uxsmd'; +import { FileStructureHandler } from './handlers/file-manager/file-structure'; +import { FileArchGenerateHandler } from './handlers/file-manager/file-arch'; +import { BackendCodeHandler } from './handlers/backend/code-generate'; +import { DBSchemaHandler } from './handlers/database/schemas/schemas'; export class BuildHandlerManager { private static instance: BuildHandlerManager; diff --git a/backend/src/build-system/util.ts b/backend/src/build-system/utils/util.ts similarity index 100% rename from backend/src/build-system/util.ts rename to backend/src/build-system/utils/util.ts diff --git a/backend/src/build-system/virtual-dir.ts b/backend/src/build-system/virtual-dir/index.ts similarity index 100% rename from backend/src/build-system/virtual-dir.ts rename to backend/src/build-system/virtual-dir/index.ts From 7bedb655c8861ae98ee60166eea517415174765c Mon Sep 17 00:00:00 2001 From: ZHallen122 Date: Sat, 14 Dec 2024 15:46:34 -0500 Subject: [PATCH 10/10] adding DatabaseRequirementHandler --- .../test.backend-code-generator.spec.ts | 17 +++++++++++++++-- backend/src/build-system/hanlder-manager.ts | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts b/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts index 71d4596d..b70d7bca 100644 --- a/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts +++ b/backend/src/build-system/__tests__/test.backend-code-generator.spec.ts @@ -83,6 +83,19 @@ describe('Sequence: PRD -> UXSD -> UXDD -> UXSS -> DBSchemas -> BackendCodeGener }, { id: 'step-4', + name: 'Generate Database Requirements', + nodes: [ + { + id: 'op:DATABASE_REQ::STATE:GENERATE', + name: 'Database Requirements Node', + type: 'DATABASE', + subType: 'SCHEMAS', + requires: ['op:UX_DATAMAP::STATE:GENERATE'], + }, + ], + }, + { + id: 'step-5', name: 'Generate Database Schemas', nodes: [ { @@ -90,12 +103,12 @@ describe('Sequence: PRD -> UXSD -> UXDD -> UXSS -> DBSchemas -> BackendCodeGener name: 'Database Schemas Node', type: 'DATABASE', subType: 'SCHEMAS', - requires: ['op:UX_DATAMAP::STATE:GENERATE'], + requires: ['op:DATABASE_REQ::STATE:GENERATE'], }, ], }, { - id: 'step-5', + id: 'step-6', name: 'Generate Backend Code', nodes: [ { diff --git a/backend/src/build-system/hanlder-manager.ts b/backend/src/build-system/hanlder-manager.ts index 1e5bd567..ee2ac723 100644 --- a/backend/src/build-system/hanlder-manager.ts +++ b/backend/src/build-system/hanlder-manager.ts @@ -8,6 +8,7 @@ import { FileStructureHandler } from './handlers/file-manager/file-structure'; import { FileArchGenerateHandler } from './handlers/file-manager/file-arch'; import { BackendCodeHandler } from './handlers/backend/code-generate'; import { DBSchemaHandler } from './handlers/database/schemas/schemas'; +import { DatabaseRequirementHandler } from './handlers/database/requirements-document'; export class BuildHandlerManager { private static instance: BuildHandlerManager; @@ -28,6 +29,7 @@ export class BuildHandlerManager { new FileArchGenerateHandler(), new BackendCodeHandler(), new DBSchemaHandler(), + new DatabaseRequirementHandler(), ]; for (const handler of builtInHandlers) {