This document provides a comprehensive overview of gitlogue's architecture, design decisions, and implementation details.
- High-Level Architecture
- Core Components
- Data Flow
- Key Design Decisions
- Module Details
- Performance Considerations
- Future Enhancements
gitlogue is built as a terminal-based application using Rust. The architecture follows a modular design with clear separation of concerns:
┌─────────────────────────────────────────────────────────┐
│ main.rs │
│ (CLI Argument Parsing) │
└────────────────────┬────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ UI │
│ (Terminal UI Coordinator) │
│ │
│ ┌────────────┬──────────────┬──────────────────────┐ │
│ │ FileTree │ Editor │ Terminal │ │
│ │ Pane │ Pane │ Pane │ │
│ └────────────┴──────────────┴──────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Status Bar Pane │ │
│ └──────────────────────────────────────────────────┘ │
└──────────┬──────────────────┬───────────────┬──────────┘
│ │ │
▼ ▼ ▼
┌──────────────────┐ ┌────────────────┐ ┌─────────────┐
│ Animation │ │ Theme │ │ Git │
│ Engine │ │ System │ │ Repository │
└──────┬───────────┘ └────────────────┘ └─────────────┘
│
▼
┌──────────────────┐
│ Syntax │
│ Highlighting │
│ (tree-sitter) │
└──────────────────┘
Responsibility: Parse command-line arguments and initialize the application.
Key Features:
- Argument parsing using
clap - Repository path validation
- Subcommand handling (e.g.,
theme list) - Configuration loading and theme selection
- Initial commit loading
Flow:
- Parse CLI arguments
- Validate repository path
- Load configuration
- Resolve theme (CLI > config > default)
- Load initial commit
- Initialize and run UI
Responsibility: Manage the terminal interface and coordinate between panes.
Key Components:
- Terminal setup and cleanup (raw mode, alternate screen)
- Event loop for keyboard input
- Layout management using
ratatui - State machine for animation flow
- Signal handling (Ctrl+C)
States:
Playing: Animation in progressWaitingForNext: Pause between commitsFinished: Animation complete (single commit mode)
Layout Structure:
┌────────────────────────────────────────┐
│ Status Bar │
├──────────────┬─────────────────────────┤
│ │ │
│ File Tree │ Editor │
│ │ │
│ │ │
├──────────────┴─────────────────────────┤
│ Terminal │
└────────────────────────────────────────┘
Responsibility: Control the typing animation and edit sequence.
Key Features:
- State machine for animation steps
- Character-by-character typing simulation
- Line insertion and deletion
- Cursor movement with realistic timing
- Git command simulation (checkout, add, commit, push)
Animation States:
Checkout: Display git checkout commandOpeningFile: Show file openingMovingCursor: Animate cursor movementTyping: Character-by-character typingDeletingLine: Line removalInsertingLine: Line insertionWaitingBetweenHunks: Pause between changesGitAdd: Git add commandGitCommit: Git commit commandGitPush: Git push commandFinished: Complete
Timing Configuration: The engine uses carefully tuned timing multipliers to create realistic animation:
- Cursor movement: Varies by distance (short/medium/long)
- Line deletion: 10× base speed
- Line insertion: 6.7× base speed
- Hunk transitions: 50× base speed
- Git commands: 16.7-66.7× base speed
Responsibility: Interface with Git repositories and extract commit data.
Key Features:
- Repository opening and validation
- Commit retrieval (random or specific)
- Diff parsing and hunk extraction
- File content loading
- Change detection (added/deleted/modified files)
Excluded Files:
- Lock files (package-lock.json, Cargo.lock, etc.)
- Minified files (.min.js, .min.css)
- Source maps (.js.map)
- Bundled files (.bundle.js)
Performance Optimizations:
- Commit caching to avoid repeated traversal
- Maximum blob size limit (500KB)
- File exclusion patterns
Responsibility: Provide syntax highlighting for code using tree-sitter.
Supported Languages (26 total):
- Systems: Rust, C, C++, Zig
- Web: TypeScript, JavaScript, HTML, CSS
- Backend: Python, Go, Ruby, PHP, Java, C#, Kotlin, Swift
- Functional: Haskell, Scala, Clojure, Elixir, Erlang
- Data: JSON, YAML, XML, Markdown, Dart
Architecture:
- Language detection by file extension
- Modular parser system (one module per language)
- Token-based highlighting with theme colors
- Highlight caching for performance
Token Types:
- Keywords, types, functions, variables
- Strings, numbers, comments
- Operators, punctuation
- Special tokens (imports, attributes, etc.)
Responsibility: Manage color schemes and UI styling.
Built-in Themes (9 total):
- tokyo-night (default)
- dracula
- nord
- solarized-dark/light
- monokai
- one-dark
- gruvbox
- catppuccin
Theme Structure:
pub struct Theme {
pub background: BackgroundColors,
pub editor: EditorColors,
pub file_tree: FileTreeColors,
pub terminal: TerminalColors,
pub status_bar: StatusBarColors,
pub syntax: SyntaxColors,
}Color Components:
- Background colors (left/right panels)
- Editor elements (line numbers, cursor, separator)
- File tree status indicators
- Terminal UI elements
- Status bar sections
- Syntax highlighting tokens
Individual UI components that render specific sections:
- Displays code with line numbers
- Shows cursor position
- Applies syntax highlighting
- Handles scrolling
- Shows directory structure
- Displays file change status (added/deleted/modified)
- Highlights current file
- Shows change statistics
- Displays git command input
- Shows command output
- Simulates terminal session
- Shows commit hash
- Displays author and date
- Shows commit message
Responsibility: Load and manage user configuration.
Status: Configuration file support is planned but not yet fully implemented.
Planned Configuration File: ~/.config/gitlogue/config.toml
Planned Settings:
theme = "dracula" # Default theme
speed = 30 # Typing speed (ms/char)Planned Priority:
- CLI arguments (highest)
- Configuration file
- Built-in defaults (lowest)
1. Parse CLI arguments
2. Validate repository path
3. Open Git repository
4. Load configuration file
5. Resolve theme selection
6. Load initial commit
7. Initialize UI with theme
8. Start animation
1. UI receives commit metadata
2. Animation engine processes changes:
a. Show git checkout
b. For each file:
- Open file
- For each hunk:
* Move cursor to position
* Type new characters
* Delete removed lines
* Insert new lines
c. Show git add
d. Show git commit
e. Show git push
3. For random mode:
- Load next random commit
- Repeat from step 2
4. For single commit mode:
- Mark as finished
- Wait for exit
1. Terminal captures keyboard events
2. Any key press sets exit flag
3. UI checks exit flag each frame
4. On exit: cleanup and restore terminal
Reasons:
- Performance: Fast enough for smooth animations
- Safety: Memory safety without garbage collection
- Ecosystem: Excellent libraries (ratatui, tree-sitter, git2)
- Binary distribution: Single executable, no runtime needed
Reasons:
- Modern terminal UI framework
- Efficient rendering (only updates changed cells)
- Layout system for responsive design
- Active community and good documentation
Reasons:
- Fast and incremental parsing
- Support for many languages
- Accurate syntax trees
- Battle-tested (used by editors like Neovim, Atom)
Reasons:
- Low-level access to Git internals
- No external Git binary required
- Efficient commit traversal
- Comprehensive API
Reasons:
- Clear animation flow
- Easy to add new states
- Pauseable and resumable
- Debugging friendly
Reasons:
- Avoid repeated repository traversal
- Faster random commit selection
- Lazy initialization (only when needed)
main.rs
├─> ui.rs
│ ├─> animation.rs
│ │ ├─> syntax/
│ │ └─> git.rs
│ ├─> panes/
│ │ ├─> editor.rs
│ │ ├─> file_tree.rs
│ │ ├─> terminal.rs
│ │ └─> status_bar.rs
│ └─> theme.rs
├─> git.rs
├─> config.rs
└─> theme.rs
pub struct CommitMetadata {
pub hash: String,
pub author: String,
pub date: DateTime<Utc>,
pub message: String,
pub files: Vec<FileChange>,
}pub struct FileChange {
pub path: String,
pub status: ChangeStatus,
pub old_content: String,
pub new_content: String,
pub hunks: Vec<DiffHunk>,
}pub struct DiffHunk {
pub old_start: usize,
pub old_lines: usize,
pub new_start: usize,
pub new_lines: usize,
pub changes: Vec<LineChange>,
}pub struct EditorBuffer {
pub lines: Vec<String>,
pub cursor_line: usize,
pub cursor_col: usize,
pub scroll_offset: usize,
pub cached_highlights: Vec<HighlightSpan>,
}- Only redraw changed regions
- Use ratatui's diffing algorithm
- Minimize terminal write operations
- Pre-calculate highlights for old/new content
- Store highlights in editor buffer
- Reuse highlights across frames
- Exclude merge commits (optional)
- Skip large commits (>1000 files)
- Filter out lock files and generated files
- Limit blob size (500KB max)
- Clear cached highlights when switching files
- Lazy load commit list
- Use monotonic time for accuracy
- Avoid busy-waiting with event polling
- Configurable frame rate
- Animation state transitions
- Git diff parsing
- Theme loading
- Syntax highlighting
- Full commit playback
- UI rendering
- Configuration loading
- Theme switching
- Visual verification of animations
- Theme appearance
- Performance with large commits
- Error handling
-
Custom Themes
- Load themes from
~/.config/gitlogue/themes/ - Theme validation and error reporting
- Hot-reloading during development
- Load themes from
-
Advanced Playback Control
- Pause/resume animation
- Speed adjustment on-the-fly
- Skip to next commit
-
Statistics Display
- Lines added/removed
- File count
- Commit time distribution
-
Export Capabilities
- Record to asciinema format
- Generate GIF/video
- Export to HTML
-
Branch Visualization
- Show branch names
- Display merge commits
- Branch switching animation
-
Author-based Filtering
- Filter by author name
- Author avatar/profile display
- Contribution statistics
-
Plugin System
- Custom animation engines
- Language support extensions
- Theme providers
-
Configuration Extensions
- Per-repository settings
- Project-specific themes
- Animation presets
-
Performance Improvements
- Multi-threaded syntax highlighting
- Incremental diff parsing
- GPU acceleration (experimental)
For information on contributing to gitlogue, see the Contributing Guidelines.
When making changes:
-
Maintain separation of concerns
- Keep modules focused and independent
- Use clear interfaces between components
-
Preserve animation quality
- Test timing changes visually
- Maintain realistic feel
-
Follow Rust best practices
- Use type safety
- Avoid unsafe code unless necessary
- Document public APIs
-
Consider performance
- Profile before optimizing
- Measure impact of changes
- Avoid premature optimization
This architecture document is maintained alongside the codebase. If you notice discrepancies or have suggestions for improvements, please open an issue or pull request.