# tiamo/spss architecture

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

- Interactive diagram: https://gitdiagram.com/tiamo/spss
- Repository: https://github.com/tiamo/spss

## Overview

##### Main Components
- Core SPSS/PSPP Processing Engine: This is distributed mainly within the src directory. Key modules include:
- The Buffer and Utils classes for low-level file I/O and common helper functions.
- The Reader and Writer classes (located in src/Sav) that serve as entry points for reading and writing .sav files.
- The Record abstraction: your design there covers different kinds of SPSS records – for example, Record/Data, Record/Document, Record/Header, Record/Info (with subtypes like CharacterEncoding, DataFileAttributes, etc.), and even a collection class (InfoCollection).
- Exception Handling: The Exception class ensures that error conditions are properly captured.
- Related Modules: The “Por” folder hints at possible additional functionality or alternative record types, so consider it as another component or sub-module within the processing engine.

##### Relationships and Interactions
- Once data is read, the Reader instantiates various Record classes (e.g., Header, Info, Data). Illustrate these as subordinate or colaborative components.
- The Info classes and associated Record components should be depicted as part of a “Record Processing” block that interacts with both Reader and Writer, perhaps indicating an “aggregation” or “has-many” relationship.
- Utilities and Exception handling which interact across these components ensuring robustness.

##### Architectural Patterns or Design Principles
- Separation of Concerns: The responsibilities between reading, record representation, and writing are clearly separated.
- Modularity: Each record type (Header, Info, Data, etc.) is encapsulated within its own class/file, reflecting a modular and maintainable design.
- Extensibility: The presence of a “Por” directory and a collection of Info subtypes indicates foresight for handling variations and potential future extensions.

##### Relevant Technologies and Frameworks
- The library is PHP-based, requiring at least PHP 5.6 along with mbstring and bcmath extensions.
- Composer is used for dependency management, so note that this library can be integrated into larger applications as a Composer package.
- Testing frameworks are used (notice phpunit.xml and tests directory), indicating that unit testing is a critical aspect of the code quality.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Processing Engine
    subgraph "Core Processing Engine"
        E1["Processing Engine"]:::core
        B["Buffer"]:::io
        R["Reader (.sav)"]:::io
        W["Writer (.sav)"]:::io
        U["Utils"]:::util
        Ex["Exception"]:::util
    end

    %% Record Processing Block
    subgraph "Record Processing"
        Rec["Record Abstraction"]:::record
        H["Header Record"]:::record
        D["Data Record"]:::record
        Doc["Document Record"]:::record
        Info["Info Record"]:::record
        IC["InfoCollection"]:::record
        VL["Value Label"]:::record
        VarR["Variable Record"]:::record
        RI["Record Interface"]:::record
        Var["Variable (Higher-level)"]:::record

        subgraph "Info Subtypes"
            CE["CharacterEncoding"]:::record
            DFA["DataFileAttributes"]:::record
            ENC["ExtendedNumberOfCases"]:::record
            LSM["LongStringMissingValues"]:::record
            LSVL["LongStringValueLabels"]:::record
            LVN["LongVariableNames"]:::record
            MFP["MachineFloatingPoint"]:::record
            MI["MachineInteger"]:::record
            UK["Unknown"]:::record
            VA["VariableAttributes"]:::record
            VDP["VariableDisplayParam"]:::record
            VLS["VeryLongString"]:::record
        end
    end

    %% Alternative Processing (Por Module)
    subgraph "Alternative Processing"
        Por["Por Module"]:::record
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Ext["PHP, Composer, mbstring, bcmath, PHPUnit"]:::external
    end

    %% Connections between core components
    R -->|"uses"| B
    W -->|"uses"| B
    R -->|"instantiates"| Rec
    W -->|"aggregates"| Rec

    %% Record details
    Rec -->|"includes"| H
    Rec -->|"includes"| D
    Rec -->|"includes"| Doc
    Rec -->|"includes"| Info
    Info -->|"has_subtypes"| CE
    Info -->|"has_subtypes"| DFA
    Info -->|"has_subtypes"| ENC
    Info -->|"has_subtypes"| LSM
    Info -->|"has_subtypes"| LSVL
    Info -->|"has_subtypes"| LVN
    Info -->|"has_subtypes"| MFP
    Info -->|"has_subtypes"| MI
    Info -->|"has_subtypes"| UK
    Info -->|"has_subtypes"| VA
    Info -->|"has_subtypes"| VDP
    Info -->|"has_subtypes"| VLS
    Rec -->|"includes"| IC
    Rec -->|"includes"| VL
    Rec -->|"includes"| VarR
    Rec -->|"implements"| RI
    Rec -->|"integrates"| Var

    %% Utility & Exception relationships
    R -->|"utilizes"| U
    W -->|"utilizes"| U
    R -->|"raises"| Ex
    W -->|"raises"| Ex

    %% External dependency connection
    E1 -->|"runs_on"| Ext

    %% Click Events
    click E1 "https://github.com/tiamo/spss/tree/master/src/"
    click B "https://github.com/tiamo/spss/blob/master/src/Buffer.php"
    click U "https://github.com/tiamo/spss/blob/master/src/Utils.php"
    click Ex "https://github.com/tiamo/spss/blob/master/src/Exception.php"
    click R "https://github.com/tiamo/spss/blob/master/src/Sav/Reader.php"
    click W "https://github.com/tiamo/spss/blob/master/src/Sav/Writer.php"
    click Rec "https://github.com/tiamo/spss/blob/master/src/Sav/Record.php"
    click H "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Header.php"
    click D "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Data.php"
    click Doc "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Document.php"
    click Info "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info.php"
    click CE "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/CharacterEncoding.php"
    click DFA "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/DataFileAttributes.php"
    click ENC "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/ExtendedNumberOfCases.php"
    click LSM "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/LongStringMissingValues.php"
    click LSVL "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/LongStringValueLabels.php"
    click LVN "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/LongVariableNames.php"
    click MFP "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/MachineFloatingPoint.php"
    click MI "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/MachineInteger.php"
    click UK "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/Unknown.php"
    click VA "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/VariableAttributes.php"
    click VDP "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/VariableDisplayParam.php"
    click VLS "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Info/VeryLongString.php"
    click IC "https://github.com/tiamo/spss/blob/master/src/Sav/Record/InfoCollection.php"
    click VL "https://github.com/tiamo/spss/blob/master/src/Sav/Record/ValueLabel.php"
    click VarR "https://github.com/tiamo/spss/blob/master/src/Sav/Record/Variable.php"
    click RI "https://github.com/tiamo/spss/blob/master/src/Sav/RecordInterface.php"
    click Var "https://github.com/tiamo/spss/blob/master/src/Sav/Variable.php"
    click Por "https://github.com/tiamo/spss/tree/master/src/Por"

    %% Styles
    classDef core fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef io fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef record fill:#C6F6C3,stroke:#333,stroke-width:2px;
    classDef util fill:#FFF7AE,stroke:#333,stroke-width:2px;
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:2px;
```
