# joseias/strmeanlib architecture

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

- Interactive diagram: https://gitdiagram.com/joseias/strmeanlib
- Repository: https://github.com/joseias/strmeanlib

## Overview

##### Project type and purpose
- StrMeanLib is a Java command-line library/tool that implements several heuristic algorithms to compute the median of a set of strings.
- It exposes a CLI entry point (Main.java) and a set of algorithms behind a common interface, configurable via conf.properties and external scoring-matrix files.

##### File structure
- Top-level:
- build.xml – Ant build script
- StrMean.jar – packaged artifact
- conf.properties – runtime configuration
- scoring_matrix_* – editable resource files
- src/strmean – main Java packages
- nbproject – NetBeans project metadata (not part of runtime)
- Key Java packages under src/strmean:
- main – utilities, constants, entry point (Main.java)
- data – data models (Operation, OpInfo, EDResult, MAResult, Example) and comparators
- distances – implementations of EditDistance (Levenshtein, Damerau-Levenshtein, restricted variants)
- malgorithms – MAlgorithm interface + concrete median-string heuristics (MAJRStatistical, MACardenas, etc.)
- opstateval – operation-state evaluators (OpStats*, used by some heuristics)

##### README for additional insights
- Describes two main algorithms and how to switch between them via OPS_STAT_EVALUATOR in conf.properties.
- Shows the runtime invocation:
java –cp StrMean.jar strmean.malgorithms.MAJRStatistical test.in test.out

a. Main components
- CLI/Entry Point (Main.java)
- Configuration Loader (reads conf.properties and matrix files)
- Algorithm Manager
– MAlgorithm interface
– Concrete algorithms in malgorithms/
- Distance Engine
– EditDistance interface
– Implementations in distances/
- Operation Evaluator
– OpStats* classes in opstateval/
- Data Model
– DTOs: Example, Operation, EDResult, MAResult, OpInfo
- I/O Layer
– Input parser (reads test.in)
– Output writer (writes to test.out)

b. Relationships and interactions
1. User invokes Main → Configuration Loader populates algorithm parameters
2. Main instantiates the chosen MAlgorithm
3. MAlgorithm orchestrates iterations:
– Requests distances from Distance Engine
– Uses Operation Evaluator (if required by the heuristic)
– Posts intermediate results into Data Model objects
4. After convergence, results are passed to I/O Layer for writing

c. Architectural patterns and design principles
- Strategy pattern (MAlgorithm vs. concrete classes; EditDistance vs. implementations; OpStats evaluators)
- Separation of concerns:
– CLI & config reading
– Core algorithm logic
– Distance computation
– Data representation
– I/O handling
- Plugin-style extensibility: new median algorithms, new distance metrics, new evaluators can be added without modifying Main.

d. Key technologies and libraries
- Java SE (no external dependencies)
- Ant build (build.xml)
- Configuration via plain properties files
- NetBeans project metadata (nbproject/)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry
    CLI["CLI Invocation\n(java -cp StrMean.jar ...)"]:::entry
    CLI -->|invokes| Main["Main"]:::entry

    %% Configuration Loader
    Main --> ConfigLoader["Configuration Loader"]:::component
    ConfigLoader --> Conf["conf.properties"]:::resource
    ConfigLoader --> SM_COP["scoring_matrix_copenhagen"]:::resource
    ConfigLoader --> SM_DNA["scoring_matrix_dna"]:::resource
    ConfigLoader --> SM_FRE["scoring_matrix_freeman"]:::resource

    %% Algorithm Manager
    Main --> MAlgIface["MAlgorithm (interface)"]:::interface
    subgraph "Concrete Algorithms" 
        MAC["MACardenas"]:::concrete
        MAF["MAFischer2000"]:::concrete
        MAHSP["MAJOPStatistical_HSP"]:::concrete
        MAJR["MAJRStatistical"]:::concrete
        MAJRM["MAJRStatisticalMultiOp"]:::concrete
        MASET["MASet"]:::concrete
    end
    MAlgIface --> MAC
    MAlgIface --> MAF
    MAlgIface --> MAHSP
    MAlgIface --> MAJR
    MAlgIface --> MAJRM
    MAlgIface --> MASET

    %% Distance Engine
    Main --> DistIface["EditDistance (interface)"]:::interface
    subgraph "Distance Implementations"
        EDLEV["EDLevenshtein"]:::concrete
        EDDAM["EDDamerauLevenshtein"]:::concrete
        EDRL["EDDLRestricted"]:::concrete
        EDRLK["EDDLRestrictedK"]:::concrete
    end
    DistIface --> EDLEV
    DistIface --> EDDAM
    DistIface --> EDRL
    DistIface --> EDRLK

    %% Operation Evaluator
    Main --> OpStatsIface["OpStats (base class)"]:::interface
    subgraph "OpStats Variants"
        JS["OpStatsJR"]:::concrete
        JRF["OpStatsJRF"]:::concrete
        JRIS["OpStatsJRIS"]:::concrete
        PS["OpStatsP"]:::concrete
    end
    OpStatsIface --> JS
    OpStatsIface --> JRF
    OpStatsIface --> JRIS
    OpStatsIface --> PS

    %% Data Model
    Main --> DataModel["Data Model"]:::component
    subgraph "DTOs"
        ExampleDTO["Example"]:::dto
        OperationDTO["Operation"]:::dto
        EDResultDTO["EDResult"]:::dto
        MAResultDTO["MAResult"]:::dto
        OpInfoDTO["OpInfo"]:::dto
    end
    DataModel --> ExampleDTO
    DataModel --> OperationDTO
    DataModel --> EDResultDTO
    DataModel --> MAResultDTO
    DataModel --> OpInfoDTO

    %% I/O Layer
    Main --> IO["I/O Layer"]:::component
    subgraph "Files"
        InputFile["test.in"]:::io
        OutputFile["test.out"]:::io
    end
    IO --> InputFile
    IO --> OutputFile

    %% Utilities & Constants
    Main --> Utils["Utilities & Constants"]:::component
    subgraph "Utils"
        JUtils["JUtils"]:::util
        JMath["JMathUtils"]:::util
        JStats["JStats"]:::util
        JConst["JConstants"]:::util
    end
    Utils --> JUtils
    Utils --> JMath
    Utils --> JStats
    Utils --> JConst

    %% Build & Packaging
    Build["Build & Packaging"]:::component
    Build --> BuildXML["build.xml"]:::resource
    Build --> Jar["StrMean.jar"]:::resource

    CLI --> Build

    %% Click Events
    click Main "https://github.com/joseias/strmeanlib/blob/master/src/strmean/main/Main.java"
    click Conf "https://github.com/joseias/strmeanlib/blob/master/conf.properties"
    click SM_COP "https://github.com/joseias/strmeanlib/tree/master/scoring_matrix_copenhagen"
    click SM_DNA "https://github.com/joseias/strmeanlib/tree/master/scoring_matrix_dna"
    click SM_FRE "https://github.com/joseias/strmeanlib/tree/master/scoring_matrix_freeman"
    click MAlgIface "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MAlgorithm.java"
    click MAC "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MACardenas.java"
    click MAF "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MAFischer2000.java"
    click MAHSP "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MAJOPStatistical_HSP.java"
    click MAJR "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MAJRStatistical.java"
    click MAJRM "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MAJRStatisticalMultiOp.java"
    click MASET "https://github.com/joseias/strmeanlib/blob/master/src/strmean/malgorithms/MASet.java"
    click DistIface "https://github.com/joseias/strmeanlib/blob/master/src/strmean/distances/EditDistance.java"
    click EDLEV "https://github.com/joseias/strmeanlib/blob/master/src/strmean/distances/EDLevenshtein.java"
    click EDDAM "https://github.com/joseias/strmeanlib/blob/master/src/strmean/distances/EDDamerauLevenshtein.java"
    click EDRL "https://github.com/joseias/strmeanlib/blob/master/src/strmean/distances/EDDLRestricted.java"
    click EDRLK "https://github.com/joseias/strmeanlib/blob/master/src/strmean/distances/EDDLRestrictedK.java"
    click OpStatsIface "https://github.com/joseias/strmeanlib/blob/master/src/strmean/opstateval/OpStats.java"
    click JS "https://github.com/joseias/strmeanlib/blob/master/src/strmean/opstateval/OpStatsJR.java"
    click JRF "https://github.com/joseias/strmeanlib/blob/master/src/strmean/opstateval/OpStatsJRF.java"
    click JRIS "https://github.com/joseias/strmeanlib/blob/master/src/strmean/opstateval/OpStatsJRIS.java"
    click PS "https://github.com/joseias/strmeanlib/blob/master/src/strmean/opstateval/OpStatsP.java"
    click ExampleDTO "https://github.com/joseias/strmeanlib/blob/master/src/strmean/data/Example.java"
    click OperationDTO "https://github.com/joseias/strmeanlib/blob/master/src/strmean/data/Operation.java"
    click EDResultDTO "https://github.com/joseias/strmeanlib/blob/master/src/strmean/data/EDResult.java"
    click MAResultDTO "https://github.com/joseias/strmeanlib/blob/master/src/strmean/data/MAResult.java"
    click OpInfoDTO "https://github.com/joseias/strmeanlib/blob/master/src/strmean/data/OpInfo.java"
    click InputFile "https://github.com/joseias/strmeanlib/blob/master/test.in"
    click OutputFile "https://github.com/joseias/strmeanlib/blob/master/test.out"
    click JUtils "https://github.com/joseias/strmeanlib/blob/master/src/strmean/main/JUtils.java"
    click JMath "https://github.com/joseias/strmeanlib/blob/master/src/strmean/main/JMathUtils.java"
    click JStats "https://github.com/joseias/strmeanlib/blob/master/src/strmean/main/JStats.java"
    click JConst "https://github.com/joseias/strmeanlib/blob/master/src/strmean/main/JConstants.java"
    click BuildXML "https://github.com/joseias/strmeanlib/blob/master/build.xml"
    click Jar "https://github.com/joseias/strmeanlib/blob/master/StrMean.jar"

    %% Styles
    classDef entry fill:#f9c2e2,stroke:#333,stroke-width:1px
    classDef interface fill:#c2e7ff,stroke:#333,stroke-width:1px
    classDef concrete fill:#d2f8d2,stroke:#333,stroke-width:1px
    classDef resource fill:#cccccc,stroke:#333,stroke-width:1px
    classDef component fill:#e8e8e8,stroke:#333,stroke-width:1px
    classDef dto fill:#fff8b3,stroke:#333,stroke-width:1px
    classDef util fill:#ffd9b3,stroke:#333,stroke-width:1px
    classDef io fill:#e0d1f9,stroke:#333,stroke-width:1px
```
