The wiki project is a full-stack prototype written in Rust and TypeScript-free static assets. It exposes a small authentication API using axum, serves Markdown-based documentation with privilege gates, and falls back to a static portfolio-style frontend. Authentication relies on JWTs signed with a local secret key and user accounts backed by SQLite.
- Authentication API:
src/user/mod.rsprovides/api/loginand/api/registerendpoints that hash-free store credentials, mint JWTs, and expose privilege levels in responses. - SQLite worker:
src/db/mod.rsimplements an asynchronous façade aroundrusqlite, spawning a blocking task to serialize SQL work and support test hooks for privilege verification. - Privileged docs:
src/docs/mod.rswraps Markdown files beneathdocs/so sections prefixed with!<level>only render for JWTs with sufficient privileges. An?editquery renders a simple editing form. - Static frontend:
frontend/hosts a portfolio shell with dropdown navigation, theme toggles, and a login form (frontend/login/) that consumes the API and stores JWTs inlocalStorage.
src/main.rs: Binds routes, nestsServeDocs, and servesfrontend/viatower_http::services::ServeDir.src/lib.rs: Exposes module wiring, lazy-initializes the global SQLite-backedDB, and embeds the signingSECRET_KEY.src/db/: Houses the database dispatcher andtestingutilities such asVerificationProbeandbackdate_privileges().src/docs/: Contains the Markdown renderer, HTML template, and client helpers likepull_jwt_or_forward_to_login.jsfor gated views.frontend/: Static HTML/CSS/JS assets for the landing page and login flow.docs/: Markdown content rendered byServeDocs;docs/plans/includes project planning notes.tests/: Async integration tests for the database module, JWT helpers, and docs renderer.next_steps.md: Running backlog of enhancement ideas and testing goals.
- Rust toolchain: Install Rust 1.79+ (edition 2024) via rustup.
- SQLite: Bundled
rusqliteuses the system library; most Linux distributions include it by default. - Secret key: Provide a binary file at
secret_key(for example, 32 random bytes) so JWT encoding/decoding works. This file is ignored by Git; generate it withopenssl rand -out secret_key 32or an equivalent tool.
- Install dependencies:
cargo fetchdownloads the Rust crates specified inCargo.toml. - Create
secret_key: Place the secret file at the repository root before running the app or tests. - Prepare docs (optional): Add Markdown pages under
docs/. Use lines like!2to gate sections to privilege level ≥2.
- Start the server:
cargo runlaunches the Axum application onhttp://127.0.0.1:3000. - Static frontend: Visit
/for the portfolio shell. The login page lives at/login/and writes JWTs tolocalStorage. - Docs browser: Navigate to
/docs/<page>(for example,/docs/apples). Supply anAuthorization: Bearer <token>header or visit without a token to trigger the redirect helper. Append?editto load the simple editor form. - Shutdown: Type
exitorquiton stdin to trigger graceful shutdown; the server also closes the database channel on exit.
- Cargo tests: Run
cargo testto execute async database tests, JWT helpers, and Markdown privilege enforcement. Tests create temporary SQLite files and may callDatabase::close()to cleanly stop the worker. - Manual verification: Use the login form to register a user, then access docs requiring elevated privileges to observe gated sections becoming visible.
- Database schema: The
userstable lives indb.sqliteduring development and is created on first run. Remove the file to reset state. - Privilege verification hooks: The
VerificationProbeinsrc/db/mod.rslets tests assert that stale privilege records invoke the (stubbed) Patreon verification call. - Future work: See
next_steps.mdfor planned coverage improvements, doc serving refinements, and HTTP handler integration tests.
This codebase is an early-stage sandbox. Credentials are stored as plaintext, and the OAuth verification flow is stubbed. Treat it as a learning project, not production-ready software.