How krey-yon/linkex works
Purpose and runtime
tross is a Rust HTTP API that retrieves public LinkedIn profiles through an authenticated server-side Voyager client, normalizes LinkedIn payloads into a stable JSON contract, and protects the upstream with caching, throttling, and circuit breaking. The executable starts in src/main.rs; application construction and shared dependencies are assembled in src/app.rs and src/state.rs.
HTTP API and request boundary
Route registration and HTTP-layer behavior live under src/api/mod.rs, with profile routes in src/api/profile.rs, account/billing routes in src/api/account.rs, and health/session system routes in src/api/system.rs. Middleware in src/api/middleware.rs provides request-level concerns such as API-key authentication, client rate limiting, request IDs, response headers, and billable-request handling.
The external boundary is JSON-over-HTTP: callers submit a LinkedIn profile URL and receive the common response envelope represented by src/domain/response.rs.
Profile retrieval orchestration
src/service/profile.rs is the central use-case layer. It validates and canonicalizes the requested profile URL, determines whether cache refresh is required, coalesces concurrent identical requests, invokes the LinkedIn repository on misses, parses the result, and returns profile metadata suitable for the API layer. src/service/mod.rs defines the service composition boundary between transport and upstream/data concerns.
Cache and persistence
Profile caching is implemented in src/service/cache.rs. It combines bounded in-memory TTL storage with optional disk persistence, loading valid persisted entries at startup and avoiding upstream work for hits. Cache decisions feed billing costs and response metadata, while refresh requests deliberately bypass normal cache reuse. Persistent cache/session paths are deployment-sensitive because containers only permit writes beneath /data.
LinkedIn authenticated upstream client
The LinkedIn subsystem is isolated in src/linkedin/. src/linkedin/client.rs performs Voyager HTTP interactions; src/linkedin/endpoints.rs defines upstream request targets; and src/linkedin/repository.rs exposes retrieval to the service layer. Authentication and durable cookie/session lifecycle are handled by src/linkedin/auth.rs and src/linkedin/session.rs, including cookie-header credentials and optional password login.
src/linkedin/throttle.rs enforces upstream spacing, bounded concurrency, retries, and circuit-breaker behavior. This isolates LinkedIn-specific failures and prevents the public API from repeatedly stressing an unavailable or rate-limiting upstream.
Parsing and stable domain model
Raw Voyager/Dash payloads cross into a dedicated parser pipeline in src/parser/mod.rs. Format-specific readers—src/parser/normalized.rs, src/parser/dash.rs, and src/parser/legacy.rs—extract source representations; src/parser/assembler.rs composes the normalized result. The stable internal/public profile schema is centered on src/domain/profile.rs, separating volatile upstream structure from the API contract.
Billing, configuration, and operations
src/billing.rs governs credit charging/refunds and supports Redis-backed balances; account endpoints expose balance and pricing. Runtime configuration, including LinkedIn credentials, cache/session paths, Redis, raw-endpoint exposure, and operational limits, is centralized in src/config.rs.
Redis is the material external infrastructure for production billing, configured through docker-compose.yml. Container deployment is defined by Dockerfile; it runs one API replica per LinkedIn credential with persistent /data storage. src/telemetry.rs provides structured operational logging, while src/error.rs maps internal/upstream failures to stable API error codes.
Main entry points: mod.rs Routes · app.rs App assembly · service/profile.rs Profile orchestration · api/profile.rs Profile endpoints
Components 22
Runtime
- Executable
src/main.rs - App assembly
src/app.rs - Shared state
src/state.rs - Error mapping
src/error.rs
Public API
- Routes
src/api/mod.rs - Request middleware · API keys, client limits, request IDs, and billable handling.
src/api/middleware.rs - Profile endpoints
src/api/profile.rs - Account endpoints
src/api/account.rs - System endpoints
src/api/system.rs - Response envelope
src/domain/response.rs
Profile Service
- Profile orchestration · Validates URLs, coalesces misses, and coordinates retrieval.
src/service/profile.rs - Profile cache · TTL cache with optional persistent entries under /data.
src/service/cache.rs - Billing · Charges or refunds based on cache and request outcomes.
src/billing.rs - Voyager parser pipeline · Reads normalized, Dash, and legacy payloads before assembly.
src/parser/mod.rs - Stable profile schema · Separates volatile LinkedIn data from the public profile model.
src/domain/profile.rs
LinkedIn Upstream
- LinkedIn repository
src/linkedin/repository.rs - Voyager client
src/linkedin/client.rs - Auth and sessions · Cookie credentials or optional password login with durable sessions.
src/linkedin/auth.rs - Upstream protection · Spacing, bounded concurrency, retries, and circuit breaking.
src/linkedin/throttle.rs
Data & Operations
- Runtime config
src/config.rs - Redis · Production backing store for billing balances.
docker-compose.yml - Telemetry
src/telemetry.rs
Connections 22
- Executable → App assembly: starts
- App assembly → Shared state: builds
- App assembly → Routes: serves
- Runtime config → App assembly: configures
- Routes → Request middleware: applies
- Routes → Profile endpoints: registers
- Routes → Account endpoints: registers
- Routes → System endpoints: registers
- Profile endpoints → Profile orchestration: retrieves profile
- Profile endpoints → Response envelope: returns
- Request middleware → Billing: handles billable requests
- Account endpoints → Billing: reads balance and pricing
- Profile orchestration → Profile cache: checks and refreshes
- Profile orchestration → LinkedIn repository: fetches on miss
- Profile orchestration → Voyager parser pipeline: parses payload
- Voyager parser pipeline → Stable profile schema: normalizes into
- LinkedIn repository → Upstream protection: protects requests with
- Upstream protection → Voyager client: permits calls to
- Voyager client → Auth and sessions: uses session
- Billing → Redis: stores balances in
- App assembly → Telemetry: initializes
- Routes → Error mapping: maps failures through