Creating a full-stack web application using Svelte (frontend) , Rust (backend) , and ArcadeDB (database) is a great way to demonstrate modern web development using a performant and cutting-edge stack. In this walkthrough, I will demonstrate how a user's request flows from the frontend to the backend, reaches the database, and returns the results back to the Svelte UI — with best practices and teaching in mind.
💡 Tech Stack Summary
📦 Frontend : SvelteKit
🦀 Backend : Rust + Axum (async framework)
🛢️ Database : ArcadeDB (Multi-model DB with REST/SQL API)
🔐 Communication : REST API using JSON
📄 Concept : A User can be created and fetched
🌀 Flow Overview
code Copy code
[SvelteKit UI] → calls → [Rust Backend API] → connects to → [ArcadeDB] → returns → [Rust API Response] → sent to → [SvelteKit UI]
✅ Use Case: Create and Fetch a User
Let’s implement a simple functionality: Create a new user and fetch all users .
📁 1. Folder/File Structure
code Copy code
/my-fullstack-app
├─ /frontend # SvelteKit app
├─ /backend # Rust backend using Axum
├─ /arcadedb # ArcadeDB data and config
🖼️ Frontend (/frontend)
🧱 src/routes/+page.svelte
svelte Copy code
<script lang="ts">
let name = '';
let users = [];
async function createUser() {
const res = await fetch('http://localhost:3000/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name })
});
if (res.ok) {
name = '';
await fetchUsers();
}
}
async function fetchUsers() {
const res = await fetch('http://localhost:3000/api/users');
users = await res.json();
}
onMount(fetchUsers);
</script>
<h1>Users</h1>
<input bind:value={name} placeholder="Enter user name" />
<button on:click={createUser}>Create</button>
<ul>
{#each users as user}
<li>{user.name} (ID: {user.id})</li>
{/each}
</ul>
SvelteKit uses reactive variables and simple fetch API calls to interact with the Rust backend.
🧩 Backend (/backend)
🦀 Dependencies (Cargo.toml)
toml Copy code
[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.11", features = ["json"] }
tower = "0.4"
☁️ main.rs
rust Copy code
use axum::{
routing::{get, post},
Json, Router,
};
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
#[derive(Serialize, Deserialize)]
struct User {
id: String,
name: String,
}
#[derive(Deserialize)]
struct NewUser {
name: String,
}
// Replace these with environment variables in production
const DATABASE_URL: &str = "http://localhost:2480";
const DB_NAME: &str = "mydb";
const DB_USER: &str = "root";
const DB_PASS: &str = "root";
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/api/users", get(get_users).post(create_user));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("Backend running on http://{}", addr);
axum::Server::bind(&addr).serve(app.into_make_service()).await.unwrap();
}
async fn get_users() -> Json<Vec<User>> {
let sql = "SELECT FROM User";
let query_url = format!("{}/api/v1/command/{}sql", DATABASE_URL, DB_NAME);
let client = reqwest::Client::new();
let res = client.post(&query_url)
.basic_auth(DB_USER, Some(DB_PASS))
.json(&serde_json::json!({ "command": sql }))
.send().await.unwrap();
let data: serde_json::Value = res.json().await.unwrap();
let users: Vec<User> = data["result"]
.as_array().unwrap()
.iter()
.map(|u| User {
id: u["@rid"].as_str().unwrap_or("").to_string(),
name: u["name"].as_str().unwrap_or("").to_string()
})
.collect();
Json(users)
}
async fn create_user(Json(payload): Json<NewUser>) -> Json<User> {
let sql = format!("INSERT INTO User SET name = '{}'", payload.name.replace("'", "''"));
let query_url = format!("{}/api/v1/command/{}sql", DATABASE_URL, DB_NAME);
let client = reqwest::Client::new();
let res = client.post(&query_url)
.basic_auth(DB_USER, Some(DB_PASS))
.json(&serde_json::json!({ "command": sql }))
.send().await.unwrap();
let data: serde_json::Value = res.json().await.unwrap();
let user = &data["result"][0];
Json(User {
id: user["@rid"].as_str().unwrap_or("").to_string(),
name: user["name"].as_str().unwrap_or("").to_string()
})
}
This backend exposes /api/users for both POST and GET. We use ArcadeDB's HTTP API (not a native driver for Rust currently) via reqwest.
🗃️ ArcadeDB Setup
Step 1: Run ArcadeDB
bash Copy code
docker run -d --name arcadedb -p 2480:2480 -e ARCADEDB_ROOT_PASSWORD=root arcadedb/arcadedb
Step 2: Access Web UI
Go to http://localhost:2480, login as root/root, and create a database called mydb.
Create a new class User in SQL:
sql Copy code
CREATE CLASS User;
CREATE PROPERTY User.name STRING;
🔄 Request Flow Explanation
📤 From Frontend
Svelte user clicks "Create".
fetch() sends POST to Rust backend at /api/users.
🔃 Backend Process
Axum receives request, deserializes JSON.
Constructs an ArcadeDB SQL string.
Sends HTTP POST to http://localhost:2480/api/v1/command/mydb/sql with creds.
Parses response from ArcadeDB.
📥 Return to Frontend
Rust backend serializes result as JSON.
Svelte receives new user list.
Reactive variable users updates and displays UI.
✅ Best Practices Applied
Security (Dev mode) : Basic HTTP Auth for DB
Escape strings to prevent SQL injection
Environment configs separated (for future .env)
Rust types mirror database schema for safety
Async/Await for efficient backend handling
Modular structuring to expand easily
🚀 Final Thoughts
This example sets you up to:
Expand into Graph traversal — ArcadeDB is multi-model.
Integrate websockets for real-time updates.
Add auth (JWTs, sessions) in Rust middleware.
Want to go further?
Use a custom driver when available.
Move SQL logic to separate service layer.
Deploy Rust backend to serverless (e.g., Fly.io, Render).
Would you like me to generate a GitHub repo with this structure or Dockerize the whole setup next?