# nafmo/bastext architecture

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

- Interactive diagram: https://gitdiagram.com/nafmo/bastext
- Repository: https://github.com/nafmo/bastext

## Overview

Key Components to Include:

##### Input Processing Layer
- Two possible input sources:
- Binary BASIC files (.prg)
- T64 archive files
- Using dtokeniz.c and t64.c components

##### Core Processing Pipeline
- Main processing flow with these components:
a. Input Mode Handler (inmode.c)
b. Tokenizer (tokenize.c)
c. Token Management (tokens.c)
d. Selection Logic (select.c)
e. Output Mode Handler (outmode.c)

##### Format Support Layer
- Supported BASIC dialects:
- BASIC 2.0
- BASIC 3.5
- BASIC 4.0
- BASIC 7.0
- BASIC 7.1
- Various extensions (TFC III, Graphics52, etc.)

**[Input Sources] → [Input Handler] → [Processing Core] → [Output Handler] → [Output Formats]**

##### Component Relationships
- Use double lines for file I/O operations

##### Decision Points
- Format detection logic
- Command-line option handling
- BASIC dialect selection process

Specific Implementation Details:

##### Version.h information as a metadata component

Key Aspects to Emphasize:

##### Command-Line Interface
- How -i/-o/-h flags affect the processing flow
- Optional modifier handling (-t, -a, -s, -d)

##### Format Detection
- Address-based autodetection logic
- Header parsing system

##### Error Handling
- Error paths for unsupported formats
- Validation checkpoints

- File types (Binary, Text, T64)
- Processing states
- Control flow types
- Component types
- Format indicators

Level of Detail:
- Keep the main flow clear and prominent
- File format specifications in notes
- Version information and supported BASIC dialects in a reference section

- Clear typography for labels
- Consistent spacing
- Export to common formats (SVG, PNG)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        BIN["Binary BASIC (.prg)"]
        T64["T64 Archives"]
    end

    subgraph "Input Processing"
        DTOK["Binary Processor"]:::processor
        T64P["T64 Handler"]:::processor
    end

    subgraph "Core Pipeline"
        INMH["Input Mode Handler"]:::core
        TOK["Tokenizer"]:::core
        TOKM["Token Management"]:::core
        SEL["Selection Logic"]:::core
        OUTMH["Output Mode Handler"]:::core
    end

    subgraph "Format Support"
        B20["BASIC 2.0"]:::format
        B35["BASIC 3.5"]:::format
        B40["BASIC 4.0"]:::format
        B70["BASIC 7.0"]:::format
        B71["BASIC 7.1"]:::format
        EXT["Extensions"]:::format
    end

    subgraph "Control"
        MAIN["Main Controller"]:::control
        META["Version Info"]:::meta
    end

    subgraph Output
        BOUT["Binary Output"]
        TOUT["Text Output"]
    end

    %% Relationships
    BIN --> DTOK
    T64 --> T64P
    DTOK & T64P --> INMH
    INMH --> TOK
    TOK --> TOKM
    TOKM --> SEL
    SEL --> OUTMH
    OUTMH --> BOUT & TOUT
    
    %% Format Support Connections
    B20 & B35 & B40 & B70 & B71 & EXT -.-> SEL

    %% Control Flow
    MAIN --> INMH & TOK & OUTMH
    META -.-> MAIN

    %% Click Events
    click DTOK "https://github.com/nafmo/bastext/blob/master/dtokeniz.c"
    click T64P "https://github.com/nafmo/bastext/blob/master/t64.c"
    click INMH "https://github.com/nafmo/bastext/blob/master/inmode.c"
    click TOK "https://github.com/nafmo/bastext/blob/master/tokenize.c"
    click TOKM "https://github.com/nafmo/bastext/blob/master/tokens.c"
    click SEL "https://github.com/nafmo/bastext/blob/master/select.c"
    click OUTMH "https://github.com/nafmo/bastext/blob/master/outmode.c"
    click MAIN "https://github.com/nafmo/bastext/blob/master/main.c"
    click META "https://github.com/nafmo/bastext/blob/master/version.h"

    %% Styling
    classDef processor fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef format fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef control fill:#e74c3c,stroke:#c0392b,color:white
    classDef meta fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        L1["Input Processing"]:::processor
        L2["Core Components"]:::core
        L3["Format Support"]:::format
        L4["Control System"]:::control
        L5["Metadata"]:::meta
    end
```
