Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"endOfLine": "auto"
}
1 change: 1 addition & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ module.exports = {
},
modulePaths: ['<rootDir>'],
moduleDirectories: ['node_modules', 'src'],
testPathIgnorePatterns: ['/template'],
};
35 changes: 34 additions & 1 deletion backend/src/build-system/__tests__/test.fullstack-gen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
description: 'Users can play music',
databaseType: 'SQLite',
steps: [
{
id: 'step-0',
name: 'Project Initialization',
parallel: false,
nodes: [
{
id: 'op:PROJECT::STATE:SETUP',
name: 'set up project folders',
},
],
},
{
id: 'step-1',
name: 'Initial Analysis',
Expand Down Expand Up @@ -96,6 +107,11 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
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'],
},
],
},
{
Expand All @@ -106,7 +122,24 @@ describe('Sequence: PRD -> UXSD -> UXSS -> UXDD -> DATABASE_REQ -> DBSchemas ->
{
id: 'op:BACKEND:CODE',
name: 'Backend Code Generator Node',
requires: ['op:DATABASE:SCHEMAS', 'op:UX:DATAMAP:DOC'],
requires: [
'op:DATABASE:SCHEMAS',
'op:UX:DATAMAP:DOC',
'op:BACKEND:REQ',
],
},
],
},
// 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'],
},
],
},
Expand Down
9 changes: 7 additions & 2 deletions backend/src/build-system/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export type GlobalDataKeys =
| 'description'
| 'platform'
| 'databaseType'
| 'projectUUID';
| 'projectUUID'
| 'backendPath'
| 'frontendPath';

/**
* Generic context data type mapping keys to any value
Expand Down Expand Up @@ -72,7 +74,10 @@ export class BuilderContext {
this.globalContext.set('description', sequence.description || '');
this.globalContext.set('platform', 'web');
this.globalContext.set('databaseType', sequence.databaseType || 'SQLite');
this.globalContext.set('projectUUID', uuidv4());
this.globalContext.set(
'projectUUID',
new Date().toISOString().slice(0, 10).replace(/:/g, '-') + '-' + uuidv4(),
);
}

async execute(): Promise<void> {
Expand Down
16 changes: 15 additions & 1 deletion backend/src/build-system/handlers/backend/code-generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
parseGenerateTag,
removeCodeBlockFences,
} from 'src/build-system/utils/database-utils';
import { saveGeneratedCode } from 'src/build-system/utils/files';
import * as path from 'path';

/**
* BackendCodeHandler is responsible for generating the backend codebase
Expand Down Expand Up @@ -33,17 +35,25 @@ export class BackendCodeHandler implements BuildHandler<string> {
// Destructure arguments with default values for optional parameters
const sitemapDoc = context.getNodeData('op:UX:SMD');
const datamapDoc = context.getNodeData('op:UX:DATAMAP:DOC');
const databaseSchemas = context.getNodeData('op:DATABASE:SCHEMAS');
//TODO: make this backend generate similar as FileGenerateHandler, do file arch, and then generate each backend code
const currentFile = 'backend.js';
//TODO: backend requirement
const backendRequirementDoc =
context.getNodeData('op:BACKEND:REQ').overview;

const currentFile = 'index.js';
const dependencyFile = 'dependencies.json';

// Generate the prompt using the provided documents and project name
const backendCodePrompt = generateBackendCodePrompt(
projectName,
sitemapDoc,
datamapDoc,
backendRequirementDoc,
databaseType,
databaseSchemas,
currentFile,
'javascript',
dependencyFile,
);

Expand All @@ -63,8 +73,12 @@ export class BackendCodeHandler implements BuildHandler<string> {
parseGenerateTag(modelResponse),
);

const uuid = context.getGlobalContext('projectUUID');
saveGeneratedCode(path.join(uuid, 'backend', currentFile), generatedCode);

this.logger.debug('Backend code generated and parsed successfully.');

// TODO: return backend api as output
return {
success: true,
data: generatedCode,
Expand Down
Loading
Loading