# aoufnihed/selconnect architecture

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

- Interactive diagram: https://gitdiagram.com/aoufnihed/selconnect
- Repository: https://github.com/aoufnihed/selconnect

## Overview

1. **What this repo is**
   - A Python automation toolkit for SEL relay configuration.
   - Its main job is to turn centralized relay settings into per-relay configuration artifacts, especially QuickSet-compatible RDB files and SCL XML files.

2. **Core architecture**
   - The repo is organized as a small pipeline: ingest settings, parse or extract relay data, transform it into templates or structured relay files, then emit outputs per relay.
   - The main package is `selprotopy`, with command-line entry points layered over the generation logic.

3. **Primary input sources**
   - `relay_settings.csv` and the sample CSVs under `samples/` are the main configuration inputs.
   - `samples/mapping_710.json` suggests relay-specific field mapping is part of the extraction path.
   - `samples/sample_710.rdb` is an example source relay file used for parsing/extraction workflows.

4. **Parsing and extraction boundary**
   - `rdb_parser.py` is the low-level parser for RDB content, using regex-style parsing according to the README.
   - `extractor.py` sits above that parser and maps parsed relay fields into a normalized configuration model, likely using the JSON mapping definitions.
   - This is the “read existing relay file and recover settings” side of the system.

5. **Generation boundary**
   - `rdb_generator.py` and `enhanced_rdb_generator.py` are the “write new relay file” side.
   - The enhanced generator is the key architectural piece: it uses the official `SEL_RDB` library to produce compound RDB files that QuickSet can read directly.
   - This separates the project from plain text templating and makes the output format itself a first-class dependency.

6. **Batch orchestration**
   - `multi_generator.py` is the batch coordinator for generating many relays from a master dataset.
   - The `out_relays/RelayXX` folders show the intended unit of deployment: one output directory per relay, each containing its own generated files.
   - This is the multi-relay boundary of the system and the main scaling mechanism.

7. **Template and reporting support**
   - `template_generator.py` and `generated_template.txt` indicate a templating layer exists for producing relay-specific text artifacts or intermediate representations.
   - `csv_report.py` generates summary/reporting outputs from processed relay data, supporting auditability and traceability of what values were generated.
   - These modules are auxiliary, but they help explain how the pipeline stays transparent.

8. **Command-line surface**
   - `cli.py` is the user-facing entry point for running extract/generate operations.
   - The README also mentions a `selprotopy-extract` command, so the package is designed to be invoked as a CLI tool rather than a library only.

9. **Outputs and integration targets**
   - The repo produces at least three important artifact types:
     - QuickSet-compatible perfect RDB files
     - SCL XML files for RTAC / SEL Architect integration
     - text templates / reports for inspection and standardization
   - The generated `out_relays/*` directories are example outputs demonstrating the expected packaging of these artifacts per relay.

10. **Data flow at a glance**
   - Master CSV / sample RDB / mapping JSON in → parser/extractor or generator logic → normalized relay settings → per-relay output files.
   - There are two main directions: “extract from existing relay file” and “generate new relay configuration from centralized data.”

11. **Project boundaries and dependencies**
   - This is a Python 3.9+ package managed with `pyproject.toml`.
   - The only external dependency called out as architecturally important is the official `SEL_RDB` library, because it determines the fidelity and compatibility of generated RDB files.
   - QuickSet, SEL Architect, and RTAC are external consumers of the outputs, not runtime dependencies of the code itself.

12. **Test structure**
   - `tests/` covers the major functional seams: CSV reporting, extraction, RDB parsing, and RDB generation.
   - That test layout mirrors the architecture well: each stage of the pipeline is tested separately rather than only through end-to-end scenarios.

13. **How to diagram it**
   - A clean architecture diagram should show:
     - input data sources at the left
     - parser/extractor and generator modules in the middle
     - batch orchestration above them
     - output artifacts to the right
     - external consumers like QuickSet and Architect consuming those outputs
   - The most important internal boundary is between “normalized relay data” and “format-specific file generation.”

Main entry points: [`out_relays`](https://github.com/aoufnihed/selconnect/tree/main/out_relays) (Relay outputs), [`selprotopy/multi_generator.py`](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/multi_generator.py) (Batch gen), [`selprotopy/extractor.py`](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/extractor.py) (Extractor), [`selprotopy/cli.py`](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/cli.py) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs"]
  node_master_csv["Master CSV<br/>input dataset<br/>[Master.csv]"]
  node_relay_settings_csv["Relay settings<br/>input dataset<br/>[relay_settings.csv]"]
  node_sample_rdb["Sample RDB<br/>input relay file<br/>[sample_710.rdb]"]
  node_mapping_json["Field map<br/>mapping spec<br/>[mapping_710.json]"]
  node_config_input_csv["Config CSV<br/>input dataset<br/>[config_input.csv]"]
end

subgraph group_core["Core pipeline"]
  node_cli["CLI<br/>entry point<br/>[cli.py]"]
  node_multi_generator["Batch gen<br/>orchestrator<br/>[multi_generator.py]"]
  node_extractor["Extractor<br/>normalizer<br/>[extractor.py]"]
  node_rdb_parser["RDB parser<br/>[rdb_parser.py]"]
  node_rdb_generator["RDB gen<br/>generator<br/>[rdb_generator.py]"]
  node_enhanced_rdb_generator["Enhanced RDB<br/>generator"]
  node_template_generator["Template gen<br/>templating"]
  node_csv_report["CSV report<br/>reporting<br/>[csv_report.py]"]
  node_normalized_data[("Relay model<br/>normalized config")]
end

subgraph group_outputs["Outputs"]
  node_out_relays[("Relay outputs<br/>deployment bundle")]
  node_template_artifacts["Templates<br/>artifact"]
  node_scl_outputs["SCL XML<br/>artifact<br/>[Relay01.scl.xml]"]
end

subgraph group_external["External consumers"]
  node_quickset_consumer(("QuickSet<br/>external tool"))
  node_architect_consumer(("SEL Architect<br/>external tool"))
  node_rtac_consumer(("RTAC<br/>external tool"))
  node_sel_rdb_lib(("SEL_RDB<br/>external library"))
end

node_cli -->|"batch run"| node_multi_generator
node_cli -->|"extract"| node_extractor
node_cli -->|"generate"| node_rdb_generator
node_master_csv -->|"drive batch"| node_multi_generator
node_relay_settings_csv -->|"inputs"| node_multi_generator
node_config_input_csv -->|"summarize"| node_csv_report
node_sample_rdb -->|"parse"| node_rdb_parser
node_mapping_json -->|"map fields"| node_extractor
node_rdb_parser -->|"parsed fields"| node_extractor
node_extractor -->|"normalize"| node_normalized_data
node_multi_generator -->|"prepare"| node_normalized_data
node_normalized_data -->|"render"| node_rdb_generator
node_normalized_data -->|"render"| node_enhanced_rdb_generator
node_normalized_data -->|"template"| node_template_generator
node_normalized_data -->|"report"| node_csv_report
node_enhanced_rdb_generator -->|"uses"| node_sel_rdb_lib
node_rdb_generator -->|"emit"| node_out_relays
node_enhanced_rdb_generator -->|"emit"| node_out_relays
node_template_generator -->|"write"| node_template_artifacts
node_multi_generator -->|"package"| node_out_relays
node_out_relays -->|"consume"| node_quickset_consumer
node_out_relays -->|"consume"| node_architect_consumer
node_out_relays -->|"consume"| node_rtac_consumer
node_template_artifacts -.->|"co-locate"| node_out_relays
node_csv_report -.->|"summaries"| node_out_relays

click node_cli "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/cli.py"
click node_multi_generator "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/multi_generator.py"
click node_extractor "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/extractor.py"
click node_rdb_parser "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/rdb_parser.py"
click node_rdb_generator "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/rdb_generator.py"
click node_enhanced_rdb_generator "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/enhanced_rdb_generator.py"
click node_template_generator "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/template_generator.py"
click node_csv_report "https://github.com/aoufnihed/selconnect/blob/main/selprotopy/csv_report.py"
click node_master_csv "https://github.com/aoufnihed/selconnect/blob/main/samples/Master.csv"
click node_relay_settings_csv "https://github.com/aoufnihed/selconnect/blob/main/relay_settings.csv"
click node_sample_rdb "https://github.com/aoufnihed/selconnect/blob/main/samples/sample_710.rdb"
click node_mapping_json "https://github.com/aoufnihed/selconnect/blob/main/samples/mapping_710.json"
click node_config_input_csv "https://github.com/aoufnihed/selconnect/blob/main/samples/config_input.csv"
click node_out_relays "https://github.com/aoufnihed/selconnect/tree/main/out_relays"
click node_template_artifacts "https://github.com/aoufnihed/selconnect/blob/main/generated_template.txt"
click node_scl_outputs "https://github.com/aoufnihed/selconnect/blob/main/out_relays/Relay01/Relay01.scl.xml"

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_master_csv,node_relay_settings_csv,node_sample_rdb,node_mapping_json,node_config_input_csv toneBlue
class node_cli,node_multi_generator,node_extractor,node_rdb_parser,node_rdb_generator,node_enhanced_rdb_generator,node_template_generator,node_csv_report,node_normalized_data toneAmber
class node_out_relays,node_template_artifacts,node_scl_outputs toneMint
class node_quickset_consumer,node_architect_consumer,node_rtac_consumer,node_sel_rdb_lib toneRose
```

## Components

### Inputs

Centralized settings, sample relay data, and field mappings

- [Master CSV](https://github.com/aoufnihed/selconnect/blob/main/samples/Master.csv): input dataset · Centralized relay settings used to drive batch generation · `samples/Master.csv`
- [Relay settings](https://github.com/aoufnihed/selconnect/blob/main/relay_settings.csv): input dataset · Primary configuration spreadsheet for generation workflows · `relay_settings.csv`
- [Sample RDB](https://github.com/aoufnihed/selconnect/blob/main/samples/sample_710.rdb): input relay file · Example source relay file used for parsing and extraction · `samples/sample_710.rdb`
- [Field map](https://github.com/aoufnihed/selconnect/blob/main/samples/mapping_710.json): mapping spec · Relay-specific field mapping used by extraction and normalization · `samples/mapping_710.json`
- [Config CSV](https://github.com/aoufnihed/selconnect/blob/main/samples/config_input.csv): input dataset · Sample CSV input used in generation and reporting examples · `samples/config_input.csv`

### Core pipeline

CLI, extraction, transformation, and generation modules

- [CLI](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/cli.py): entry point · User-facing command entry for extract and generate workflows · `selprotopy/cli.py`
- [Batch gen](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/multi_generator.py): orchestrator · Coordinates generation across many relays from a master dataset · `selprotopy/multi_generator.py`
- [Extractor](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/extractor.py): normalizer · Maps parsed relay fields into a normalized configuration model · `selprotopy/extractor.py`
- [RDB parser](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/rdb_parser.py): parser · Low-level parser for existing RDB content · `selprotopy/rdb_parser.py`
- [RDB gen](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/rdb_generator.py): generator · Builds standard RDB relay files from structured settings · `selprotopy/rdb_generator.py`
- [Enhanced RDB](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/enhanced_rdb_generator.py): generator · Uses SEL_RDB to produce QuickSet-compatible compound RDB files · `selprotopy/enhanced_rdb_generator.py`
- [Template gen](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/template_generator.py): templating · Produces relay-specific text templates and intermediate artifacts · `selprotopy/template_generator.py`
- [CSV report](https://github.com/aoufnihed/selconnect/blob/main/selprotopy/csv_report.py): reporting · Summarizes processed relay data into audit-friendly reports · `selprotopy/csv_report.py`
- **Relay model**: normalized config · Intermediate relay settings model shared across generation paths

### Outputs

Per-relay artifacts and reporting outputs

- [Relay outputs](https://github.com/aoufnihed/selconnect/tree/main/out_relays): deployment bundle · One output directory per relay containing generated artifacts · `out_relays`
- [Templates](https://github.com/aoufnihed/selconnect/blob/main/generated_template.txt): artifact · Per-relay generated template text files · `generated_template.txt`
- [SCL XML](https://github.com/aoufnihed/selconnect/blob/main/out_relays/Relay01/Relay01.scl.xml): artifact · Per-relay SCL XML outputs for downstream integration · `out_relays/Relay01/Relay01.scl.xml`

### External consumers

Downstream tools that consume generated artifacts

- **QuickSet**: external tool · Consumes generated RDB artifacts
- **SEL Architect**: external tool · Consumes SCL XML artifacts
- **RTAC**: external tool · Downstream integration target for SCL artifacts
- **SEL_RDB**: external library · Official library used by the enhanced generator for compatible RDB output

## Connections

- CLI → Batch gen: batch run · CLI invokes multi-relay generation workflows
- CLI → Extractor: extract · CLI can launch extraction from existing relay files
- CLI → RDB gen: generate · CLI can trigger file generation from normalized settings
- Master CSV → Batch gen: drive batch · Master relay settings feed the batch coordinator
- Relay settings → Batch gen: inputs · Central settings input for generation runs
- Config CSV → CSV report: summarize · CSV inputs feed reporting and audit outputs
- Sample RDB → RDB parser: parse · Existing relay file is parsed into structured fields
- Field map → Extractor: map fields · Field mapping guides extraction and normalization
- RDB parser → Extractor: parsed fields · Extractor consumes parsed relay data
- Extractor → Relay model: normalize · Recovered relay values are assembled into a shared model
- Batch gen → Relay model: prepare · Batch orchestration produces relay-specific normalized inputs
- Relay model → RDB gen: render · Structured settings are turned into standard RDB output
- Relay model → Enhanced RDB: render · Structured settings are turned into QuickSet-compatible compound RDB output
- Relay model → Template gen: template · Normalized relay data can be rendered as text templates
- Relay model → CSV report: report · Normalized data is summarized for traceability
- Enhanced RDB → SEL_RDB: uses · Enhanced generation depends on the official SEL_RDB library
- RDB gen → Relay outputs: emit · Generated relay artifacts are written into per-relay output folders
- Enhanced RDB → Relay outputs: emit · Compound RDB outputs are placed in per-relay folders
- Template gen → Templates: write · Template text artifacts are produced for inspection and reuse
- Batch gen → Relay outputs: package · Batch flow packages outputs one directory per relay
- Relay outputs → QuickSet: consume · QuickSet reads generated RDB artifacts
- Relay outputs → SEL Architect: consume · SEL Architect consumes generated SCL XML artifacts
- Relay outputs → RTAC: consume · RTAC consumes SCL XML integration artifacts
- Templates → Relay outputs: co-locate · Template artifacts live alongside other relay outputs
- CSV report → Relay outputs: summaries · Reports are written as part of the generated relay output set
