---
description: When user asks about code generation, uses the GENERATE_CODE or CREATE_REPO commands, or discusses generating code from documentation, guide them through the process and explain requirements
globs: ["**/code_context/**/*"]
alwaysApply: false
---
# Code Generation
## Commands
### GENERATE_CODE
Generates code based on completed documentation
#### Arguments:
- `project_name` (string, required): Name of the project to generate code for
- `output_path` (string, required): Path where generated code will be stored (can be a different repository)
- `code_type` (string): Type of code to generate. Options: "frontend", "backend", "full_stack", "extension", "library". Default: "full_stack"
- `language` (string): Primary language to use. Options: "javascript", "typescript", "python", "java", "ruby", "go", "php". Default: "typescript"
- `style_guide` (string): Style guide to follow for code generation. Default: based on project type
- `include_tests` (boolean): Whether to generate tests for the code. Default: true
- `github_repo` (string): Optional GitHub repository to create/push to
- `methodologies` (comma-separated): Development methodologies to apply. Options: "tdd", "bdd", "scrum", "ci", "pair". Required.
- `git_workflow` (string): Git workflow to use. Options: "github_flow", "gitflow", "trunk_based", "no_workflow". Required.
#### Behavior with Existing Documentation:
When the GENERATE_CODE command is invoked without parameters, the system MUST:
1. **Check Project Memory**: Extract project details from existing documentation. If none, suggest PAELLA command.
2. **Auto-Populate Parameters**: Use values from documentation, prompt only for missing ones.
3. **Summarize Documentation Analysis**: Confirm extracted components, APIs, data models. Highlight missing info.
4. **Review and Confirmation**: Present parameters for confirmation, allow overrides, confirm critical decisions (output path, repo).
#### Required Conversation Flow:
If parameters are missing, initiate a conversation to gather:
1. **Project Info**: Verify name, type; ask for output path.
2. **Methodologies**: Ask for TDD, BDD, etc., explain implications.
3. **Git Workflow**: Ask for preferred workflow (GitHub Flow, GitFlow, etc.), explain benefits.
4. **Language/Stack**: Confirm language, ask for frameworks/libraries.
5. **Testing Strategy**: Confirm test inclusion, ask for coverage goals, test types.
6. **Repo Management**: Ask about creating a new repo, type, visibility, CI/CD setup.
Code generation starts ONLY after all required parameters are gathered.
### CREATE_REPO
Creates a new repository for generated code
#### Arguments:
- `repo_name` (string, required): Name of the repository to create
- `repo_type` (string): Type of repository. Options: "github", "gitlab", "local". Default: "github"
- `visibility` (string): Repository visibility. Options: "public", "private". Default: "private"
- `include_ci` (boolean): Whether to include CI/CD configuration. Default: true
- `license` (string): License to use. Options: "MIT", "Apache-2.0", "GPL-3.0", etc. Default: "MIT"
## Code Generation Architecture & Process
1. **Documentation Analysis**: Extract requirements, architecture, components, APIs.
2. **Scaffolding**: Generate project structure.
3. **Component Generation**: Create individual components.
4. **Integration**: Connect components.
5. **Testing**: Generate tests.
6. **Deployment/Repo**: Configure CI/CD, manage repository.
## Documentation Sources Used
- Architecture Documents
- API Specifications
- Component Specifications
- Data Models
- User Stories
## Code Quality Assurance
Generated code undergoes linting, testing (unit, integration, E2E), security scanning, and documentation generation.
# Code Generation from Documentation
This module handles the generation of code based on documentation and repository analysis.
## Command Definition
```
GENERATE-DOC [repo_path=/path/to/repo] [context_path=/path/to/context] [output=/path/to/output] [template=template_name]
```
## Process Steps
1. **Repository Analysis**:
- If `repo_path` is provided, it uses repopack to extract repository content to text
- If not, it looks for existing content in the `/Users/jlcases/codigo/paelladoc/code_context/extracted` directory
2. **Context Analysis**:
- Analyzes the extracted content for architecture patterns, API endpoints, and database schemas
- Stores analysis results in the `/Users/jlcases/codigo/paelladoc/code_context/analyzed` directory
3. **Interactive Documentation Generation**:
- Asks relevant questions about the project based on the analysis:
- Project purpose and goals
- Target audience
- Key features and functionality
- Technical requirements and constraints
- API usage patterns
- Database design considerations
- Security requirements
4. **Documentation Creation**:
- Generates comprehensive documentation based on the analysis and responses
- Stores documentation in the `/Users/jlcases/codigo/paelladoc/code_context/generated` directory
## Example Usage
```
GENERATE-DOC repo_path=/Users/jlcases/projects/my-api-project
```
## Interactive Workflow
When the command is executed, it follows this conversation flow:
1. **Repository Analysis Confirmation**:
```
I'll analyze the repository at /Users/jlcases/projects/my-api-project.
Would you like me to focus on any specific part of the codebase?
```
2. **Project Purpose Questions**:
```
Based on my analysis, this appears to be a RESTful API with authentication.
What is the primary purpose of this API?
Who are the intended users?
```
3. **Technical Details Confirmation**:
```
I detected these endpoints:
- GET /api/users
- POST /api/auth/login
- GET /api/products
Are there any missing endpoints or functionality?
```
4. **Documentation Structure Proposal**:
```
Based on our discussion, I'll generate documentation with these sections:
1. Project Overview
2. Architecture
3. API Reference
4. Database Schema
5. Deployment Guide
Would you like to add or remove any sections?
```
5. **Final Documentation Generation**:
```
I've generated the documentation. You can find it at:
/Users/jlcases/codigo/paelladoc/code_context/generated/my-api-project/
```
## Integration with extract_repo_content.py
The command uses the script at `.cursor/rules/scripts/extract_repo_content.py` to perform the repository extraction, which leverages repopack-py to convert the codebase to text.