Zum Hauptinhalt springen

πŸ› οΈ The Code Factory

The defining feature of Ferrox is its ability to break the boundary between Backend and Frontend.

Traditionally, backend engineers write an API in Rust/Java/Go, and frontend engineers manually rewrite the exact same interfaces and API calls in TypeScript. This leads to massive synchronization bugs, broken builds, and wasted time.

Ferrox solves this permanently via the Code Factory.

1. Type Generation (ts-rs)​

When you define a Data Transfer Object (DTO) in Rust, you decorate it with #[derive(TS)].

use validator::Validate;
use ts_rs::TS;

#[derive(Debug, Clone, Serialize, Deserialize, Validate, TS)]
#[ts(export)]
pub struct CreateUserDto {
pub email: String,
pub age: u8,
}

During compilation, Ferrox automatically exports a pristine CreateUserDto.ts file. If the backend engineer changes age: u8 to age: i32 in Rust, the TypeScript interface updates automatically. The Frontend build will fail if it doesn't adapt to the new contract.

2. API Client Generation​

Beyond just types, Ferrox can generate the entire network logic.

By running the Ferrox CLI:

ferrox generate --lang ts --output ./frontend/src/api

The Code Factory scans your project and outputs a FerroxClient.ts file into your frontend directory.

The Generated Client (0 Dependencies)​

The generated client uses the native JavaScript fetch API, meaning it requires zero NPM dependencies (no axios needed).

// AUTO-GENERATED BY FERROX CODE FACTORY
import { CreateUserDto } from './CreateUserDto';

export class FerroxClient {
private baseUrl: string;
private token: string;

constructor(baseUrl: string, token: string) {
this.baseUrl = baseUrl;
this.token = token;
}

private async request<T>(endpoint: string, options: RequestInit): Promise<T> {
const headers = new Headers(options.headers);

// Zero-Trust: Automatic token injection
headers.set('Authorization', `Bearer ${this.token}`);
headers.set('Content-Type', 'application/json');

const response = await fetch(`${this.baseUrl}${endpoint}`, {
...options,
headers,
});

if (!response.ok) {
throw new Error(`API Error: ${response.statusText}`);
}

return response.json();
}
}

This generated SDK abstracts away headers, serialization, and JWT injection. Your React or Next.js developers just need to instantiate the client and call the strongly-typed methods.