# davieira/poliedro-gpt architecture

> Architecture diagram of the GitHub repository davieira/poliedro-gpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davieira/poliedro-gpt
- Repository: https://github.com/davieira/poliedro-gpt

## Overview

#### Purpose and Entry Points
Poliedro MCP is an unofficial Python bridge to the Poliedro P+ portal. It exposes student grades, assessments, messages, and calendar data through a REST/OpenAPI API for ChatGPT and MCP tools for Claude. Main service entry point: `src/poliedro_mcp/api.py`; local CLI/MCP entry points: `src/poliedro_mcp/cli.py`, `src/poliedro_mcp/server.py`.

#### API and Portal Integration
The REST layer serves `/api/v1/*`, OAuth endpoints, OpenAPI, privacy content, and health-oriented routes. It translates authenticated requests into Poliedro P+ API calls through shared client/service abstractions.
- `src/poliedro_mcp/api.py`
- `src/poliedro_mcp/api_base.py`
- `src/poliedro_mcp/client.py`
- `src/poliedro_mcp/services.py`

#### Poliedro Authentication and User Isolation
Users submit P+ credentials during OAuth/MCP login. The service validates them against Poliedro, obtains a temporary portal JWT, and keeps it associated with the current OAuth flow/session rather than a shared account. User context is the boundary preventing one user’s OAuth token from accessing another user’s P+ data.
- `src/poliedro_mcp/auth.py`
- `src/poliedro_mcp/user_context.py`
- `src/poliedro_mcp/profile_discovery.py`

#### ChatGPT OAuth Flow
ChatGPT Actions use conventional authorization-code OAuth: authorization/login UI, code exchange, and bearer-token access to REST resources. OAuth client configuration is environment-driven, with a configurable client ID and required signing secret.
- `src/poliedro_mcp/oauth_proxy.py`
- `src/poliedro_mcp/oauth_config.py`
- `src/poliedro_mcp/auth.py`

#### Remote Claude MCP Flow
The remote MCP endpoint provides Streamable HTTP tools plus OAuth authorization-server metadata and Dynamic Client Registration for Claude Custom Connectors. MCP OAuth tokens authenticate tool invocations; tools retrieve data through the same Poliedro service boundary as REST.
- `src/poliedro_mcp/mcp_remote.py`
- `src/poliedro_mcp/mcp_auth_provider.py`
- `src/poliedro_mcp/mcp_oauth_tokens.py`
- `src/poliedro_mcp/mcp_tools.py`

#### Local Claude Desktop Mode
Local MCP runs as a Python process and can obtain credentials from the host machine’s keychain via an interactive setup command. This is distinct from remote deployment: local configuration/credentials may exist on the user machine, while production is designed not to persist portal credentials.
- `src/poliedro_mcp/server.py`
- `src/poliedro_mcp/setup_login.py`
- `src/poliedro_mcp/config_loader.py`

#### Runtime and Deployment Boundaries
The runtime is Python (packaging in `pyproject.toml`, dependencies in `requirements.txt`) and is deployable as a container or Render service. Production requires `OAUTH_CLIENT_SECRET` and public `API_BASE_URL`; it depends externally on Poliedro P+ and on ChatGPT/Claude as OAuth or MCP clients.
- `Dockerfile`
- `render.yaml`
- `docker-compose.yml`
- `runtime.txt`

Main entry points: [`src/poliedro_mcp/mcp_remote.py`](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_remote.py) (Remote MCP endpoint), [`src/poliedro_mcp/services.py`](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/services.py) (Portal services), [`src/poliedro_mcp/api_base.py`](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/api_base.py) (API resource layer), [`src/poliedro_mcp/oauth_proxy.py`](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/oauth_proxy.py) (ChatGPT OAuth flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client Channels"]
  node_chatgpt(("ChatGPT Actions<br/>OAuth client"))
  node_claude_remote(("Claude Custom Connector<br/>MCP OAuth client"))
  node_claude_local(("Claude Desktop<br/>local MCP host"))
end

subgraph group_api["Application API"]
  node_rest_api["REST and OpenAPI API<br/>Python API<br/>[api.py]"]
  node_api_base["API resource layer<br/>shared API layer<br/>[api_base.py]"]
  node_portal_services["Portal services<br/>service boundary<br/>[services.py]"]
  node_portal_client["Poliedro client<br/>HTTP client<br/>[client.py]"]
  node_remote_mcp["Remote MCP endpoint<br/>Streamable HTTP MCP<br/>[mcp_remote.py]"]
  node_mcp_tools["MCP tools<br/>tool layer<br/>[mcp_tools.py]"]
end

subgraph group_auth["Authentication"]
  node_oauth_proxy["ChatGPT OAuth flow<br/>authorization server<br/>[oauth_proxy.py]"]
  node_oauth_config["OAuth configuration<br/>environment config<br/>[oauth_config.py]"]
  node_portal_auth["Portal credential validation<br/>authentication service<br/>[auth.py]"]
  node_user_context["Per-user context<br/>session isolation<br/>[user_context.py]"]
  node_profile_discovery["Profile discovery<br/>portal identity"]
  node_mcp_auth["MCP token provider<br/>OAuth provider"]
  node_mcp_tokens["MCP OAuth tokens<br/>token service"]
end

subgraph group_local["Local MCP"]
  node_local_mcp["Local MCP server<br/>Python process<br/>[server.py]"]
  node_local_setup["Interactive local login<br/>credential setup<br/>[setup_login.py]"]
  node_local_config["Local config loader<br/>local configuration<br/>[config_loader.py]"]
end

subgraph group_runtime["Deployment"]
  node_deployment["Container / Render runtime<br/>deployment target<br/>[render.yaml]"]
end

node_poliedro{{"Poliedro P+ portal<br/>external portal API"}}

node_chatgpt -->|"authorization code OAuth"| node_oauth_proxy
node_chatgpt -->|"bearer API requests"| node_rest_api
node_oauth_proxy -->|"loads client settings"| node_oauth_config
node_oauth_proxy -->|"login credentials"| node_portal_auth
node_portal_auth -->|"validates identity"| node_profile_discovery
node_portal_auth -->|"stores portal JWT per flow"| node_user_context
node_rest_api -->|"routes resources"| node_api_base
node_api_base -->|"resolves user access"| node_user_context
node_api_base -->|"requests student data"| node_portal_services
node_portal_services -->|"uses"| node_portal_client
node_portal_client -->|"P+ API calls"| node_poliedro
node_claude_remote -->|"Streamable HTTP MCP"| node_remote_mcp
node_remote_mcp -->|"OAuth authorization"| node_mcp_auth
node_mcp_auth -->|"issues and verifies tokens"| node_mcp_tokens
node_remote_mcp -->|"tool invocations"| node_mcp_tools
node_mcp_tools -->|"shared data boundary"| node_portal_services
node_claude_local -->|"stdio MCP"| node_local_mcp
node_local_setup -->|"writes local credential config"| node_local_config
node_local_mcp -->|"loads local credentials"| node_local_config
node_local_mcp -->|"uses shared services"| node_portal_services
node_deployment -->|"hosts"| node_rest_api
node_deployment -->|"hosts"| node_remote_mcp

click node_rest_api "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/api.py"
click node_api_base "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/api_base.py"
click node_portal_services "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/services.py"
click node_portal_client "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/client.py"
click node_oauth_proxy "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/oauth_proxy.py"
click node_oauth_config "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/oauth_config.py"
click node_portal_auth "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/auth.py"
click node_user_context "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/user_context.py"
click node_profile_discovery "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/profile_discovery.py"
click node_remote_mcp "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_remote.py"
click node_mcp_auth "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_auth_provider.py"
click node_mcp_tokens "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_oauth_tokens.py"
click node_mcp_tools "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_tools.py"
click node_local_mcp "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/server.py"
click node_local_setup "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/setup_login.py"
click node_local_config "https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/config_loader.py"
click node_deployment "https://github.com/davieira/poliedro-gpt/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_chatgpt,node_claude_remote,node_claude_local toneBlue
class node_rest_api,node_api_base,node_portal_services,node_portal_client,node_remote_mcp,node_mcp_tools toneAmber
class node_oauth_proxy,node_oauth_config,node_portal_auth,node_user_context,node_profile_discovery,node_mcp_auth,node_mcp_tokens toneMint
class node_local_mcp,node_local_setup,node_local_config toneRose
class node_deployment toneIndigo
class node_poliedro toneNeutral
```

## Components

### Client Channels

- **ChatGPT Actions**: OAuth client
- **Claude Custom Connector**: MCP OAuth client
- **Claude Desktop**: local MCP host

### Application API

- [REST and OpenAPI API](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/api.py): Python API · Serves /api/v1 resources, OpenAPI, privacy, and health routes. · `src/poliedro_mcp/api.py`
- [API resource layer](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/api_base.py): shared API layer · `src/poliedro_mcp/api_base.py`
- [Portal services](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/services.py): service boundary · Maps authenticated requests to grades, assessments, messages, and calendar data. · `src/poliedro_mcp/services.py`
- [Poliedro client](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/client.py): HTTP client · `src/poliedro_mcp/client.py`
- [Remote MCP endpoint](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_remote.py): Streamable HTTP MCP · Exposes tools plus OAuth metadata and dynamic client registration. · `src/poliedro_mcp/mcp_remote.py`
- [MCP tools](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_tools.py): tool layer · `src/poliedro_mcp/mcp_tools.py`

### Authentication

- [ChatGPT OAuth flow](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/oauth_proxy.py): authorization server · Provides login, authorization-code exchange, and bearer-token handling. · `src/poliedro_mcp/oauth_proxy.py`
- [OAuth configuration](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/oauth_config.py): environment config · Uses client ID and signing secret configuration. · `src/poliedro_mcp/oauth_config.py`
- [Portal credential validation](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/auth.py): authentication service · Validates P+ credentials and obtains a temporary portal JWT. · `src/poliedro_mcp/auth.py`
- [Per-user context](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/user_context.py): session isolation · Associates portal access with the current OAuth flow or session. · `src/poliedro_mcp/user_context.py`
- [Profile discovery](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/profile_discovery.py): portal identity · `src/poliedro_mcp/profile_discovery.py`
- [MCP token provider](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_auth_provider.py): OAuth provider · `src/poliedro_mcp/mcp_auth_provider.py`
- [MCP OAuth tokens](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/mcp_oauth_tokens.py): token service · `src/poliedro_mcp/mcp_oauth_tokens.py`

### Local MCP

- [Local MCP server](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/server.py): Python process · `src/poliedro_mcp/server.py`
- [Interactive local login](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/setup_login.py): credential setup · Obtains host-machine keychain credentials for local use. · `src/poliedro_mcp/setup_login.py`
- [Local config loader](https://github.com/davieira/poliedro-gpt/blob/main/src/poliedro_mcp/config_loader.py): local configuration · `src/poliedro_mcp/config_loader.py`

### Deployment

- [Container / Render runtime](https://github.com/davieira/poliedro-gpt/blob/main/render.yaml): deployment target · Production requires OAUTH_CLIENT_SECRET and public API_BASE_URL. · `render.yaml`

### Other components

- **Poliedro P+ portal**: external portal API

## Connections

- ChatGPT Actions → ChatGPT OAuth flow: authorization code OAuth
- ChatGPT Actions → REST and OpenAPI API: bearer API requests
- ChatGPT OAuth flow → OAuth configuration: loads client settings
- ChatGPT OAuth flow → Portal credential validation: login credentials
- Portal credential validation → Profile discovery: validates identity
- Portal credential validation → Per-user context: stores portal JWT per flow
- REST and OpenAPI API → API resource layer: routes resources
- API resource layer → Per-user context: resolves user access
- API resource layer → Portal services: requests student data
- Portal services → Poliedro client: uses
- Poliedro client → Poliedro P+ portal: P+ API calls
- Claude Custom Connector → Remote MCP endpoint: Streamable HTTP MCP
- Remote MCP endpoint → MCP token provider: OAuth authorization
- MCP token provider → MCP OAuth tokens: issues and verifies tokens
- Remote MCP endpoint → MCP tools: tool invocations
- MCP tools → Portal services: shared data boundary
- Claude Desktop → Local MCP server: stdio MCP
- Interactive local login → Local config loader: writes local credential config
- Local MCP server → Local config loader: loads local credentials
- Local MCP server → Portal services: uses shared services
- Container / Render runtime → REST and OpenAPI API: hosts
- Container / Render runtime → Remote MCP endpoint: hosts
