Technical Documentation - TRusTY
Version: 0.8.2-SNAPSHOT Last Updated: 2025-12-01 Architecture: Domain-Driven Design (DDD) + Clean Architecture
TRusTY is an OpenID Connect (OIDC) provider implementing FAPI 2.0 security standards, built with Rust and Python.
Table of Contents
- Architecture Overview
- Server - Rust (Port 8081)
- Client - Python Flask (Port 5001/5002)
- Technology Stack
- Database & Persistence
- Security Features
- Deployment
Architecture Overview
High-Level Architecture
| |
Design Principles
- Domain-Driven Design (DDD): Clear separation of business logic and infrastructure
- Clean Architecture: Dependencies point inward (Domain ← Application ← Infrastructure ← Presentation)
- SOLID Principles: Single Responsibility, Dependency Inversion, etc.
- Test-Driven Development: Comprehensive unit and integration tests
Server - Rust (Port 8081)
Project Structure
| |
Domain Layer
Entities (Aggregate Roots):
User- User accounts with credentialsClient- OIDC clients (apps requesting authentication)Session- User sessionsAuthorizationCode- Short-lived codes for token exchangeAuthorizationSession- Authorization request tracking
Value Objects:
Claims- JWT claimsScope- Authorization scopesUserId,ClientId,SessionId- Typed IDs
Domain Services:
PasswordService- Password hashing/verification (bcrypt)DpopService- DPoP token binding logic
Application Layer
Services (orchestrate use cases):
TokenService- Token generation/validationUserService- User claims creationAuthorizationCodeService- Auth code lifecycleSessionService- Session management
Infrastructure Layer
Repositories (data access):
- SQLite implementations (
sqlxcrate) - In-memory implementations (for testing)
- Factory pattern for backend selection (config-driven)
Services (technical implementations):
JwtService- JWT sign/verify (RS256)JwksService- Public key managementDpopValidator- DPoP proof validation (RFC 9449)ParService- PAR request storage (in-memory, 90s TTL)I18nService- Internationalization (Fluent.rs)AuditService- Audit logging to SQLite
Presentation Layer
Handlers (HTTP endpoints):
- RESTful API endpoints
- Form handling (login, logout)
- Error responses (JSON/HTML)
Client - Python Flask (Port 5001/5002)
Demo Client Types
Standard OIDC Client (app.py - Port 5001):
- Authorization Code Flow
- PKCE (S256)
- client_secret_post authentication
- Session-based state management
FAPI 2.0 Client (fapi_client.py - Port 5002):
- PAR (Pushed Authorization Request)
- PKCE (S256 - mandatory)
- private_key_jwt authentication
- DPoP token binding
- Ephemeral DPoP keys per session
Client Structure
| |
Python Dependencies
| |
Technology Stack
Server (Rust)
| Component | Technology | Version | Purpose |
|---|---|---|---|
| Web Framework | Axum | 0.8 | Async HTTP server |
| Runtime | Tokio | 1.0 | Async runtime |
| Database | SQLite | - | Embedded database |
| ORM | sqlx | 0.8 | Async SQL toolkit |
| JWT | jsonwebtoken | 9.0 | JWT sign/verify |
| Crypto | rsa, rand | 0.9 | RSA keys, random |
| Password | bcrypt | 0.15 | Secure hashing |
| Serialization | serde, serde_json | 1.0 | JSON/YAML parsing |
| Templates | handlebars | 4.0 | HTML rendering |
| i18n | fluent-templates | 0.11 | Translations |
| Logging | tracing | 0.1 | Structured logging |
| Telemetry | OpenTelemetry | 0.24 | Distributed tracing |
| Sessions | tower-sessions | 0.12 | Session management |
| Config | serde_yaml | 0.9 | YAML configuration |
Client (Python)
| Component | Technology | Purpose |
|---|---|---|
| Web Framework | Flask | HTTP server |
| HTTP Client | requests, Authlib | OIDC client |
| JWT | PyJWT | Token parsing |
| Crypto | cryptography | RSA keys, DPoP |
| i18n | Flask-Babel | Translations |
| Sessions | Flask-Session | Session storage |
Database & Persistence
SQLite Schema
Tables:
users- User accounts (id UUID, username, email, password_hash, created_at)clients- OIDC clients (id, client_secret, redirect_uris, jwks, auth_method, etc.)sessions- User sessions (id UUID, user_id FK, created_at, expires_at, is_active)authorization_codes- Auth codes (code, user_id FK, client_id FK, redirect_uri, scope, code_challenge, created_at, expires_at, used)par_requests- PAR requests (request_uri, client_id, params JSON, created_at, expires_at)audit_log- Audit events (event_type, user_id, client_id, ip_address, user_agent, details JSON, timestamp)revoked_tokens- Revoked token JTIs (jti, token_type, revoked_at, expires_at)
Migration System
- SQL migration files in
server/migrations/ - Applied on server startup (idempotent)
- Version tracking in
_migrationstable (future)
Backend Selection
Configurable via config.yaml:
| |
Repository factory pattern allows easy addition of PostgreSQL, MySQL, etc.
Security Features
Implemented Standards
| Feature | Specification | Status |
|---|---|---|
| OIDC Core 1.0 | OpenID Connect Core | ✅ Implemented |
| PKCE (S256) | RFC 7636 | ✅ Mandatory |
| PAR | RFC 9126 | ✅ Implemented |
| private_key_jwt | RFC 7523 | ✅ Implemented |
| DPoP | RFC 9449 | ✅ Implemented |
| FAPI 2.0 | FAPI 2.0 Security Profile | ✅ Implemented |
| RP-Initiated Logout | OIDC RP-Initiated Logout 1.0 | ✅ Implemented |
| Token Revocation | RFC 7009 | ✅ Implemented |
| Token Introspection | RFC 7662 | ✅ Implemented |
Security Mechanisms
Authentication:
- bcrypt password hashing (cost 12)
- Asymmetric client authentication (RS256 JWT)
- Session-based authentication for UI
Token Security:
- RS256 signature (2048-bit keys)
- Short-lived tokens (access: 1h, auth code: 90s)
- Token binding with DPoP (jkt validation)
- Token revocation tracking
Request Security:
- PKCE (S256 only, plain rejected)
- State parameter (CSRF protection)
- Nonce (replay protection)
- PAR (parameter tampering protection)
- Signed JWT request objects
Audit:
- All authentication attempts logged
- Token operations tracked
- IP address + User-Agent captured
Deployment
Docker Support
Dockerfile (Rust server):
| |
docker-compose.yml:
| |
Railway Deployment
CI/CD with GitHub Actions:
mainbranch → Production environmentdevbranch → Development environment- PR → Tests only (no deployment)
Environment Variables:
BUILD_VERSION- Git tag or SNAPSHOT-{timestamp}RUST_LOG- Log levelDATABASE_PATH- SQLite file pathISSUER_URL- OIDC issuer URL
File Structure (FHS-compliant)
| |
Configuration
Server Config (server/config.yaml)
| |
Client Config (client/.env)
| |
Development
Prerequisites
Server:
- Rust 1.83+
- SQLite3
- OpenSSL
Client:
- Python 3.11+
- pip
Setup
| |
Testing
| |
API Endpoints
See OIDC Flow Documentation for detailed endpoint documentation.
Quick Reference:
GET /.well-known/openid-configuration- OIDC DiscoveryGET /.well-known/jwks.json- Public keys (JWKS)GET /auth- Authorization endpointPOST /token- Token endpointGET /userinfo- UserInfo endpointPOST /par- Pushed Authorization RequestPOST /revoke- Token revocationPOST /introspect- Token introspectionGET /logout- RP-Initiated LogoutGET /health- Health check
Monitoring & Observability
Logging
- Structured logging with
tracing - JSON format for production
- File rotation (daily logs)
- Log levels: TRACE, DEBUG, INFO, WARN, ERROR
Metrics (Observability Endpoints)
GET /observability/sessions- Active sessions countGET /observability/tokens- Token statisticsGET /observability/clients- Client info
OpenTelemetry (Future)
- Distributed tracing support
- OTLP exporter configuration
- Jaeger/Zipkin integration ready
References
Document Version: 2.0 Status: Production-ready Last Review: 2025-12-01