# Architecture

## Purpose

Repo Sync Service owns repository acquisition and snapshot lifecycle.

## Boundaries

- REST control plane for webhooks, admin sync, and health/status
- Git/Bitbucket integration via `GitProvider` (TW-17)
- Redis event publishing via `EventPublisher` (TW-16)
- MongoDB metadata persistence for repositories and snapshots (TW-19)
- No code parsing or commit analysis in this service

## Flow

```text
Bitbucket Webhook / Admin Sync
  → SyncService
  → GitProvider (clone/fetch/diff)
  → MongoDB (repository + snapshot metadata)
  → Redis Streams (repo.snapshot.ready, files.changed)
  → Code Parser + Commit Intelligence (downstream)
```

## Storage layers

| Layer | Technology | Data |
| --- | --- | --- |
| Git workspace | Filesystem | Cloned repositories |
| Event bus | Redis Streams | Indexing events |
| Metadata | MongoDB | Repositories, snapshots, sync jobs |

See [mongodb.md](mongodb.md) for local Docker and Atlas setup.

## Dependencies

- Redis (required today)
- MongoDB (TW-19 — metadata; local compose included for dev)
- Local placeholder contracts in `internal/contracts/`
- Shared `code-intelligence-contracts` module will be added after Bitbucket hosting setup
