This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Rust workspace for tracking personal life and faith statistics from multiple data sources. It includes:
- Bible memorization tracking from Anki
- Bible reading time from KOReader
- Prayer time tracking (future)
- A web API and frontend for viewing combined statistics
The project uses a three-tier architecture: data source crates → aggregation layer → presentation layer (API/CLI/frontend).
This repository uses Cargo workspace with the following crates:
- ankistats: Anki Bible verse memorization statistics (library + CLI)
- readingstats: KOReader Bible reading time statistics (library + CLI)
- prayerstats: Prayer time tracking (library + CLI, not yet implemented)
- statsutils: Shared date/time utilities used by all stats crates
- faithstats: Combines data from multiple sources into unified statistics (library + CLI)
- backend: Axum REST API server exposing all statistics as JSON endpoints
- frontend: SvelteKit web application for viewing statistics (separate from Rust workspace)
# Build the entire workspace
cargo build
# Build specific package
cargo build -p ankistats
cargo build -p faithstats
cargo build -p backend
# Run tests
cargo test
# Run tests for specific package
cargo test -p ankistats
# Check code without building
cargo check
# Run clippy linter
cargo clippy --all-targets --all-features
# Format code
cargo fmtEach stats crate provides its own CLI. See individual CLAUDE.md files for details.
# Ankistats CLI (individual Anki stats)
cargo run -p ankistats -- books /path/to/collection.anki2
cargo run -p ankistats -- today /path/to/collection.anki2
cargo run -p ankistats -- daily /path/to/collection.anki2
cargo run -p ankistats -- weekly /path/to/collection.anki2
# Readingstats CLI (individual reading stats)
cargo run -p readingstats -- daily /path/to/statistics.sqlite3
# Faithstats CLI (combined stats from all sources)
# Requires .env file with ANKI_DATABASE_PATH and KOREADER_DATABASE_PATH
cargo run -p faithstats -- daily# Create .env file with required environment variables
cp .env.example .env
# Edit .env with your database paths and API key
# Run the server
cargo run -p backendThe server starts on http://0.0.0.0:3000 with Swagger UI at http://localhost:3000/swagger-ui/
The top-level Makefile provides shortcuts when you have a collection.anki2 file in the ankistats directory:
make build # Build ankistats
make test # Generate test data and run tests
make books # Run ankistats books command
make today # Run ankistats today command
make daily # Run faithstats daily command (combined stats)
make weekly # Run ankistats weekly command
make backend # Run backend with test credentialscd frontend
# Install dependencies
npm ci
# Start development server
npm run dev
# Type checking
npm run check # Run once
npm run check:watch # Watch mode
# Code quality
npm run lint # Check formatting and linting
npm run format # Auto-format with Prettier
# Build for production
npm run build
npm run preview # Preview production build
# Generate API client types from backend OpenAPI spec
npm run generate-api:local # From local backend (http://localhost:3000)
npm run generate-api:prod # From production backendThe repository includes GitHub Actions workflows that run on push and pull requests:
# Rust checks (format, lint, build, test)
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo build --verbose
cargo test --verbose
# Frontend checks (format, lint, type-check)
cd frontend
npm run format:check
npx eslint .
npm run checkThe project is structured in three layers:
-
Data Source Crates (ankistats, readingstats, prayerstats)
- Each crate provides a library API and CLI for a specific data source
- Libraries expose functions like
get_last_30_days_stats(db_path)that return structured data - CLIs format and display the data as tables
- No dependencies on web frameworks or other stats crates
-
Aggregation Layer (faithstats)
- Combines data from multiple sources into unified statistics
- Merges by date, using zero values when data is missing for a particular day
- Provides both library API and CLI
- Depends on all data source crates
-
Presentation Layer (backend, frontend)
- backend: Axum REST API that wraps library functions in HTTP endpoints with authentication
- frontend: SvelteKit application that consumes the API and displays interactive charts
- Backend uses
.envfile for configuration (database paths, API key) - Frontend generates TypeScript types from backend's OpenAPI spec
For combined faith statistics:
- Frontend makes authenticated request to
GET /api/faith/daily - Backend calls
faithstats::get_faith_daily_stats(anki_path, koreader_path) - Faithstats calls
ankistats::get_last_30_days_stats()andreadingstats::get_last_30_days_stats() - Each stats crate queries its respective SQLite database
- Faithstats merges the results by date
- Backend serializes to JSON and returns to frontend
- Frontend renders charts using the unified data
The backend exposes these endpoints (see backend/src/main.rs for details):
Public (no auth):
GET /health- Health checkGET /swagger-ui/- Interactive API documentationGET /openapi.json- OpenAPI specification
Authenticated (Bearer token required):
GET /api/anki/books- Bible book statisticsGET /api/anki/today- Today's Anki study timeGET /api/anki/daily- Last 30 days Anki study timeGET /api/anki/weekly- Last 12 weeks Anki study timeGET /api/faith/daily- Combined daily stats from all sources (Anki + reading)
Authentication uses Bearer token that must match the API_KEY environment variable.
These components require environment variables. Create a .env file in the workspace root (see .env.example):
- ANKI_DATABASE_PATH (required): Path to Anki collection.anki2 database file
- KOREADER_DATABASE_PATH (required): Path to KOReader statistics.sqlite3 database file
- API_KEY (required, backend only): Secret key for API authentication
The individual crate CLIs (ankistats, readingstats) do not use environment variables. Database paths are passed as command-line arguments:
cargo run -p ankistats -- daily /path/to/collection.anki2
cargo run -p readingstats -- daily /path/to/statistics.sqlite3The project includes Dockerfiles for containerized deployment of both backend and frontend.
The root Dockerfile builds the Rust backend API. When deploying:
- Set the required environment variables (
ANKI_DATABASE_PATH,KOREADER_DATABASE_PATH,API_KEY) - Mount volumes containing the database files
- Expose port 3000 for the backend API
docker build -t lifestats-backend -f Dockerfile .
docker run -p 3000:3000 --env-file .env lifestats-backendThe frontend/Dockerfile builds the SvelteKit frontend as a Node.js application. The frontend runs on port 3000:
cd frontend
docker build -t lifestats-frontend .
docker run -p 3000:3000 lifestats-frontendThe frontend is configured for Node.js deployment via @sveltejs/adapter-node.
Each crate has its own CLAUDE.md file with detailed implementation information:
- ankistats/CLAUDE.md - Anki database schema, custom SQLite functions, verse parsing
- faithstats/CLAUDE.md - Data merging algorithm, aggregation logic
- backend/CLAUDE.md - Authentication middleware, OpenAPI documentation
- frontend/CLAUDE.md - SvelteKit configuration, Svelte 5 runes syntax, Tailwind CSS v4