|
| 1 | +# Architecture |
| 2 | + |
| 3 | +## Directory Structure |
| 4 | + |
| 5 | +``` |
| 6 | +src/ |
| 7 | +├── index.ts # Main entry point |
| 8 | +├── plugin/ # Plugin module |
| 9 | +├── storage/ # Storage backend abstraction |
| 10 | +├── sync/ # Sync engine and operations |
| 11 | +├── crypto/ # Encryption utilities |
| 12 | +├── data/ # Data loading module |
| 13 | +└── types/ # TypeScript definitions |
| 14 | +``` |
| 15 | + |
| 16 | +## Modules |
| 17 | + |
| 18 | +### plugin/ |
| 19 | + |
| 20 | +OpenCode plugin integration. |
| 21 | + |
| 22 | +| File | Purpose | |
| 23 | +|------|---------| |
| 24 | +| `plugin.ts` | Plugin definition and hooks | |
| 25 | +| `state-manager.ts` | Plugin state management | |
| 26 | +| `sync-handler.ts` | Sync operation handler | |
| 27 | +| `types.ts` | Plugin types | |
| 28 | + |
| 29 | +### storage/ |
| 30 | + |
| 31 | +Storage backend abstraction for GitHub repository. |
| 32 | + |
| 33 | +| File | Purpose | |
| 34 | +|------|---------| |
| 35 | +| `interface.ts` | StorageBackend interface | |
| 36 | +| `repo/repo-client.ts` | GitHub API client | |
| 37 | +| `repo/fetch.ts` | Fetch with retry logic | |
| 38 | +| `repo/errors.ts` | API error types | |
| 39 | + |
| 40 | +### sync/engine/ |
| 41 | + |
| 42 | +Core sync orchestration. |
| 43 | + |
| 44 | +| File | Purpose | |
| 45 | +|------|---------| |
| 46 | +| `sync-engine.ts` | Main sync orchestration | |
| 47 | +| `state.ts` | Local state management | |
| 48 | +| `manifest.ts` | Manifest operations | |
| 49 | +| `result.ts` | Result builders | |
| 50 | +| `helpers.ts` | Engine utilities | |
| 51 | +| `retry.ts` | Retry logic | |
| 52 | +| `errors.ts` | Sync error types | |
| 53 | +| `types.ts` | Engine types | |
| 54 | + |
| 55 | +### sync/operations/ |
| 56 | + |
| 57 | +Push, pull, and merge operations. |
| 58 | + |
| 59 | +| File | Purpose | |
| 60 | +|------|---------| |
| 61 | +| `push.ts` | Push to remote | |
| 62 | +| `pull.ts` | Pull from remote | |
| 63 | +| `merge-operation.ts` | Merge conflicts | |
| 64 | +| `sharding.ts` | Item sharding | |
| 65 | +| `helpers.ts` | Operation utilities | |
| 66 | +| `crypto-helpers.ts` | Encryption helpers | |
| 67 | +| `types.ts` | Operation types | |
| 68 | + |
| 69 | +### sync/merge/ |
| 70 | + |
| 71 | +Three-way merge algorithms. |
| 72 | + |
| 73 | +| File | Purpose | |
| 74 | +|------|---------| |
| 75 | +| `json-merge.ts` | JSON merge algorithm | |
| 76 | +| `jsonl-merge.ts` | JSONL merge algorithm | |
| 77 | +| `utils.ts` | Merge utilities | |
| 78 | +| `types.ts` | Merge types | |
| 79 | + |
| 80 | +### sync/watcher/ |
| 81 | + |
| 82 | +File system watcher for auto-sync. |
| 83 | + |
| 84 | +| File | Purpose | |
| 85 | +|------|---------| |
| 86 | +| `file-watcher.ts` | Main watcher class | |
| 87 | +| `directory-watcher.ts` | Directory watching | |
| 88 | +| `ignore-patterns.ts` | File ignore rules | |
| 89 | +| `types.ts` | Watcher types | |
| 90 | + |
| 91 | +### sync/ (root files) |
| 92 | + |
| 93 | +| File | Purpose | |
| 94 | +|------|---------| |
| 95 | +| `vector-clock.ts` | Vector clock operations | |
| 96 | +| `packer.ts` | Blob compression | |
| 97 | +| `item-packer.ts` | Per-item compression | |
| 98 | +| `tombstone.ts` | Deletion tracking | |
| 99 | +| `local-lock.ts` | Local sync locking | |
| 100 | + |
| 101 | +### crypto/ |
| 102 | + |
| 103 | +| File | Purpose | |
| 104 | +|------|---------| |
| 105 | +| `encrypt.ts` | AES-256-GCM encryption | |
| 106 | + |
| 107 | +### data/ |
| 108 | + |
| 109 | +Local data loading and persistence. |
| 110 | + |
| 111 | +| File | Purpose | |
| 112 | +|------|---------| |
| 113 | +| `category-loader.ts` | Load by category | |
| 114 | +| `directory-loader.ts` | Directory traversal | |
| 115 | +| `parsers.ts` | JSON/JSONL parsing | |
| 116 | +| `writer.ts` | Write local data | |
| 117 | +| `state.ts` | Config/state persistence | |
| 118 | + |
| 119 | +### types/ |
| 120 | + |
| 121 | +TypeScript type definitions. |
| 122 | + |
| 123 | +| File | Purpose | |
| 124 | +|------|---------| |
| 125 | +| `config.ts` | Config types | |
| 126 | +| `manifest.ts` | Manifest types | |
| 127 | +| `sync.ts` | Sync result types | |
| 128 | +| `vector-clock.ts` | Vector clock types | |
| 129 | +| `categories.ts` | Category definitions | |
| 130 | +| `paths.ts` | Path configuration | |
| 131 | + |
| 132 | +## Data Flow |
| 133 | + |
| 134 | +``` |
| 135 | +Local Files → Data Loader → Sync Engine → Storage Backend → GitHub Repo |
| 136 | + ↑ |
| 137 | + Vector Clock |
| 138 | + Merge Logic |
| 139 | + Encryption |
| 140 | +``` |
| 141 | + |
| 142 | +## Key Concepts |
| 143 | + |
| 144 | +### Vector Clocks |
| 145 | +Track causality between machines. See `sync/vector-clock.ts`. |
| 146 | + |
| 147 | +### Three-Way Merge |
| 148 | +Resolve conflicts using common ancestor. See `sync/merge/`. |
| 149 | + |
| 150 | +### Tombstones |
| 151 | +Track deletions for propagation. See `sync/tombstone.ts`. |
| 152 | + |
| 153 | +### Sharding |
| 154 | +Split large item collections across files. See `sync/operations/sharding.ts`. |
0 commit comments