# thasneemshaik09/tross-linkedin-api architecture

> Architecture diagram of the GitHub repository thasneemshaik09/tross-linkedin-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thasneemshaik09/tross-linkedin-api
- Repository: https://github.com/thasneemshaik09/tross-linkedin-api

## Overview

#### Purpose and Entrypoints
A Python 3.11/3.12 FastAPI service exposing LinkedIn public-profile data as a stable JSON API. Primary runtime entrypoint is `app/main.py`; it serves GET/POST `/api/profile`, debug `/api/profile/raw`, and `/health`. Public response contracts live in `app/models.py`.

#### HTTP/API Boundary
`app/main.py` owns FastAPI routing, request validation, optional `X-API-Key` enforcement, and exception-to-HTTP response handling. It accepts a LinkedIn URL rather than a profile ID; URL normalization/extraction is isolated in `app/linkedin/urls.py`. Typed domain/upstream failures are defined in `app/errors.py`, allowing controlled 400/401/404/429/502/503 responses rather than leaked internal errors.

#### Profile Retrieval Orchestration
`app/service.py` is the application workflow boundary:
1. Parse URL to LinkedIn public ID.
2. Resolve identity and profile URN.
3. Fetch profile section resources concurrently.
4. Parse upstream entities into the public schema.
5. Return profile plus retrieval metadata.
It also provides an in-memory TTL cache, reducing repeat upstream calls and pressure on the shared LinkedIn account.

#### LinkedIn Voyager Integration
`app/linkedin/client.py` is the sole external-service adapter. Using async `httpx`, it calls authenticated LinkedIn private Voyager “dash” REST endpoints: identity first, then positions, education, skills, certifications, and languages keyed by the resolved profile URN. It constructs required cookies, CSRF/rest.li headers, finder query parameters, and optional proxy routing. This is a hard boundary: LinkedIn’s private payloads and auth behavior do not escape the adapter/parser layer.

#### Translation and Schema Stability
`app/linkedin/parser.py` translates Voyager normalized `{data, included}` payloads, discriminated by `$type`, into application-owned Pydantic models in `app/models.py`. Parsing is defensive against missing or renamed upstream fields; unavailable sections become null/empty schema values. This decouples consumers from LinkedIn’s volatile internal resource formats.

#### Configuration, Credentials, and Deployment
`app/config.py` loads environment-backed runtime settings, including `LINKEDIN_LI_AT`, `LINKEDIN_JSESSIONID`, optional `API_KEY`, cache settings, and `PROXY_URL`. LinkedIn requires an authenticated session and CSRF cookie/header pairing. Cloud deployments may require a residential/mobile egress proxy because datacenter IPs can trigger LinkedIn login/checkpoint flows. Container deployment is defined by `Dockerfile`; Render provisioning and health checks are defined in `render.yaml`.

#### Runtime Dependencies and Operational Constraints
The runtime is server-side only: FastAPI/Uvicorn provide HTTPS API hosting, `httpx` performs outbound Voyager calls, and Pydantic validates/contracts API data. There is no browser automation runtime. Upstream failure isolation is intentional: failure of an individual profile section degrades that section to empty, while identity/auth/rate-limit failures control the overall request outcome.

Main entry points: [`app/main.py`](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/main.py) (FastAPI routes), [`app/service.py`](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/service.py) (Profile workflow), [`app/linkedin/client.py`](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/client.py) (Voyager client), [`render.yaml`](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/render.yaml) (Render deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API service"]
  node_main["FastAPI routes<br/>HTTP boundary<br/>[main.py]"]
  node_models["Public contracts<br/>Pydantic models<br/>[models.py]"]
  node_errors["Typed failures<br/>error model<br/>[errors.py]"]
end

subgraph group_domain["Application"]
  node_service["Profile workflow<br/>application service<br/>[service.py]"]
  node_url_parser["LinkedIn URL parser<br/>normalizer<br/>[urls.py]"]
  node_cache[("TTL cache<br/>in-memory cache<br/>[service.py]")]
end

subgraph group_linkedin["LinkedIn integration"]
  node_voyager_client["Voyager client<br/>external adapter<br/>[client.py]"]
  node_parser["Voyager parser<br/>translation layer<br/>[parser.py]"]
  node_linkedin{{"LinkedIn Voyager<br/>external service"}}
end

subgraph group_ops["Runtime &amp; deployment"]
  node_config["Runtime settings<br/>environment config<br/>[config.py]"]
  node_proxy{{"Optional egress proxy<br/>network service"}}
  node_container["Container image<br/>deployment package"]
  node_render{{"Render deployment<br/>hosting platform<br/>[render.yaml]"}}
end

node_client(("API consumer<br/>client"))

node_client -->|"GET/POST profile requests"| node_main
node_main -->|"validates and serializes"| node_models
node_main -->|"invokes retrieval"| node_service
node_main -->|"maps failures"| node_errors
node_main -->|"reads API-key policy"| node_config
node_service -->|"extracts public ID"| node_url_parser
node_service -->|"reads and writes"| node_cache
node_service -->|"resolves identity and fetches sections"| node_voyager_client
node_service -->|"translates resources"| node_parser
node_parser -->|"builds stable profile"| node_models
node_voyager_client -->|"authenticated async REST"| node_linkedin
node_voyager_client -->|"uses cookies, CSRF, proxy"| node_config
node_voyager_client -.->|"optional routing"| node_proxy
node_container -->|"runs application"| node_main
node_render -->|"deploys"| node_container
node_render -.->|"health checks"| node_main

click node_main "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/main.py"
click node_models "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/models.py"
click node_errors "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/errors.py"
click node_service "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/service.py"
click node_url_parser "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/urls.py"
click node_cache "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/service.py"
click node_voyager_client "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/client.py"
click node_parser "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/parser.py"
click node_config "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/config.py"
click node_container "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/Dockerfile"
click node_render "https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/render.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_models,node_errors toneBlue
class node_service,node_url_parser,node_cache toneAmber
class node_voyager_client,node_parser,node_linkedin toneMint
class node_config,node_proxy,node_container,node_render toneRose
class node_client toneNeutral
```

## Components

### API service

- [FastAPI routes](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/main.py): HTTP boundary · Serves profile, raw-debug, and health endpoints. · `app/main.py`
- [Public contracts](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/models.py): Pydantic models · Stable JSON request and response schemas. · `app/models.py`
- [Typed failures](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/errors.py): error model · Maps domain and upstream failures to controlled HTTP responses. · `app/errors.py`

### Application

- [Profile workflow](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/service.py): application service · Coordinates ID resolution, concurrent retrieval, parsing, metadata, and TTL caching. · `app/service.py`
- [LinkedIn URL parser](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/urls.py): normalizer · Extracts a public LinkedIn ID from the submitted URL. · `app/linkedin/urls.py`
- [TTL cache](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/service.py): in-memory cache · Avoids repeat upstream retrieval for cached profiles. · `app/service.py`

### LinkedIn integration

- [Voyager client](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/client.py): external adapter · Authenticated async adapter for private LinkedIn Voyager endpoints. · `app/linkedin/client.py`
- [Voyager parser](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/linkedin/parser.py): translation layer · Defensively maps normalized Voyager payloads into public models. · `app/linkedin/parser.py`
- **LinkedIn Voyager**: external service · Private profile resources and authenticated session boundary.

### Runtime & deployment

- [Runtime settings](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/app/config.py): environment config · Loads session cookies, API key, cache, and proxy settings. · `app/config.py`
- **Optional egress proxy**: network service · Residential/mobile routing can avoid LinkedIn checkpoint flows.
- [Container image](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/Dockerfile): deployment package · `Dockerfile`
- [Render deployment](https://github.com/thasneemshaik09/tross-linkedin-api/blob/main/render.yaml): hosting platform · Provisions the service and health checks. · `render.yaml`

### Other components

- **API consumer**: client

## Connections

- API consumer → FastAPI routes: GET/POST profile requests
- FastAPI routes → Public contracts: validates and serializes
- FastAPI routes → Profile workflow: invokes retrieval
- FastAPI routes → Typed failures: maps failures
- FastAPI routes → Runtime settings: reads API-key policy
- Profile workflow → LinkedIn URL parser: extracts public ID
- Profile workflow → TTL cache: reads and writes
- Profile workflow → Voyager client: resolves identity and fetches sections · Section requests run concurrently after URN resolution.
- Profile workflow → Voyager parser: translates resources
- Voyager parser → Public contracts: builds stable profile
- Voyager client → LinkedIn Voyager: authenticated async REST
- Voyager client → Runtime settings: uses cookies, CSRF, proxy
- Voyager client → Optional egress proxy: optional routing
- Container image → FastAPI routes: runs application
- Render deployment → Container image: deploys
- Render deployment → FastAPI routes: health checks
