Status: β Phase 3 Complete - Clean Architecture + PRF Implementation (Core Complete, Not Production Ready)
π Phase 3 Milestone Achieved (January 2025):
- β Clean Architecture implementation with Uncle Bob's principles
- β WebAuthn PRF support with HKDF key derivation
- β Universal fallback compatibility for all devices
- β Complete zero-knowledge encryption architecture
- β Core features complete with comprehensive security
- β Modern React frontend with landing pages and animations
- π§ Phase 4 Required for Production: Multi-Device Sync & Production Hardening
2FAir is a zero-knowledge, end-to-end encrypted TOTP (Time-based One-Time Password) vault that puts security and privacy first. Your TOTP secrets are encrypted client-side using WebAuthn-derived keys with PRF (Pseudo-Random Function) support, ensuring the server never sees your plaintext data.
- Domain-Driven Design: Proper separation of concerns with domain, application, infrastructure, and interface layers
- SOLID Principles: Dependency inversion, interface segregation, and clean dependencies
- Package Organization: Domain-specific directories (crypto, totp, webauthn) following Go best practices
- Interface-Based Design: All services implement domain interfaces for testability and maintainability
- No Import Cycles: Clean dependency graph with proper architectural boundaries
- PRF-First Key Derivation: WebAuthn PRF β HKDF-SHA256 β AES-256-GCM key (when available)
- Universal Fallback: credential.id β PBKDF2-SHA256 β AES-256-GCM key (for compatibility)
- End-to-End Encryption: AES-256-GCM with client-side encryption
- WebAuthn Integration: Hardware-backed key derivation from biometric/security keys
- No Server Access: Server never sees plaintext TOTP secrets or codes
- Session-Based Keys: Consistent encryption keys throughout the browser session
- Client-Side Generation: All TOTP codes generated using the
otpauthlibrary - Real-Time Updates: Codes auto-refresh every 30 seconds with progress indicators
- Multi-Algorithm Support: SHA1, SHA256, SHA512 algorithms
- Standard Compatibility: Works with Google Authenticator, Authy, and all TOTP apps
- QR Code Import: Import TOTP secrets via QR code scanning
- React Frontend: TypeScript + HeroUI + TanStack Query + Zustand state management
- Go Backend: Clean architecture + Gin framework + PostgreSQL + SQLC + WebAuthn PRF
- OAuth Authentication: Google OAuth 2.0 integration
- WebAuthn Registration: Complete credential management with PRF support
- Responsive Design: Beautiful UI that works on desktop and mobile browsers
- Clean Architecture: Proper layer separation for security and maintainability
- PRF Extension: WebAuthn Pseudo-Random Function for optimal security
- HKDF Key Derivation: RFC 5869 compliant key derivation from PRF
- Comprehensive Validation: Input validation at all layers
- Security Headers: CORS, CSP, HSTS, and security headers configured
- Authentication Required: All endpoints properly protected with JWT + WebAuthn
- Audit Trail: Comprehensive logging for security events
- Docker & Docker Compose (recommended for quickest setup)
- Go 1.22+ (for local development)
- Node.js 18+ & Yarn (for frontend development)
- PostgreSQL 15+ (for local database)
# Clone repository
git clone <repository-url>
cd 2FAir
# Start all services (frontend, backend, database)
docker-compose -f server/docker-compose.dev.yaml up -d
# Check service health
docker-compose -f server/docker-compose.dev.yaml psServices will be available at:
- Frontend: http://localhost:5173 (React + Vite dev server)
- Backend API: http://localhost:8080 (Go + Gin API)
- Database: localhost:5432 (PostgreSQL)
# Navigate to server directory
cd server
# Install dependencies
go mod download
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration (see server/README.md)
# Start PostgreSQL (via Docker)
make db-up
# Generate SQLC code
make generate
# Run database migrations
go run ./cmd/server -migrate up
# Start backend server
make run
# or: go run cmd/server/main.go# Navigate to client directory
cd client
# Install dependencies
yarn install
# Set up environment variables
cp .env.example .env.local
# Edit .env.local with your backend URL
# Start development server
yarn dev# Test backend health
curl http://localhost:8080/health
# Test frontend
open http://localhost:5173βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client (React) β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β Components β β Hooks β β State Mgmt β β
β β β’ HeroUI β β β’ TanStack β β β’ Zustand β β
β β β’ WebAuthn PRF β β β’ Auth hooks β β β’ OTP state β β
β β β’ TOTP UI β β β’ OTP hooks β β β’ Auth state β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTPS/JSON
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Server (Go - Clean Architecture) β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β interfaces/http/ (Interface Layer) β β
β β β’ Gin Handlers β’ Middleware β’ HTTP Server β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β application/usecases/ (Application Layer) β β
β β β’ Auth Service β’ OTP Service β’ Business Logic β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β domain/ (Domain Layer) β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββββββ β β
β β β entities/ β β interfaces/ β β dto/ β β β
β β β β’ User β β β’ AuthSvc β β β’ Request/Response β β β
β β β β’ OTP β β β’ OTPSvc β β β’ Data Transfer β β β
β β β β’ WebAuthn β β β’ Repos β β β’ Validation β β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β infrastructure/ (Infrastructure Layer) β β
β β βββββββββββ βββββββββββ βββββββββββ βββββββββββββββββββββββ β β
β β β crypto/ β β totp/ β βwebauthn/β β database/ β β β
β β β β’ AES β β β’ TOTP β β β’ PRF β β β’ PostgreSQL β β β
β β β β’ HKDF β β β’ Codes β β β’ Auth β β β’ SQLC Queries β β β
β β βββββββββββ βββββββββββ βββββββββββ β β’ Repositories β β β
β β β β’ Migrations β β β
β β βββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β PostgreSQL β
β β’ Encrypted β
β TOTP Secrets β
β β’ User Data β
β β’ Credentials β
βββββββββββββββββββ
- Testability: All dependencies injected via interfaces
- Maintainability: Clear separation of concerns
- Scalability: Easy to add new features without coupling
- Security: Domain layer enforces business rules
- Flexibility: Easy to swap implementations (database, crypto, etc.)
1. User Authentication
OAuth (Google) β JWT Token β User Session
2. WebAuthn Setup
User registers biometric/security key β PRF Extension Detection
3. Enhanced Key Derivation (PRF-First)
ββ PRF Available? ββ
β β
βΌ YES βΌ NO
PRF β HKDF credential.id β PBKDF2
β β
ββ AES-256-GCM βββββ
4. Client-Side Encryption
TOTP Secret β AES Encrypt β "ciphertext.iv.authTag"
5. Secure Storage
Server stores encrypted data only (never plaintext)
6. Client-Side TOTP Generation
Decrypt secret β Generate codes with otpauth library
- Zero-Knowledge: Server cannot decrypt user data under any circumstances
- PRF Security: Hardware-backed key derivation when available
- Universal Compatibility: Works with all WebAuthn devices
- Perfect Forward Secrecy: Session keys not stored persistently
- Tamper Detection: GCM authentication prevents data modification
- Audit Trail: All security events logged
- React 18 with TypeScript for type safety
- HeroUI for beautiful, accessible UI components
- TanStack Query for server state management and caching
- Zustand for client-side state management
- OTPAuth for industry-standard TOTP code generation
- WebAuthn API with PRF extension support
- Vite for fast development and optimized builds
- Go 1.22+ with clean architecture principles
- Gin web framework with comprehensive middleware
- PostgreSQL 15+ with SQLC for type-safe database operations
- WebAuthn PRF for enhanced hardware-backed security
- OAuth 2.0 (Google) for user authentication
- JWT for secure session management
- HKDF (RFC 5869) for cryptographic key derivation
- AES-256-GCM for authenticated encryption
- Docker and Docker Compose for development and deployment
- PostgreSQL for secure data persistence
- Gin middleware for CORS, security headers, logging
- SQLC for compile-time SQL validation
- Goose for database migrations
- Clean Architecture: Domain-driven design with proper layer separation
- OAuth Authentication: Google OAuth 2.0 with JWT session management
- WebAuthn PRF: Enhanced hardware-backed key derivation
- Fallback Compatibility: Universal support for all WebAuthn devices
- Zero-Knowledge E2E Encryption: Client-side AES-256-GCM encryption
- TOTP Management: Full CRUD operations with secure storage
- Real-Time TOTP Generation: Client-side code generation with progress indicators
- Beautiful Frontend: Modern React SPA with HeroUI components
- Database Layer: PostgreSQL with SQLC type-safe queries
- RESTful API: Comprehensive API with error handling and validation
- Security: Multiple layers of protection with audit logging
- Development Tools: Complete development workflow with Docker
- Single OAuth Provider: Only Google OAuth implemented
- Browser-Only: No mobile app or browser extension
- No Multi-Device Sync: Single device limitation (Phase 4 requirement)
- No Backup/Recovery: Manual backup not yet implemented (Phase 4 requirement)
- Development Security: Not hardened for production deployment
- No Rate Limiting: Production-grade rate limiting not implemented
- No Monitoring: Production monitoring and alerting not configured
- Multi-Device Synchronization: Encrypted sync across devices with PRF support
- Backup & Recovery: Secure backup codes and recovery mechanisms
- Security Audit: Comprehensive penetration testing and hardening
- Performance Optimization: Caching, rate limiting, optimization
- Production Monitoring: Health checks, alerting, and observability
- Production Deployment: Production-ready configurations and automation
- Server README - Backend implementation details
- Implementation Roadmap - Phase-by-phase development
- API Documentation - Complete API reference
- Deployment Guide - Production deployment instructions
- System Architecture - Clean architecture deep dive
- Cryptographic Design - PRF and encryption details
- Database Schema - Database design and relationships
- API Design - RESTful API design principles
- Features Overview - Complete feature list and status
- Documentation Updates - Change log
# 1. Start database
cd server && make db-up
# 2. Start backend (Terminal 1)
make run
# 3. Start frontend (Terminal 2)
cd ../client && yarn dev
# Access application
# Frontend: http://localhost:5173
# Backend API: http://localhost:8080
# Health Check: http://localhost:8080/healthmake help # Show all available commands
make build # Build the application
make run # Run the application
make test # Run all tests
make test-cover # Run tests with coverage
make generate # Generate SQLC code
make db-up # Start database services
make db-down # Stop database services
make lint # Run linter
make fmt # Format codeyarn dev # Start development server
yarn build # Build for production
yarn test # Run tests
yarn lint # Run ESLint
yarn type-check # TypeScript type checkingcd server
# Run all tests
make test
# Run tests with coverage
make test-cover
# Run specific test packages
go test ./internal/application/usecases/...
go test ./internal/infrastructure/crypto/...cd client
# Run all tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test:coverageUse Docker Compose for the complete development environment:
cd server
make docker-runSee Deployment Guide for production setup including:
- Docker production configurations
- Environment variable security
- Nginx reverse proxy setup
- SSL/TLS certificate configuration
- Database backup and monitoring strategies
We welcome contributions! Please follow these guidelines:
- Clean Architecture: Follow the established layer patterns
- Go Code: Use
gofmt,golint, and follow Go best practices - TypeScript: Strict type checking and ESLint compliance
- Testing: Write tests for new functionality
- Documentation: Update docs for new features
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Ensure all tests pass (
make testin both server/ and client/) - Update documentation as needed
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- WebAuthn Community for passwordless authentication standards and PRF extension
- OTPAuth Library for robust client-side TOTP implementation
- HeroUI Team for beautiful and accessible React components
- Go Community for excellent tooling, libraries, and clean architecture patterns
- Clean Architecture principles by Robert C. Martin (Uncle Bob)
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: For security issues, please email security@yourdomain.com
2FAir implements a true zero-knowledge architecture with clean architecture principles:
- Clean Layer Separation: Domain β Application β Infrastructure β Interface layers
- User Authentication: OAuth 2.0 creates secure user sessions
- WebAuthn Setup: Hardware security key registration with PRF detection
- Enhanced Key Derivation: PRF β HKDF β AES key (preferred) or credential.id β PBKDF2 (fallback)
- Client-Side Encryption: TOTP secrets encrypted with AES-256-GCM before transmission
- Secure Storage: Server stores only encrypted
ciphertext.iv.authTagdata - Code Generation: Client decrypts secrets and generates TOTP codes using
otpauth - Session Management: Encryption keys cached in memory for seamless UX
The server never sees your TOTP secrets or codes in plaintext, with best-in-class security when your device supports PRF, all built on a maintainable clean architecture foundation!
Phase 3 Complete β
- Clean Architecture + PRF Implementation
Phase 4 Required π§ - Multi-Device Sync & Production Hardening for Production Readiness