Skip to content

Commit fc98640

Browse files
Add documentation for repository rules feature
1 parent b443d41 commit fc98640

3 files changed

Lines changed: 203 additions & 0 deletions

File tree

docs/docs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
"introduction/faq"
2626
]
2727
},
28+
{
29+
"group": "Organizations",
30+
"pages": [
31+
"organizations/get-organizations",
32+
"organizations/repositories/repository-rules"
33+
]
34+
},
2835
{
2936
"group": "Integrations",
3037
"pages": [

docs/images/repo-rules-setting.png

Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
---
2+
title: Repository Rules
3+
description: Learn how to configure custom rules for Codegen to follow when working with your repositories
4+
---
5+
6+
# Repository Rules
7+
8+
Repository rules allow you to define specific instructions that Codegen will follow when working with your codebase. These rules can help ensure that Codegen adheres to your team's coding standards, follows project-specific conventions, or handles certain files in specific ways.
9+
10+
## Overview
11+
12+
Repository rules are custom instructions written in markdown format that guide Codegen's behavior when interacting with your repository. These rules can be defined in two ways:
13+
14+
1. **Through the Codegen web interface** - Configure rules in your repository settings
15+
2. **Using rule files in your repository** - Create special files that Codegen automatically detects
16+
17+
When Codegen works with your repository, it automatically detects and follows these rules, ensuring that its actions align with your team's expectations and requirements.
18+
19+
## Configuring Rules via Web Interface
20+
21+
The simplest way to configure repository rules is through the Codegen web interface:
22+
23+
1. Log in to your Codegen account at [codegen.sh](https://codegen.sh)
24+
2. Navigate to **Repositories** in the sidebar
25+
3. Select the repository you want to configure
26+
4. In the repository settings page, find the **Repository rules** section
27+
5. Enter your rules in markdown format in the text area
28+
6. Click **Save** to apply your changes
29+
30+
![Repository Rules Setting](../../images/repo-rules-setting.png)
31+
32+
## Configuring Rules via Files
33+
34+
Alternatively, you can define rules directly in your repository using special files. Codegen automatically detects and follows rules defined in these files:
35+
36+
- `.cursorrules` - A file at the root of your repository
37+
- `.clinerules` - A file at the root of your repository
38+
- `.windsurfrules` - A file at the root of your repository
39+
- `.cursor/rules/**/*.mdc` - Any `.mdc` files in the `.cursor/rules` directory
40+
- `**/*.mdc` - Any `.mdc` files anywhere in your repository
41+
42+
These files should contain your rules in markdown format. When Codegen works with your repository, it automatically detects these files and follows the rules defined in them.
43+
44+
### Example: Creating Rules in `.cursor/rules`
45+
46+
1. Create a `.cursor/rules` directory in your repository:
47+
48+
```bash
49+
mkdir -p .cursor/rules
50+
```
51+
52+
2. Create a new file with your rules, for example `.cursor/rules/coding-standards.mdc`:
53+
54+
```markdown
55+
# Coding Standards
56+
57+
1. **File Organization**
58+
- Place all React components in the `src/components` directory
59+
- Place all utility functions in the `src/utils` directory
60+
- Place all API calls in the `src/api` directory
61+
62+
2. **Naming Conventions**
63+
- Use PascalCase for component names
64+
- Use camelCase for function and variable names
65+
- Use UPPER_SNAKE_CASE for constants
66+
67+
3. **Code Style**
68+
- Use 2 spaces for indentation
69+
- Use single quotes for strings
70+
- Add semicolons at the end of statements
71+
- Maximum line length is 80 characters
72+
```
73+
74+
3. Commit and push these changes to your repository
75+
76+
## Rule Format and Examples
77+
78+
Repository rules are written in markdown format, which allows for rich formatting and structure. Here are some examples of effective repository rules:
79+
80+
### Example 1: General Development Guidelines
81+
82+
```markdown
83+
# Development Guidelines
84+
85+
## Code Structure
86+
- Follow the MVC pattern for all new features
87+
- Place all database models in the `app/models` directory
88+
- Place all controllers in the `app/controllers` directory
89+
- Place all views in the `app/views` directory
90+
91+
## Testing Requirements
92+
- Write unit tests for all new functions
93+
- Maintain at least 80% code coverage
94+
- Use descriptive test names that explain what is being tested
95+
96+
## Documentation
97+
- Add JSDoc comments to all public functions
98+
- Update the README.md when adding new features
99+
- Document all API endpoints in the API.md file
100+
```
101+
102+
### Example 2: Project-Specific Instructions
103+
104+
```markdown
105+
# Project-Specific Instructions
106+
107+
## Feature Flags
108+
- All new features should be behind a feature flag
109+
- Feature flags should be defined in `config/feature_flags.js`
110+
- Default value for all feature flags should be `false` in development
111+
112+
## Database Migrations
113+
- Never modify existing migrations
114+
- Create new migrations for all schema changes
115+
- Follow the naming convention: `YYYYMMDD_description.js`
116+
117+
## Third-Party Services
118+
- All API keys should be stored in environment variables
119+
- Never commit API keys or secrets to the repository
120+
- Document all third-party service integrations in `docs/integrations.md`
121+
```
122+
123+
### Example 3: Task Approach Template
124+
125+
```markdown
126+
# Task Approach
127+
128+
1. **Analysis & Planning**
129+
- First, analyze the requirements thoroughly
130+
- Create a detailed implementation plan with clear steps
131+
- I'll review and approve before you start coding
132+
133+
2. **Development Guidelines**
134+
- Make small, focused changes
135+
- Commit early and frequently with descriptive messages
136+
- Open a PR as soon as possible to catch integration issues
137+
- Follow all monorepo guidelines and project architecture
138+
139+
3. **Quality Standards**
140+
- Write tests for all new functionality
141+
- Include appropriate documentation
142+
- Consider edge cases and error handling
143+
- Ensure code is performant and maintainable
144+
145+
4. **Communication**
146+
- Don't write code until you're highly confident (95%+) in your approach
147+
- Ask clarifying questions when requirements are ambiguous
148+
- Provide regular status updates
149+
- Flag any potential architectural concerns early
150+
151+
5. **Architecture**
152+
- For significant changes, create Architecture Decision Records (ADRs)
153+
- Place ADRs in docs/technical/architecture/decisions
154+
- Explain tradeoffs and alternatives considered
155+
```
156+
157+
## Best Practices
158+
159+
To get the most out of repository rules, follow these best practices:
160+
161+
1. **Be specific and clear** - Write rules that are specific, clear, and actionable
162+
2. **Organize rules logically** - Group related rules together and use headings to create a clear structure
163+
3. **Focus on what matters** - Include rules that are important for your project and team
164+
4. **Keep rules up to date** - Regularly review and update your rules as your project evolves
165+
5. **Use examples** - Include examples to illustrate how rules should be applied
166+
6. **Explain the why** - Explain why rules exist to help Codegen understand their importance
167+
168+
## Rule Precedence
169+
170+
If you define rules in multiple places, Codegen follows this precedence order:
171+
172+
1. Rules defined in the web interface
173+
2. Rules defined in repository files (`.cursorrules`, `.clinerules`, `.windsurfrules`)
174+
3. Rules defined in `.cursor/rules/**/*.mdc` files
175+
4. Rules defined in other `.mdc` files
176+
177+
Rules defined in the web interface take precedence over rules defined in files.
178+
179+
## Troubleshooting
180+
181+
If Codegen is not following your repository rules as expected, check the following:
182+
183+
1. **Rule format** - Ensure your rules are written in valid markdown format
184+
2. **Rule location** - Verify that your rule files are in the correct location
185+
3. **Rule content** - Make sure your rules are clear, specific, and actionable
186+
4. **Rule conflicts** - Check for conflicting rules in different locations
187+
5. **Rule updates** - Ensure you've saved your changes in the web interface or committed and pushed your file changes
188+
189+
## Conclusion
190+
191+
Repository rules are a powerful way to customize Codegen's behavior and ensure it follows your team's standards and conventions. By defining clear, specific rules, you can help Codegen work more effectively with your codebase and produce better results.
192+
193+
For more information about working with Codegen, check out our [documentation](https://docs.codegen.sh).
194+

0 commit comments

Comments
 (0)