Real-world applications using Ifá-Lang's 7 technology stacks
Stacks are high-level abstractions that combine multiple domains for specific application types.
End-to-end encryption, secure key management, digital signatures
// Secure message sender
ayanmo Crypto = import("@stacks/crypto");
ise encrypt_message(recipient_pubkey, message) {
// Generate ephemeral key pair
ayanmo ephemeral = Crypto.generate_keypair();
// Derive shared secret using ECDH
ayanmo shared = Crypto.ecdh(ephemeral.private, recipient_pubkey);
// Encrypt with AES-256-GCM
ayanmo nonce = Crypto.random_bytes(12);
ayanmo ciphertext = Crypto.aes_encrypt(shared, nonce, message);
padap? {
"ephemeral_pub": ephemeral.public,
"nonce": nonce,
"ciphertext": ciphertext
};
}
// Usage
ayanmo encrypted = encrypt_message(bob_public_key, "Secret meeting at noon");
Otura.post("https://api.example.com/messages", encrypted);
REST APIs, WebSocket servers, database connections, middleware
// auth_server.ifa - JWT-based authentication
ayanmo Backend = import("@stacks/backend");
ayanmo router = Backend.router();
ayanmo JWT_SECRET = Ogbe.env("JWT_SECRET");
// POST /auth/login
router.post("/auth/login", (req, res) => {
ayanmo body = req.json();
ayanmo user = db_find_user(body["email"]);
ti (user == nil) {
res.status(401).json({"error": "Invalid credentials"});
padap?;
}
ti (!Irete.verify_password(body["password"], user["password_hash"])) {
res.status(401).json({"error": "Invalid credentials"});
padap?;
}
// Generate JWT
ayanmo token = Backend.jwt_sign({
"sub": user["id"],
"email": user["email"],
"exp": Iwori.now() + 86400 // 24 hours
}, JWT_SECRET);
res.json({"token": token, "user": {"id": user["id"], "email": user["email"]}});
});
// Middleware: verify JWT
ise auth_middleware(req, res, next) {
ayanmo auth = req.header("Authorization");
ti (auth == nil || !Ika.starts_with(auth, "Bearer ")) {
res.status(401).json({"error": "Missing token"});
padap?;
}
ayanmo token = Ika.substring(auth, 7, Ika.len(auth));
ayanmo payload = Backend.jwt_verify(token, JWT_SECRET);
ti (payload == nil) {
res.status(401).json({"error": "Invalid token"});
padap?;
}
req.user = payload;
next();
}
Backend.serve(router, 3000);
HTML generation, component rendering, static site building
// ssg.ifa - Static site generator
ayanmo Frontend = import("@stacks/frontend");
ise build_blog() {
ayanmo posts = [];
ayanmo files = Odi.list("content/posts");
// Parse markdown posts
fun file ninu files {
ti (Ika.ends_with(file, ".md")) {
ayanmo content = Odi.read("content/posts/" + file);
ayanmo post = Frontend.parse_markdown(content);
ayanmo posts = Ogunda.push(posts, post);
}
}
// Sort by date
ayanmo posts = Osa.sort_by(posts, |p| p["date"]);
// Generate index page
ayanmo index_html = Frontend.render("templates/index.html", {
"title": "My Blog",
"posts": posts
});
Odi.write("dist/index.html", index_html);
// Generate individual post pages
fun post ninu posts {
ayanmo html = Frontend.render("templates/post.html", post);
Odi.write("dist/posts/" + post["slug"] + ".html", html);
}
Irosu.fo("? Built " + Ogunda.len(posts) + " posts");
}
build_blog();
2D/3D rendering, sprites, collision, input handling, game loops
// platformer.ifa - Simple 2D game
ayanmo Game = import("@stacks/gamedev");
ayanmo player = {
"x": 100, "y": 300,
"vx": 0, "vy": 0,
"on_ground": iro
};
ayanmo GRAVITY = 0.5;
ayanmo JUMP_FORCE = -12;
ayanmo SPEED = 5;
ise update() {
// Input handling
ti (Game.key_down("ArrowLeft")) {
player["vx"] = -SPEED;
} bib?k? ti (Game.key_down("ArrowRight")) {
player["vx"] = SPEED;
} bib?k? {
player["vx"] = 0;
}
ti (Game.key_pressed("Space") && player["on_ground"]) {
player["vy"] = JUMP_FORCE;
player["on_ground"] = iro;
}
// Physics
player["vy"] = player["vy"] + GRAVITY;
player["x"] = player["x"] + player["vx"];
player["y"] = player["y"] + player["vy"];
// Ground collision
ti (player["y"] >= 400) {
player["y"] = 400;
player["vy"] = 0;
player["on_ground"] = otito;
}
}
ise draw() {
Game.clear("#87CEEB"); // Sky blue
Game.rect(0, 420, 800, 80, "#228B22"); // Ground
Game.rect(player["x"], player["y"], 32, 48, "#FF6347"); // Player
}
Game.run(800, 600, "Platformer", update, draw);
Neural networks, training, inference, data preprocessing
// sentiment.ifa - Text sentiment classifier
ayanmo ML = import("@stacks/ml");
// Load pre-trained model
ayanmo model = ML.load_model("models/sentiment.onnx");
ise analyze_sentiment(text) {
// Tokenize and embed
ayanmo tokens = ML.tokenize(text);
ayanmo embeddings = ML.embed(tokens);
// Run inference
ayanmo output = model.predict(embeddings);
// Interpret output
ayanmo positive = output[0];
ayanmo negative = output[1];
ti (positive > negative) {
padap? {"sentiment": "positive", "confidence": positive};
} bib?k? {
padap? {"sentiment": "negative", "confidence": negative};
}
}
// Usage
ayanmo reviews = [
"This product is amazing!",
"Terrible experience, never again.",
"It's okay, nothing special."
];
fun review ninu reviews {
ayanmo result = analyze_sentiment(review);
Irosu.fo(review);
Irosu.fo(" ? " + result["sentiment"] + " (" + result["confidence"] + ")\n");
}
Sensor reading, GPIO control, MQTT messaging, device management
// temp_monitor.ifa - IoT temperature sensor
ayanmo IoT = import("@stacks/iot");
ayanmo SENSOR_PIN = 4;
ayanmo ALERT_THRESHOLD = 30.0;
ise read_temperature() {
ayanmo raw = IoT.analog_read(SENSOR_PIN);
// Convert ADC value to Celsius
ayanmo voltage = (raw / 1024.0) * 3.3;
ayanmo celsius = (voltage - 0.5) * 100.0;
padap? celsius;
}
ise send_alert(temp) {
ayanmo message = {
"device_id": IoT.device_id(),
"temperature": temp,
"timestamp": Iwori.now(),
"alert": "HIGH_TEMP"
};
IoT.mqtt_publish("sensors/alerts", Ogbe.format_json(message));
}
// Main monitoring loop
Irosu.fo("Starting temperature monitor...");
nigba (otito) {
ayanmo temp = read_temperature();
Irosu.fo("Temperature: " + temp + "°C");
ti (temp > ALERT_THRESHOLD) {
send_alert(temp);
IoT.led_on(13); // Warning LED
} bib?k? {
IoT.led_off(13);
}
Oyeku.sleep(5000); // Read every 5 seconds
}
Full-stack apps combining Backend + Frontend + ML
// fusion_app.ifa - Full-stack image classifier
ayanmo Fusion = import("@stacks/fusion");
// ML model for image classification
ayanmo classifier = Fusion.ml.load_model("models/imagenet.onnx");
// API endpoint
Fusion.api.post("/classify", (req, res) => {
ayanmo image = req.file("image");
// Preprocess image
ayanmo tensor = Fusion.ml.image_to_tensor(image, 224, 224);
// Run classification
ayanmo predictions = classifier.predict(tensor);
ayanmo top5 = Fusion.ml.top_k(predictions, 5);
res.json({"predictions": top5});
});
// Static files for web UI
Fusion.static("/", "public/");
// Start server
Fusion.serve(8080);