# evirgenfurkan/pbinject architecture

> Architecture diagram of the GitHub repository evirgenfurkan/pbinject, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/evirgenfurkan/pbinject
- Repository: https://github.com/evirgenfurkan/pbinject

## Overview

PBInject is a single-file Python CLI that synchronizes CSV exports or local CSV files into PocketBase collections. The main workflow reads and normalizes source rows against runtime collection schemas, resolves relations, compares rows with existing records to plan creates, updates and deletions, then applies the plan and logs a summary. The README also documents multi-collection and watch modes. The implementation is concentrated in pbinject.py; unsampled portions limit detail on relation resolution and request execution.

Main entry points: [`pbinject.py`](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py) (Watch loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_source["CSV input"]
  node_csv["CSV source<br/>[pbinject.py]"]
  node_normalize["Normalize rows<br/>[pbinject.py]"]
end

subgraph group_sync["Sync planning"]
  node_planner["Sync planner<br/>[pbinject.py]"]
  node_guard["Deletion guard<br/>[pbinject.py]"]
end

subgraph group_pocketbase["PocketBase access"]
  node_schema["Schema and key<br/>[pbinject.py]"]
  node_relations["Relation resolution<br/>[pbinject.py]"]
  node_records[("Existing records<br/>[pbinject.py]")]
  node_writer["Batch and fallback<br/>[pbinject.py]"]
end

subgraph group_operations["Apply and record"]
  node_logger["Operation log<br/>[pbinject.py]"]
  node_watch["Watch loop<br/>[pbinject.py]"]
end

node_user(("Operator"))
node_pocketbase_service[("PocketBase")]

node_user -->|"starts sync"| node_watch
node_watch -->|"selects source"| node_csv
node_csv -->|"parses rows"| node_normalize
node_normalize -->|"maps fields"| node_schema
node_schema -->|"fetches schema"| node_pocketbase_service
node_normalize -->|"resolves values"| node_relations
node_relations -->|"looks up or creates"| node_pocketbase_service
node_watch -->|"fetches records"| node_records
node_records -->|"reads pages"| node_pocketbase_service
node_watch -->|"plans sync"| node_planner
node_planner -->|"presents deletion plan"| node_guard
node_guard -->|"approves changes"| node_writer
node_writer -->|"applies requests"| node_pocketbase_service
node_watch -->|"appends summary"| node_logger

click node_csv "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_normalize "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_schema "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_relations "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_records "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_planner "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_guard "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_writer "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_logger "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"
click node_watch "https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_csv,node_normalize toneBlue
class node_planner,node_guard,node_pocketbase_service toneAmber
class node_schema,node_relations,node_records,node_writer toneMint
class node_logger,node_watch toneRose
class node_user toneIndigo
```

## Components

### CSV input

- [CSV source](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`
- [Normalize rows](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`

### Sync planning

- [Sync planner](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`
- [Deletion guard](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`

### PocketBase access

- [Schema and key](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`
- [Relation resolution](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`
- [Existing records](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`
- [Batch and fallback](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`

### Apply and record

- [Operation log](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`
- [Watch loop](https://github.com/evirgenfurkan/pbinject/blob/main/pbinject.py): `pbinject.py`

### Other components

- **Operator**
- **PocketBase**

## Connections

- Operator → Watch loop: starts sync (evidence: `README.md`)
- Watch loop → CSV source: selects source (evidence: `pbinject.py`)
- CSV source → Normalize rows: parses rows (evidence: `pbinject.py`)
- Normalize rows → Schema and key: maps fields (evidence: `pbinject.py`)
- Schema and key → PocketBase: fetches schema (evidence: `pbinject.py`)
- Normalize rows → Relation resolution: resolves values (evidence: `pbinject.py`)
- Relation resolution → PocketBase: looks up or creates (evidence: `README.md`)
- Watch loop → Existing records: fetches records (evidence: `pbinject.py`)
- Existing records → PocketBase: reads pages (evidence: `pbinject.py`)
- Watch loop → Sync planner: plans sync (evidence: `pbinject.py`)
- Sync planner → Deletion guard: presents deletion plan (evidence: `README.md`)
- Deletion guard → Batch and fallback: approves changes (evidence: `README.md`)
- Batch and fallback → PocketBase: applies requests (evidence: `README.md`)
- Watch loop → Operation log: appends summary (evidence: `pbinject.py`)
