Phichain is built as a modular Rust workspace using the Bevy game engine and ECS (Entity Component System) architecture. This document explains the project structure, design decisions, and data flow.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ivan-1f/phichain/llms.txt
Use this file to discover all available pages before exploring further.
Project Structure
Phichain uses a Cargo workspace with multiple specialized crates:Crate Overview
phichain-chart
Core data structures for charts, notes, events, and BPM management.
- Chart format definitions
- Beat calculation system
- Serialization/deserialization
- Format migration
phichain-editor
Main application - Interactive chart editor with egui UI.
- Bevy + egui integration
- Timeline editing
- Audio playback
- Project management
phichain-game
Playback engine - Renders and plays charts.
- Note rendering
- Hit effects
- Score calculation
- Audio synchronization
phichain-converter
CLI tool for converting between chart formats.
- Format detection
- Batch conversion
- Standalone binary
phichain-renderer
Rendering utility for generating chart videos/images.
- Headless rendering
- Video export
- Image sequences
phichain-assets
Asset management for loading game resources.
- Image loading
- Audio loading
- Resource caching
phichain-compiler
Chart compilation - Processes charts for runtime.
- Event processing
- Optimization
- Validation
Core Dependencies
Bevy Engine (0.16.1)
Phichain is built on Bevy, a data-driven game engine using ECS architecture. Key Bevy features used:bevy_sprite- 2D rendering for notes and judgement linesbevy_ui- Native UI componentsbevy_asset- Asset loading and hot-reloadingbevy_window- Window managementbevy_state- State machine for editor/playback modes
bevy_kira_audio- Audio playback with precise timingbevy_egui- egui integration for editor UIbevy_prototype_lyon- Vector graphics renderingbevy-persistent- Save/load system data
egui (0.31.1)
The editor uses egui for its immediate-mode UI:egui_dock- Docking panel systemegui_extras- Additional widgets and featuresegui-phosphor- Icon libraryegui-toast- Notification system
The editor uses
bevy_egui with the immutable_ctx feature for better integration with Bevy’s ECS.Architecture Patterns
Entity Component System (ECS)
Phichain follows Bevy’s ECS architecture: Entities: Represent chart objects (notes, judgement lines, events) Components: Data attached to entitiesChart Data Model
The chart data model hierarchy:-
Project - Top-level container
- Metadata (title, artist, difficulty)
- Audio file reference
- Illustration image
-
Chart - Contains all chart data
- Multiple judgement lines
- BPM list for timing
-
Judgement Lines - The moving lines that notes are attached to
- Notes (tap, hold, drag, flick)
- Events (movement, rotation, alpha)
-
BPM List - Timing information
- BPM changes throughout the chart
- Beat calculation utilities
Beat System
Phichain uses a beat-based timing system rather than absolute time:- Precise timing independent of BPM
- Easy tempo changes
- Musical alignment
Event System
Judgement line behavior is controlled by events:- Movement events - Control X/Y position
- Rotation events - Control angle
- Alpha events - Control opacity
- Speed events - Control note scroll speed
- Start/end times (in beats)
- Start/end values
- Easing function
Format Conversion Pipeline
Parsing
External chart formats (Re:PhiEdit, official format, etc.) are parsed into intermediate representations.
Conversion
The
phichain-converter crate converts formats into the standard phichain-chart data model.Game Engine Integration
The editor integrates the game engine for real-time preview:Editor State Management
The editor uses Bevy’s state system for different modes:- HomeState - Project selection and settings
- EditorState - Active chart editing
- PlaybackState - Chart preview/playback
UI Architecture
The editor UI is organized into tabs:Module Responsibilities
phichain-chart
Purpose: Pure data structures with no game engine dependencies Key modules:beat.rs- Beat/time calculationsbpm_list.rs- BPM management and tempo mappingevent.rs- Line events (movement, rotation, alpha)note.rs- Note types and propertiesline.rs- Judgement line dataproject.rs- Top-level project containerformat/- Serialization for different formatsmigration/- Format version migration
phichain-editor
Purpose: Main application with UI and editing logic Key modules:main.rs- Application entry point and Bevy setuptab/- UI tabs (arrangement, events, inspector)editing/- Editing operations and undo/redoproject.rs- Project managementaudio.rs- Audio playback integrationtimeline/- Timeline rendering and interactionhotkey/- Keyboard shortcutsautosave/- Auto-save systemexport.rs- Chart export functionality
phichain-game
Purpose: Core gameplay and rendering engine Key modules:core.rs- Main game loop and timingline.rs- Judgement line renderingnote.rs- Note spawning and rendering (handled by events)hit_effect.rs- Visual effects for hitsaudio.rs- Audio synchronizationui.rs- In-game UI (score, combo)loader.rs- Chart loading from files
Design Decisions
Why Bevy?
Data-driven architecture
Data-driven architecture
Bevy’s ECS is perfect for managing thousands of notes and events efficiently.
Hot reloading
Hot reloading
Bevy’s asset system enables hot-reloading of charts and assets during development.
Cross-platform
Cross-platform
Bevy provides excellent cross-platform support (Windows, macOS, Linux, Web).
Performance
Performance
ECS architecture provides excellent performance for real-time rendering and editing.
Why egui?
Immediate mode
Immediate mode
Immediate-mode GUI is simpler for complex editor UIs with dynamic content.
Bevy integration
Bevy integration
bevy_egui provides seamless integration with minimal overhead.Rich widgets
Rich widgets
egui has excellent built-in widgets for editors (sliders, text inputs, trees).
Customizable
Customizable
Easy to create custom widgets and styling for the editor.
Beat-based Timing
Using beats instead of absolute time: Pros:- Musical alignment is natural
- Tempo changes don’t require recalculating note times
- Easier for chart authors to work with
- Requires BPM list for playback
- More complex beat-to-time conversion
Workspace Organization
Separate crates provide:- Modularity - Clear separation of concerns
- Reusability - Chart library usable in other projects
- Compilation speed - Only rebuild changed crates
- CLI tools - Converter and renderer as standalone binaries
Data Flow Diagram
Performance Considerations
The editor handles charts with 10,000+ notes efficiently using Bevy’s ECS.
- Spatial partitioning - Only render visible notes
- Object pooling - Reuse entities for hit effects
- Event batching - Group similar events for processing
- Lazy evaluation - Compute values only when needed
- Caching - Cache beat-to-time conversions
Next Steps
Building
Learn how to build Phichain from source
Contributing
Start contributing to the project