# yokenzan/receiptisan architecture

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

- Interactive diagram: https://gitdiagram.com/yokenzan/receiptisan
- Repository: https://github.com/yokenzan/receiptisan

## Overview

This project, receiptisan, is a command-line Ruby application aimed at parsing and previewing electronic receipt files (specifically for inpatient “出来高レセプト”) from a standardized input file (RECEIPTC.UKE). The tool uses a mix of CSV master files and configuration files (organized by year) to manage parsing rules such as abbreviations and tagging, and it offers various output formats (SVG, YAML, JSON) for the receipt preview.

##### Main Components
- Command-Line Interface (CLI)
– Entry point provided by files such as exe/receiptisan and the bin scripts.
– This layer manages the user commands (e.g., “--preview”) and delegates to lower-level modules.
- Parser Module
– Located within lib/receiptisan/model/receipt_computer/digitalized_receipt and its parser subdirectories.
– Responsible for interpreting the receipt file’s content, handling buffer, context, and producing an internal representation.
- Master Data & Configuration Management
– The “config” and “csv/master” directories indicate that the application supports multiple years and different configuration files (e.g., abbrev and tag files).
– The modules under lib/receiptisan/model/receipt_computer/master handle the lookup of diagnosis, treatment, and other master data.
- Output/Preview Generation
– Implemented in lib/receiptisan/output/preview.
– This component takes processed data and generates preview outputs (HTML with embedded SVG, YAML or JSON for internal data).
- Utility & Helper Components
– Contains utility functions, formatting, date manipulation, and common IO-handling.
– Found under lib/receiptisan/util and related subdirectories.
- Testing & CI Integration
– The “spec” and “.github/workflows” directories indicate automated tests and continuous integration processes (via workflows such as release.yml and ruby.yml).

##### Relationships and Interactions
- The CLI layer receives user input and calls the core engine.
- The core engine uses the parser module to read input receipt files.
- The parser interfaces with configuration and CSV master data modules to correctly interpret the content.
- After processing, the output module then generates the preview in the specified format.
- Utility modules support all above components with common functionality such as formatting and encoding.
- The testing suite validates the behavior relations through unit tests structured in the “spec” directories.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each main component (CLI, Parser, Master/Config, Output) is isolated to enhance maintainability.
- Modular Design: The directory structure clearly separates functional modules (e.g., digitalized_receipt, master, output preview).
- Layered Architecture: Input flows from the CLI layer down through the model (with parsing and business logic) then up to the output layer.
- Extensibility: The design allows for future expansion (e.g., extending support beyond inpatient receipts or adding new formats) by keeping responsibilities separate.

##### Additional Elements to Incorporate
- For every component, add a label (e.g., “CLI – Entry Point”, “Parser – Digital Receipt Parser”, “Master – Configuration & Lookup”, “Output – Preview Renderer”).
- User Input → CLI → Parser.
- Parser → Master Data Module (for lookup/config).
- Parser → Output Module (for generating previews).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User"):::external

    subgraph "Command-Line Interface"
        CLI_exe("CLI - Entry Point"):::cli
        CLI_bin("CLI - Helper Scripts"):::cli
    end

    PR("Parser - Digital Receipt Parser"):::parser

    subgraph "Master Data & Configuration"
        CF("Config Files"):::config
        CM("CSV Master Data"):::config
        MM("Master Modules"):::config
    end

    OUT("Output - Preview Generation"):::output

    UT("Utility & Helpers"):::utility

    subgraph "Testing & CI"
        TS("Testing Framework"):::testing
        CI("CI Workflows"):::testing
    end

    U -->|"input"| CLI_exe
    CLI_exe -->|"delegates"| PR
    CLI_bin --- PR

    PR -->|"uses"| CF
    PR -->|"uses"| CM
    PR -->|"uses"| MM
    PR -->|"processes"| OUT

    UT --- CLI_exe
    UT --- PR
    UT --- CF
    UT --- CM
    UT --- MM
    UT --- OUT

    TS --- PR
    TS --- OUT
    CI --- TS

    click CLI_exe "https://github.com/yokenzan/receiptisan/tree/master/exe/receiptisan"
    click CLI_bin "https://github.com/yokenzan/receiptisan/tree/master/bin/"
    click PR "https://github.com/yokenzan/receiptisan/tree/master/lib/receiptisan/model/receipt_computer/digitalized_receipt/parser"
    click CF "https://github.com/yokenzan/receiptisan/tree/master/config/"
    click CM "https://github.com/yokenzan/receiptisan/tree/master/csv/master/"
    click MM "https://github.com/yokenzan/receiptisan/tree/master/lib/receiptisan/model/receipt_computer/master"
    click OUT "https://github.com/yokenzan/receiptisan/tree/master/lib/receiptisan/output/preview"
    click UT "https://github.com/yokenzan/receiptisan/tree/master/lib/receiptisan/util"
    click TS "https://github.com/yokenzan/receiptisan/tree/master/spec/"
    click CI "https://github.com/yokenzan/receiptisan/tree/master/.github/workflows/"

    classDef external fill:#f9f,stroke:#333,stroke-width:2px;
    classDef cli fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef parser fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef config fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef output fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef utility fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef testing fill:#FFA500,stroke:#333,stroke-width:2px;
```
