# sweetherb100/ai-code-decoder architecture

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

- Interactive diagram: https://gitdiagram.com/sweetherb100/ai-code-decoder
- Repository: https://github.com/sweetherb100/ai-code-decoder

## Overview

AI Code Decode Agent is a Streamlit learning tool that explains submitted Python without executing it. A user submits code, optionally with surrounding context, and selects an audience level. The decoder performs static AST analysis, selects up to three learning targets, looks up official Python documentation, and uses an Agents SDK agent to produce a What/Why/Source/Example/Check response; quality checks validate cited documentation. The README also documents tracing and supported-syntax capabilities. Edges reflect shown calls or README-documented external behavior; unsampled subsystems are not inferred.

Main entry points: [`agent/decoder.py`](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/decoder.py) (Agent decoder), [`agent/models.py`](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/models.py) (Data models), [`agent/pipeline.py`](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/pipeline.py) (Evidence pipeline), [`agent/documentation.py`](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/documentation.py) (Python docs lookup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Streamlit app<br/>[app.py]"]
end

subgraph group_analysis["Code analysis"]
  node_analyzer["AST analyzer<br/>[analyzer.py]"]
  node_models["Data models<br/>[models.py]"]
end

subgraph group_evidence["Learning evidence"]
  node_planner["Learning planner<br/>[planner.py]"]
  node_pipeline["Evidence pipeline<br/>[pipeline.py]"]
  node_documentation["Python docs lookup<br/>[documentation.py]"]
end

subgraph group_generation["Agent response"]
  node_decoder["Agent decoder<br/>[decoder.py]"]
  node_tools["Function tool<br/>[tools.py]"]
  node_runcontext["Run context<br/>[run_context.py]"]
  node_prompts["Tutor instructions<br/>[prompts.py]"]
  node_quality["Source validator<br/>[quality.py]"]
end

node_user(("Code learner"))
node_officialdocs["Python documentation"]
node_openai{{"OpenAI API"}}

node_user -->|"submits code"| node_app
node_app -->|"requests decode"| node_decoder
node_decoder -->|"analyzes code"| node_analyzer
node_analyzer -->|"builds analysis"| node_models
node_decoder -->|"registers tool"| node_tools
node_decoder -->|"loads instructions"| node_prompts
node_decoder -->|"shares run state"| node_runcontext
node_decoder -->|"validates response"| node_quality
node_tools -->|"reads and updates"| node_runcontext
node_tools -->|"runs pipeline"| node_pipeline
node_pipeline -->|"builds plan"| node_planner
node_pipeline -->|"looks up targets"| node_documentation
node_planner -->|"creates plan"| node_models
node_documentation -->|"returns evidence"| node_models
node_quality -->|"checks response"| node_models
node_documentation -->|"fetches pages"| node_officialdocs
node_decoder -.->|"sends code for response"| node_openai
node_decoder -->|"returns result"| node_app

click node_app "https://github.com/sweetherb100/ai-code-decoder/blob/main/app.py"
click node_decoder "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/decoder.py"
click node_analyzer "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/analyzer.py"
click node_models "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/models.py"
click node_planner "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/planner.py"
click node_pipeline "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/pipeline.py"
click node_documentation "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/documentation.py"
click node_tools "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/tools.py"
click node_runcontext "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/run_context.py"
click node_prompts "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/prompts.py"
click node_quality "https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/quality.py"

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_app toneBlue
class node_analyzer,node_models toneAmber
class node_planner,node_pipeline,node_documentation,node_openai toneMint
class node_decoder,node_tools,node_runcontext,node_prompts,node_quality toneRose
class node_user,node_officialdocs toneIndigo
```

## Components

### User interface

- [Streamlit app](https://github.com/sweetherb100/ai-code-decoder/blob/main/app.py): `app.py`

### Code analysis

- [AST analyzer](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/analyzer.py): `agent/analyzer.py`
- [Data models](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/models.py): `agent/models.py`

### Learning evidence

- [Learning planner](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/planner.py): `agent/planner.py`
- [Evidence pipeline](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/pipeline.py): `agent/pipeline.py`
- [Python docs lookup](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/documentation.py): `agent/documentation.py`

### Agent response

- [Agent decoder](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/decoder.py): `agent/decoder.py`
- [Function tool](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/tools.py): `agent/tools.py`
- [Run context](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/run_context.py): `agent/run_context.py`
- [Tutor instructions](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/prompts.py): `agent/prompts.py`
- [Source validator](https://github.com/sweetherb100/ai-code-decoder/blob/main/agent/quality.py): `agent/quality.py`

### Other components

- **Code learner**
- **Python documentation**
- **OpenAI API**

## Connections

- Code learner → Streamlit app: submits code (evidence: `app.py`)
- Streamlit app → Agent decoder: requests decode (evidence: `app.py`)
- Agent decoder → AST analyzer: analyzes code (evidence: `agent/decoder.py`)
- AST analyzer → Data models: builds analysis (evidence: `agent/analyzer.py`)
- Agent decoder → Function tool: registers tool (evidence: `agent/decoder.py`)
- Agent decoder → Tutor instructions: loads instructions (evidence: `agent/decoder.py`)
- Agent decoder → Run context: shares run state (evidence: `agent/decoder.py`)
- Agent decoder → Source validator: validates response (evidence: `agent/decoder.py`)
- Function tool → Run context: reads and updates (evidence: `agent/tools.py`)
- Function tool → Evidence pipeline: runs pipeline (evidence: `agent/tools.py`)
- Evidence pipeline → Learning planner: builds plan (evidence: `agent/pipeline.py`)
- Evidence pipeline → Python docs lookup: looks up targets (evidence: `agent/pipeline.py`)
- Learning planner → Data models: creates plan (evidence: `agent/planner.py`)
- Python docs lookup → Data models: returns evidence (evidence: `agent/documentation.py`)
- Source validator → Data models: checks response (evidence: `agent/quality.py`)
- Python docs lookup → Python documentation: fetches pages (evidence: `agent/documentation.py`)
- Agent decoder → OpenAI API: sends code for response (evidence: `README.md`)
- Agent decoder → Streamlit app: returns result (evidence: `app.py`)
