# krystal1110/moview architecture

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

- Interactive diagram: https://gitdiagram.com/krystal1110/moview
- Repository: https://github.com/krystal1110/moview

## Overview

##### Project type and purpose
- It embeds the open-source Capstone C disassembly engine to render instruction listings.

##### File structure
- Top-level folders:
- MOView.xcodeproj – Xcode project file
- MOView/ – application source root
- – Assets.xcassets, ContentView.swift, MOViewApp.swift (entry point)
- – Tools/ – all parsing, conversion, file-I/O, and Capstone C code
- – Model/ – data models representing Mach-O headers, load commands, sections, modules
- – Views/ – SwiftUI view components (FileView, MachoView, ParseView, etc.)
- External/config files:
- Bridging header for mixing Swift and Obj-C/C (CapstoneHelper)
- .github/workflows/swiftLint.yml (linting pipeline)

##### Main components and their interactions
a. UI Layer (SwiftUI)
- MOViewApp.swift (App entry) → ContentView.swift → child views under Views/
- Presents file-open UI, module tree, section details, disassembly panes
b. Application Logic / Service Layer
- FileManager/File.swift – reads raw Mach-O file bytes
- MachO parsing: Tools/MachoTool.swift + MachO/Parse + MachO/Interpreter + LoadCommand classes → builds in-memory representations
- ConversionTools – transforms raw data into human-readable forms
- CapstoneHelper (Obj-C/Bridging) → Capstone C library under Tools/Capstone → provides instruction decoding
c. Model Layer
- Data structures under Tools/Model/MachoBaseModel and Tools/Model/Module → hold header, load command, section, symbol table, swift-metadata, etc.
d. External Dependency
- Capstone C library source tree (Tools/Capstone) compiled into the application via bridging headers

##### Architectural patterns & design principles
- MVVM-style separation (Views vs. underlying data models + service code)
- Modular layering: UI → Service → Model → External C library
- Clear boundaries and explicit bridging for C code
- Single process, in-memory data flow, no external server

­– Presentation (SwiftUI Views)
­– Application Services (FileManager, MachOTool, ConversionTools)
­– Domain Model (MachoBaseModel, Module models)
­– Native Engine (Capstone C library)
­– External (Filesystem as data source)
­– User → UI Layer (file-open action)
­– UI → FileManager → raw bytes
­– Raw bytes → MachOTool.parse() → Model instances
­– Model data → ConversionTools (formatting)
­– Views subscribe to Model → render lists
­– For disassembly: Model.textSection → CapstoneHelper → Capstone Engine → decoded instructions → back to Views
c. Patterns:
­– “MVVM-like” between Views and Model/Services
­– “Bridging” boundary between Swift and C code
d. Label key technologies next to components:
­– SwiftUI (Views)
­– Swift (Tools, Model)
­– Objective-C bridging (CapstoneHelper)
­– C (Capstone disassembler)
­– Green for data models
­– Orange for bridging/interop
­– Red for external C library
­– Gray for filesystem

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Filesystem
    FS["Filesystem (macOS)"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        App["MOViewApp.swift<br/>(SwiftUI App Entry)"]:::swift
        Content["ContentView.swift"]:::swift
        FileV["FileView.swift"]:::swift
        ParseV["ParseView.swift"]:::swift
        MachoV["MachoView.swift"]:::swift
        ModuleV["MachoModuleView.swift"]:::swift
    end

    %% Application Services Layer
    subgraph "Application Services" 
        direction TB
        FM["File.swift<br/>(FileManager)"]:::swift
        MT["MachoTool.swift"]:::swift
        ParseDir["Parse Submodule"]:::swift
        InterpDir["Interpreter Submodule"]:::swift
        LC["LoadCommand Submodule"]:::swift
        ConvTools["ConversionTools"]:::swift
    end

    %% Domain Model Layer
    subgraph "Domain Model" 
        direction TB
        BaseModels["MachoBaseModel<br/>(green)"]:::model
        ModuleModels["Module Models"]:::model
        AggregModel["MachoModule.swift"]:::model
        DataExpl["DataExplanation.swift"]:::model
    end

    %% Bridging Layer
    subgraph "Bridging Layer" 
        direction TB
        BridgeHeader["MachoTool-Bridging-Header.h"]:::bridge
        CapHelper["CapStoneHelper.h/m"]:::bridge
    end

    %% Native Engine
    subgraph "Native Engine (C)" 
        direction TB
        CapstoneCore["Capstone C Library"]:::clib
    end

    %% External Resources
    subgraph "External Resources" 
        direction TB
        Assets["Assets.xcassets"]:::external
        Entitlements["MOView.entitlements"]:::external
        XcodeProj["MOView.xcodeproj"]:::external
        Lint[".github/workflows/swiftLint.yml"]:::external
    end

    %% Connections
    FS -->|open file| App
    App -->|"init UI"| Content
    Content --> FileV
    Content --> ParseV
    Content --> MachoV
    Content --> ModuleV

    FileV --> FM
    FM --> FS
    ParseV --> FM
    MachoV --> MT
    ModuleV --> MT

    MT --> ParseDir
    MT --> InterpDir
    MT --> LC
    MT --> BaseModels
    MT --> ModuleModels

    BaseModels --> AggregModel
    ModuleModels --> AggregModel
    AggregModel --> DataExpl

    AggregModel --> ConvTools
    ConvTools --> Content

    AggregModel -->|text sections| BridgeHeader
    BridgeHeader --> CapHelper
    CapHelper --> CapstoneCore
    CapstoneCore -->|decoded instructions| Content

    %% Click Events
    click App "https://github.com/krystal1110/moview/blob/main/MOView/MOViewApp.swift"
    click Content "https://github.com/krystal1110/moview/blob/main/MOView/ContentView.swift"
    click FileV "https://github.com/krystal1110/moview/blob/main/MOView/Views/FileView.swift"
    click ParseV "https://github.com/krystal1110/moview/blob/main/MOView/Views/ParseView.swift"
    click MachoV "https://github.com/krystal1110/moview/blob/main/MOView/Views/MachoView.swift"
    click ModuleV "https://github.com/krystal1110/moview/blob/main/MOView/Views/MachoModuleView.swift"
    click FM "https://github.com/krystal1110/moview/blob/main/MOView/Tools/FileManager/File.swift"
    click MT "https://github.com/krystal1110/moview/blob/main/MOView/Tools/MachoTool.swift"
    click ParseDir "https://github.com/krystal1110/moview/tree/main/MOView/Tools/Macho/Parse/"
    click InterpDir "https://github.com/krystal1110/moview/tree/main/MOView/Tools/Macho/Interpreter/"
    click LC "https://github.com/krystal1110/moview/tree/main/MOView/Tools/Macho/LoadCommand/"
    click ConvTools "https://github.com/krystal1110/moview/blob/main/MOView/Tools/ConversionTools/TranslationRead.swift"
    click BridgeHeader "https://github.com/krystal1110/moview/blob/main/MOView/Tools/Tools/MachoTool-Bridging-Header.h"
    click CapHelper "https://github.com/krystal1110/moview/blob/main/MOView/Tools/Tools/CapStoneHelper/CapStoneHelper.h"
    click CapstoneCore "https://github.com/krystal1110/moview/tree/main/MOView/Tools/Capstone/"
    click Assets "https://github.com/krystal1110/moview/tree/main/MOView/Assets.xcassets/"
    click Entitlements "https://github.com/krystal1110/moview/blob/main/MOView/MOView.entitlements"
    click XcodeProj "https://github.com/krystal1110/moview/blob/main/MOView.xcodeproj"
    click Lint "https://github.com/krystal1110/moview/blob/main/.github/workflows/swiftLint.yml"

    %% Styles
    classDef swift fill:#blue,stroke:#000,color:#fff
    classDef model fill:#green,stroke:#000,color:#000
    classDef bridge fill:#orange,stroke:#000,color:#000
    classDef clib fill:#red,stroke:#000,color:#fff
    classDef external fill:#gray,stroke:#000,color:#000
```
