This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Hilo is a Rust-based social pairing backend for Project Contigo that matches university students based on interests and preferences. It uses email verification with university domains, collects user forms (like questionnaires), and provides a matching algorithm to pair compatible users.
- Framework: Axum web framework with tokio async runtime
- Database: PostgreSQL with SQLx for compile-time checked queries
- Authentication: JWT tokens with refresh token support
- Email: Configurable email service (ExternalEmailer for production, LogEmailer for development)
- File Storage: Local filesystem for user-uploaded images
- Matching System: Background service with configurable scoring algorithm
AppState: Shared application state containing all services and configurationTagSystem: Hierarchical tag structure loaded fromtags.jsonwith O(1) lookup mapsMatchingService: Background service for generating match previews and final matchingJwtService: JWT token generation and validation- Email services with trait-based abstraction
- Build:
cargo build(debug profile only) - Test all:
cargo test - Test single:
cargo test --test test_name - Migrations:
sqlx migrate run - SQLx offline prepare:
cargo sqlx prepare -- --all-targets - Start postgres:
podman-compose -f podman-compose.dev.yml up --detach db - Reset postgres:
podman-compose -f podman-compose.dev.yml down -v
Required environment variables are documented in .env. Key variables:
DATABASE_URL: PostgreSQL connection stringADDRESS: Server bind addressJWT_SECRET: JWT signing secretEMAIL_PROVIDER: "external" or "log"ALLOWED_DOMAINS: Colon-separated list of allowed university email domains- Matching system parameters
- All integration tests use
#[sqlx::test]macro for automatic test database setup - Test utilities in
tests/common/mod.rsprovidespawn_app()andMockEmailer - Tests spawn server at random port, use reqwest client for API testing
- Valid test emails must use domains from
ALLOWED_DOMAINS(e.g.,mails.tsinghua.edu.cn) - Tests use special env and json files under
tests/data/
- Import order: std library, external crates, local modules
- Use
tracingfor telemetry (not println or log) - Constants in
utils/constant.rs, major config in.env - Custom errors use
thiserror - Database queries use sqlx macros for compile-time checking
- Global objects use
AppStateorstd::sync::LazyLock - It's cheap to clone
PgPoolsince it internally holds an Arc, but do not clone heavy objects
users: User accounts with verification status flow (unverified→verification_pending→verified)forms: User questionnaire responses with tag selectionsrefresh_tokens: JWT refresh token storagematch_previews: Pre-computed match suggestionsfinal_matches: Admin-triggered final matching results
src/handlers/: HTTP endpoint handlers grouped by functionalitysrc/services/: Business logic (email, JWT, matching algorithm)src/models/: Data structures and database modelssrc/middleware.rs: Authentication middlewaresrc/utils/: Constants, validators, upload utilitiesmigrations/: SQLx database migrationstests/: Integration tests with common test utilities