# asheriff-bot/loop architecture

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

- Interactive diagram: https://gitdiagram.com/asheriff-bot/loop
- Repository: https://github.com/asheriff-bot/loop

## Overview

#### Purpose and Entry Points
This repository combines a playable Mastermind-style Locksmith game with a coursework-sized AI development automation system implementing Plan–Execute–Summary (PES). Run the Flask game through `./script/server`; operate the engineering loop through `./loop.sh` or `python -m loop_engine`. Primary application startup is in `game/__main__.py` and loop CLI startup is in `loop_engine/__main__.py`.

#### Game Web Application
The game is a Flask server backed by SQLite. `game/app.py` owns HTTP routes, app construction, and integration between request handlers, persistence, and game rules. Browser UI is rendered from `game/templates/index.html`, with client behavior in `game/static/game.js`. The server boundary is local HTTP at port 5055 per the supplied server script.

#### Game Domain and Persistence
Core Locksmith/Mastermind rules—including guesses and feedback—belong in `game/logic.py`. `game/db.py` encapsulates SQLite storage and separates durable game state from request/UI logic. `game/daily.py` provides daily-game behavior, making date-derived challenge selection a distinct product concern. Relevant paths: `game/logic.py`, `game/db.py`, `game/daily.py`.

#### PES Agent Orchestration
`PESAgent` coordinates iterative Plan → Execute → Summary processing until a completion promise is returned or the configured iteration limit is reached. `loop_engine/agent.py` is the high-level control loop; `loop_engine/stages.py` tracks the explicit assignment workflow stages (`specify`, `review`, `plan`, `build`) and step completion. This is the principal boundary between the automation framework and repository work.

#### Planning, Execution, and Summarization
Planning converts project context and stage requirements into proposed work via `loop_engine/planner.py`. Execution dispatches an agent/backend and applies its output through `loop_engine/executor.py`. Summarization records outcomes and feeds subsequent iterations through `loop_engine/summarizer.py` and `loop_engine/memory.py`. Prompt templates define role-specific instructions in `prompts/PROMPT_plan.md`, `prompts/PROMPT_execute.md`, and `prompts/PROMPT_summary.md`.

#### Backends and External Integrations
The backend abstraction in `loop_engine/backends.py` supports offline `dry_run`, filesystem-oriented `echo`, and GitHub Copilot CLI execution. `loop_engine/config.py` loads project and backend settings from `config.yaml`; `loop_engine/models.py` carries shared loop-domain structures. Copilot is the only declared external AI service/tool dependency; dry-run enables deterministic local testing without an LLM.

#### Evaluation, Git, and Durable Loop State
`loop_engine/evaluator.py` provides evaluation metrics and can gate automated PES progress. `loop_engine/git_ops.py` supports stage-level commit workflow. Operational artifacts bridge agent iterations and human review: `IMPLEMENTATION_PLAN.md` is the living plan, `prompts.txt` records prompt history, and `running.md` documents execution. Product requirements and rubric constraints are authoritative inputs under `specs/00-assignment-rubric.md` and related specs.

Main entry points: [`game/app.py`](https://github.com/asheriff-bot/loop/blob/main/game/app.py) (Flask app and routes), [`loop_engine/agent.py`](https://github.com/asheriff-bot/loop/blob/main/loop_engine/agent.py) (PES agent), [`loop_engine/executor.py`](https://github.com/asheriff-bot/loop/blob/main/loop_engine/executor.py) (Executor), [`loop_engine/planner.py`](https://github.com/asheriff-bot/loop/blob/main/loop_engine/planner.py) (Planner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_game["Locksmith Game"]
  node_game_entry{{"Game startup<br/>Python entry point<br/>[__main__.py]"}}
  node_flask_app["Flask app and routes<br/>HTTP server<br/>[app.py]"]
  node_browser_ui["Browser UI<br/>HTML and JavaScript<br/>[index.html]"]
  node_game_client["Client behavior<br/>browser script<br/>[game.js]"]
  node_game_rules["Mastermind rules<br/>domain logic<br/>[logic.py]"]
  node_daily_game["Daily challenge<br/>product logic<br/>[daily.py]"]
  node_game_db[("Game persistence<br/>SQLite access<br/>[db.py]")]
end

subgraph group_pes["PES Automation"]
  node_loop_cli{{"Loop CLI startup<br/>Python entry point<br/>[__main__.py]"}}
  node_pes_agent["PES agent<br/>orchestrator<br/>[agent.py]"]
  node_workflow_stages["Assignment stages<br/>workflow state<br/>[stages.py]"]
  node_planner["Planner<br/>PES stage<br/>[planner.py]"]
  node_executor["Executor<br/>PES stage<br/>[executor.py]"]
  node_summarizer["Summarizer<br/>PES stage<br/>[summarizer.py]"]
  node_memory[("Loop memory<br/>iteration state<br/>[memory.py]")]
  node_backends["Agent backends<br/>backend abstraction<br/>[backends.py]"]
  node_evaluator["Evaluator<br/>progress gate<br/>[evaluator.py]"]
  node_git_ops["Git workflow<br/>stage commits<br/>[git_ops.py]"]
  node_config["Loop configuration<br/>settings<br/>[config.py]"]
end

subgraph group_inputs["Project Context"]
  node_prompts["Role prompts<br/>prompt templates<br/>[PROMPT_plan.md]"]
  node_requirements["Assignment requirements<br/>authoritative specs"]
  node_operational_artifacts["Work artifacts<br/>human review state"]
end

node_game_entry -->|"starts"| node_flask_app
node_flask_app -->|"renders"| node_browser_ui
node_browser_ui -->|"loads"| node_game_client
node_game_client -->|"local HTTP"| node_flask_app
node_flask_app -->|"applies rules"| node_game_rules
node_flask_app -->|"selects challenge"| node_daily_game
node_flask_app -->|"reads and writes state"| node_game_db
node_loop_cli -->|"starts"| node_pes_agent
node_pes_agent -->|"tracks progress"| node_workflow_stages
node_pes_agent -->|"plan"| node_planner
node_planner -->|"proposed work"| node_executor
node_executor -->|"execution outcome"| node_summarizer
node_summarizer -->|"records outcome"| node_memory
node_memory -.->|"iteration context"| node_planner
node_executor -->|"dispatches"| node_backends
node_pes_agent -->|"evaluates progress"| node_evaluator
node_executor -->|"stage commits"| node_git_ops
node_config -.->|"iteration settings"| node_pes_agent
node_prompts -.->|"plan instructions"| node_planner
node_prompts -.->|"execute instructions"| node_executor
node_prompts -.->|"summary instructions"| node_summarizer
node_requirements -.->|"work constraints"| node_planner
node_operational_artifacts -.->|"review context"| node_pes_agent

click node_game_entry "https://github.com/asheriff-bot/loop/blob/main/game/__main__.py"
click node_flask_app "https://github.com/asheriff-bot/loop/blob/main/game/app.py"
click node_browser_ui "https://github.com/asheriff-bot/loop/blob/main/game/templates/index.html"
click node_game_client "https://github.com/asheriff-bot/loop/blob/main/game/static/game.js"
click node_game_rules "https://github.com/asheriff-bot/loop/blob/main/game/logic.py"
click node_daily_game "https://github.com/asheriff-bot/loop/blob/main/game/daily.py"
click node_game_db "https://github.com/asheriff-bot/loop/blob/main/game/db.py"
click node_loop_cli "https://github.com/asheriff-bot/loop/blob/main/loop_engine/__main__.py"
click node_pes_agent "https://github.com/asheriff-bot/loop/blob/main/loop_engine/agent.py"
click node_workflow_stages "https://github.com/asheriff-bot/loop/blob/main/loop_engine/stages.py"
click node_planner "https://github.com/asheriff-bot/loop/blob/main/loop_engine/planner.py"
click node_executor "https://github.com/asheriff-bot/loop/blob/main/loop_engine/executor.py"
click node_summarizer "https://github.com/asheriff-bot/loop/blob/main/loop_engine/summarizer.py"
click node_memory "https://github.com/asheriff-bot/loop/blob/main/loop_engine/memory.py"
click node_backends "https://github.com/asheriff-bot/loop/blob/main/loop_engine/backends.py"
click node_evaluator "https://github.com/asheriff-bot/loop/blob/main/loop_engine/evaluator.py"
click node_git_ops "https://github.com/asheriff-bot/loop/blob/main/loop_engine/git_ops.py"
click node_config "https://github.com/asheriff-bot/loop/blob/main/loop_engine/config.py"
click node_prompts "https://github.com/asheriff-bot/loop/blob/main/prompts/PROMPT_plan.md"
click node_requirements "https://github.com/asheriff-bot/loop/blob/main/specs/00-assignment-rubric.md"
click node_operational_artifacts "https://github.com/asheriff-bot/loop/blob/main/IMPLEMENTATION_PLAN.md"

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_game_entry,node_flask_app,node_browser_ui,node_game_client,node_game_rules,node_daily_game,node_game_db toneBlue
class node_loop_cli,node_pes_agent,node_workflow_stages,node_planner,node_executor,node_summarizer,node_memory,node_backends,node_evaluator,node_git_ops,node_config toneAmber
class node_prompts,node_requirements,node_operational_artifacts toneMint
```

## Components

### Locksmith Game

Playable Flask Mastermind application.

- [Game startup](https://github.com/asheriff-bot/loop/blob/main/game/__main__.py): Python entry point · `game/__main__.py`
- [Flask app and routes](https://github.com/asheriff-bot/loop/blob/main/game/app.py): HTTP server · Serves the local game API and UI on port 5055. · `game/app.py`
- [Browser UI](https://github.com/asheriff-bot/loop/blob/main/game/templates/index.html): HTML and JavaScript · `game/templates/index.html`
- [Client behavior](https://github.com/asheriff-bot/loop/blob/main/game/static/game.js): browser script · `game/static/game.js`
- [Mastermind rules](https://github.com/asheriff-bot/loop/blob/main/game/logic.py): domain logic · Computes guesses and feedback. · `game/logic.py`
- [Daily challenge](https://github.com/asheriff-bot/loop/blob/main/game/daily.py): product logic · Selects date-derived challenges. · `game/daily.py`
- [Game persistence](https://github.com/asheriff-bot/loop/blob/main/game/db.py): SQLite access · Encapsulates durable game state. · `game/db.py`

### PES Automation

Plan–Execute–Summary engineering loop.

- [Loop CLI startup](https://github.com/asheriff-bot/loop/blob/main/loop_engine/__main__.py): Python entry point · `loop_engine/__main__.py`
- [PES agent](https://github.com/asheriff-bot/loop/blob/main/loop_engine/agent.py): orchestrator · Repeats Plan → Execute → Summary until completion or iteration limit. · `loop_engine/agent.py`
- [Assignment stages](https://github.com/asheriff-bot/loop/blob/main/loop_engine/stages.py): workflow state · Tracks specify, review, plan, and build progress. · `loop_engine/stages.py`
- [Planner](https://github.com/asheriff-bot/loop/blob/main/loop_engine/planner.py): PES stage · `loop_engine/planner.py`
- [Executor](https://github.com/asheriff-bot/loop/blob/main/loop_engine/executor.py): PES stage · Dispatches work and applies backend output. · `loop_engine/executor.py`
- [Summarizer](https://github.com/asheriff-bot/loop/blob/main/loop_engine/summarizer.py): PES stage · `loop_engine/summarizer.py`
- [Loop memory](https://github.com/asheriff-bot/loop/blob/main/loop_engine/memory.py): iteration state · Carries outcomes into later iterations. · `loop_engine/memory.py`
- [Agent backends](https://github.com/asheriff-bot/loop/blob/main/loop_engine/backends.py): backend abstraction · Selects dry-run, echo, or Copilot CLI execution. · `loop_engine/backends.py`
- [Evaluator](https://github.com/asheriff-bot/loop/blob/main/loop_engine/evaluator.py): progress gate · Provides metrics that can gate PES progress. · `loop_engine/evaluator.py`
- [Git workflow](https://github.com/asheriff-bot/loop/blob/main/loop_engine/git_ops.py): stage commits · `loop_engine/git_ops.py`
- [Loop configuration](https://github.com/asheriff-bot/loop/blob/main/loop_engine/config.py): settings · Loads project and backend settings. · `loop_engine/config.py`

### Project Context

Requirements, prompts, and operational artifacts.

- [Role prompts](https://github.com/asheriff-bot/loop/blob/main/prompts/PROMPT_plan.md): prompt templates · Plan, execute, and summary instructions. · `prompts/PROMPT_plan.md`
- [Assignment requirements](https://github.com/asheriff-bot/loop/blob/main/specs/00-assignment-rubric.md): authoritative specs · Rubric and related specifications constrain work. · `specs/00-assignment-rubric.md`
- [Work artifacts](https://github.com/asheriff-bot/loop/blob/main/IMPLEMENTATION_PLAN.md): human review state · Living plan, prompt history, and execution record. · `IMPLEMENTATION_PLAN.md`

## Connections

- Game startup → Flask app and routes: starts
- Flask app and routes → Browser UI: renders
- Browser UI → Client behavior: loads
- Client behavior → Flask app and routes: local HTTP
- Flask app and routes → Mastermind rules: applies rules
- Flask app and routes → Daily challenge: selects challenge
- Flask app and routes → Game persistence: reads and writes state
- Loop CLI startup → PES agent: starts
- PES agent → Assignment stages: tracks progress
- PES agent → Planner: plan
- Planner → Executor: proposed work
- Executor → Summarizer: execution outcome
- Summarizer → Loop memory: records outcome
- Loop memory → Planner: iteration context
- Executor → Agent backends: dispatches
- PES agent → Evaluator: evaluates progress
- Executor → Git workflow: stage commits
- Loop configuration → PES agent: iteration settings
- Role prompts → Planner: plan instructions
- Role prompts → Executor: execute instructions
- Role prompts → Summarizer: summary instructions
- Assignment requirements → Planner: work constraints
- Work artifacts → PES agent: review context
