Use the Rix Facade
The Rix facade is the public entry point for using Rix packages from one clean API.
Instead of including each package separately, you can include:
#include <rix.hpp>Then use the global rix object:
rix.auth
rix.debugThe facade is the recommended public style for this documentation.
Basic usage
Create a small file:
mkdir -p ~/rix-facade-example
cd ~/rix-facade-example
touch main.cppAdd this code:
#include <rix.hpp>
int main()
{
rix.debug.print("Hello from Rix");
auto auth = rix.auth.memory();
auto registered = auth.register_user({"ada@example.com","correct-password"});
if (registered.failed())
{
const auto &error = registered.error();
rix.debug.eprint(
"auth error:",
rix.auth.error.to_string(error),
error.message()
);
return 1;
}
rix.debug.print("registered:", registered.value().email());
return 0;
}Run it:
vix run main.cppIf Rix is not available yet, install the facade package:
vix install -g rix/rixThen run again:
vix run main.cppFacade model
The facade groups selected Rix packages under one object:
rix.auth
rix.debugThis keeps application code simple.
For example, Auth is available through:
rix.auth.memory()
rix.auth.password.hash(...)
rix.auth.config.production()
rix.auth.error.to_string(...)Debug helpers are available through:
rix.debug.print(...)
rix.debug.eprint(...)
rix.debug.log(...)
rix.debug.format(...)Why use the facade
The facade gives a stable, readable API for application code.
Instead of writing lower-level package setup first, public examples can start with:
auto auth = rix.auth.memory();That is easier to read than manually creating stores and wiring the lower-level auth service.
The lower-level API still exists for advanced usage, but the facade is the recommended starting point.
Install the facade in a project
For a real Vix project, add the facade package:
vix add rix/rix
vix installThen add it to vix.app:
deps = [
"rix/rix",
]A small vix.app can look like this:
name = "hello-rix"
type = "executable"
standard = "c++20"
output_dir = "bin"
sources = [
"src/main.cpp",
]
include_dirs = [
"include",
"src",
]
deps = [
"rix/rix",
]
packages = [
"vix",
]
links = [
"vix::vix",
]
resources = [
".env=.env",
]Then build and run:
vix build
vix runFeature macros
By default, including rix.hpp enables the available facade modules.
#include <rix.hpp>For smaller builds, define only the modules you want before including rix.hpp.
For Auth only:
#define RIX_ENABLE_AUTH
#include <rix.hpp>
int main()
{
auto auth = rix.auth.memory();
return 0;
}For Auth and Debug:
#define RIX_ENABLE_AUTH
#define RIX_ENABLE_DEBUG
#include <rix.hpp>
int main()
{
rix.debug.print("Auth enabled");
auto auth = rix.auth.memory();
return 0;
}Feature macros must be defined before including rix.hpp.
Correct:
#define RIX_ENABLE_AUTH
#include <rix.hpp>Wrong:
#include <rix.hpp>
#define RIX_ENABLE_AUTHPublic API and lower-level API
Public documentation should prefer:
#include <rix.hpp>
auto auth = rix.auth.memory();The lower-level namespace is still available:
rixlib::authUse lower-level APIs when you need advanced integration, custom stores, independent package usage, or implementation-level control.
For normal application code, prefer:
rix.authAuth through the facade
Create memory auth:
auto auth = rix.auth.memory();Register a user:
auto registered = auth.register_user({
"ada@example.com",
"correct-password"});Login:
auto login = auth.login({
"ada@example.com",
"correct-password"});Authenticate a session:
auto session = auth.authenticate_session(
login.value().session.id());Logout:
auto status = auth.logout(
login.value().session.id());Password helpers through the facade
Hash a password:
auto hashed = rix.auth.password.hash("correct-password");Verify a password:
const bool valid = rix.auth.password.verify(
"correct-password",
hashed.value());Check a wrong password:
const bool invalid = rix.auth.password.verify(
"wrong-password",
hashed.value());Configuration through the facade
Use development configuration:
auto config = rix.auth.config.development();
auto auth = rix.auth.memory(config);Use production configuration:
auto config = rix.auth.config.production();
config.set_min_password_length(12);
config.set_issuer("my-app");
auto auth = rix.auth.memory(config);For durable applications, production configuration is usually used with database auth:
auto config = rix.auth.config.production();
auto auth = rix.auth.database(db, config);Error helpers through the facade
Rix Auth uses explicit result values.
When an operation fails, use the facade error helper:
if (login.failed())
{
const auto &error = login.error();
rix.debug.eprint(
"auth error:",
rix.auth.error.to_string(error),
error.message());
return 1;
}Use:
rix.auth.error.to_string(error)for stable error names.
Use:
error.message()for human-readable diagnostics.
Store helpers through the facade
Most applications should use:
auto auth = rix.auth.memory();or:
auto auth = rix.auth.database(db);For custom managed stores, use:
auto users = rix.auth.stores.memory_users();
auto sessions = rix.auth.stores.memory_sessions();
auto auth = rix.auth.managed(
std::move(users),
std::move(sessions));The managed API owns the stores inside the returned auth service.
Use it when you need custom store creation but still want safe ownership.
Advanced caller-owned stores
The facade also exposes an advanced create API:
auto users = rix.auth.stores.memory_users();
auto sessions = rix.auth.stores.memory_sessions();
auto auth = rix.auth.create(
*users,
*sessions);In this case, the caller owns the stores.
The stores must stay alive for as long as auth is used.
For public application code, prefer:
auto auth = rix.auth.memory();or:
auto auth = rix.auth.database(db);or:
auto auth = rix.auth.managed(
rix.auth.stores.memory_users(),
rix.auth.stores.memory_sessions());Facade vs independent packages
Use the facade when you want one clean public API:
#include <rix.hpp>
auto auth = rix.auth.memory();Use an independent package when you only want one package and prefer direct package-level usage:
#include <rix/auth.hpp>The recommended path for these docs is:
#include <rix.hpp>and:
rix.authWhat you should remember
Use the Rix facade with:
#include <rix.hpp>Use mounted packages through:
rix.auth
rix.debugInstall the facade in a project with:
vix add rix/rix
vix installDeclare it in vix.app:
deps = [
"rix/rix",
]Use feature macros before including rix.hpp when you want a smaller facade.
Next step
Continue with the Auth package.
Next: Auth Overview