You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
chodak166 65dbfaca25 Added tavern test plans 3 months ago
.devcontainer Added CLI app with major pl/en dict-based encoding and decoding 4 months ago
apps Added tavern test plans 3 months ago
lib Added initial tavern tests 3 months ago
resources Added CLI app with major pl/en dict-based encoding and decoding 4 months ago
tavern-tests Added tavern test plans 3 months ago
.gitignore Initial commit 6 months ago
Cargo.toml Added app_cli/app_api crates 4 months ago
README.md Added initial tavern tests 3 months ago
config.toml Added initial tavern tests 3 months ago

README.md

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

cargo build --release

Configuration

Create a config.toml file in the project root:

[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:

    firebase emulators:start --only auth
    

    The emulator runs on port 9099 by default.

  2. Configure the application to use the emulator:

    [auth]
    firebase_emulator_url = "http://localhost:9099"
    api_tokens = ["dev-api-key"]
    
  3. Get a test token from the emulator:

    # 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:

    curl -X GET "http://localhost:3000/api/v1/info" \
      -H "Authorization: Bearer <your-firebase-token>"
    

Running with API Keys

  1. Configure API keys in config.toml:

    [auth]
    api_tokens = ["my-secret-api-key"]
    
  2. Make authenticated requests:

    curl -X GET "http://localhost:3000/api/v1/info" \
      -H "X-API-Key: my-secret-api-key"
    

Starting the Server

cargo run --release -- listen

Or with custom options:

cargo run --release -- listen --host 127.0.0.1 --port 8080

API Endpoints

info Check

GET /api/v1/info

Dictionary Management

GET /api/v1/dicts
GET /api/v1/dicts/:name

Major System Encoding/Decoding

POST /api/v1/major/encode
POST /api/v1/major/decode

Authentication

POST /api/v1/auth/login

Development

Run in development mode with auto-reload:

cargo run -- listen

Testing

Run tests:

cargo test

License

MIT