# amogharajsandur/newton-ai-agent architecture

> Architecture diagram of the GitHub repository amogharajsandur/newton-ai-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amogharajsandur/newton-ai-agent
- Repository: https://github.com/amogharajsandur/newton-ai-agent

## Overview

Newton AI Agent is a Chrome extension and FastAPI service that detects Newton School tasks, sends them to a selected LLM, and applies the returned answer. The documented workflow includes portal identity capture, question extraction, solving, and submission; the backend also records users and solve attempts. The repository contains task-history API code, but the sampled application entry point mounts only the solve router. The dashboard source shown is a Vite starter screen, not evidence of the documented future usage dashboard.

Main entry points: [`backend/app/routes/solve.py`](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/routes/solve.py) (Solve endpoint), [`extension/src/background.js`](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/background.js) (Solve dispatch), [`extension/src/content.js`](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/content.js) (Task detection), [`backend/app/services/solver.py`](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/services/solver.py) (Prompt and validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Chrome extension"]
  node_settings["Provider settings<br/>[options.js]"]
  node_authbridge["JWT capture<br/>[auth_bridge.js]"]
  node_content["Task detection<br/>[content.js]"]
  node_pagebridge["Editor bridge<br/>[page_bridge.js]"]
  node_background["Solve dispatch<br/>[background.js]"]
  node_popup["Extension popup<br/>[popup.js]"]
end

subgraph group_backend["Solve backend"]
  node_api["FastAPI entry<br/>[main.py]"]
  node_solve["Solve endpoint<br/>[solve.py]"]
  node_schemas["Request models<br/>[schemas.py]"]
  node_solver["Prompt and validation<br/>[solver.py]"]
  node_config["Config and encryption<br/>[config.py]"]
end

subgraph group_storage["Identity and records"]
  node_supabaseclient["Supabase client<br/>[supabase.py]"]
  node_database[("Supabase records<br/>[schema.sql]")]
  node_taskroutes["Task history API<br/>[tasks.py]"]
end

subgraph group_providers["LLM providers"]
  node_llm{{"Selected LLM"}}
end

node_student(("Student"))
node_portal["Newton portal"]
node_dashboard["Dashboard starter<br/>[App.tsx]"]

node_student -->|"uses"| node_portal
node_student -->|"configures"| node_settings
node_portal -->|"sends authenticated requests"| node_authbridge
node_authbridge -->|"dispatches identity"| node_content
node_portal -->|"provides task page"| node_content
node_content -->|"requests editor access"| node_pagebridge
node_content -->|"sends question"| node_background
node_settings -->|"supplies provider settings"| node_background
node_background -->|"POST /solve"| node_api
node_api -->|"mounts router"| node_solve
node_solve -->|"validates request"| node_schemas
node_solve -->|"encrypts key"| node_config
node_solve -->|"upserts and logs"| node_supabaseclient
node_solve -->|"calls solver"| node_solver
node_solver -->|"dispatches prompt"| node_llm
node_llm -->|"returns response"| node_solver
node_supabaseclient -.->|"accesses records"| node_database
node_taskroutes -->|"queries task records"| node_supabaseclient
node_solve -->|"returns answer"| node_background
node_background -->|"fills and submits"| node_portal
node_student -.->|"can open"| node_dashboard

click node_settings "https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/options.js"
click node_authbridge "https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/auth_bridge.js"
click node_content "https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/content.js"
click node_pagebridge "https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/page_bridge.js"
click node_background "https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/background.js"
click node_popup "https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/popup.js"
click node_api "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/main.py"
click node_solve "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/routes/solve.py"
click node_schemas "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/models/schemas.py"
click node_solver "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/services/solver.py"
click node_config "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/config.py"
click node_supabaseclient "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/db/supabase.py"
click node_database "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/db/schema.sql"
click node_taskroutes "https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/routes/tasks.py"
click node_dashboard "https://github.com/amogharajsandur/newton-ai-agent/blob/main/dashboard/src/App.tsx"

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_settings,node_authbridge,node_content,node_pagebridge,node_background,node_popup toneBlue
class node_api,node_solve,node_schemas,node_solver,node_config toneAmber
class node_supabaseclient,node_database,node_taskroutes toneMint
class node_llm toneRose
class node_student,node_portal toneIndigo
class node_dashboard toneTeal
```

## Components

### Chrome extension

- [Provider settings](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/options.js): `extension/src/options.js`
- [JWT capture](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/auth_bridge.js): `extension/src/auth_bridge.js`
- [Task detection](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/content.js): `extension/src/content.js`
- [Editor bridge](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/page_bridge.js): `extension/src/page_bridge.js`
- [Solve dispatch](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/background.js): `extension/src/background.js`
- [Extension popup](https://github.com/amogharajsandur/newton-ai-agent/blob/main/extension/src/popup.js): `extension/src/popup.js`

### Solve backend

- [FastAPI entry](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/main.py): `backend/app/main.py`
- [Solve endpoint](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/routes/solve.py): `backend/app/routes/solve.py`
- [Request models](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/models/schemas.py): `backend/app/models/schemas.py`
- [Prompt and validation](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/services/solver.py): `backend/app/services/solver.py`
- [Config and encryption](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/config.py): `backend/app/config.py`

### Identity and records

- [Supabase client](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/db/supabase.py): `backend/app/db/supabase.py`
- [Supabase records](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/db/schema.sql): `backend/app/db/schema.sql`
- [Task history API](https://github.com/amogharajsandur/newton-ai-agent/blob/main/backend/app/routes/tasks.py): `backend/app/routes/tasks.py`

### LLM providers

- **Selected LLM**

### Other components

- **Student**
- **Newton portal**
- [Dashboard starter](https://github.com/amogharajsandur/newton-ai-agent/blob/main/dashboard/src/App.tsx): `dashboard/src/App.tsx`

## Connections

- Student → Newton portal: uses (evidence: `README.md`)
- Student → Provider settings: configures (evidence: `README.md`)
- Newton portal → JWT capture: sends authenticated requests (evidence: `extension/src/auth_bridge.js`)
- JWT capture → Task detection: dispatches identity (evidence: `extension/src/auth_bridge.js`)
- Newton portal → Task detection: provides task page (evidence: `README.md`)
- Task detection → Editor bridge: requests editor access (evidence: `README.md`)
- Task detection → Solve dispatch: sends question (evidence: `README.md`)
- Provider settings → Solve dispatch: supplies provider settings (evidence: `README.md`)
- Solve dispatch → FastAPI entry: POST /solve (evidence: `README.md`)
- FastAPI entry → Solve endpoint: mounts router (evidence: `backend/app/main.py`)
- Solve endpoint → Request models: validates request (evidence: `backend/app/routes/solve.py`)
- Solve endpoint → Config and encryption: encrypts key (evidence: `backend/app/routes/solve.py`)
- Solve endpoint → Supabase client: upserts and logs (evidence: `backend/app/routes/solve.py`)
- Solve endpoint → Prompt and validation: calls solver (evidence: `backend/app/routes/solve.py`)
- Prompt and validation → Selected LLM: dispatches prompt (evidence: `backend/app/services/solver.py`)
- Selected LLM → Prompt and validation: returns response (evidence: `backend/app/services/solver.py`)
- Supabase client → Supabase records: accesses records
- Task history API → Supabase client: queries task records (evidence: `backend/app/routes/tasks.py`)
- Solve endpoint → Solve dispatch: returns answer (evidence: `README.md`)
- Solve dispatch → Newton portal: fills and submits (evidence: `README.md`)
- Student → Dashboard starter: can open
