# charan9716/traffic_rl_project architecture

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

- Interactive diagram: https://gitdiagram.com/charan9716/traffic_rl_project
- Repository: https://github.com/charan9716/traffic_rl_project

## Overview

This repository is a traffic-signal RL simulator, with a Streamlit dashboard as its documented product workflow: users configure finite queues, run or step an episode, and inspect signal choices, vehicle delays, and episode metrics. A separate Python runner trains a tabular Q-agent against a fixed-policy baseline and launches a Pygame view. The DQN implementation is present but is not wired into either runtime path in the shown source; the dashboard describes it as a possible replacement. Edges reflect only calls or behavior documented in the supplied excerpts.

Main entry points: [`streamlit_app.py`](https://github.com/charan9716/traffic_rl_project/blob/main/streamlit_app.py) (Dashboard and Tracking), [`environment.py`](https://github.com/charan9716/traffic_rl_project/blob/main/environment.py) (Intersection Environment), [`main.py`](https://github.com/charan9716/traffic_rl_project/blob/main/main.py) (Training Runner), [`gui.py`](https://github.com/charan9716/traffic_rl_project/blob/main/gui.py) (Pygame View)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Streamlit Dashboard"]
  node_streamlit["Dashboard and Tracking<br/>[streamlit_app.py]"]
end

subgraph group_simulation["Traffic Simulation"]
  node_environment["Intersection Environment<br/>[environment.py]"]
end

subgraph group_learning["Learning and Policies"]
  node_q_agent["Tabular Q-Agent<br/>[q_agent.py]"]
  node_dqn_agent["DQN Agent<br/>[dqn_agent.py]"]
  node_baseline["Fixed-Phase Policy<br/>[baseline.py]"]
end

subgraph group_legacy["Training and Pygame"]
  node_runner["Training Runner<br/>[main.py]"]
  node_pygame["Pygame View<br/>[gui.py]"]
end

node_user(("User"))

node_user -->|"configures and observes"| node_streamlit
node_streamlit -->|"creates and resets"| node_environment
node_streamlit -->|"chooses phase"| node_environment
node_streamlit -->|"steps episode"| node_environment
node_streamlit -->|"reads queues and metrics"| node_environment
node_runner -->|"creates and resets"| node_environment
node_runner -->|"steps episode"| node_environment
node_runner -->|"chooses and updates"| node_q_agent
node_runner -->|"gets fixed actions"| node_baseline
node_runner -->|"launches view"| node_pygame
node_pygame -->|"steps episode"| node_environment
node_pygame -->|"chooses actions"| node_q_agent
node_streamlit -.->|"possible policy replacement"| node_dqn_agent

click node_streamlit "https://github.com/charan9716/traffic_rl_project/blob/main/streamlit_app.py"
click node_environment "https://github.com/charan9716/traffic_rl_project/blob/main/environment.py"
click node_q_agent "https://github.com/charan9716/traffic_rl_project/blob/main/q_agent.py"
click node_dqn_agent "https://github.com/charan9716/traffic_rl_project/blob/main/dqn_agent.py"
click node_runner "https://github.com/charan9716/traffic_rl_project/blob/main/main.py"
click node_baseline "https://github.com/charan9716/traffic_rl_project/blob/main/baseline.py"
click node_pygame "https://github.com/charan9716/traffic_rl_project/blob/main/gui.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_streamlit,node_user toneBlue
class node_environment toneAmber
class node_q_agent,node_dqn_agent,node_baseline toneMint
class node_runner,node_pygame toneRose
```

## Components

### Streamlit Dashboard

- [Dashboard and Tracking](https://github.com/charan9716/traffic_rl_project/blob/main/streamlit_app.py): `streamlit_app.py`

### Traffic Simulation

- [Intersection Environment](https://github.com/charan9716/traffic_rl_project/blob/main/environment.py): `environment.py`

### Learning and Policies

- [Tabular Q-Agent](https://github.com/charan9716/traffic_rl_project/blob/main/q_agent.py): `q_agent.py`
- [DQN Agent](https://github.com/charan9716/traffic_rl_project/blob/main/dqn_agent.py): `dqn_agent.py`
- [Fixed-Phase Policy](https://github.com/charan9716/traffic_rl_project/blob/main/baseline.py): `baseline.py`

### Training and Pygame

- [Training Runner](https://github.com/charan9716/traffic_rl_project/blob/main/main.py): `main.py`
- [Pygame View](https://github.com/charan9716/traffic_rl_project/blob/main/gui.py): `gui.py`

### Other components

- **User**

## Connections

- User → Dashboard and Tracking: configures and observes (evidence: `README.md`)
- Dashboard and Tracking → Intersection Environment: creates and resets (evidence: `streamlit_app.py`)
- Dashboard and Tracking → Intersection Environment: chooses phase (evidence: `streamlit_app.py`)
- Dashboard and Tracking → Intersection Environment: steps episode (evidence: `streamlit_app.py`)
- Dashboard and Tracking → Intersection Environment: reads queues and metrics (evidence: `streamlit_app.py`)
- Training Runner → Intersection Environment: creates and resets (evidence: `main.py`)
- Training Runner → Intersection Environment: steps episode (evidence: `main.py`)
- Training Runner → Tabular Q-Agent: chooses and updates (evidence: `main.py`)
- Training Runner → Fixed-Phase Policy: gets fixed actions (evidence: `main.py`)
- Training Runner → Pygame View: launches view (evidence: `main.py`)
- Pygame View → Intersection Environment: steps episode (evidence: `gui.py`)
- Pygame View → Tabular Q-Agent: chooses actions (evidence: `gui.py`)
- Dashboard and Tracking → DQN Agent: possible policy replacement
