# vascocosta/csv_db architecture

> Architecture diagram of the GitHub repository vascocosta/csv_db, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vascocosta/csv_db
- Repository: https://github.com/vascocosta/csv_db

## Overview

##### Component Details

a. Public API Layer:
- Main Database struct with its public methods:
- find()
- insert()
- delete()
- update()
- Type parameters showing generic document support
- Serde integration for serialization/deserialization

b. Processing Layer:
- An "Async Handler" component showing Tokio's spawn_blocking
- A "Document Processor" component showing:
- Serialization/Deserialization logic
- Predicate filtering
- Document transformation

c. Storage Layer:
- CSV file handling component
- File system interactions
- Demonstrate collection-to-file mapping

##### Data Flow Representation
- Transformation flow:
- Generic Document <-> Serialized Data <-> CSV Records

##### Important Elements

a. External Dependencies (show as connected systems):
- csv crate
- serde
- tokio

b. File System Integration:
- How collections map to .csv files
- Automatic file/directory creation

##### The direct mapping to CSV files

- Any special symbols used

Keep the abstraction level focused on the architectural components while showing the key interactions between the CSV handling, async processing, and document serialization layers. This will help developers understand both the high-level structure and the specific implementation details of the system.

Remember to show the error propagation paths and how the system handles file system operations, as these are critical aspects of the database's functionality.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef external fill:#4CAF50,stroke:#2E7D32,color:white
    classDef async fill:#FFC107,stroke:#FFA000,color:black
    classDef storage fill:#9E9E9E,stroke:#616161,color:white
    classDef api fill:#03A9F4,stroke:#0288D1,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[External Dependencies]:::external
        L3[Async Operations]:::async
        L4[Storage Components]:::storage
        L5[API Components]:::api
        L6["--> Sync Flow"]
        L7["-.-> Async Flow"]
    end

    %% Main Components
    DB[Database Struct]:::core
    click DB "https://github.com/vascocosta/csv_db/blob/main/src/lib.rs"

    %% Public API Layer
    subgraph API
        Methods["Public Methods<br/>find()<br/>insert()<br/>delete()<br/>update()"]:::api
        click Methods "https://github.com/vascocosta/csv_db/blob/main/src/lib.rs"
        TypeParams["Generic Document<T><br/>where T: Serialize + DeserializeOwned"]:::api
    end

    %% Processing Layer
    subgraph Processing
        AsyncHandler["Async Handler<br/>(Tokio spawn_blocking)"]:::async
        DocProcessor["Document Processor<br/>- Serialization<br/>- Filtering<br/>- Transformation"]:::core
    end

    %% Storage Layer
    subgraph Storage
        CSVHandler["CSV Handler"]:::storage
        FileSystem["File System<br/>Operations"]:::storage
    end

    %% External Dependencies
    subgraph Dependencies
        Serde["Serde"]:::external
        CSV["csv crate"]:::external
        Tokio["Tokio"]:::external
        click Dependencies "https://github.com/vascocosta/csv_db/blob/main/Cargo.toml"
    end

    %% Relationships
    DB --> Methods
    Methods --> TypeParams
    Methods -.-> AsyncHandler
    AsyncHandler --> DocProcessor
    DocProcessor --> CSVHandler
    CSVHandler --> FileSystem
    
    DocProcessor --> Serde
    CSVHandler --> CSV
    AsyncHandler --> Tokio

    %% Error Flow
    FileSystem -.-> |"Error Propagation"| CSVHandler
    CSVHandler -.-> |"Error Propagation"| DocProcessor
    DocProcessor -.-> |"Error Propagation"| AsyncHandler
    AsyncHandler -.-> |"Error Propagation"| Methods
```
