# peinan/peinan-utils-py architecture

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

- Interactive diagram: https://gitdiagram.com/peinan/peinan-utils-py
- Repository: https://github.com/peinan/peinan-utils-py

## Overview

##### Main Components
- Package Core (peinan_utils): This is the primary module directory. Within it, you have several sub-components:
- Parser: Responsible for tokenizing text and extracting morphological details.
- Vectorizer: Implements functions to create word and character n-grams (with options for beginning/ending tokens).
- Statist: Handles statistical analysis of texts (e.g., calculating token and vocabulary counts) and can operate on external text files such as sample.txt.
- Matplotlib Utils: Provides utilities to setup matplotlib (especially with support for Japanese fonts) so that plotting looks correct.
- Logger: A module to provide logging functionality during processing.
- Supporting Assets:
- Fonts: A directory under peinan_utils containing the appropriate Japanese fonts needed for matplotlib visualizations.
- Configuration/Versioning Files: Files like VERSION, pyproject.toml, and the Makefile which support builds, version management, and installation.
- External Dependencies: Although not shown in the file tree, usage of libraries like matplotlib (and possibly mecab for dictionary parsing) is evident from the README.

##### Depicting Relationships and Interactions
- Each component is relatively independent; however, they can be visualized as forming a cohesive library:
- The Parser may feed processed text to the Vectorizer if used in tandem in a larger analysis pipeline. Similarly, the Statist module can use outputs from the Parser.
- The Matplotlib Utils module does not directly interact with the analysis components but is essential for rendering results visually, so an external link to “Visualization” (via matplotlib) should be shown.

##### Highlighting Architectural Patterns and Design Principles
- Modular Architecture: Emphasize that each functionality is encapsulated in its own module for separation of concerns and testability.
- Reusability: Highlight that the library is designed to be installed via pip and imported into other projects easily.
- Extensibility: Acknowledge that the presence of configurable elements (e.g., dictionary paths in the Parser’s set_dict method) suggests the system is built with flexibility in mind.
- Lightweight Dependency Injection: Although dependencies are implicitly managed (e.g., fonts for matplotlib), the design allows clients to plug in alternative resources when needed.

- Branch off to:
- Parser: Converts text to tokens and extracts features.
- Vectorizer: Processes the parsed text into n-grams.
- Statist: Computes word/character statistics based on the parsed input.
- A side branch for Logger that “listens” to operations in the above modules.
- Conclude the flow by showing Matplotlib Utils as a separate component that takes processed data (or statistical summaries) to produce visuals.
- A small separate section for “Assets & Configuration” which connects to the relevant modules (for example, Font assets are utilized by Matplotlib Utils).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Node
    INPUT("Input Text"):::input

    %% Package Core Directory
    CORE("peinan_utils (Package Core)"):::package

    %% Core Modules Layer
    subgraph "Core Modules"
        PARSER("Parser Module"):::module
        VECT("Vectorizer Module"):::module
        STAT("Statist Module"):::module
        MUTILS("Matplotlib Utils"):::module
        LOGGER("Logger Module"):::utility
    end

    %% Assets & Configuration Layer
    subgraph "Assets & Configuration"
        FONTS("Fonts"):::asset
        VERSION("VERSION"):::asset
        PYPROJ("pyproject.toml"):::asset
        MAKE("Makefile"):::asset
    end

    %% External Dependencies Layer
    subgraph "External Dependencies"
        PYTHON("Python 3.6+"):::external
        MPL("matplotlib"):::external
        MECAB("Mecab"):::external
    end

    %% Data Flow Connections
    INPUT -->|"processes"| PARSER
    PARSER -->|"feeds tokens"| VECT
    PARSER -->|"feeds tokens"| STAT
    PARSER -->|"logs"| LOGGER
    VECT -->|"logs"| LOGGER
    STAT -->|"logs"| LOGGER
    VECT -->|"visualizes"| MUTILS
    STAT -->|"visualizes"| MUTILS
    FONTS -->|"provides fonts"| MUTILS

    %% External Dependencies Connections
    MPL -->|"used-by"| MUTILS
    MECAB -->|"configures"| PARSER

    %% Package Core Relationships
    CORE --- PARSER
    CORE --- VECT
    CORE --- STAT
    CORE --- MUTILS
    CORE --- LOGGER

    %% Click Events
    click CORE "https://github.com/peinan/peinan-utils-py/tree/master/peinan_utils"
    click PARSER "https://github.com/peinan/peinan-utils-py/blob/master/peinan_utils/parser.py"
    click VECT "https://github.com/peinan/peinan-utils-py/blob/master/peinan_utils/vectorizer.py"
    click STAT "https://github.com/peinan/peinan-utils-py/blob/master/peinan_utils/stat_utils.py"
    click MUTILS "https://github.com/peinan/peinan-utils-py/blob/master/peinan_utils/matplotlib_utils.py"
    click LOGGER "https://github.com/peinan/peinan-utils-py/blob/master/peinan_utils/logger.py"
    click FONTS "https://github.com/peinan/peinan-utils-py/tree/master/peinan_utils/fonts"
    click VERSION "https://github.com/peinan/peinan-utils-py/tree/master/peinan_utils/VERSION"
    click PYPROJ "https://github.com/peinan/peinan-utils-py/blob/master/pyproject.toml"
    click MAKE "https://github.com/peinan/peinan-utils-py/tree/master/Makefile"

    %% Styles
    classDef module fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef input fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef asset fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef package fill:#e2e3e5,stroke:#333,stroke-width:2px;
    classDef utility fill:#d1ecf1,stroke:#333,stroke-width:2px;
```
