Get a structured map of the project’s codebase, including directory organization, module descriptions, and architectural overview. This endpoint is optimized for onboarding new developers and providing context to AI code reviewers.
def generate_onboarding_guide(repo): """Create an interactive onboarding guide for new developers.""" project_map = get_project_map(repo=repo) print(f"Welcome to {repo}! Let's explore the codebase.\n") # Core modules first core_components = [m for m in project_map['memories'] if 'main' in m['metadata'].get('path', '').lower() or 'core' in m['metadata'].get('path', '').lower()] print("📍 Core Components:") for comp in core_components: print(f" • {comp['metadata'].get('path')}") print(f" {comp['memory']}\n") # API endpoints api_components = [m for m in project_map['memories'] if 'api' in m['metadata'].get('path', '').lower()] print("🌐 API Endpoints:") for comp in api_components: print(f" • {comp['metadata'].get('path')}") print(f" {comp['memory']}\n") # Services services = [m for m in project_map['memories'] if 'service' in m['metadata'].get('component_type', '')] print("⚙️ Services:") for svc in services: print(f" • {svc['metadata'].get('path')}") print(f" {svc['memory']}\n")
def build_review_context(repo, changed_files): """ Build relevant context for AI reviewer based on changed files. Args: repo: Repository name changed_files: List of file paths modified in the PR """ project_map = get_project_map(repo=repo) # Find relevant project map entries relevant_context = [] for memory in project_map['memories']: path = memory['metadata'].get('path', '') # Check if any changed file is in this path if any(path in changed_file or changed_file.startswith(path) for changed_file in changed_files): relevant_context.append(memory) # Build context string context = "## Relevant Project Context\n\n" for memory in relevant_context: context += f"**{memory['metadata'].get('path')}**: {memory['memory']}\n\n" return context# Example usagechanged_files = ['app/api/v1/reviews.py', 'app/models/event.py']context = build_review_context('acme/api-server', changed_files)print(context)
def search_project_map(repo, query): """Search project map for specific components or functionality.""" data = get_project_map(repo=repo) results = [] query_lower = query.lower() for memory in data['memories']: path = memory['metadata'].get('path', '').lower() description = memory['memory'].lower() if query_lower in path or query_lower in description: results.append(memory) return results# Find all authentication-related componentsauth_components = search_project_map('acme/api-server', 'auth')print(f"Found {len(auth_components)} authentication-related components:\n")for comp in auth_components: print(f"📍 {comp['metadata'].get('path')}") print(f" {comp['memory']}\n")
The project map is automatically generated when you connect a repository. To update it:
# Trigger a rescan to update the project mapresponse = requests.post( "https://api.nectr.ai/api/v1/memory/rescan", headers={"Authorization": f"Bearer {token}"}, params={"repo": "acme/api-server"})print(f"Status: {response.json()['status']}")# Output: Status: rescan_started# Wait a few minutes, then fetch the updated project maptime.sleep(180)project_map = get_project_map(repo="acme/api-server")