How oxide-byte/rust-berlin-leptos works
Project type and purpose
• This is a full-stack Rust web application that implements the “Rust Hack and Learn” Berlin challenge.
• Frontend: a Leptos (WASM) single-page app styled with Tailwind, compiled and served via Trunk in development, and shipped as static assets in production.
• Backend: an Axum HTTP server (with Tower), exposing a GraphQL API via Juniper, serving both dynamic GraphQL endpoints (query, mutation, subscription) and static assets.
• Database: SurrealDB, accessed from Rust service layers.
File structure
• Top-level:
• client/ – Leptos SPA source code
• server/ – Axum GraphQL server, static file host, business logic
• data/ – sample JSON used by file-import service or tests
• docs/ – auto-generated static build of the SPA (for GitHub Pages)
• docker-compose.yaml – multi-container orchestration (likely SurrealDB + server)
• client/:
• src/component – UI components (app shell, tables, modals, clock, navigation)
• src/graphql – auto-generated GraphQL query/mutation/subscription code
• src/model – typed Rust models mirroring GraphQL types
• Trunk.toml, Tailwind config, index.html – front-end build and asset pipeline
• server/:
• src/config – DB connection, environment
• src/graphql – GraphQL schema/domain, resolvers (query, mutation, subscription)
• src/repository – data access for meetup URLs
• src/service – file import, DB initialization, higher-level business logic
• static/ – production-ready built SPA assets
Key architecture insights from README
• The acronym SALT: SurrealDB, Axum, Leptos, Tailwind + GraphQL
• Dev flow: trunk serve spins up local static server + live-reload frontend; cargo run on server starts GraphQL endpoints + static file server.
• Production flow: trunk build --release → copy client/dist into server/static; Axum serves at /web, GraphiQL at /graphiql, Playground at /playground.
a. Main components
1. Frontend (Leptos SPA)
2. GraphQL API server (Axum + Juniper)
3. SurrealDB (persistent data store)
4. (Optional) Developer tooling: Trunk dev server, GraphiQL/Playground UIs
b. Relationships & data flows
• The browser loads the WASM + HTML/CSS from the static assets endpoint on the Axum server (or Trunk dev server).
• The Leptos app issues GraphQL queries/mutations/subscriptions over HTTP/WS to the Axum server.
• Axum’s GraphQL handlers invoke service layer → repository → SurrealDB.
• For subscriptions, Juniper’s subscription resolver pushes updates over WebSockets to the client.
• File-import service reads data.json and seeds SurrealDB on startup (via init_database).
c. Architectural patterns & design principles
• Layered architecture on the server:
• Config → DB connection
• GraphQL resolvers (schema/domain)
• Service layer (business logic)
• Repository (data access)
• Frontend separation:
• Components (UI)
• GraphQL client code (auto-generated)
• Models (typed data)
• Clear boundary between static asset hosting and dynamic GraphQL API within the same server.
d. Key technologies
• Frontend: Leptos (WASM), Thaw (state hydration), Tailwind CSS, Trunk, GraphQL client
• Backend: Rust, Axum, Tower, Juniper-Axum, SurrealDB driver
• Dev/Test: Trunk live-reload, GraphiQL, Playground