# AI Open Source Capstone class
## Unit 3: Codebase Navigation and Feature Tracing
Diving into a large codebase is intimidating. We'll introduce a set of prompts that help you divide the codebase into small, manageable pieces that you can visualize and digest.
### 1. Setup Re-usable prompts
Cursor, Claude Code, and Copilot all support invoking custom prompts via a shortcut command.
For example, type "/my_custom_prompt", and it will paste in the text from the appropriate markdown file. You can configure these custom prompts globally or by project.
1. For Cursor, navigate to ~/.cursor/commands (create the directory if it doesn't exist)
2. For Copilot, launch VS Code, and open the Command Palette (Ctrl-shift-p on Windows, Cmd-shift-p on OS X). Type "Chat: New Prompt". Select User Data Folder to create a global command.
- 
### 2. Exploring use cases
A use case is a task that a user can do in a library or application. When approaching a complex codebases, one of the best ways to explore it is via its primary use cases.
For example, use cases for Instagram are:
- A user can see photos from their friends feed
- A user can take a photo, apply a filter, and post to their feed
- A user can view an explore tab where they see trending photos
- A user can like a photo
- A user can see all photos that they've liked
Each use case will flow through a portion of the system architecture, and you can follow its trail.
**Try it out**
1. Open one of the open source repositories in Cursor or Copilot.
2. Add the command for "[explore_use_cases.md](https://gist.githubusercontent.com/timothy1ee/fda045a15951e10c45e22ca7682b7513/raw/07218ed95c6a7cc6372fc5070e6f373ecc400551/explore_use_cases.md)" by following the [instructions above](#1-Setup-Re-usable-prompts).
3. Open the AI panel and type "/explore_use_cases"
Note: in the prompt, we tell it to save use cases to a file. In general, it's useful to build an expanding set of memory files related to system design, architectural decisions, and codebase practices. This will keep your AI anchored and more efficient.
### 3. Lifecycle of a feature
Once you have a target use case, it's valuable to map out the "lifecycle" of the feature. A lifecycle will show you the flow of the code through the system, as well as key components and services.
A mature codebase is like a mansion with a thousand rooms. It can take years to wrap your mind around an architecture, and most engineers only know portions of it. Instead, you become more familiar with areas of the codebase that you visit often.
This method is a more narrow and focused way of understanding a codebase.
You'll get diagrams that look like this:

Once you've studied the lifecycle, try to make changes at various points of the lifecycle (change the view, add log statements, etc) to continue to explore that region.
**Try it out**
1. Choose one of the use cases you mapped out above
2. Add the command for "[lifecycle.md](https://gist.githubusercontent.com/timothy1ee/fda045a15951e10c45e22ca7682b7513/raw/91df4574ecd1d9b1fe73ca7a570df7c7d3f7fd22/lifecycle.md)" by following the [instructions above](#1-Setup-Re-usable-prompts).
3. Open the AI panel and type "/lifecycle"
### 4. Building a System Architecture Diagram
Build a picture of the system architecture by walking through the lifecycle files. If you try to build a system architecture for a large codebase with a single prompt and no lifecycle files, the output often has errors.
Once you've generated the system architecture, do the following:
- Instruct the agent to walk through a lifecycle and confirm the system architecture at each step.
- Create a new lifecycle for another use case, and instruct the agent to update the system architecture.
**Try it out**
1. Choose one of the use cases you mapped out above
2. Add the command for "[system_overview.md](https://gist.githubusercontent.com/timothy1ee/fda045a15951e10c45e22ca7682b7513/raw/1560e5e771089831d71745f8e2c0c3aa76986b63/system_overview.md)" by following the [instructions above](#1-Setup-Re-usable-prompts).
3. Open the AI panel and type "/system_overview"
### 5. Tackling an issue
Now that you have a high level understanding of the system and the the lifecycles of a few major use cases, you're ready to tackle issues.
The system overview and lifecycle files that you generated will be fed into the AI agent, and it'll have a much more informed view of the codebase.
**Try it out**
1. Pick a GitHub issue in your project
2. Instruct the AI agent to research the lifecycle of the use case in that issue
3. Instruct the AI agent to give you a primer/cheatsheet for any language or framework concepts or libraries you need to understand in order to tackle the feature.