# masaue/jan-js-lib architecture

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

- Interactive diagram: https://gitdiagram.com/masaue/jan-js-lib
- Repository: https://github.com/masaue/jan-js-lib

## Overview

##### Project type and purpose
- This is an open-source TypeScript library (NPM package) named “jan-js-lib” whose sole purpose is to calculate Mahjong hand scores under the Mahjong Competition Rules (and work-in-progress Zung Jung Mahjong).
- There is no frontend or backend service; it is a purely computational domain library, consumed by other applications.

##### File structure
- Top-level files and folders
- package.json / package-lock.json / LICENSE / .gitignore / tsconfig*.json
- README.md, README-ja.md, documents/ (supporting docs)
- src/main/ts/… (the library’s domain and calculation code)
- src/test/js/… (unit tests against the compiled JS)
- Within src/main/ts/, you see a clear domain module breakdown under “jan/”:
- Domain entities and types: janpai.ts, mentsu.ts, hand.ts, complete-info.ts, etc.
- Utility modules for pattern detection and scoring: mcr-util.ts, yaku-util.ts, zjm-util.ts.
- Enumeration and ID definitions: janpai-id.ts, mentsu-type.ts, suit.ts, wind.ts.
- Build and deployment
- tsconfig.json configures local development
- tsconfig-publish.json likely controls compiled output for NPM
- No CI/CD or Docker artifacts—publishing is via npm (per documents/HowToPublish.md).

##### Key insights from the README
- Exports a set of classes/types (CompleteInfo, Hand, Janpai, McrUtil, Mentsu, etc.).
- Usage example shows the flow: build a Hand, pass it plus CompleteInfo into McrUtil.complete(), then inspect the returned object (point total + yakuList).
- There is no external database or network; it’s pure in-memory computation.

##### Detail
- Distinction between MCR and ZJM rule modules.
- Publish path (src → dist → npm) and the test path (dist → tests).
- Keep labels succinct but precise (e.g., “McrUtil.complete() → CompleteResult”).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Consumer
    User["Consumer Application"]:::external

    %% API Layer
    subgraph "API / Public Interface"
        API["index.ts"]:::api
    end

    %% Domain Model Layer
    subgraph "Domain Model" 
        JP["janpai.ts"]:::domain
        MT["mentsu.ts"]:::domain
        HD["hand.ts"]:::domain
        CI["complete-info.ts"]:::domain
        CT["complete-type.ts"]:::domain
        CaT["call-type.ts"]:::domain
        MTy["mentsu-type.ts"]:::domain
        ST["suit.ts"]:::domain
        WD["wind.ts"]:::domain
        JID["janpai-id.ts"]:::domain
    end

    %% Scoring Engine Layer
    subgraph "Scoring Engine"
        subgraph "MCR Rules"
            MCRU["mcr-util.ts"]:::engine
            MCRC["mcr-complete.ts"]:::engine
            MCRY["mcr-yaku.ts"]:::engine
        end
        subgraph "ZJM Rules (WIP)"
            ZJMU["zjm-util.ts"]:::engine
            ZJMY["zjm-yaku.ts"]:::engine
        end
        subgraph "Shared Utilities"
            YU["yaku-util.ts"]:::engine
            MU["mentsu-util.ts"]:::engine
            HU["hand-util.ts"]:::engine
            JANU["jan-util.ts"]:::engine
        end
    end

    %% Build & Publish Pipeline
    subgraph "Build & Publish"
        TSC["tsconfig.json"]:::build
        TSC_PUB["tsconfig-publish.json"]:::build
        PKG["package.json"]:::build
        PKG_LOCK["package-lock.json"]:::build
        HOWTO["HowToPublish.md"]:::build
    end

    %% Testing Harness
    subgraph "Testing Harness"
        T1["jan-js-lib-test.js"]:::test
        T2["complete-pattern-test.js"]:::test
        T3["hand-test.js"]:::test
        T4["hand-util-test.js"]:::test
        T5["jan-util-test.js"]:::test
        T6["mcr-util-test.js"]:::test
        T7["yaku-util-test.js"]:::test
        T8["zjm-util-test.js"]:::test
    end

    %% Documentation & Patterns
    subgraph "Documentation & Patterns"
        RD1["README.md"]:::doc
        RD2["README-ja.md"]:::doc
        DP1["McrYakuPattern.md"]:::doc
        DP2["McrYakuPattern-ja.md"]:::doc
    end

    %% Connections
    User -->|"imports"| API
    API -->|"uses"| JP
    API -->|"uses"| MT
    API -->|"uses"| HD
    API -->|"uses"| CI
    API -->|"uses"| CT
    API -->|"uses"| CaT
    API -->|"uses"| MTy
    API -->|"uses"| ST
    API -->|"uses"| WD
    API -->|"uses"| JID
    API -->|"invokes"| MCRU
    API -->|"invokes"| ZJMU

    MCRU -->|"calls"| MCRC
    MCRU -->|"detects yaku via"| MCRY
    ZJMU -->|"detects yaku via"| ZJMY

    MCRU -->|"utilizes"| YU
    MCRU -->|"utilizes"| MU
    MCRU -->|"utilizes"| HU
    MCRU -->|"utilizes"| JANU
    ZJMU -->|"utilizes"| YU
    ZJMU -->|"utilizes"| MU
    ZJMU -->|"utilizes"| HU
    ZJMU -->|"utilizes"| JANU

    %% Build and Test
    API -->|"source for build"| TSC
    TSC -->|"compile to dist"| PKG
    PKG -->|"publish via npm"| HOWTO
    PKG -->|"lock deps"| PKG_LOCK

    %% Tests run on dist
    T1 & T2 & T3 & T4 & T5 & T6 & T7 & T8 -->|"run on dist JS"| PKG

    %% Documentation links
    HOWTO --> RD1
    HOWTO --> RD2
    HOWTO --> DP1
    HOWTO --> DP2

    %% Click Events
    click API "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/index.ts"
    click JP "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/janpai.ts"
    click MT "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/mentsu.ts"
    click HD "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/hand.ts"
    click CI "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/complete-info.ts"
    click CT "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/complete-type.ts"
    click CaT "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/call-type.ts"
    click MTy "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/mentsu-type.ts"
    click ST "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/suit.ts"
    click WD "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/wind.ts"
    click JID "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/janpai-id.ts"
    click MCRU "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/mcr-util.ts"
    click MCRC "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/mcr-complete.ts"
    click MCRY "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/mcr-yaku.ts"
    click ZJMU "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/zjm-util.ts"
    click ZJMY "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/zjm-yaku.ts"
    click YU "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/yaku-util.ts"
    click MU "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/mentsu-util.ts"
    click HU "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/hand-util.ts"
    click JANU "https://github.com/masaue/jan-js-lib/blob/main/src/main/ts/jan/jan-util.ts"
    click TSC "https://github.com/masaue/jan-js-lib/blob/main/tsconfig.json"
    click TSC_PUB "https://github.com/masaue/jan-js-lib/blob/main/tsconfig-publish.json"
    click PKG "https://github.com/masaue/jan-js-lib/blob/main/package.json"
    click PKG_LOCK "https://github.com/masaue/jan-js-lib/blob/main/package-lock.json"
    click HOWTO "https://github.com/masaue/jan-js-lib/blob/main/documents/HowToPublish.md"
    click T1 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan-js-lib-test.js"
    click T2 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/complete-pattern-test.js"
    click T3 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/hand-test.js"
    click T4 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/hand-util-test.js"
    click T5 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/jan-util-test.js"
    click T6 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/mcr-util-test.js"
    click T7 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/yaku-util-test.js"
    click T8 "https://github.com/masaue/jan-js-lib/blob/main/src/test/js/jan/zjm-util-test.js"

    %% Styles
    classDef domain fill:#ADD8E6,stroke:#000
    classDef engine fill:#90EE90,stroke:#000
    classDef api fill:#FFFACD,stroke:#000
    classDef build fill:#D3D3D3,stroke:#000
    classDef test fill:#D3D3D3,stroke:#000
    classDef doc fill:#E6E6FA,stroke:#000
    classDef external fill:#FFFFFF,stroke:#000,stroke-dasharray: 5 5
```
