# mjdarby/fic architecture

> Architecture diagram of the GitHub repository mjdarby/fic, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mjdarby/fic
- Repository: https://github.com/mjdarby/fic

## Overview

Key Components to Include:

##### Input Processing Layer
- File Input Handler (for Z-code game files)
- User Input Handler (for game commands)
- Input Stream Manager (for handling different input sources)

##### Core Interpreter Components
- Memory Manager (mentioned in TODOs as needing splitting)
- Opcode Executor (extensive list of implemented opcodes)
- State Manager (for save/restore/undo functionality)

##### Output Processing Layer
- Text Renderer
- Window Manager (for terminal display)
- Stream Manager (for output handling)

- [Game File/User Input] → [Interpreter Core] → [Display Output]

##### Component Relationships
- File input → Memory Manager
- Memory Manager ↔ Opcode Executor
- Opcode Executor → Output Manager
- User Input → Input Stream Manager → Opcode Executor

##### Memory Management
- Planned split of Memory class into subcomponents
- Interaction with save/restore functionality

##### Opcode Execution
- Opcodes by version (V1-V5, V7-V8)
- Separation between implemented and pending opcodes

##### Input/Output Streams
- Multiple input sources (file, user, replay)
- Output streams with different purposes

- Version-specific features (different patterns)
- Data flow directions
- Component interaction types

Additional Notes:
##### Clear boundaries between
- File handling
- Memory management
- Opcode execution
- Rendering

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef input fill:#a8d1f0,stroke:#000
    classDef core fill:#90EE90,stroke:#000
    classDef output fill:#FFE5B4,stroke:#000
    classDef planned fill:#FFB6C1,stroke:#000,stroke-dasharray: 5 5
    classDef testing fill:#DDA0DD,stroke:#000

    %% Input Layer
    subgraph InputLayer["Input Processing Layer"]
        FileInput["Z-code File Input"]:::input
        UserInput["User Input Handler"]:::input
        InputManager["Input Stream Manager"]:::input
    end

    %% Core Interpreter
    subgraph CoreInterpreter["Core Interpreter Components"]
        MainInterpreter["Main Interpreter Core"]:::core
        MemoryManager["Memory Manager"]:::core
        OpcodeExec["Opcode Executor"]:::core
        StateManager["State Manager"]:::core
        ByteValidator["Byte Testing/Validation"]:::testing
    end

    %% Output Layer
    subgraph OutputLayer["Output Processing Layer"]
        TextRender["Text Renderer"]:::output
        WindowMgr["Window Manager"]:::output
        OutputManager["Stream Manager"]:::output
    end

    %% Planned Features
    SoundSystem["Sound System"]:::planned
    GUIClient["GUI Client"]:::planned

    %% Relationships
    FileInput --> MainInterpreter
    UserInput --> InputManager
    InputManager --> MainInterpreter
    
    MainInterpreter --> MemoryManager
    MainInterpreter --> OpcodeExec
    MainInterpreter --> StateManager
    ByteValidator --> MainInterpreter
    
    MemoryManager <--> StateManager
    OpcodeExec --> OutputManager
    OutputManager --> TextRender
    TextRender --> WindowMgr

    %% Click events
    click MainInterpreter "https://github.com/mjdarby/Fic/blob/master/fic.py"
    click ByteValidator "https://github.com/mjdarby/Fic/blob/master/bytetest.py"

    %% Legend
    subgraph Legend["Legend"]
        L1["Input Components"]:::input
        L2["Core Components"]:::core
        L3["Output Components"]:::output
        L4["Planned Features"]:::planned
        L5["Testing Components"]:::testing
    end
```
