aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/docs/content/en/architecture.mdx
blob: 5f55c5e9adb702d7de613445d5af7130b229a256 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
---
title: Architecture
description: Technical architecture and design of DropOut Minecraft Launcher
---

# Architecture

DropOut is built with a modern tech stack designed for performance, security, and cross-platform compatibility.

## Technology Stack

### Backend (Rust)
- **Framework**: Tauri v2
- **Language**: Rust (Edition 2021)
- **Async Runtime**: Tokio
- **HTTP Client**: reqwest with native-tls

### Frontend (Svelte)
- **Framework**: Svelte 5 (with runes)
- **Styling**: Tailwind CSS 4
- **Build Tool**: Vite with Rolldown
- **Package Manager**: pnpm

### Documentation
- **Framework**: Fumadocs with React Router v7
- **Content**: MDX files
- **Styling**: Tailwind CSS 4

## System Architecture

```
┌─────────────────────────────────────────────────────────┐
│                    Frontend (Svelte 5)                   │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌─────────┐ │
│  │  Stores  │  │Components│  │ UI Views │  │Particles│ │
│  └────┬─────┘  └────┬─────┘  └────┬─────┘  └────┬────┘ │
│       │             │             │              │      │
│       └─────────────┴─────────────┴──────────────┘      │
│                          │                              │
│                   Tauri Commands                        │
│                    Events/Emitters                      │
└──────────────────────────┬──────────────────────────────┘
                           │
┌──────────────────────────┴──────────────────────────────┐
│                  Backend (Rust/Tauri)                    │
│  ┌─────────────────────────────────────────────────┐    │
│  │               main.rs (Commands)                 │    │
│  └──────────────┬──────────────────────────────────┘    │
│                 │                                        │
│  ┌──────────────┴───────────────────────────────┐       │
│  │               Core Modules                   │       │
│  │  ┌──────┐ ┌────────┐ ┌──────┐ ┌──────────┐  │       │
│  │  │ Auth │ │Download│ │ Java │ │ Instance │  │       │
│  │  └──────┘ └────────┘ └──────┘ └──────────┘  │       │
│  │  ┌──────┐ ┌────────┐ ┌──────┐ ┌──────────┐  │       │
│  │  │Fabric│ │ Forge  │ │Config│ │Manifest  │  │       │
│  │  └──────┘ └────────┘ └──────┘ └──────────┘  │       │
│  └──────────────────────────────────────────────┘       │
│                                                          │
│  ┌─────────────────────────────────────────────────┐    │
│  │                Utils & Helpers                   │    │
│  │  • ZIP extraction  • Path utilities             │    │
│  └─────────────────────────────────────────────────┘    │
└──────────────────────────┬──────────────────────────────┘
                           │
                    External APIs
                           │
        ┌──────────────────┼──────────────────┐
        │                  │                  │
  ┌─────┴────┐      ┌──────┴─────┐    ┌──────┴─────┐
  │  Mojang  │      │   Fabric   │    │   Forge    │
  │   APIs   │      │    Meta    │    │   Maven    │
  └──────────┘      └────────────┘    └────────────┘
```

## Core Components

### Frontend State Management

DropOut uses **Svelte 5 runes** for reactive state management:

```typescript
// stores/auth.svelte.ts
export class AuthState {
  currentAccount = $state<Account | null>(null);  // Reactive
  isLoginModalOpen = $state(false);
  
  $effect(() => {  // Side effects
    // Auto-runs when dependencies change
  });
}
```

**Key Stores:**
- `auth.svelte.ts`: Authentication state and login flow
- `settings.svelte.ts`: Launcher settings and Java detection
- `game.svelte.ts`: Game running state and logs
- `instances.svelte.ts`: Instance management
- `ui.svelte.ts`: UI state (toasts, modals, active view)

### Backend Architecture

#### Command Pattern
All Tauri commands follow this structure:

```rust
#[tauri::command]
async fn command_name(
    window: Window,
    state: State<'_, SomeState>,
    param: Type,
) -> Result<ReturnType, String> {
    emit_log!(window, "Status message");
    // Async logic
    Ok(result)
}
```

#### Event Communication

**Rust → Frontend (Progress Updates):**
```rust
window.emit("launcher-log", "Downloading...")?;
window.emit("download-progress", progress_struct)?;
```

**Frontend → Rust (Commands):**
```typescript
import { invoke } from "@tauri-apps/api/core";
const result = await invoke("start_game", { versionId: "1.20.4" });
```

### Core Modules

#### Authentication (`core/auth.rs`)
- **Microsoft OAuth 2.0**: Device Code Flow
- **Offline Authentication**: Local UUID generation
- **Token Management**: Refresh token storage and auto-refresh
- **Xbox Live Integration**: Full authentication chain

**Authentication Flow:**
1. Device Code Request → MS Token
2. Xbox Live Authentication
3. XSTS Authorization
4. Minecraft Token Exchange
5. Profile Fetching

#### Downloader (`core/downloader.rs`)
- **Concurrent Downloads**: Configurable thread pool
- **Resume Support**: `.part` and `.part.meta` files
- **Multi-segment Downloads**: Large files split into chunks
- **Checksum Verification**: SHA1/SHA256 validation
- **Progress Tracking**: Real-time events to frontend

#### Java Management (`core/java.rs`)
- **Auto-detection**: Scans system paths
- **Adoptium Integration**: Download JDK/JRE on-demand
- **Catalog Caching**: 24-hour cache for version lists
- **Installation**: Extracts to app data directory
- **Cancellation**: Atomic flag for download cancellation

#### Fabric Support (`core/fabric.rs`)
- **Meta API Integration**: Fetch loader versions
- **Profile Generation**: Creates version JSON
- **Library Resolution**: Maven artifact handling

#### Forge Support (`core/forge.rs`)
- **Installer Execution**: Runs Forge installer
- **Profile Parsing**: Extracts install profile
- **Library Management**: Handles Forge-specific libraries

#### Instance System (`core/instance.rs`)
- **Isolation**: Separate directories per instance
- **Configuration**: Per-instance settings
- **Mod Management**: Instance-specific mods
- **Version Locking**: Reproducible environments

#### Version Management
- **Manifest Parsing** (`manifest.rs`): Mojang version manifest
- **Inheritance System** (`version_merge.rs`): Parent version merging
- **Game Version** (`game_version.rs`): JSON parsing and validation
- **Rules Engine** (`rules.rs`): OS/feature conditional logic

### File Structure

```
~/.local/share/com.dropout.launcher/  (Linux)
~/Library/Application Support/com.dropout.launcher/  (macOS)
%APPDATA%/com.dropout.launcher/  (Windows)
├── versions/
│   └── <version_id>/
│       ├── <version_id>.json
│       ├── <version_id>.jar
│       └── natives/
├── libraries/
│   └── <maven-path>/
├── assets/
│   ├── indexes/
│   └── objects/
├── instances/
│   └── <instance_name>/
│       ├── mods/
│       ├── config/
│       └── saves/
├── java/
│   └── <version>/
├── config.json
└── accounts.json
```

## Data Flow

### Game Launch Sequence

1. **Frontend**: User clicks "Launch Game"
2. **Command**: `start_game(version_id)` invoked
3. **Backend Processing**:
   - Load version JSON (with inheritance)
   - Resolve all libraries
   - Download missing assets
   - Extract native libraries
   - Build classpath
   - Construct JVM arguments
   - Replace placeholders
4. **Process Spawn**: Launch Java with arguments
5. **Stream Logs**: Emit stdout/stderr to frontend
6. **Monitor**: Track game process status

### Download Flow

1. **Queue Creation**: List of files to download
2. **Concurrent Processing**: Semaphore-limited threads
3. **Resume Check**: Verify existing `.part` files
4. **Download**: Multi-segment for large files
5. **Verification**: Checksum validation
6. **Progress Events**: Real-time updates to UI
7. **Completion**: Move from `.part` to final location

### Authentication Flow

1. **Device Code Request**: Get user code + device code
2. **User Authorization**: User visits URL and enters code
3. **Token Polling**: Frontend polls for completion
4. **Token Exchange**: MS token → Xbox → XSTS → Minecraft
5. **Profile Fetch**: Get username and UUID
6. **Storage**: Save account with refresh token
7. **Auto-refresh**: Background token refresh on expiry

## Platform-Specific Considerations

### Linux
- Uses GTK WebView (`webkit2gtk`)
- System Java detection from `/usr/lib/jvm`
- Desktop file integration

### macOS
- Uses system WebKit
- App bundle structure
- Keychain integration for secure storage

### Windows
- Uses WebView2 runtime
- Registry Java detection
- MSI installer support
- No console window in release builds

## Performance Optimizations

- **Concurrent Downloads**: Parallel asset/library downloads
- **Lazy Loading**: Load version manifests on-demand
- **Caching**: Java catalog, version manifests
- **Native Code**: Rust for CPU-intensive operations
- **Async I/O**: Tokio for non-blocking operations

## Security Features

- **Token Encryption**: Secure storage of auth tokens
- **HTTPS Only**: All external API calls
- **Checksum Validation**: File integrity verification
- **Sandboxed Execution**: Tauri security model
- **No Arbitrary Code**: No eval or dynamic code execution