Base application lifecycle kit for modern C++.
app provides a minimal, deterministic application runtime foundation designed for Vix application scaffolding.
- Explicit start / stop lifecycle
- Structured run loop
- Graceful shutdown (SIGINT, SIGTERM)
- Hook-based initialization and cleanup
Header-only. Standard library only. Zero external dependencies.
https://vixcpp.com/registry/pkg/vix/app
Every long-running C++ application eventually needs:
- Startup initialization
- Graceful shutdown
- Signal handling
- Lifecycle structure
- A main run loop
- Clean separation between bootstrap and runtime
Most projects either:
- Put everything inside
main() - Reimplement ad-hoc loops
- Forget proper shutdown handling
- Mix lifecycle and business logic
app provides:
- A minimal lifecycle base class
- Explicit hooks (
on_start,on_stop) - Customizable run loop
- Safe stop signaling
- Clean extension points
No logging system. No HTTP layer. No async runtime.
Just a deterministic application foundation.
vix add vix/app
vix depsgit clone https://github.com/vixcpp/app.gitAdd the include/ directory to your project.
Requires C++17 or newer. No external dependencies.
#include <app/app.hpp>
#include <iostream>
class MyApp : public vix::app::Application
{
protected:
void loop_step() override
{
std::cout << "tick\n";
stop(); // stop after one iteration
}
};
int main()
{
MyApp app;
app.on_start([] {
std::cout << "starting\n";
});
app.on_stop([] {
std::cout << "stopping\n";
});
app.run();
}#include <app/app.hpp>
#include <chrono>
#include <iostream>
#include <thread>
class CustomApp : public vix::app::Application
{
protected:
void run_loop() override
{
for (int i = 0; i < 5 && is_running(); ++i)
{
std::cout << "step: " << i << "\n";
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
stop();
}
};
int main()
{
CustomApp app;
app.run();
}Application::run()Application::stop()Application::is_running()Application::on_start()Application::on_stop()
Protected extension points:
Application::run_loop()Application::loop_step()Application::tick_interval()
Execution order:
run()on_start()hookrun_loop()stop()requestedon_stop()hook- exit
Signals handled:
SIGINTSIGTERM
Graceful shutdown is guaranteed if stop() is triggered.
All operations are constant time.
| Operation | Time complexity |
|---|---|
run() start |
O(1) |
stop() |
O(1) |
is_running() |
O(1) |
The run loop complexity depends on user-defined behavior.
- Deterministic lifecycle
- Explicit extension points
- No hidden threads
- No global state (except controlled signal pointer)
- Minimal abstraction
- Stable foundation for higher-level runtimes
This library provides primitives only.
If you need:
- HTTP server runtime
- WebSocket handling
- Async I/O engine
- Microservice orchestration
Build them on top of this layer (web_app, service_app, realtime_app, etc.).
Run:
vix build
vix testTests verify:
- Lifecycle execution
- Hook execution
- Proper stop behavior
- Loop iteration
- Graceful termination
MIT License
Copyright (c) Gaspard Kirira