Skip to content

CG-17133: Add Codegen Bot documentation #1032

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
117 changes: 117 additions & 0 deletions docs/gen/how-it-works.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
title: "How Codegen Works"
sidebarTitle: "How It Works"
icon: "gears"
iconType: "solid"
---

# How Codegen Works

Codegen is an expert software engineering agent designed to help development teams build better software. This document explains the architecture and workflow of Codegen.

## Architecture Overview

Codegen operates through a sophisticated system with several key components:

<Frame caption="Codegen Architecture">
<img src="/images/codegen-architecture.png" alt="Codegen Architecture Diagram" />
</Frame>

### Core Components

1. **Trigger System**
- Monitors various channels (Slack, GitHub, Linear, API)
- Detects when users mention or interact with Codegen
- Captures context from the triggering environment

2. **Context Gathering**
- Analyzes the codebase structure
- Retrieves relevant information from integrations
- Builds a comprehensive understanding of the task

3. **Task Planning**
- Breaks down complex requests into actionable steps
- Determines the optimal approach to solve the problem
- Identifies required tools and resources

4. **Execution Engine**
- Runs commands in a sandboxed environment
- Makes code changes through precise edits
- Interacts with external services via API

5. **Response Generation**
- Creates clear, concise responses
- Formats information appropriately for the channel
- Provides links to relevant resources

## Workflow

When you interact with Codegen, the following process occurs:

1. **Trigger**: You mention Codegen in Slack, tag it in a GitHub PR, or interact with it in Linear
2. **Context Analysis**: Codegen gathers relevant information about your request
3. **Planning**: It determines the best approach to solve your problem
4. **Execution**: Codegen performs necessary actions (code analysis, edits, searches)
5. **Response**: It provides a helpful response in the same channel where you triggered it

## Available Tools

Codegen has access to a powerful set of tools:

### Code Analysis & Navigation
- Search codebases using text or regex patterns
- View file contents and metadata
- Analyze code structure and dependencies
- Reveal symbol definitions and usages

### File Operations
- View, create, edit, and delete files
- Rename files while updating all imports
- Move symbols between files
- Commit changes to disk

### Semantic Editing
- Make precise, context-aware code edits
- Analyze affected code structures
- Preview changes before applying
- Ensure code quality with linting

### Web Search
- Search the web for information
- View specific web pages for reference

### Integration Tools
- Create and manage GitHub issues and PRs
- Interact with Linear tickets
- Send messages in Slack
- And more...

## Best Practices for Working with Codegen

To get the most out of Codegen:

1. **Be Specific**: Clearly describe what you want Codegen to do
2. **Provide Context**: Mention relevant files, issues, or PRs
3. **Break Down Complex Tasks**: Ask for one thing at a time for best results
4. **Review Changes**: Always review PRs created by Codegen before merging
5. **Provide Feedback**: Let Codegen know if its response was helpful

## Security and Privacy

Codegen operates with security as a priority:

- All code operations happen in isolated sandboxed environments
- Codegen only accesses repositories you've explicitly granted it access to
- Your code is never used to train AI models
- All operations follow the principle of least privilege

## Limitations

While powerful, Codegen has some limitations:

- It cannot access private networks or systems outside its integrations
- Very large codebases may take longer to analyze
- Complex architectural decisions still benefit from human oversight
- It works best with well-structured, documented code

For more information about Codegen's capabilities, see the [Capabilities](/gen/capabilities) page.
196 changes: 196 additions & 0 deletions docs/gen/use-cases.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
title: "Common Use Cases"
sidebarTitle: "Use Cases"
icon: "lightbulb"
iconType: "solid"
---

# Common Use Cases for Codegen

Codegen is designed to streamline your development workflow and help you accomplish tasks more efficiently. Here are some common ways teams use Codegen:

## Code Research and Understanding

<AccordionGroup>
<Accordion title="Exploring Unfamiliar Codebases" icon="compass">
```
@codegen How does the authentication flow work in our app?
```

Codegen will analyze the codebase, identify authentication-related files, and explain the flow with relevant code snippets and diagrams.
</Accordion>

<Accordion title="Finding Code Examples" icon="magnifying-glass">
```
@codegen Show me examples of how we use the API client in our codebase
```

Codegen will search for and present examples of API client usage across your codebase, helping you understand patterns and conventions.
</Accordion>

<Accordion title="Tracing Function Calls" icon="route">
```
@codegen Trace the execution path of the processPayment function
```

Codegen will analyze the call graph to show you how the function is called, what dependencies it has, and what other functions it calls.
</Accordion>
</AccordionGroup>

## Code Modifications and Refactoring

<AccordionGroup>
<Accordion title="Implementing New Features" icon="plus">
```
@codegen Add input validation to the user registration form
```

Codegen will locate the registration form, implement appropriate validation logic, and create a PR with the changes.
</Accordion>

<Accordion title="Fixing Bugs" icon="bug">
```
@codegen Fix the issue where the dashboard doesn't load user data
```

Codegen will investigate the issue, identify the root cause, and implement a fix with appropriate error handling.
</Accordion>

<Accordion title="Refactoring Code" icon="arrows-rotate">
```
@codegen Refactor the UserService class to use dependency injection
```

Codegen will restructure the class to follow dependency injection patterns while maintaining functionality.
</Accordion>

<Accordion title="Updating Dependencies" icon="arrow-up">
```
@codegen Update our React components to use the latest API
```

Codegen will identify components using deprecated APIs and update them to use the current recommended patterns.
</Accordion>
</AccordionGroup>

## Code Reviews and Quality

<AccordionGroup>
<Accordion title="Reviewing Pull Requests" icon="code-pull-request">
```
@codegen Review PR #123
```

Codegen will analyze the PR, provide feedback on code quality, suggest improvements, and identify potential issues.
</Accordion>

<Accordion title="Improving Test Coverage" icon="vial">
```
@codegen Add unit tests for the PaymentProcessor class
```

Codegen will create comprehensive tests covering different scenarios and edge cases for the specified class.
</Accordion>

<Accordion title="Code Quality Checks" icon="check">
```
@codegen Check our error handling in the API routes
```

Codegen will analyze error handling patterns, identify inconsistencies or gaps, and suggest improvements.
</Accordion>
</AccordionGroup>

## Documentation and Knowledge Sharing

<AccordionGroup>
<Accordion title="Generating Documentation" icon="file-lines">
```
@codegen Create documentation for our authentication API
```

Codegen will analyze the API and create comprehensive documentation with endpoints, parameters, and examples.
</Accordion>

<Accordion title="Explaining Complex Logic" icon="diagram-project">
```
@codegen Explain the caching strategy in our app
```

Codegen will analyze the caching implementation and provide a clear explanation with diagrams and examples.
</Accordion>

<Accordion title="Creating Onboarding Materials" icon="user-plus">
```
@codegen Create a guide for new developers on our project structure
```

Codegen will generate a comprehensive guide explaining the project's architecture, key components, and conventions.
</Accordion>
</AccordionGroup>

## Project Management

<AccordionGroup>
<Accordion title="Issue Triage" icon="clipboard-list">
```
@codegen Find all issues related to authentication
```

Codegen will search through Linear or GitHub issues to find and summarize authentication-related tasks.
</Accordion>

<Accordion title="Task Breakdown" icon="puzzle-piece">
```
@codegen Break down the task of implementing the new notification system
```

Codegen will analyze the requirements and create a detailed breakdown of subtasks needed to implement the feature.
</Accordion>

<Accordion title="Status Updates" icon="chart-line">
```
@codegen What's the status of our API migration project?
```

Codegen will gather information from issues, PRs, and commits to provide a comprehensive status update.
</Accordion>
</AccordionGroup>

## Advanced Use Cases

<AccordionGroup>
<Accordion title="Large-Scale Refactoring" icon="wand-magic-sparkles">
```
@codegen Convert all our Promise-based code to use async/await
```

Codegen can help plan and execute large-scale code transformations across your codebase.
</Accordion>

<Accordion title="Architecture Analysis" icon="building">
```
@codegen Analyze our microservice dependencies
```

Codegen will map out service dependencies, identify potential bottlenecks, and suggest architectural improvements.
</Accordion>

<Accordion title="Performance Optimization" icon="gauge-high">
```
@codegen Identify performance bottlenecks in our rendering logic
```

Codegen will analyze the code for performance issues and suggest optimizations with measurable impact.
</Accordion>
</AccordionGroup>

## Getting Started

To start using Codegen for these use cases:

1. [Install Codegen](https://codegen.sh/install) and connect it to your GitHub, Slack, and Linear accounts
2. Mention `@codegen` in your Slack channel followed by your request
3. Review Codegen's response and provide feedback to help it improve

For more detailed information on Codegen's capabilities, see the [Capabilities](/gen/capabilities) page.
Loading
Loading