How qu3ai/qu3-app works
Project Type and Purpose
• This is a specialized client–server application written in Python.
• On the client side, it’s a CLI tool (src/main.py) that implements post-quantum cryptography (PQC) protocols to communicate securely with an MCP server.
• A mock server (scripts/mock_mcp_server.py) is provided for development and testing.
• Purpose: Establish a quantum-safe session, send encrypted inference or policy-update requests, and verify server attestations.
File Structure
• Top-level:
• README.md, config.yaml, requirements.txt
• scripts/ — contains the FastAPI mock server (mock_mcp_server.py)
• src/ — main application modules: main.py, mcp_client.py, pqc_utils.py, config_utils.py
• tests/ — unit tests for each core module
• Key libraries & configs:
• config.yaml — holds key_directory and server_url
• Requirements include liboqs-python, cryptography, requests, typer, and fastapi (for mock)
Pull Insights from the README
• Graph of module dependencies on the client
• Key patterns:
• Separation of concerns: CLI orchestration (src/main.py), cryptographic operations (pqc_utils), configuration & key management (config_utils), networking (mcp_client using requests), mock server for testing.
a. Main Components
• Client Side
1. CLI Layer (Typer) – Entry point: src/main.py
2. Business Logic / Client SDK – src/mcp_client.py
3. Crypto Utilities – src/pqc_utils.py
4. Config & Key Management – src/config_utils.py + config.yaml + filesystem (~/.qu3/keys/)
5. Networking – HTTP via requests.Session
6. External Libraries – liboqs_python, cryptography, PyYAML, Typer
• Server Side (Mock)
1. FastAPI App – scripts/mock_mcp_server.py
2. Config & Key Management – Reuses src/config_utils.py
3. Endpoints – /keys, /kem-handshake/initiate, /inference, /policy-update
4. In-memory model stubs – model_caps, model_reverse
5. External Libraries – fastapi, uvicorn, same PQC libs
b. Relationships & Interactions
• CLI → Client SDK (mcp_client) → Config Utils + PQC Utils → Network Layer → mock server → back to client
• File System: both client & server read/write key files
• Network calls: GET /keys → POST /kem-handshake/initiate → POST /inference or /policy-update
• Crypto workloads: KEM handshake, AES-GCM encryption, SPHINCS+ signing/verification, HKDF
c. Architectural Patterns & Principles
• Layered architecture: CLI / orchestration, SDK/core logic, utilities (crypto, config), transport (HTTP)
• Single-responsibility modules (clear separation of key management, crypto ops, network calls)
• Dependency injection via configuration (server URL, key directory)
• Testability: mock server in scripts/, unit tests in tests/
d. Key Technologies
• Python 3, Typer (CLI), FastAPI (mock server)
• liboqs-python (post-quantum KEM & signature)
• cryptography (AES-GCM, HKDF)
• requests (HTTP client)
• PyYAML (config file parsing)