# pcreux/csv-importer architecture

> Architecture diagram of the GitHub repository pcreux/csv-importer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pcreux/csv-importer
- Repository: https://github.com/pcreux/csv-importer

## Overview

##### Main Components

a. Core Components:
- CSV Reader Component
- Column Mapping Engine
- Runner/Processor
- Reporting System
- Model Interface Layer

b. Supporting Components:
- Configuration System
- DSL Interface
- Validation Layer

**Top Layer (Input/Interface Layer):**
- Show the entry points (CSV File/String/Path Input)
- DSL Interface for configuration

**Middle Layer (Processing Layer):**
- CSV Reader
- Column Mapper
- Runner
- Validator

**Bottom Layer (Integration Layer):**
- Model Interface (ActiveRecord/ORM)
- Storage Layer

##### Component Relationships

- Input → CSV Reader → Column Mapper
- Column Mapper → Runner
- Runner → Model Interface
- All components → Reporting System

##### Specific Implementation Details to Highlight

a. CSV Processing Pipeline:
**Input → CSVReader → Header Validation → Column Mapping → Row Processing → Model Updates**

b. Configuration Flow:
**DSL Definition → Column Definitions → Mapping Rules → Transformers**

##### Key Features to Emphasize

- Column mapping with aliases
- Transformation functions
- Error handling strategies
- Validation rules
- Callback hooks (after_build, after_save)

##### Technical Details

Annotations showing:
- Supported input formats
- Encoding handling
- Quote character customization
- Identifier strategies
- Error handling modes (skip/abort)

##### Implementation Notes

- Column.rb and ColumnDefinition.rb for mapping
- CSVReader.rb for input processing
- Runner.rb for execution
- Report.rb and ReportMessage.rb for feedback
- Row.rb for row-level processing

##### Integration Points

Clear interfaces for:
- ORM integration requirements (transaction, find_by, save)
- Custom model support
- External system hooks

**Input → Validation → Processing → Storage → Reporting**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        CSV[CSV File/String/Path]
        DSL[DSL Interface]:::interface
    end

    subgraph Processing
        Reader[CSV Reader]:::core
        ColMap[Column Mapping Engine]:::core
        Runner[Runner/Processor]:::core
        Valid[Validation Layer]:::validation
    end

    subgraph Integration
        Model[Model Interface]:::integration
        DB[(Database)]:::integration
    end

    subgraph Reporting
        Report[Reporting System]:::reporting
        RepMsg[Report Messages]:::reporting
    end

    subgraph Configuration
        Config[Configuration System]:::config
        Header[Header Processing]:::config
        Row[Row Processing]:::config
    end

    %% Relationships
    CSV --> Reader
    DSL --> Config
    Config --> ColMap
    Reader --> Header
    Header --> ColMap
    ColMap --> Runner
    Runner --> Row
    Row --> Model
    Model --> DB
    Runner --> Report
    Report --> RepMsg

    %% Bidirectional flows
    Runner <--> Valid
    Model <--> Valid

    %% Click events
    click Reader "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/csv_reader.rb"
    click ColMap "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/column.rb"
    click Runner "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/runner.rb"
    click Report "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/report.rb"
    click RepMsg "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/report_message.rb"
    click Config "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/config.rb"
    click DSL "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/dsl.rb"
    click Header "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/header.rb"
    click Row "https://github.com/pcreux/csv-importer/blob/main/lib/csv_importer/row.rb"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef interface fill:#4CAF50,stroke:#2E7D32,color:white
    classDef validation fill:#FFC107,stroke:#FFA000,color:black
    classDef reporting fill:#FF9800,stroke:#F57C00,color:white
    classDef integration fill:#9E9E9E,stroke:#616161,color:white
    classDef config fill:#3F51B5,stroke:#303F9F,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Interface Components]:::interface
        L3[Validation Components]:::validation
        L4[Reporting Components]:::reporting
        L5[Integration Components]:::integration
        L6[Configuration Components]:::config
    end
```
