# phialsbasement/chain-of-recursive-thoughts architecture

> Architecture diagram of the GitHub repository phialsbasement/chain-of-recursive-thoughts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phialsbasement/chain-of-recursive-thoughts
- Repository: https://github.com/phialsbasement/chain-of-recursive-thoughts

## Overview

##### Project type and purpose
- From the README (“Chain of Recursive Thoughts”) and file tree, this is a full-stack web application whose core logic (“CoRT”) implements recursive AI self-evaluation by generating, comparing, and selecting alternative responses.
- The frontend is a React/Tailwind UI; the backend is Python scripts (`recthink_web.py`, `recursive_thinking_ai.py`) that orchestrate LLM calls (via OpenRouter, Mistral 3.1 etc.).

##### File structure
- Top-level:
- `frontend/`: Create-React-App project (JSX components, context, API helper, Tailwind config).
- `recthink_web.py`: Python web server entrypoint.
- `recursive_thinking_ai.py`: Core AI orchestration library.
- `requirements.txt`: Python deps.
- `demos/`: standalone demo scripts for CLI usage.
- Key patterns:
- Frontend/Backend separation.
- API layer (`frontend/src/api.js`) calling backend endpoints.
- AI orchestration layer in Python.

##### Additional architectural insights from README
- The system loops: initial generation → N thinking rounds → multiple alternatives → self-evaluation → pick best.
- Web UI is “early dev” so the Python server likely serves a REST or WebSocket API for the React app.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        RA["React App"]:::frontend
        IDX["index.js"]:::frontend
        APP["App.js & App.css"]:::frontend
        APIH["api.js"]:::frontend
        UI["RecursiveThinkingInterface.jsx"]:::frontend
        CNTX["RecThinkContext.js"]:::frontend
        TW["tailwind.config.js"]:::frontend
        PJSON["package.json"]:::frontend
        PLOCK["package-lock.json"]:::frontend
    end

    %% Server Layer
    subgraph "Server (Python)"
        direction TB
        API["recthink_web.py"]:::backend
        AI["recursive_thinking_ai.py"]:::backend
        REQ["requirements.txt"]:::backend
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LLM["Mistral 3.1 / OpenRouter API"]:::external
    end

    %% CLI Demos
    subgraph "CLI Demos"
        direction TB
        D1["rec-tic-tac.py"]:::cli
        D2["tic-tac.py"]:::cli
    end

    %% Data Flow
    RA -->|"HTTP/WS API Call"| API
    API -->|"invoke recursion"| AI
    AI -->|"initial prompt & rounds"| LLM
    LLM -->|"responses"| AI
    AI -->|"final selection"| API
    API -->|"API Response"| RA

    D1 -->|"CLI invocation"| AI
    D2 -->|"CLI invocation"| AI

    %% Click Events
    click RA "https://github.com/phialsbasement/chain-of-recursive-thoughts/tree/main/frontend/"
    click IDX "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/src/index.js"
    click APP "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/src/App.js"
    click APIH "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/src/api.js"
    click UI "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/src/components/RecursiveThinkingInterface.jsx"
    click CNTX "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/src/context/RecThinkContext.js"
    click TW "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/tailwind.config.js"
    click PJSON "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/package.json"
    click PLOCK "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/frontend/package-lock.json"
    click API "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/recthink_web.py"
    click AI "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/recursive_thinking_ai.py"
    click REQ "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/requirements.txt"
    click D1 "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/demos/rec-tic-tac.py"
    click D2 "https://github.com/phialsbasement/chain-of-recursive-thoughts/blob/main/demos/tic-tac.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef cli fill:#FFD700,stroke:#333,stroke-width:1px
```
