# How to Register and Manage Multiple Repositories with Code-Review-Graph (CRG)

> Easily register and manage multiple repositories with Code-Review-Graph CRG using its JSON registry. Reference codebases via short names in CLI commands or Python API calls.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: how-to-guide
- Published: 2026-08-08

---

**Code-Review-Graph maintains a JSON-based registry at `~/.code-review-graph/registry.json` that maps repository aliases to absolute paths, allowing you to register multiple codebases and reference them via short names in CLI commands or Python API calls.**

Code-Review-Graph (CRG) is designed to handle single or multiple codebases simultaneously through a lightweight registry system. Whether you're analyzing microservices or monorepos, understanding how to register and manage multiple repositories with CRG enables seamless graph generation across your entire codebase. The registry functionality is implemented in the `tirth8205/code-review-graph` repository and provides both programmatic Python APIs and convenient CLI commands.

## Understanding the CRG Registry Architecture

### Registry Storage and Configuration

The registry location is determined by **[`code_review_graph/constants.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/constants.py)** (lines 10-25), which checks for the **`$CRG_HOME`** environment variable. If set, CRG uses that directory; otherwise, it defaults to `~/.code-review-graph/`. Within this directory, the **[`registry.json`](https://github.com/tirth8205/code-review-graph/blob/main/registry.json)** file stores each repository's absolute path and optional alias as JSON objects.

### Core Registry Implementation

The **`Registry`** class in **[`code_review_graph/registry.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/registry.py)** provides the primary interface for repository management:

- **`Registry.register(path, alias=None, data_dir=None)`** (lines 67-95): Validates the target directory contains a `.git`, `.svn`, or `.code-review-graph` marker before creating or updating an entry.
- **`Registry.unregister(path_or_alias)`** (lines 19-39): Removes entries by path or alias.
- **`Registry.list_repos()`** (lines 41-48): Returns all registered repositories.
- **`resolve_repo()`** (lines 91-126): Resolves user-supplied aliases or relative paths to absolute repository locations used throughout the CLI.

## CLI Commands for Repository Registration

### Registering New Repositories

Use the **`register`** command to add repositories to the global registry:

```bash
code-review-graph register /path/to/project --alias proj

```

This validates the repository markers and writes an entry to [`registry.json`](https://github.com/tirth8205/code-review-graph/blob/main/registry.json):

```json
{"path":"/home/user/project","alias":"proj"}

```

### Managing Registered Repositories

List all known repositories:

```bash
code-review-graph repos

```

Remove a repository when no longer needed:

```bash
code-review-graph unregister proj

```

## Automating Multi-Repo Workflows with the Daemon

### Persistent Daemon Configuration

For continuous monitoring, CRG uses a separate **[`watch.toml`](https://github.com/tirth8205/code-review-graph/blob/main/watch.toml)** file (stored in the same `$CRG_HOME` directory) managed through daemon-specific commands documented in **[`docs/COMMANDS.md`](https://github.com/tirth8205/code-review-graph/blob/main/docs/COMMANDS.md)** (lines 90-104).

### Daemon Management Commands

- **`code-review-graph daemon add <path> [--alias <name>]`**: Persists repos to [`watch.toml`](https://github.com/tirth8205/code-review-graph/blob/main/watch.toml) for automatic watching.
- **`code-review-graph daemon remove <path_or_alias>`**: Stops watching and removes from config.
- **`code-review-graph daemon status`**: Displays currently watched repositories.

The daemon spawns `code-review-graph watch` subprocesses for each entry, automatically rebuilding graphs when files change.

## Practical Implementation Examples

### Manual Repository Workflow

Register and build graphs for multiple repositories:

```bash

# Register two services

code-review-graph register ~/service-a --alias svc-a
code-review-graph register ~/service-b --alias svc-b

# Verify registration

code-review-graph repos

# Build graphs using aliases

code-review-graph --repo svc-a build
code-review-graph --repo svc-b build

```

### Programmatic Registry Access

Interact with the registry directly in Python:

```python
from code_review_graph.registry import Registry

reg = Registry()  # Loads ~/.code-review-graph/registry.json

# Register with alias

reg.register("/home/alice/project", alias="proj")

# List all entries

print(reg.list_repos())

# Output: [{'path': '/home/alice/project', 'alias': 'proj'}]

# Remove by alias

reg.unregister("proj")

```

### Automated Daemon Setup

Enable background watching for multiple repos:

```bash
code-review-graph daemon add ~/service-a --alias svc-a
code-review-graph daemon add ~/service-b --alias svc-b
code-review-graph daemon start
code-review-graph daemon status

```

## Summary

- CRG stores repository metadata in **[`registry.json`](https://github.com/tirth8205/code-review-graph/blob/main/registry.json)** within **`$CRG_HOME`** (defaulting to `~/.code-review-graph/`).
- The **`Registry`** class in [`code_review_graph/registry.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/registry.py) handles validation, registration, and resolution.
- Use **`code-review-graph register`** and **`unregister`** to manage the CLI registry.
- The daemon uses **[`watch.toml`](https://github.com/tirth8205/code-review-graph/blob/main/watch.toml)** for persistent multi-repo watching via **`daemon add`** and **`daemon remove`**.
- Aliases resolve to absolute paths through **`resolve_repo()`** for all graph operations.

## Frequently Asked Questions

### What repository markers does CRG validate during registration?

According to [`code_review_graph/registry.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/registry.py) (lines 67-95), CRG validates that the target directory contains a `.git`, `.svn`, or `.code-review-graph` marker file before allowing registration. This ensures only actual code repositories or previously initialized CRG projects are added to the registry.

### Can I use relative paths when registering repositories?

While you can provide relative paths to the `register` command, CRG stores the absolute path in [`registry.json`](https://github.com/tirth8205/code-review-graph/blob/main/registry.json). The `resolve_repo()` function (lines 91-126) handles path resolution, converting any alias or relative path supplied to CLI commands into the absolute location required for graph database operations.

### How do I change the default registry location?

Set the **`$CRG_HOME`** environment variable before running CRG commands. As defined in [`code_review_graph/constants.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/constants.py) (lines 10-25), this variable overrides the default `~/.code-review-graph/` directory, moving both [`registry.json`](https://github.com/tirth8205/code-review-graph/blob/main/registry.json) and [`watch.toml`](https://github.com/tirth8205/code-review-graph/blob/main/watch.toml) to your specified location.

### What is the difference between `unregister` and `daemon remove`?

The **`unregister`** command removes entries from [`registry.json`](https://github.com/tirth8205/code-review-graph/blob/main/registry.json), affecting only the static registry used for alias resolution. The **`daemon remove`** command removes entries from [`watch.toml`](https://github.com/tirth8205/code-review-graph/blob/main/watch.toml), stopping the background watcher from monitoring that repository. A repository can be registered for CLI use without being watched by the daemon, and vice versa.