# tylemagne/gopher360 architecture

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

- Interactive diagram: https://gitdiagram.com/tylemagne/gopher360
- Repository: https://github.com/tylemagne/gopher360

## Overview

##### Project type and purpose
- Gopher360 is a standalone Windows desktop utility (open-source tool) written in C++, packaged as a Visual Studio solution.
- Its goal is to capture Xbox/PlayStation controller input via XInput (or an emulation layer) and translate those events into standard keyboard and mouse events so that any application or game can be controlled from a couch.

##### File structure
Top-level:
- Configs/ – sample and default .ini files, documentation for custom button-to-key mappings.
- README.md, LICENSE – project description, build & usage instructions, GPL license.
- Windows/ – Visual Studio solution, C++ source and header files, resource files for the Gopher executable.
Inside Windows/:
- Gopher.sln / .vcxproj* – Visual Studio project files.
- CXBOXController.{cpp,h} – wraps XInput for reading controller state.
- ConfigFile.{cpp,h} – reads/writes config .ini, exposes mapping data.
- Convert.h – mapping logic from controller codes to virtual key codes.
- Gopher.{cpp,h}, main.cpp – core event loop, orchestration of input→mapping→output.

##### README for additional insights
- Describes supported controllers (X360, XOne, DualShock via emulation).
- Explains default bindings and how users can rebind via config.ini.
- Lists external dependencies (Visual C++ 2015 runtime, optional DS3Tool or DS4Windows for PS controllers).

1. Controller Device (Xbox360/Xbone/DS)
2. XInput / Emulation Layer (Input API)
3. CXBOXController Module (Input Reader)
4. Config Manager (ConfigFile Module + Configs folder)
5. Mapping Engine (Convert Module)
6. Core Orchestrator (Gopher class + main event loop)
7. Output Generator (Win32 SendInput, mouse_event calls)
8. Target Application (Any PC app/game)
- Controller → XInput API (poll controller state)
- XInput API → CXBOXController (encapsulate raw input)
- CXBOXController + Config Manager → Mapping Engine (lookup button→key mapping)
- Mapping Engine → Output Generator (emit virtual keyboard/mouse events)
- Output Generator → OS Input Subsystem → Target Application
c. Architectural patterns and principles:
- Modular layering: separation of input capture, configuration, mapping, and output.
- Adapter (CXBOXController adapts XInput to a common interface).
- Single event-driven processing loop in Gopher.
d. Key technologies/frameworks:
- XInput / DirectX SDK (Xbox controllers)
- Optional DS3Tool/DS4Windows (DualShock emulation)
- Win32 Input Simulation APIs (SendInput, mouse_event)
- INI parsing (ConfigFile)
- Visual C++ 2015 runtime

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        direction TB
        Controller["Controller Device\n(Xbox360/Xbone/DS)"]:::input
        XInputAPI["XInput / Emulation Layer"]:::input
        CXBOXController["CXBOXController Module\n(CXBOXController.cpp/h)"]:::input
    end

    %% Config & Mapping Layer
    subgraph "Configuration & Mapping"
        direction TB
        ConfigModule["Config Manager Module\n(ConfigFile.cpp/h)"]:::config
        ConfigsFolder["Configs Directory\n(config_default.ini, README.MD)"]:::config
        MappingEngine["Mapping Engine\n(Convert.h)"]:::config
    end

    %% Core Layer
    subgraph "Core Orchestrator"
        direction TB
        CoreOrch["Core Orchestrator\n(Gopher.cpp/h, main.cpp)"]:::core
    end

    %% Output Layer
    subgraph "Output Layer"
        direction TB
        OutputGen["Output Generator\n(Win32 SendInput, mouse_event)"]:::output
        OSInput["OS Input Subsystem"]:::external
    end

    %% External Target
    TargetApp["Target Application\n(Any PC App/Game)"]:::external

    %% Documentation & Licensing
    subgraph "Project Files"
        direction TB
        VSProj["Visual Studio Solution & Projects\n(.sln, .vcxproj*, .filters, .user)"]:::external
        ResourceFiles["Resource Files\n(Resource.rc, .aps, resource.h)"]:::external
        Docs["Documentation & Licensing\nREADME.md, LICENSE"]:::external
    end

    %% Connections
    Controller -->|"poll state"| XInputAPI
    XInputAPI -->|"raw input"| CXBOXController
    CXBOXController -->|"controller state"| MappingEngine
    ConfigModule -->|"mapping data"| MappingEngine
    ConfigsFolder -->|"sample configs"| ConfigModule
    MappingEngine -->|"virtual events"| OutputGen
    CoreOrch -->|"event loop"| CXBOXController
    CoreOrch -->|"orchestrates"| MappingEngine
    CoreOrch -->|"dispatches"| OutputGen
    OutputGen -->|"injection"| OSInput
    OSInput -->|"delivers events"| TargetApp

    %% Click Events
    click CXBOXController "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/CXBOXController.cpp"
    click CXBOXController "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/CXBOXController.h"
    click ConfigModule "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/ConfigFile.cpp"
    click ConfigModule "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/ConfigFile.h"
    click ConfigsFolder "https://github.com/tylemagne/gopher360/blob/master/Configs/config_default.ini"
    click ConfigsFolder "https://github.com/tylemagne/gopher360/blob/master/Configs/README.MD"
    click MappingEngine "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Convert.h"
    click CoreOrch "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Gopher.cpp"
    click CoreOrch "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Gopher.h"
    click CoreOrch "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/main.cpp"
    click VSProj "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher.sln"
    click VSProj "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Gopher.vcxproj"
    click VSProj "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Gopher.vcxproj.filters"
    click VSProj "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Gopher.vcxproj.user"
    click ResourceFiles "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Resource.rc"
    click ResourceFiles "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/Resource.aps"
    click ResourceFiles "https://github.com/tylemagne/gopher360/blob/master/Windows/Gopher/resource.h"
    click Docs "https://github.com/tylemagne/gopher360/blob/master/README.md"
    click Docs "https://github.com/tylemagne/gopher360/tree/master/LICENSE"

    %% Styles
    classDef input fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef config fill:#E6F7D7,stroke:#28a745,color:#28a745;
    classDef core fill:#FFE6CC,stroke:#d73a49,color:#d73a49;
    classDef output fill:#FFDADA,stroke:#b31d28,color:#b31d28;
    classDef external fill:#F0F0F0,stroke:#6a737d,color:#6a737d;
```
