Skip to main content

API Reference

3 mins · Edit content

Zylix API Reference
#

Complete API documentation for all Zylix modules. This reference covers the public APIs for building cross-platform applications with Zylix.

Module Overview
#

Core Modules
#

ModuleDescription
StateApplication state management with diff tracking
EventsEvent system for user interactions
VDOMVirtual DOM implementation
ComponentComponent system with lifecycle
RouterClient-side routing
ABIC ABI for platform integration

Feature Modules
#

ModuleDescription
AIAI/ML integration (LLM, Whisper)
AnimationTimeline, state machine, Lottie, Live2D
Graphics3D3D rendering with scene graph
ServerHTTP/gRPC server runtime
EdgeEdge platform adapters (Cloudflare, Vercel, AWS)
DatabaseDatabase connectivity

Productivity Modules
#

ModuleDescription
PDFPDF generation and parsing
ExcelExcel file handling
NodeFlowNode-based UI system

Performance Modules
#

ModuleDescription
PerformanceProfiling, memory pools, render batching
Error BoundaryError isolation and recovery
AnalyticsCrash reporting and analytics
BundleBundle analysis and tree shaking

Quick Reference
#

State Management
#

const zylix = @import("zylix");

// Initialize state
zylix.state.init();
defer zylix.state.deinit();

// Access state
const current = zylix.state.getState();
std.debug.print("Counter: {d}\n", .{current.app.counter});

// Modify state
zylix.state.handleIncrement();

// Get diff for UI updates
const diff = zylix.state.calculateDiff();

Event Handling
#

const events = zylix.events;

// Dispatch event
const result = events.dispatch(
    @intFromEnum(events.EventType.counter_increment),
    null,
    0
);

// With payload
const payload = events.ButtonEvent{ .button_id = 0 };
_ = events.dispatch(
    @intFromEnum(events.EventType.button_press),
    @ptrCast(&payload),
    @sizeOf(events.ButtonEvent)
);

HTTP Server
#

const server = zylix.server;

var app = try server.Zylix.init(allocator, .{
    .port = 8080,
    .workers = 4,
});
defer app.deinit();

app.get("/", handleIndex);
app.get("/api/users", handleUsers);
app.post("/api/users", createUser);

try app.listen();

Performance Profiling
#

const perf = zylix.perf;

var profiler = try perf.Profiler.init(allocator, .{
    .enable_diff_cache = true,
    .target_frame_time_ns = 16_666_667, // 60fps
});
defer profiler.deinit();

// Measure section
var section = profiler.beginSection("render");
renderFrame();
const duration = profiler.endSection(&section);

// Check metrics
const metrics = profiler.getMetrics();
if (!metrics.isWithinTarget(16_666_667)) {
    std.debug.print("Slow frame: {d}ms\n", .{duration / 1_000_000});
}

Error Boundaries
#

const error_boundary = zylix.perf.error_boundary;

var boundary = try error_boundary.ErrorBoundary.init(allocator, "App");
defer boundary.deinit();

_ = boundary
    .onError(handleError)
    .fallback(renderFallback)
    .withMaxRetries(3);

// Catch errors
boundary.catchError(
    error_boundary.ErrorContext.init("Render failed", .@"error")
);

// Recovery
if (boundary.tryRecover()) {
    // Retry
} else {
    // Use fallback
}

Type Reference
#

Core Types
#

// State types
pub const State = zylix.State;
pub const AppState = zylix.AppState;
pub const UIState = zylix.UIState;

// Event types
pub const EventType = zylix.EventType;

// Server types
pub const Zylix = zylix.Zylix;
pub const HttpRequest = zylix.HttpRequest;
pub const HttpResponse = zylix.HttpResponse;

// Performance types
pub const Profiler = zylix.Profiler;
pub const PerfConfig = zylix.PerfConfig;
pub const PerfMetrics = zylix.PerfMetrics;

// Edge types
pub const EdgePlatform = zylix.EdgePlatform;
pub const CloudflareAdapter = zylix.CloudflareAdapter;
pub const VercelAdapter = zylix.VercelAdapter;

Configuration Types
#

// Performance configuration
pub const PerfConfig = struct {
    enable_diff_cache: bool = true,
    max_diff_cache_size: usize = 1000,
    enable_memory_pool: bool = true,
    pool_initial_size: usize = 1024 * 1024,
    enable_render_batching: bool = true,
    target_frame_time_ns: u64 = 16_666_667,
    enable_error_boundaries: bool = true,
    enable_analytics: bool = false,
    enable_crash_reporting: bool = false,
    optimization_level: OptimizationLevel = .balanced,
};

Language Bindings
#

TypeScript (@zylix/test)
#

import {
  ZylixResult,
  ZylixPriority,
  ZylixEventType,
  TodoFilterMode,
  type TodoItem,
} from '@zylix/test';

// Event types match core/src/events.zig
ZylixEventType.COUNTER_INCREMENT  // 0x1000
ZylixEventType.TODO_ADD           // 0x2000

// Result codes
if (result === ZylixResult.OK) {
  // Success
}

// Priority levels
queueEvent(eventType, ZylixPriority.HIGH);

// Todo filter modes
setFilter(TodoFilterMode.ACTIVE);

Python (zylix_test)
#

from zylix_test import (
    ZylixResult,
    ZylixPriority,
    ZylixEventType,
    TodoFilterMode,
    TodoItem,
)

# Event types match core/src/events.zig
ZylixEventType.COUNTER_INCREMENT  # 0x1000
ZylixEventType.TODO_ADD           # 0x2000

# Result codes
if result == ZylixResult.OK:
    # Success

# Priority levels
queue_event(event_type, ZylixPriority.HIGH)

# Todo filter modes
set_filter(TodoFilterMode.ACTIVE)

Event Type Constants
#

CategoryEventValue
LifecycleAPP_INIT0x0001
LifecycleAPP_TERMINATE0x0002
LifecycleAPP_FOREGROUND0x0003
LifecycleAPP_BACKGROUND0x0004
UserBUTTON_PRESS0x0100
UserTEXT_INPUT0x0101
NavigationNAVIGATE0x0200
NavigationNAVIGATE_BACK0x0201
CounterCOUNTER_INCREMENT0x1000
CounterCOUNTER_DECREMENT0x1001
CounterCOUNTER_RESET0x1002
TodoTODO_ADD0x2000
TodoTODO_REMOVE0x2001
TodoTODO_TOGGLE0x2002
TodoTODO_CLEAR_COMPLETED0x2004
TodoTODO_SET_FILTER0x2005

Build Commands
#

# Native build
cd core && zig build

# Run tests
cd core && zig build test

# Cross-compilation
zig build -Dtarget=wasm32-freestanding    # WebAssembly
zig build -Dtarget=aarch64-macos          # macOS ARM64
zig build -Dtarget=aarch64-linux-android  # Android ARM64
zig build -Dtarget=x86_64-linux           # Linux x64
zig build -Dtarget=x86_64-windows         # Windows x64

Full API Documentation
#

For complete API documentation with all types, functions, and examples, see:

Related Resources#