Codebase Awareness
How MyDeskBot understands and works with your entire codebase.
What is Codebase Awareness?
Codebase Awareness is MyDeskBot's ability to understand your entire project structure, not just the current file. It analyzes dependencies, imports, file relationships, and patterns to provide more relevant and accurate assistance.
How It Works
1. Project Indexing
MyDeskBot indexes your project:
- File Structure: Organizes all files and directories
- Dependencies: Tracks imports and package dependencies
- Symbols: Extracts functions, classes, variables
- Relationships: Maps connections between files and symbols
- Documentation: Reads comments and docstrings
2. Context Building
When you interact with MyDeskBot, it builds context:
- Current File: The file you're working in
- Related Files: Files that import or are imported
- Open Files: Files currently open in your editor
- Recent Files: Files you've recently edited
- Project Type: Framework, language, and patterns
3. Pattern Recognition
MyDeskBot learns patterns:
- Naming Conventions: How you name variables, functions
- Code Structure: How you organize code
- Error Handling: Your error handling patterns
- Testing Style: How you structure tests
- Documentation: Your comment and docstring style
Capabilities
1. Cross-File Understanding
MyDeskBot understands relationships across files:
# In utils/validation.py
def validate_email(email: str) -> bool:
return '@' in email
# In models/user.py
# MyDeskBot knows about validate_email
class User:
def __init__(self, email: str):
if not validate_email(email): # Uses the validation from utils
raise ValueError("Invalid email")
self.email = email2. Import Suggestions
Suggests the right imports:
# Type:
datetime.now()
# MyDeskBot suggests:
from datetime import datetime
datetime.now()3. Pattern Completion
Completes patterns based on your codebase:
// If you have this pattern:
public class Service {
private final Repository repository;
public Service(Repository repository) {
this.repository = repository;
}
public Entity getById(Long id) {
return repository.findById(id)
.orElseThrow(() -> new NotFoundException(id));
}
}
// MyDeskBot suggests similar for new services:
public class UserService {
private final UserRepository userRepository;
public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
public User getById(Long id) {
return userRepository.findById(id)
.orElseThrow(() -> new UserNotFoundException(id));
}
}4. Semantic Search
Search your codebase semantically:
User: Find the authentication logic
MyDeskBot: Found authentication in:
- src/auth/login.js - User login implementation
- src/middleware/auth.js - JWT authentication middleware
- src/services/auth.js - Authentication serviceConfiguration
Indexing Settings
{
"mydeskbot.codebaseAwareness": {
"enabled": true,
"indexing": {
"enabled": true,
"autoUpdate": true,
"includePatterns": ["**/*.{js,ts,py,java,go,rs}"],
"excludePatterns": [
"node_modules/**",
"**/*.min.js",
"dist/**",
"build/**"
]
},
"context": {
"maxFiles": 10,
"maxLinesPerFile": 100,
"includeRelatedFiles": true
}
}
}Language-Specific Settings
{
"mydeskbot.codebaseAwareness.languages": {
"javascript": {
"nodeModules": true,
"typeDefinitions": true
},
"python": {
"venv": true,
"sitePackages": true
},
"java": {
"mavenDependencies": true,
"gradleDependencies": true
}
}
}Best Practices
1. Use Descriptive Names
Descriptive names help MyDeskBot understand:
# Good
def calculate_total_price(items):
pass
# Harder for MyDeskBot
def calc(items):
pass2. Add Type Hints
Types improve understanding:
# With types
def process_data(data: List[Item]) -> List[ProcessedItem]:
return [item.process() for item in data]
# Without types (harder for MyDeskBot)
def process_data(data):
return [item.process() for item in data]3. Document Your Code
Documentation provides context:
def calculate_discount(price: float, discount_rate: float) -> float:
"""Calculate discounted price.
Args:
price: Original price
discount_rate: Discount rate (0.0 to 1.0)
Returns:
Discounted price
"""
return price * (1 - discount_rate)4. Maintain Consistent Style
Consistent style helps MyDeskBot learn:
# Consistent naming
def get_user(id: int) -> User:
pass
def get_order(id: int) -> Order:
pass
def get_product(id: int) -> Product:
pass5. Organize Files Logically
Logical organization improves context:
src/
├── models/ # Data models
├── services/ # Business logic
├── controllers/ # API endpoints
└── utils/ # UtilitiesAdvanced Features
1. Multi-Project Awareness
Work with multiple related projects:
{
"mydeskbot.codebaseAwareness.projects": {
"main": "/path/to/main",
"shared": "/path/to/shared/lib",
"frontend": "/path/to/frontend"
}
}2. Custom Patterns
Define custom patterns:
{
"mydeskbot.codebaseAwareness.patterns": {
"repository": {
"prefix": "",
"suffix": "Repository",
"methods": ["findById", "findAll", "save", "delete"]
},
"controller": {
"prefix": "",
"suffix": "Controller",
"methods": ["index", "show", "create", "update", "destroy"]
}
}
}3. Domain Knowledge
Add domain-specific knowledge:
{
"mydeskbot.codebaseAwareness.domain": {
"entities": ["User", "Order", "Product"],
"actions": ["create", "update", "delete", "fetch"],
"validators": ["validateEmail", "validatePhone"]
}
}Troubleshooting
Indexing Issues
Problem: MyDeskBot doesn't understand my code
Solutions:
- Force re-index: Command Palette → "Re-index Project"
- Check file permissions
- Verify file types are supported
- Clear cache: Command Palette → "Clear Cache"
Poor Suggestions
Problem: Suggestions aren't relevant
Solutions:
- Add more documentation
- Use type hints
- Maintain consistent style
- Increase context window
- Open related files
Performance Issues
Problem: Slow indexing or suggestions
Solutions:
- Reduce context files
- Exclude large directories
- Disable auto-indexing
- Increase debounce delay
Use Cases
Use Case 1: Learning a Codebase
User: Explain the authentication flow in this project
MyDeskBot: This project uses JWT-based authentication:
1. User submits credentials to /auth/login
2. AuthService validates credentials
3. JWT token is generated and returned
4. Client includes token in subsequent requests
5. AuthMiddleware validates token before protected routes
Key files:
- src/auth/login.js - Login endpoint
- src/middleware/auth.js - Token validation
- src/services/auth.js - Authentication logicUse Case 2: Finding Related Code
User: Find all files that use the User model
MyDeskBot: User model is used in:
- src/controllers/userController.js (CRUD operations)
- src/services/userService.js (Business logic)
- src/middleware/auth.js (Authentication)
- src/routes/userRoutes.js (Route definitions)Use Case 3: Understanding Impact
User: If I change the User interface, what will break?
MyDeskBot: Changing User interface will affect:
- src/controllers/userController.js (uses User)
- src/services/userService.js (uses User)
- src/types/userTypes.ts (extends User)
Recommendation: Update TypeScript definitions first