# Phomnemic A phonemic encoding/decoding system with dictionary management and REST API. ## Configure and Run ### Prerequisites - Rust 1.70 or later - SQLite (for local database) - Firebase Auth (optional, for JWT authentication) ### Installation ```bash cargo build --release ``` ### Configuration Create a `config.toml` file in the project root: ```toml [listen] host = "0.0.0.0" port = 3000 log_level = "info" [auth] firebase_project_id = "your-firebase-project-id" firebase_emulator_url = "http://localhost:9099" api_tokens = ["your-api-key-1", "your-api-key-2"] [database] url = "sqlite:app.db" ``` #### Authentication Options The application supports two authentication methods: 1. **Firebase JWT Authentication** (for frontend clients) - Set `firebase_project_id` to your Firebase project ID - Or use `firebase_emulator_url` for local development with Firebase Auth Emulator 2. **API Key Authentication** (for server-to-server or CLI access) - Add valid API keys to the `api_tokens` array - Send requests with `X-API-Key` header containing your API key ### Running with Firebase Auth Emulator 1. Start the Firebase Auth Emulator: ```bash firebase emulators:start --only auth ``` The emulator runs on port 9099 by default. 2. Configure the application to use the emulator: ```toml [auth] firebase_emulator_url = "http://localhost:9099" api_tokens = ["dev-api-key"] ``` 3. Get a test token from the emulator: ```bash # Using curl curl -X POST "http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=fake-api-key" \ -H "Content-Type: application/json" \ -d '{ "email": "test@example.com", "password": "password", "returnSecureToken": true }' ``` 4. Make authenticated requests: ```bash curl -X GET "http://localhost:3000/api/v1/info" \ -H "Authorization: Bearer " ``` ### Running with API Keys 1. Configure API keys in `config.toml`: ```toml [auth] api_tokens = ["my-secret-api-key"] ``` 2. Make authenticated requests: ```bash curl -X GET "http://localhost:3000/api/v1/info" \ -H "X-API-Key: my-secret-api-key" ``` ### Starting the Server ```bash cargo run --release -- listen ``` Or with custom options: ```bash cargo run --release -- listen --host 127.0.0.1 --port 8080 ``` ### API Endpoints #### info Check ```bash GET /api/v1/info ``` #### Dictionary Management ```bash GET /api/v1/dicts GET /api/v1/dicts/:name ``` #### Major System Encoding/Decoding ```bash POST /api/v1/major/encode POST /api/v1/major/decode ``` #### Authentication ```bash POST /api/v1/auth/login ``` ### Development Run in development mode with auto-reload: ```bash cargo run -- listen ``` ### Testing Run tests: ```bash cargo test ``` ### License MIT