-
Notifications
You must be signed in to change notification settings - Fork 3
Feat(backend) file structure #59
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
Changes from all commits
9d91437
5bbfdd9
bfda89c
89a2b0b
f508d88
101d779
79c9631
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
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'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
export class FileStructureHandler implements BuildHandler { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
readonly id = 'op:File_Structure::STATE:GENERATE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
async run(context: BuilderContext, args: unknown): Promise<BuildResult> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log('Generating File Structure Document...'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
// extract relevant data from the context | ||||||||||||||||||||||||||||||||||||||||||||||||||||
const projectName = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
context.getData('projectName') || 'Default Project Name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
const prompt = prompts.generateFileStructurePrompt( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
projectName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
args as string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: change later | ||||||||||||||||||||||||||||||||||||||||||||||||||||
args as string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
'FrameWork Holder', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+16
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve type safety and remove hardcoded values Several issues in this code segment need attention:
Consider this safer implementation: + interface FileStructureArgs {
+ sitemapDoc: string;
+ dataAnalysisDoc: string;
+ framework: string;
+ }
+
+ if (!args || typeof args !== 'object') {
+ throw new Error('Invalid arguments provided to FileStructureHandler');
+ }
+
+ const typedArgs = args as FileStructureArgs;
+
const prompt = prompts.generateFileStructurePrompt(
projectName,
- args as string,
- // TODO: change later
- args as string,
- 'FrameWork Holder',
+ typedArgs.sitemapDoc,
+ typedArgs.dataAnalysisDoc,
+ typedArgs.framework,
); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
const fileStructureContent = await context.model.chatSync( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
content: prompt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
'gpt-4o-mini', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
success: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
data: fileStructureContent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+24
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and input validation The model interaction lacks error handling and the response isn't validated before returning. Consider this improved implementation: + if (!prompt) {
+ throw new Error('Failed to generate prompt for file structure');
+ }
+
+ try {
const fileStructureContent = await context.model.chatSync(
{
content: prompt,
},
'gpt-4o-mini',
);
+
+ if (!fileStructureContent) {
+ throw new Error('No content generated by the model');
+ }
+
return {
success: true,
data: fileStructureContent,
};
+ } catch (error) {
+ context.logger.error('Failed to generate file structure', { error });
+ return {
+ success: false,
+ error: error instanceof Error ? error.message : 'Unknown error occurred',
+ };
+ }
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,64 @@ | ||||||||||||||||||||||||||||||||||||
export const prompts = { | ||||||||||||||||||||||||||||||||||||
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} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
Comment on lines
+8
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add parameter validation and utilize the framework parameter.
): string => {
+ if (!projectName || !sitemapDoc || !dataAnalysisDoc || !framework) {
+ throw new Error('All parameters are required for generating file structure prompt');
+ }
+ const fileExtension = framework.toLowerCase().includes('react') ? 'tsx' : 'js';
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. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
### 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. | ||||||||||||||||||||||||||||||||||||
Comment on lines
+40
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make file extensions framework-agnostic. The file naming guidelines assume React with TypeScript ( Use meaningful and descriptive file names.
- For components, include an index.tsx file in each folder to simplify imports.
+ For components, include an index.${fileExtension} 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.
+ Use index.${fileExtension} as the main file inside the component folder.
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
File Comments: | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
Include comments describing the purpose of each file or folder to improve readability. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
Self check: | ||||||||||||||||||||||||||||||||||||
1, Are you consider all the cases 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/example files inside. | ||||||||||||||||||||||||||||||||||||
Add comments to describe the purpose of each file/folder. | ||||||||||||||||||||||||||||||||||||
End with: "\`\`\`" | ||||||||||||||||||||||||||||||||||||
`; | ||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Operation ID format needs standardization
The operation IDs in the codebase show inconsistencies in their format:
OP:
prefix while others use lowercaseop:
File_Structure
,UX_Structure
) while others use plain uppercase (PRD
,UXSMD
)::
as separators while others use single colon:
STATE:
segment is present in some IDs but missing in othersExamples of inconsistencies:
OP:DATABASE:SCHEMAS
vsop:File_Structure::STATE:GENERATE
op:UX_Structure::STATE:GENERATE
vsop:UXSMD::STATE:GENERATE
op:PROJECT::STATE:SETUP
vsOP:DATABASE:SCHEMAS
🔗 Analysis chain
Verify the operation ID format consistency
The operation ID
op:File_Structure::STATE:GENERATE
follows a specific format. Let's verify this format is consistent with other handlers in the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 479