# digital-go-jp/lawqa_jp architecture

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

- Interactive diagram: https://gitdiagram.com/digital-go-jp/lawqa_jp
- Repository: https://github.com/digital-go-jp/lawqa_jp

## Overview

##### Project type and purpose
- This is not a traditional source‐code project but a structured dataset repository for multiple‐choice QA on Japanese law.
- The dataset supports tasks such as information retrieval, RAG pipelines, LLM fine-tuning, evaluation, and ground-truth curation.

##### File structure
- Top-level: LICENSE.md, README.md, and a single data/ directory.
- data/ contains:
- law_list.json – list of statutes referenced in questions
- selection.json – original Q&A JSON
- selection.csv – tabular CSV export
- selection_randomized.json – randomized‐option variants
- selection_with_reference_randomized.json – filtered + randomized for reference‐heavy items
- No code, build scripts, or deployment descriptors are present; this is a pure data asset.

##### README for additional insights
- Describes intended use cases (QA system training/evaluation, RAG pipeline tests, LLM aggregation).
- Documents file formats, fields, and markdown conventions for headings and external legal references.

##### Main components
a. Data Storage Layer
- Raw files in data/ (JSON, CSV) housed in a versioned data‐repository (e.g., Git/LFS or object storage).
b. Preprocessing Module
- Scripts or services that load selection.json ➔ validate schema ➔ produce CSV or randomized JSON variants.
c. Knowledge Base Index
- law_list.json feeds into a search index (Elasticsearch, vector DB) for RAG or retrieval tasks.
d. Inference & Evaluation Layer
- External LLM APIs (e.g., OpenAI, local LLM) receive context + question ➔ generate candidate answers.
- Evaluation service compares outputs against ‘output’ field in the dataset.
e. Aggregation & Curation Service
- Aggregates multiple LLM responses, applies heuristics to build ground truth or vote-based labels.
f. Frontend/UI (optional)
- A dashboard for exploring questions, reviewing references, sampling randomized sets.

##### Relationships & interactions
- Data Repository ➔ Preprocessing ➔ outputs variants stored back.
- Preprocessing + law_list.json ➔ index builder ➔ Search/Vector DB.
- Inference Layer pulls questions + context from data store and hits Search/Vector DB for retrieval‐augmented context.
- LLM API calls return responses to Evaluation Layer.
- Evaluation results feed into Curation Service and analytics dashboards.

##### Architectural patterns & design principles
- Pipeline pattern: clear stages (ingest → preprocess → index → infer → evaluate → curate).
- Separation of concerns:
- Data at rest vs. data in motion
- Storage vs. compute vs. external services
- Extensibility: plug in new LLMs, swap vector DBs, add new data variants.

##### Relevant technologies (examples)
- Object storage/Git LFS for dataset
- Python or Node.js preprocessing scripts
- Elasticsearch, FAISS, or Pinecone for RAG index
- External LLM services (OpenAI, Cohere)
- Evaluation via PyTest or custom metrics modules
- Web dashboard: React or Streamlit

##### Final advice
- Be meticulous in labeling every field or artifact that participates in the pipeline.
- Dataset variants as separate nodes if they serve different use cases.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Data Storage Layer
    subgraph "Data Storage Layer"
        LICENSE["LICENSE.md"]:::storage
        README["README.md"]:::storage
        subgraph "data/" 
            lawList["law_list.json"]:::storage
            rawQA["selection.json"]:::storage
            csvVariant["selection.csv"]:::storage
            randVar["selection_randomized.json"]:::storage
            refRandVar["selection_with_reference_randomized.json"]:::storage
        end
    end

    %% Preprocessing Module
    subgraph "Preprocessing Module"
        Preprocessor["Preprocessor Service"]:::processing
    end

    %% Knowledge Base Index
    subgraph "Knowledge Base Index"
        IndexBuilder["Index Builder"]:::processing
        SearchDB["Search/Vector DB"]:::processing
    end

    %% Inference & Evaluation Layer
    subgraph "Inference & Evaluation Layer"
        InferenceService["Inference Service"]:::processing
        LLMAPI["External LLM APIs"]:::external
        EvaluationService["Evaluation Service"]:::processing
    end

    %% Aggregation & Curation Service
    subgraph "Aggregation & Curation Service"
        CurationService["Curation Service"]:::processing
    end

    %% Frontend/UI
    subgraph "User Interface"
        UISvc["Dashboard UI"]:::ui
    end

    %% Connections
    LICENSE -->|versioned data| Preprocessor
    README -->|metadata| Preprocessor
    rawQA -->|raw JSON| Preprocessor
    Preprocessor -->|CSV export| csvVariant
    Preprocessor -->|randomized JSON| randVar
    Preprocessor -->|filtered+randomized JSON| refRandVar

    lawList -->|statutes list| IndexBuilder
    IndexBuilder -->|vector embeddings| SearchDB

    rawQA -->|questions| InferenceService
    SearchDB -->|retrieval context| InferenceService
    InferenceService -->|LLM request/response| LLMAPI
    LLMAPI -->|responses| InferenceService

    InferenceService -->|candidate answers| EvaluationService
    EvaluationService -->|evaluation report| CurationService
    CurationService -->|curated data| Preprocessor

    UISvc -->|explore dataset| rawQA
    UISvc -->|view metrics| EvaluationService

    %% Click Events
    click LICENSE "https://github.com/digital-go-jp/lawqa_jp/blob/main/LICENSE.md"
    click README "https://github.com/digital-go-jp/lawqa_jp/blob/main/README.md"
    click lawList "https://github.com/digital-go-jp/lawqa_jp/blob/main/data/law_list.json"
    click rawQA "https://github.com/digital-go-jp/lawqa_jp/blob/main/data/selection.json"
    click csvVariant "https://github.com/digital-go-jp/lawqa_jp/blob/main/data/selection.csv"
    click randVar "https://github.com/digital-go-jp/lawqa_jp/blob/main/data/selection_randomized.json"
    click refRandVar "https://github.com/digital-go-jp/lawqa_jp/blob/main/data/selection_with_reference_randomized.json"

    %% Styles
    classDef storage fill:#1f77b4,stroke:#000,color:#fff
    classDef processing fill:#2ca02c,stroke:#000,color:#fff
    classDef external fill:#ff7f0e,stroke:#000,color:#fff
    classDef ui fill:#9467bd,stroke:#000,color:#fff
```
