Skip to content

Commit 1aee75c

Browse files
committed
polish Vix internals documentation
1 parent 44dbe63 commit 1aee75c

7 files changed

Lines changed: 163 additions & 93 deletions

File tree

internals/architecture.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Architecture
22

3-
Vix is not only an HTTP framework. Internally, it is composed of several layers: developer workflow, runtime core, application APIs, module system, diagnostics, build pipeline, and production runtime.
3+
Vix is not only an HTTP framework.
4+
Internally, it is composed of several layers:
5+
- developer workflow,
6+
- runtime core,
7+
- application APIs,
8+
- module system,
9+
- diagnostics,
10+
- build pipeline,
11+
- and production runtime.
412

513
```txt
614
CLI → project detection → build/run pipeline → runtime modules → application
@@ -51,11 +59,11 @@ Application code
5159

5260
## Execution modes
5361

54-
| Mode | Used when | Build strategy |
55-
|------|-----------|---------------|
56-
| Script mode | `vix run main.cpp` — one .cpp file | Direct compile |
57-
| Project mode | CMakeLists.txt, vix.json, src/ present | CMake / project build |
58-
| Manifest mode | `app.vix` manifest present | Manifest-described build |
62+
| Mode | Used when | Build strategy |
63+
|---------------|---------------------------------------- |-----------------------------------|
64+
| Script mode | Running one `.cpp` file with `vix run`. | Uses direct compilation. |
65+
| Project mode | `CMakeLists.txt`, `vix.json`, or `src/` is present. | Uses the project build system. |
66+
| Manifest mode | An `app.vix` manifest is present. | Uses the manifest-defined build. |
5967

6068
## Public API layer
6169

@@ -167,17 +175,19 @@ HTTP may use JSON. JSON should not depend on HTTP. Avoid circular dependencies.
167175

168176
## Design principles
169177

170-
1. **Application-first** start from what you want to build, not from build config
171-
2. **Explicit C++** ownership, lifetimes, types, and errors remain understandable
172-
3. **Fast path for simple cases** — one file should be fast to run
173-
4. **Modules are focused** each module solves a clear problem
174-
5. **Reliability matters** — safe errors, durable operations, retries, health checks
175-
6. **No unnecessary magic** the system should remain debuggable
178+
1. **Application-first:** start from what you want to build, not from build configuration.
179+
2. **Explicit C++:** ownership, lifetimes, types, and errors remain understandable.
180+
3. **Fast path for simple cases:** a single file should run quickly.
181+
4. **Modules are focused:** each module solves a clear, well-defined problem.
182+
5. **Reliability matters:** handle errors safely with durable operations, retries, and health checks.
183+
6. **No unnecessary magic:** the system should remain transparent and debuggable.
176184

177185
## What you should remember
178186

179-
The main layers are: CLI workflow → public APIs → runtime modules → core foundation → system layer.
187+
The main layers are:
188+
CLI workflow → public APIs → runtime modules → core foundation → system layer.
180189

181-
The core idea: **make C++ applications easier to build without hiding C++.**
190+
The core idea:
191+
**make C++ applications easier to build without hiding C++.**
182192

183193
Next: [Runtime Model](/internals/runtime-model)

internals/cache-system.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Goal: **do not repeat expensive work when the inputs did not change.**
2222

2323
## Main cache areas
2424

25-
| Area | Path | Purpose |
26-
|------|------|---------|
27-
| Registry index | `~/.vix/registry/index` | Package metadata |
28-
| Store cache | `~/.vix/store/git` | Downloaded packages and commits |
29-
| Global packages | `~/.vix/global` | Globally installed packages |
30-
| Artifact cache | `~/.vix/cache/build` | Build artifacts |
25+
| Area | Path | Purpose |
26+
|-----------------|-------------------------|-----------------------------------------|
27+
| Registry index | `~/.vix/registry/index` | Stores package metadata. |
28+
| Store cache | `~/.vix/store/git` | Stores downloaded packages and commits. |
29+
| Global packages | `~/.vix/global` | Stores globally installed packages. |
30+
| Artifact cache | `~/.vix/cache/build` | Stores build artifacts. |
3131

3232
## vix info
3333

@@ -169,11 +169,11 @@ Cache accelerates repeated work. Source code, manifests, lock files, and package
169169

170170
## Design principles
171171

172-
1. **Invisible when healthy** developers shouldn't think about cache during normal work
173-
2. **Visible when debugging** `vix info` exposes cache state clearly
174-
3. **Safe** never reuse if inputs don't match
175-
4. **Rebuildable** artifact cache can always be regenerated
176-
5. **Correctness over speed** a fast but wrong cache is worse than no cache
172+
1. **Invisible when healthy:** developers should not think about cache during normal work.
173+
2. **Visible when debugging:** `vix info` exposes cache state clearly.
174+
3. **Safe:** never reuse cached data when inputs do not match.
175+
4. **Rebuildable:** artifact cache can always be regenerated.
176+
5. **Correctness over speed:** a fast but wrong cache is worse than no cache.
177177

178178
## What you should remember
179179

@@ -184,7 +184,8 @@ Cache accelerates repeated work. Source code, manifests, lock files, and package
184184
~/.vix/cache/build → build artifacts
185185
```
186186

187-
Use `vix info` to inspect cache state. Use `vix --version` and the failing command for bug reports.
187+
Use `vix info` to inspect cache state.
188+
Use `vix --version` and the failing command for bug reports.
188189

189190
The core idea: **cache makes Vix faster, but correctness always comes first.**
190191

internals/design-decisions.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ C++ should feel direct for application development without losing its power.
88

99
## Summary of key decisions
1010

11-
| Decision | Reason |
12-
|----------|--------|
13-
| Runtime, not new language | Keep C++ power and improve workflow |
14-
| Direct compile | Make single-file C++ fast and simple |
15-
| CMake support | Keep real project builds correct |
16-
| Explicit APIs | Avoid hidden behavior |
17-
| Public module headers | Keep docs stable and learnable |
18-
| Middleware | Keep shared logic out of routes |
19-
| Config via .env | Change runtime behavior without recompiling |
20-
| Prepared statements | Safer database access |
21-
| Cache is temporary | Avoid treating cache as durable state |
22-
| Sync persists first | Prevent lost operations |
23-
| P2P as transport | Keep connection logic separate from delivery logic |
24-
| Diagnostics | Make C++ errors easier to act on |
25-
| Benchmark mode | Measure performance with less noise |
26-
| Native deployment | Run as a normal Linux service |
11+
| Decision | Reason |
12+
|---------------------------|--------------------------------------------------|
13+
| Runtime, not new language | Keeps the power of C++ while improving workflow. |
14+
| Direct compile | Makes single-file C++ fast and simple. |
15+
| CMake support | Keeps real project builds correct and portable. |
16+
| Explicit APIs | Avoids hidden behavior and unexpected magic. |
17+
| Public module headers | Keeps documentation stable and learnable. |
18+
| Middleware | Keeps shared logic out of route handlers. |
19+
| Config via `.env` | Changes runtime behavior without recompiling. |
20+
| Prepared statements | Provides safer database access. |
21+
| Cache is temporary | Avoids treating cache as durable state. |
22+
| Sync persists first | Prevents local operations from being lost. |
23+
| P2P as transport | Separates connection logic from delivery logic. |
24+
| Diagnostics | Makes C++ errors easier to understand and fix. |
25+
| Benchmark mode | Measures performance with less runtime noise. |
26+
| Native deployment | Runs applications as normal Linux services. |
2727

2828
## 1. Vix is a runtime, not a new language
2929

@@ -32,6 +32,7 @@ Vix keeps C++, improves the workflow around it:
3232
```cpp
3333
#include <vix.hpp>
3434
using namespace vix;
35+
3536
int main()
3637
{
3738
App app;
@@ -274,9 +275,22 @@ Production readiness is part of normal app design.
274275

275276
## 26. Logs must be safe
276277

277-
Good logs: startup, request method/path, error code, duration, sync failure, P2P stats.
278+
Good logs include:
279+
280+
- Startup events
281+
- Request method and path
282+
- Error codes
283+
- Request duration
284+
- Sync failures
285+
- P2P statistics
286+
287+
Never log:
278288

279-
Never log: passwords, tokens, cookies, private keys, authorization headers.
289+
- Passwords
290+
- Tokens
291+
- Cookies
292+
- Private keys
293+
- Authorization headers
280294

281295
## 27. One-file docs are intentional
282296

@@ -308,7 +322,8 @@ Vix is designed around a balance:
308322
simple workflow + explicit C++ + production reliability
309323
```
310324

311-
The core design idea: **make C++ application development feel direct without hiding how the system works.**
325+
The core design idea:
326+
**make C++ application development feel direct without hiding how the system works.**
312327

313328
Vix helps developers move from:
314329

internals/direct-compile.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Direct Compile
22

3-
Direct compile is the fast path behind `vix run main.cpp`. It allows a single C++ file to be compiled and run immediately.
3+
Direct compile is the fast path behind `vix run main.cpp`.
4+
It allows a single C++ file to be compiled and run immediately.
45

56
```txt
67
main.cpp → detect script mode → compile directly → cache binary → run
78
```
89

910
## The problem direct compile solves
1011

11-
Traditional C++ requires build setup even for small files. Direct compile removes this friction:
12+
Traditional C++ requires build setup even for small files.
13+
Direct compile removes this friction:
1214

1315
```bash
1416
mkdir -p ~/tmp/vix-demo
@@ -27,10 +29,10 @@ read CLI arguments → detect that main.cpp is a file → enter script mode
2729

2830
## Script mode vs project mode
2931

30-
| Mode | Best for | Build strategy |
31-
|------|----------|---------------|
32-
| Direct compile | One .cpp file | Compile file directly |
33-
| Project build | Real app/project | Use project config and build system |
32+
| Mode | Best for | Build strategy |
33+
|----------------|----------------------------|----------------------------------------|
34+
| Direct compile | A single `.cpp` file. | Compiles the file directly. |
35+
| Project build | A real application project.| Uses project config and build system. |
3436

3537
Direct compile answers: "Can I quickly compile and run this one file?"
3638

@@ -120,7 +122,8 @@ Docs examples should use public headers, not internal repository paths.
120122

121123
## Working directory
122124

123-
The program runs from the current working directory. Relative paths depend on where you run the command:
125+
The program runs from the current working directory.
126+
Relative paths depend on where you run the command:
124127

125128
```cpp
126129
res.file("public/index.html"); // looks for ./public/index.html
@@ -204,11 +207,11 @@ cd ~/my-app && vix run main.cpp
204207

205208
## Design principles
206209

207-
1. **Fast simple path** `vix run main.cpp` should just work
208-
2. **Keep C++ explicit** Vix makes the workflow smoother, not invisible
209-
3. **Cache safely** never reuse stale binaries incorrectly
210-
4. **Fall back when needed** project mode exists for complex cases
211-
5. **Good diagnostics** when compilation fails, explain what to try next
210+
1. **Fast simple path:** `vix run main.cpp` should just work.
211+
2. **Keep C++ explicit:** Vix makes the workflow smoother, not invisible.
212+
3. **Cache safely:** never reuse stale binaries incorrectly.
213+
4. **Fall back when needed:** project mode exists for complex cases.
214+
5. **Good diagnostics:** when compilation fails, explain what to try next.
212215

213216
## What you should remember
214217

internals/error-diagnostics.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ undefined reference to ...
1515
terminate called without an active exception
1616
```
1717

18-
and not know what to do. Vix diagnostics answer three questions: **what happened, where, and what to try next.**
18+
and not know what to do. Vix diagnostics answer three questions:
19+
**what happened, where, and what to try next.**
1920

2021
## Diagnostic layers
2122

22-
Vix handles: compile errors, link errors, build system errors, runtime crashes, sanitizer reports, known C++ mistakes, unclassified failures.
23+
Vix handles:
24+
25+
- Compile errors
26+
- Link errors
27+
- Build system errors
28+
- Runtime crashes
29+
- Sanitizer reports
30+
- Known C++ mistakes
31+
- Unclassified failures
2332

2433
## Build error flow
2534

@@ -46,6 +55,7 @@ main.cpp:8:3
4655
```txt
4756
error: expected ';'
4857
hint: missing ';' (often the previous line)
58+
4959
error: use of undeclared identifier 'std'
5060
hint: std is not visible here (include the required standard header)
5161
```
@@ -129,8 +139,10 @@ hint: index out of bounds (check vector/string indexing)
129139
```txt
130140
runtime error: heap-buffer-overflow
131141
hint: heap out-of-bounds (check vector/string indexing and sizes)
142+
132143
runtime error: heap-use-after-free
133144
hint: you used memory after it was freed (dangling pointer/reference)
145+
134146
runtime error: double free
135147
hint: the same allocation was freed twice (double owner or duplicate delete/free)
136148
```
@@ -221,21 +233,26 @@ parsed compiler errors → try specialized rules → if handled: print friendly
221233

222234
## Design principles
223235

224-
1. First error matters mostshow it clearly
225-
2. Show source context code frames over long logs
226-
3. Hide repeated noisededuplicate
227-
4. Prefer specific explanations — "division by zero" beats "runtime error"
228-
5. Give next actioninclude a practical hint
229-
6. Keep fallback honestshow raw log if unknown
230-
7. Do not hide C++explain errors, don't remove the need to understand them
236+
1. **First error matters most:** show the first meaningful error clearly.
237+
2. **Show source context:** prefer code frames over long raw logs.
238+
3. **Hide repeated noise:** deduplicate repeated diagnostics.
239+
4. **Prefer specific explanations:** `division by zero` is better than `runtime error`.
240+
5. **Give the next action:** include a practical hint when possible.
241+
6. **Keep fallback honest:** show the raw log when the error is unknown.
242+
7. **Do not hide C++:** explain errors without removing the need to understand them.
231243

232244
## What you should remember
233245

234246
```txt
235247
raw log → parse → classify → deduplicate → code frame → hint
236248
```
237249

238-
Vix handles: compiler errors, linker errors, runtime crashes, sanitizer reports, common C++ mistakes.
250+
Vix handles:
251+
- compiler errors,
252+
- linker errors,
253+
- runtime crashes,
254+
- sanitizer reports,
255+
- common C++ mistakes.
239256

240257
The core idea: **a good error message should teach the next step.**
241258

0 commit comments

Comments
 (0)