summaryrefslogtreecommitdiff
path: root/archived/projt-launcher/docs/contributing/ARCHITECTURE.md
blob: a83334e604f3a872e99693d3b7231d2214e19a86 (plain)
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
# Architecture

High-level design and component interaction in ProjT Launcher.

---

## Layers

```
┌─────────────────────────────────────────┐
│              UI Layer                   │
│         launcher/ui/ (Qt Widgets)       │
├─────────────────────────────────────────┤
│            Core Layer                   │
│   launcher/minecraft/, net/, java/      │
├─────────────────────────────────────────┤
│            Task System                  │
│           launcher/tasks/               │
└─────────────────────────────────────────┘
```

### UI Layer

**Location**: `launcher/ui/`

- Qt Widgets interface
- Renders state, handles user input
- No direct I/O or network access

### Core Layer

**Location**: `launcher/`, `launcher/minecraft/`, `launcher/net/`, `launcher/java/`

- Business logic
- Data models
- Network operations
- No UI dependencies

### Task System

**Location**: `launcher/tasks/`

- Long-running operations
- Async work (downloads, extraction)
- Progress reporting

---

## Key Principles

### Separation of Concerns

UI classes display state and forward user intent. They do not perform:

- File I/O
- Network requests
- Long computations

### Communication Pattern

UI communicates with core via signals/slots:

```cpp
auto task = makeShared<DownloadTask>(url);
connect(task.get(), &Task::progress, this, &MainWindow::updateProgress);
connect(task.get(), &Task::finished, this, &MainWindow::onDownloadComplete);
task->start();
```

### Threading

| Thread | Purpose |
|--------|---------|
| Main | UI rendering only |
| Worker | File I/O, networking, hashing |

Operations > 10ms should be async.

---

## Task System

### Creating a Task

```cpp
class MyTask : public Task {
    Q_OBJECT

protected:
    void executeTask() override {
        setStatus("Working...");
        setProgress(0);

        // Do work
        for (int i = 0; i < 100; i++) {
            if (isCancelled()) {
                emitFailed("Cancelled");
                return;
            }
            setProgress(i);
        }

        emitSucceeded();
    }
};
```

### Running a Task

```cpp
auto task = makeShared<MyTask>();
connect(task.get(), &Task::succeeded, this, &MyClass::onSuccess);
connect(task.get(), &Task::failed, this, &MyClass::onFailure);
task->start();
```

---

## Application Lifecycle

1. **Startup**: `main.cpp` creates `Application` singleton
2. **Setup**: Load settings, accounts, instances
3. **UI Launch**: Create `MainWindow`
4. **Runtime**: Event loop processes user actions
5. **Shutdown**: Save state, release resources

---

## Service Objects

Long-lived non-UI classes owned by Application:

- `AccountManager` - Microsoft/offline accounts
- `InstanceManager` - Minecraft instances
- `NetworkManager` - HTTP operations
- `SettingsManager` - Configuration

Access via `Application::instance()->serviceName()`.

---

## Common Violations

**Don't do these**:

| Violation | Fix |
|-----------|-----|
| `sleep()` in UI | Use Task |
| Network in UI class | Move to core service |
| UI import in core | Remove dependency |
| Direct file I/O in UI | Use Task |

---

## Module Dependencies

```
ui/ ──→ minecraft/ ──→ net/
         │              │
         └──→ tasks/ ←──┘
               │
               └──→ java/
```

**Rules**:

- No circular dependencies
- `ui/` depends on everything
- Core modules are independent
- `tasks/` is a utility layer

---

## Related

- [Project Structure](./PROJECT_STRUCTURE.md)
- [Testing](./TESTING.md)