# arya2004/mainframe-project architecture

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

- Interactive diagram: https://gitdiagram.com/arya2004/mainframe-project
- Repository: https://github.com/arya2004/mainframe-project

## Overview

##### Project Type and Purpose
- The project is a COBOL application that merges three input files, sorts the combined records by a key field, and writes the result to an output file.
- Its primary purpose is to demonstrate file handling and sorting using COBOL’s built-in SORT verb.

##### Analyzing the File Structure
- The top-level directories include configuration/CI support files (.github, Makefile, CONTRIBUTING, etc.) and the source directory.
- The source directory contains the actual COBOL source code (MERGE-SORT-FILES.CBL) and the data files (FILE1.DAT, FILE2.DAT, FILE3.DAT, OUTPUT.DAT).
- Although the temporary sort file (SORTFILE.TMP) is not explicitly in the file tree, the README clarifies its role; it’s an integral part of the execution process.

##### Key Components
A. Input File Readers:
- Three input data components representing FILE1.DAT, FILE2.DAT, and FILE3.DAT.
- That each file contains records with a KEY and DATA fields.
B. Merge/Intermediate Processing Component:
- A component that “merges” the contents of all three input files into a single stream.
- A temporary file (SORTFILE.TMP) is used here to hold merged data before sorting.
C. Sorting Component:
- Use of COBOL’s SORT verb which processes data based on the key field.
- Transformation (unsorted merged data → sorted data).
D. Output File Writer:
- A component that writes the sorted records into OUTPUT.DAT.
E. Build/Compilation Environment (Optional but Informative):
- An optional note about the build process using the Makefile and compilation via a COBOL compiler (like GnuCOBOL’s cobc).

##### Relationships and Data Flow
- That the COBOL program inherently executes these phases sequentially — reading, merging, sorting, and then outputting the records.

##### Architectural Patterns or Design Principles
- The design follows a linear batch processing pipeline — clear separation of concerns for input processing, sorting logic, and output generation.
- The emphasis is on data flow and transformation rather than a complex interactive application.
- It demonstrates procedural programming and structured design typical of COBOL applications.

##### Detail Level
- Including the temporary sort file (even if transient) is essential to fully capture the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Input File Readers"
        FILE1["FILE1.DAT"]:::file
        FILE2["FILE2.DAT"]:::file
        FILE3["FILE3.DAT"]:::file
    end

    subgraph "Merge/Intermediate Processing"
        MERGE["Merge/Intermediate Processing (SORTFILE.TMP)"]:::processing
    end

    subgraph "Sorting Component"
        SORT["COBOL Sort Operation"]:::processing
    end

    subgraph "Output File Writer"
        OUTPUT["OUTPUT.DAT"]:::file
    end

    subgraph "Build/Compilation Environment"
        MAKEFILE["Makefile"]:::build
    end

    FILE1 -->|"reads"| MERGE
    FILE2 -->|"reads"| MERGE
    FILE3 -->|"reads"| MERGE
    MERGE -->|"merges_to"| SORT
    SORT -->|"writes"| OUTPUT

    click FILE1 "https://github.com/arya2004/mainframe-project/blob/main/source/FILE1.DAT"
    click FILE2 "https://github.com/arya2004/mainframe-project/blob/main/source/FILE2.DAT"
    click FILE3 "https://github.com/arya2004/mainframe-project/blob/main/source/FILE3.DAT"
    click MERGE "https://github.com/arya2004/mainframe-project/blob/main/source/MERGE-SORT-FILES.CBL"
    click SORT "https://github.com/arya2004/mainframe-project/blob/main/source/MERGE-SORT-FILES.CBL"
    click OUTPUT "https://github.com/arya2004/mainframe-project/blob/main/source/OUTPUT.DAT"
    click MAKEFILE "https://github.com/arya2004/mainframe-project/tree/main/Makefile"

    classDef file fill:#a2d9ce,stroke:#1f618d,stroke-width:2px;
    classDef processing fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef build fill:#f5cba7,stroke:#cb4335,stroke-width:2px;
```
