---
title: Startup Sequence
description: A detailed breakdown of the system initialization and bootstrap orchestration.
icon: Zap
---
import { Steps, Step } from 'fumadocs-ui/components/steps';
The startup sequence in Vane is a tightly orchestrated process designed to ensure that all internal states, configuration registries, and background services are ready before any network listeners are activated. This sequential approach prevents race conditions and ensures that the first connection accepted by Vane always finds a fully initialized system.
The sequence is managed by the `start()` function in `src/bootstrap/startup.rs`.
## Initialization Flow
<Steps>
<Step>
### Foundation & Infrastructure
The process begins by establishing the runtime environment.
- **Crypto Setup**: Initializes `aws-lc-rs` or `ring`.
- **Environment**: Loads `.env` and sets log level.
- **Readiness Check**: Ensures that critical configuration directories exist, creating them if they are missing.
<Mermaid
chart="
graph LR
Main[main.rs] -->|start| Crypto[Init Crypto]
Crypto --> Env[Load .env]
Env --> Logger[Init Logger]
Logger --> Check{Config Dirs Exist?}
Check -- No --> Create[Create Dirs]
Check -- Yes --> Next([Next Step])
Create --> Next
"
/>
</Step>
<Step>
### Registry Loading
Vane uses atomic `ArcSwap` registries for lock-free state management. These are populated sequentially from disk.
<Mermaid
chart="
graph LR
Loader[File Loader] --> Nodes[nodes.json]
Loader --> Certs[certs/]
Loader --> Ports[ports.json]
Loader --> Resolvers[resolvers/]
Loader --> Apps[applications/]
Nodes -->|Store| NODES_STATE
Certs -->|Store| CERT_REGISTRY
Ports -->|Store| CONFIG_STATE
Resolvers -->|Store| RESOLVER_REGISTRY
Apps -->|Store| APPLICATION_REGISTRY
"
/>
</Step>
<Step>
### System Activation
Before opening ports, internal subsystems are spun up to support the traffic flow.
<Mermaid
chart="
graph LR
Init[Init Subsystems] --> Tasks[Spawn Background Tasks]
Init --> Plugins[Load Plugins]
Init --> Monitor[Start L7 Memory Monitor]
Plugins -->|Validate| ExtRegistry[External Plugin Registry]
Monitor -->|Loop| MemCheck[Check Free RAM]
"
/>
</Step>
<Step>
### Network & Management
With the state fully loaded, Vane interacts with the outside world by binding ports and starting the management interface.
<Mermaid
chart="
graph LR
Bind[Bind Listeners] --> TCP[TCP Loops]
Bind --> UDP[UDP Loops]
Start --> Hotswap[Spawn Watchers]
Start --> API[Console API]
TCP & UDP -->|Ready| Traffic([Accept Traffic])
"
/>
</Step>
<Step>
### Runtime Loop & Shutdown
The main thread enters a signal wait state. Upon receiving a termination signal, the graceful shutdown sequence triggers.
<Mermaid
chart="
graph LR
Wait[Wait for Signal] -->|SIGINT/TERM| Shutdown
Shutdown --> StopAPI[Stop API]
Shutdown --> Exit([Process Exit])
"
/>
</Step>
</Steps>
<Callout type="info" title="Resilient Startup">
Vane is designed to be resilient. If configuration files are missing or invalid during startup, it
will typically log an error and continue with an empty or default state rather than crashing. This
ensures the process remains alive and can be corrected via hot-reloading.
</Callout>