M2a: server workspace, kvitt-domain, skeleton routes, OpenAPI match, Dockerfile

Cargo workspace (kvitt-domain, kvitt-server, kvitt-import), Rust 1.99.1 pinned.
kvitt-domain passes every Rust vector and adds next_occurrence_date (D-015).
kvitt-server: config, SQLite pool (WAL, §8.9 pragmas), migration 0001 identical to
the contract schema, error type for all 25 codes, auth extractor and protocol
layer, all 33 routes (E-1/E-2 implemented, the rest 501), utoipa document equal
to contracts/openapi.yaml, seams for M3/M4/M9, serve/migrate/healthcheck.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-17 21:25:35 +02:00
parent c277ee37c2
commit 06f48ef9e9
71 changed files with 9187 additions and 0 deletions
@@ -0,0 +1,63 @@
//! The audit log seam (SPEC §14.4.7). M2a defines the trait and a no-op; M4 owns `src/audit/**` and replaces the
//! implementation with one that computes the field diff and inserts the `audit_log` row.
//!
//! Callers (sync push in M4, recurring generation in E-28 and the scheduler, the importer in M9) call
//! [`AuditWriter::write`] inside their own `BEGIN IMMEDIATE` transaction, passing the wire object before and after
//! the change; the writer derives `changes` per SPEC §14.4.7 and takes the entry's `server_version` from the same
//! transaction.
use std::future::Future;
use std::pin::Pin;
use sqlx::SqliteConnection;
use uuid::Uuid;
use crate::error::AppError;
use crate::wire::{AuditAction, AuditSource, EntityType};
/// A boxed, sendable future (object-safe async trait methods).
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
/// One audit event to record.
#[derive(Debug, Clone, PartialEq)]
pub struct AuditEvent {
pub entity_type: EntityType,
pub entity_id: Uuid,
pub action: AuditAction,
pub source: AuditSource,
pub actor_user_id: Uuid,
/// `None` for the scheduler and the importer.
pub actor_device_id: Option<Uuid>,
/// The pushed `updated_at` (for `delete`, the pushed `deleted_at`); server now for scheduler and importer.
pub client_at: String,
/// Server now.
pub server_at: String,
/// The full wire object (`Expense` or `Settlement` as JSON) before the change; `None` for `create`.
pub before: Option<serde_json::Value>,
/// The full wire object after the change.
pub after: serde_json::Value,
}
/// Writes audit entries.
pub trait AuditWriter: Send + Sync + 'static {
/// Records `event` on `conn`, which is inside the caller's write transaction. Returns the entry's id.
fn write<'a>(
&'a self,
conn: &'a mut SqliteConnection,
event: AuditEvent,
) -> BoxFuture<'a, Result<Uuid, AppError>>;
}
/// Writes nothing. Used until M4 lands its writer.
#[derive(Debug, Clone, Copy, Default)]
pub struct NoopAuditWriter;
impl AuditWriter for NoopAuditWriter {
fn write<'a>(
&'a self,
_conn: &'a mut SqliteConnection,
_event: AuditEvent,
) -> BoxFuture<'a, Result<Uuid, AppError>> {
Box::pin(async { Ok(Uuid::now_v7()) })
}
}