# z33mscessex/code_recycle architecture

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

- Interactive diagram: https://gitdiagram.com/z33mscessex/code_recycle
- Repository: https://github.com/z33mscessex/code_recycle

## Overview

code_recycle is a local-first search tool for reusing code and verified research notes. The main workflow is to configure folders and rules, scan eligible files, split them into searchable entries, build a SQLite index, then search it and return locations and snippets with reuse rules and secret checks applied. Users can run this through the CLI or an MCP client; optional local embeddings augment keyword ranking. The graph follows the shown CLI, indexing, search, and server calls; unsampled secret-scanner internals are represented only as a subsystem.

Main entry points: [`code_recycle/cli.py`](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/cli.py) (CLI commands), [`code_recycle/search.py`](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/search.py) (Search and ranking), [`code_recycle/index.py`](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/index.py) (Index builder), [`code_recycle/server.py`](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/server.py) (MCP server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_cli["CLI commands<br/>[cli.py]"]
  node_server["MCP server<br/>[server.py]"]
  node_settings["Settings loader<br/>[settings.py]"]
end

subgraph group_indexing["Index construction"]
  node_walker["File walker<br/>[files.py]"]
  node_secret_screen["Secret screening<br/>[secret_check.py]"]
  node_chunking["Chunk parsing<br/>[chunks.py]"]
  node_builder["Index builder<br/>[index.py]"]
end

subgraph group_retrieval["Search and safeguards"]
  node_search["Search and ranking<br/>[search.py]"]
  node_result_scan["Result secret check<br/>[secret_check.py]"]
  node_answer["Answer formatting<br/>[search.py]"]
end

subgraph group_storage["Local index and embeddings"]
  node_db[("SQLite search index<br/>[index.py]")]
  node_embed["Embedding support<br/>[embed.py]"]
end

node_user(("User"))
node_mcp_host(("MCP client"))
node_folders["Local folders"]

node_user -->|"runs commands"| node_cli
node_cli -->|"loads settings"| node_settings
node_mcp_host -->|"launches tool"| node_server
node_server -->|"loads settings"| node_settings
node_cli -->|"builds index"| node_builder
node_cli -->|"runs search"| node_search
node_cli -->|"starts server"| node_server
node_server -->|"runs search"| node_search
node_server -->|"formats answer"| node_answer
node_folders -->|"provides files"| node_walker
node_settings -->|"sets scan rules"| node_walker
node_walker -->|"scans files"| node_secret_screen
node_builder -->|"walks folders"| node_walker
node_builder -->|"splits files"| node_chunking
node_builder -->|"writes chunks"| node_db
node_builder -.->|"creates vectors"| node_embed
node_search -->|"reads candidates"| node_db
node_search -.->|"augments ranking"| node_embed
node_search -->|"checks results"| node_result_scan
node_search -->|"formats results"| node_answer
node_cli -->|"prints results"| node_user
node_answer -->|"returns answer"| node_mcp_host

click node_cli "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/cli.py"
click node_server "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/server.py"
click node_settings "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/settings.py"
click node_walker "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/files.py"
click node_secret_screen "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/secret_check.py"
click node_chunking "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/chunks.py"
click node_builder "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/index.py"
click node_db "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/index.py"
click node_embed "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/embed.py"
click node_search "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/search.py"
click node_result_scan "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/secret_check.py"
click node_answer "https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/search.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_cli,node_server,node_settings,node_user,node_mcp_host toneBlue
class node_walker,node_secret_screen,node_chunking,node_builder toneAmber
class node_search,node_result_scan,node_answer toneMint
class node_db,node_embed toneRose
class node_folders toneIndigo
```

## Components

### User entry points

- [CLI commands](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/cli.py): `code_recycle/cli.py`
- [MCP server](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/server.py): `code_recycle/server.py`
- [Settings loader](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/settings.py): `code_recycle/settings.py`

### Index construction

- [File walker](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/files.py): `code_recycle/files.py`
- [Secret screening](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/secret_check.py): `code_recycle/secret_check.py`
- [Chunk parsing](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/chunks.py): `code_recycle/chunks.py`
- [Index builder](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/index.py): `code_recycle/index.py`

### Search and safeguards

- [Search and ranking](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/search.py): `code_recycle/search.py`
- [Result secret check](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/secret_check.py): `code_recycle/secret_check.py`
- [Answer formatting](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/search.py): `code_recycle/search.py`

### Local index and embeddings

- [SQLite search index](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/index.py): `code_recycle/index.py`
- [Embedding support](https://github.com/z33mscessex/code_recycle/blob/main/code_recycle/embed.py): `code_recycle/embed.py`

### Other components

- **User**
- **MCP client**
- **Local folders**

## Connections

- User → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → Settings loader: loads settings (evidence: `code_recycle/cli.py`)
- MCP client → MCP server: launches tool (evidence: `README.md`)
- MCP server → Settings loader: loads settings (evidence: `code_recycle/server.py`)
- CLI commands → Index builder: builds index (evidence: `code_recycle/cli.py`)
- CLI commands → Search and ranking: runs search (evidence: `code_recycle/cli.py`)
- CLI commands → MCP server: starts server (evidence: `code_recycle/cli.py`)
- MCP server → Search and ranking: runs search (evidence: `code_recycle/server.py`)
- MCP server → Answer formatting: formats answer (evidence: `code_recycle/server.py`)
- Local folders → File walker: provides files
- Settings loader → File walker: sets scan rules (evidence: `code_recycle/files.py`)
- File walker → Secret screening: scans files (evidence: `code_recycle/files.py`)
- Index builder → File walker: walks folders (evidence: `code_recycle/index.py`)
- Index builder → Chunk parsing: splits files (evidence: `code_recycle/index.py`)
- Index builder → SQLite search index: writes chunks (evidence: `code_recycle/index.py`)
- Index builder → Embedding support: creates vectors (evidence: `code_recycle/index.py`)
- Search and ranking → SQLite search index: reads candidates (evidence: `code_recycle/search.py`)
- Search and ranking → Embedding support: augments ranking (evidence: `code_recycle/search.py`)
- Search and ranking → Result secret check: checks results (evidence: `code_recycle/search.py`)
- Search and ranking → Answer formatting: formats results (evidence: `code_recycle/cli.py`)
- CLI commands → User: prints results (evidence: `code_recycle/cli.py`)
- Answer formatting → MCP client: returns answer
