# snuri00/ps2-web-recomp architecture

> Architecture diagram of the GitHub repository snuri00/ps2-web-recomp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/snuri00/ps2-web-recomp
- Repository: https://github.com/snuri00/ps2-web-recomp

## Overview

PS2 Web Recomp turns a user-supplied game disc image into ahead-of-time recompiled C++ and runs it as a browser-hosted PS2 system. The main runtime path is generated game code through the EE system and its emulated hardware/services to graphics, sound, and video output. The README documents major capabilities and worker boundaries; source excerpts and the index provide only partial implementation wiring, so uncertain links are omitted.

Main entry points: [`runtime/src/system.cpp`](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/system.cpp) (PS2 system), [`runtime/src/gs/gs.cpp`](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/gs.cpp) (Graphics Synthesizer), [`host/web.cpp`](https://github.com/snuri00/ps2-web-recomp/blob/main/host/web.cpp) (Browser integration), [`runtime/include/ps2/generated.hpp`](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/include/ps2/generated.hpp) (Generated game code)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Game preparation"]
  node_discprep["Disc preparation<br/>[disc.py]"]
  node_elf["ELF reader<br/>[elf.cpp]"]
  node_analysis["Code analysis<br/>[analysis.cpp]"]
  node_codegen["EE code generation<br/>[codegen.cpp]"]
  node_vucompiler["VU compilation<br/>[vurecomp.cpp]"]
  node_generated["Generated game code<br/>[generated.hpp]"]
end

subgraph group_ee["EE runtime"]
  node_system["PS2 system<br/>[system.cpp]"]
  node_eehardware["EE hardware<br/>[hw.cpp]"]
  node_kernel["EE kernel<br/>[kernel.cpp]"]
  node_vectors["Vector units<br/>[vu_micro.cpp]"]
  node_jit["VU JIT<br/>[vu_jit.cpp]"]
end

subgraph group_iop["IOP services"]
  node_iopcpu["IOP processor<br/>[cpu.cpp]"]
  node_iopkernel["IOP kernel and libraries<br/>[kernel.cpp]"]
  node_sif["SIF bridge<br/>[sif.cpp]"]
  node_disc["Disc access<br/>[disc.cpp]"]
  node_sound["SPU2 audio<br/>[spu2.cpp]"]
  node_movies["MPEG-2 decoder<br/>[ipu.cpp]"]
end

subgraph group_graphics["Graphics pipeline"]
  node_gs["Graphics Synthesizer<br/>[gs.cpp]"]
  node_raster["Software rasterizer<br/>[raster.cpp]"]
  node_gpu["WebGPU renderer<br/>[gpu.cpp]"]
  node_queue["Graphics command queue<br/>[queue.cpp]"]
end

subgraph group_browser["Browser output"]
  node_host["Runtime host<br/>[main.cpp]"]
  node_web["Browser integration<br/>[web.cpp]"]
  node_window["Window output<br/>[window.cpp]"]
end

node_owner(("Game owner"))

node_owner -->|"provides image"| node_discprep
node_discprep -.->|"extracts executable"| node_elf
node_elf -->|"reads executable"| node_analysis
node_analysis -->|"provides program"| node_codegen
node_codegen -->|"emits C++"| node_generated
node_vucompiler -->|"emits SIMD code"| node_generated
node_generated -->|"registers code"| node_host
node_host -->|"starts runtime"| node_system
node_system -->|"models hardware"| node_eehardware
node_system -->|"provides EE services"| node_kernel
node_system -->|"runs IOP"| node_iopcpu
node_iopcpu -->|"uses kernel services"| node_iopkernel
node_iopkernel -->|"dispatches SIF calls"| node_sif
node_sif -.->|"requests disc data"| node_disc
node_system -->|"runs microprograms"| node_vectors
node_vectors -->|"compiles unseen programs"| node_jit
node_system -->|"sends graphics work"| node_gs
node_gs -->|"draws reference output"| node_raster
node_gs -->|"dispatches rendering"| node_gpu
node_gs -->|"posts commands"| node_queue
node_queue -.->|"delivers render work"| node_web
node_system -->|"emulates sound"| node_sound
node_sound -->|"streams audio"| node_web
node_system -->|"decodes movies"| node_movies
node_gpu -->|"presents frames"| node_web
node_web -.->|"targets display"| node_window

click node_discprep "https://github.com/snuri00/ps2-web-recomp/blob/main/scripts/disc.py"
click node_elf "https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/elf.cpp"
click node_analysis "https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/analysis.cpp"
click node_codegen "https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/codegen.cpp"
click node_vucompiler "https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/vurecomp.cpp"
click node_generated "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/include/ps2/generated.hpp"
click node_host "https://github.com/snuri00/ps2-web-recomp/blob/main/host/main.cpp"
click node_system "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/system.cpp"
click node_eehardware "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/hw.cpp"
click node_kernel "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/kernel.cpp"
click node_vectors "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/vu_micro.cpp"
click node_jit "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/vu_jit.cpp"
click node_iopcpu "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/cpu.cpp"
click node_iopkernel "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/kernel.cpp"
click node_sif "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/sif.cpp"
click node_disc "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/disc.cpp"
click node_sound "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/spu2.cpp"
click node_movies "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/ipu/ipu.cpp"
click node_gs "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/gs.cpp"
click node_raster "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/raster.cpp"
click node_gpu "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/gpu/gpu.cpp"
click node_queue "https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/queue.cpp"
click node_web "https://github.com/snuri00/ps2-web-recomp/blob/main/host/web.cpp"
click node_window "https://github.com/snuri00/ps2-web-recomp/blob/main/host/window.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_discprep,node_elf,node_analysis,node_codegen,node_vucompiler,node_generated toneBlue
class node_system,node_eehardware,node_kernel,node_vectors,node_jit toneAmber
class node_iopcpu,node_iopkernel,node_sif,node_disc,node_sound,node_movies toneMint
class node_gs,node_raster,node_gpu,node_queue toneRose
class node_host,node_web,node_window,node_owner toneIndigo
```

## Components

### Game preparation

- [Disc preparation](https://github.com/snuri00/ps2-web-recomp/blob/main/scripts/disc.py): `scripts/disc.py`
- [ELF reader](https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/elf.cpp): `recomp/elf.cpp`
- [Code analysis](https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/analysis.cpp): `recomp/analysis.cpp`
- [EE code generation](https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/codegen.cpp): `recomp/codegen.cpp`
- [VU compilation](https://github.com/snuri00/ps2-web-recomp/blob/main/recomp/vurecomp.cpp): `recomp/vurecomp.cpp`
- [Generated game code](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/include/ps2/generated.hpp): `runtime/include/ps2/generated.hpp`

### EE runtime

- [PS2 system](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/system.cpp): `runtime/src/system.cpp`
- [EE hardware](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/hw.cpp): `runtime/src/hw.cpp`
- [EE kernel](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/kernel.cpp): `runtime/src/kernel.cpp`
- [Vector units](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/vu_micro.cpp): `runtime/src/vu_micro.cpp`
- [VU JIT](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/vu_jit.cpp): `runtime/src/vu_jit.cpp`

### IOP services

- [IOP processor](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/cpu.cpp): `runtime/src/iop/cpu.cpp`
- [IOP kernel and libraries](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/kernel.cpp): `runtime/src/iop/kernel.cpp`
- [SIF bridge](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/sif.cpp): `runtime/src/iop/sif.cpp`
- [Disc access](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/disc.cpp): `runtime/src/disc.cpp`
- [SPU2 audio](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/iop/spu2.cpp): `runtime/src/iop/spu2.cpp`
- [MPEG-2 decoder](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/ipu/ipu.cpp): `runtime/src/ipu/ipu.cpp`

### Graphics pipeline

- [Graphics Synthesizer](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/gs.cpp): `runtime/src/gs/gs.cpp`
- [Software rasterizer](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/raster.cpp): `runtime/src/gs/raster.cpp`
- [WebGPU renderer](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/gpu/gpu.cpp): `runtime/src/gs/gpu/gpu.cpp`
- [Graphics command queue](https://github.com/snuri00/ps2-web-recomp/blob/main/runtime/src/gs/queue.cpp): `runtime/src/gs/queue.cpp`

### Browser output

- [Runtime host](https://github.com/snuri00/ps2-web-recomp/blob/main/host/main.cpp): `host/main.cpp`
- [Browser integration](https://github.com/snuri00/ps2-web-recomp/blob/main/host/web.cpp): `host/web.cpp`
- [Window output](https://github.com/snuri00/ps2-web-recomp/blob/main/host/window.cpp): `host/window.cpp`

### Other components

- **Game owner**

## Connections

- Game owner → Disc preparation: provides image
- Disc preparation → ELF reader: extracts executable
- ELF reader → Code analysis: reads executable
- Code analysis → EE code generation: provides program
- EE code generation → Generated game code: emits C++
- VU compilation → Generated game code: emits SIMD code
- Generated game code → Runtime host: registers code (evidence: `host/main.cpp`)
- Runtime host → PS2 system: starts runtime (evidence: `host/main.cpp`)
- PS2 system → EE hardware: models hardware
- PS2 system → EE kernel: provides EE services
- PS2 system → IOP processor: runs IOP
- IOP processor → IOP kernel and libraries: uses kernel services
- IOP kernel and libraries → SIF bridge: dispatches SIF calls (evidence: `runtime/src/iop/sif.cpp`)
- SIF bridge → Disc access: requests disc data
- PS2 system → Vector units: runs microprograms
- Vector units → VU JIT: compiles unseen programs (evidence: `runtime/src/vu_micro.cpp`)
- PS2 system → Graphics Synthesizer: sends graphics work
- Graphics Synthesizer → Software rasterizer: draws reference output (evidence: `runtime/src/gs/gs.cpp`)
- Graphics Synthesizer → WebGPU renderer: dispatches rendering (evidence: `runtime/src/gs/gs.cpp`)
- Graphics Synthesizer → Graphics command queue: posts commands (evidence: `runtime/src/gs/gs.cpp`)
- Graphics command queue → Browser integration: delivers render work
- PS2 system → SPU2 audio: emulates sound
- SPU2 audio → Browser integration: streams audio
- PS2 system → MPEG-2 decoder: decodes movies
- WebGPU renderer → Browser integration: presents frames
- Browser integration → Window output: targets display
