# vsoch/codeart architecture

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

- Interactive diagram: https://gitdiagram.com/vsoch/codeart
- Repository: https://github.com/vsoch/codeart

## Overview

1. **What this repository is**
   Code Art is a Python library and small CLI for turning source code into visual artifacts. Its core idea is to parse repositories or folders, group files by extension or custom logic, train 3D word-embedding models on code tokens, and then render those embeddings as colors, images, and HTML galleries.

2. **Primary entry points**
   The main programmatic API is centered on `codeart.main.CodeBase`. The command-line entry point lives in `codeart/client.py` and currently exposes a `textart` action for generating per-file code images. The README examples also show direct library usage for gallery generation, vector extraction, and image rendering.

3. **Input and repository ingestion**
   `CodeBase` accepts either local folders or GitHub repositories. The ingestion layer walks files beneath a root, filters for readable files, and assigns each file to a group. The default grouping is by extension, but callers can override that with a custom function or an explicit group name.

4. **Corpus organization boundary**
   The repo treats “group” as the central analysis boundary. Groups can be language extensions like `.py` or `.patch`, a catch-all `all` group, or a custom partition such as creation year. This grouping decision drives model training, color statistics, and downstream visualizations.

5. **Tokenization and language analysis**
   `codeart/nlp.py` and related helpers are responsible for extracting terms from code files and preparing them for embedding training. The architecture assumes code tokens can be learned into a semantic space, then reused consistently for visualization across files in the same group or across all groups.

6. **Model training and vector generation**
   `CodeBase.train`, `train_all`, and `get_vectors` form the core analysis pipeline. The system trains a separate model per group or one shared model across groups, with embeddings sized to 3 dimensions so they can be mapped directly into RGB space. The resulting vectors are exposed as tabular data for plotting, CSV export, and color analysis.

7. **Color mapping subsystem**
   `codeart/colors.py` converts embedding vectors into color lookups and color statistics. A key output is the mapping from token to RGB plus prevalence information per group, which is later used to drive opacity/transparency in the interactive colormap views.

8. **Rendering and image generation**
   `codeart/graphics.py` is the presentation layer for turning vectors and color lookups into artifacts. It generates per-file code images, interactive colormap pages, gradient grids, and text-based art. This module is where the analytical data becomes visual output.

9. **Static web assets and browser UI**
   The `codeart/static` directory contains HTML templates and D3-based JavaScript used to render gallery pages and interactive views. This means the package can produce self-contained web output without requiring a running server. The static assets are part of the output boundary, not the analysis pipeline itself.

10. **Supporting utilities and naming**
   `codeart/utils.py` provides reusable grouping helpers, such as grouping files by creation year. `codeart/namer.py` likely handles naming of generated artifacts, while `codeart/version.py` and packaging files support distribution. These are small but important for stable output generation and reproducibility.

11. **Runtime and packaging shape**
   The project is a standard Python package (`setup.py`, `MANIFEST.in`, `requirements.txt`) with bundled fonts and static assets. The presence of GitHub Actions indicates automated CI for packaging or tests. There is no evidence of a long-running backend service; the architecture is batch-oriented and artifact-producing.

12. **End-to-end data flow**
   The overall flow is: ingest files from a repo or folder → group them → tokenize code → train embedding models → convert vectors to RGB colors → render images/HTML/CSV outputs. The main architectural separation is between analysis/modeling in `main.py`/`nlp.py` and presentation in `colors.py`/`graphics.py`/`static`.

Main entry points: [`codeart/graphics.py`](https://github.com/vsoch/codeart/blob/master/codeart/graphics.py) (Graphics), [`codeart/main.py`](https://github.com/vsoch/codeart/blob/master/codeart/main.py) (CodeBase), [`codeart/colors.py`](https://github.com/vsoch/codeart/blob/master/codeart/colors.py) (Colors), [`codeart/nlp.py`](https://github.com/vsoch/codeart/blob/master/codeart/nlp.py) (Tokenize)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_cli["CLI / entrypoints"]
  node_n_client["CLI<br/>entrypoint<br/>[client.py]"]
end

subgraph group_g_core["Analysis core"]
  node_n_main["CodeBase<br/>orchestrator<br/>[main.py]"]
  node_n_nlp["Tokenize<br/>nlp pipeline<br/>[nlp.py]"]
  node_n_utils["Groupers<br/>grouping helpers<br/>[utils.py]"]
  node_n_namer["Naming<br/>[namer.py]"]
end

subgraph group_g_render["Rendering"]
  node_n_colors["Colors<br/>color mapping<br/>[colors.py]"]
  node_n_graphics["Graphics<br/>renderer<br/>[graphics.py]"]
end

subgraph group_g_assets["Static assets"]
  node_n_template["Template<br/>[template.html]"]
  node_n_codeart_html["Gallery HTML<br/>html view<br/>[codeart.html]"]
  node_n_tree_html["Tree HTML<br/>html view<br/>[tree.html]"]
  node_n_grid_html["Grid HTML<br/>html view"]
  node_n_d3["D3<br/>browser js<br/>[d3.v3.js]"]
  node_n_fonts[("Fonts<br/>asset pack")]
end

subgraph group_g_packaging["Packaging"]
  node_n_init["Package API<br/>package facade<br/>[__init__.py]"]
  node_n_setup["Setup<br/>packaging<br/>[setup.py]"]
  node_n_requirements["Deps<br/>dependencies<br/>[requirements.txt]"]
end

node_n_client -->|"invokes"| node_n_main
node_n_main -->|"groups files"| node_n_utils
node_n_main -->|"tokenizes"| node_n_nlp
node_n_main -->|"names outputs"| node_n_namer
node_n_main -->|"builds vectors"| node_n_colors
node_n_main -->|"renders"| node_n_graphics
node_n_nlp -->|"feeds tokens"| node_n_colors
node_n_colors -->|"maps color"| node_n_graphics
node_n_graphics -->|"fills"| node_n_template
node_n_graphics -->|"outputs"| node_n_codeart_html
node_n_graphics -->|"outputs"| node_n_tree_html
node_n_graphics -->|"outputs"| node_n_grid_html
node_n_graphics -->|"uses"| node_n_d3
node_n_graphics -->|"uses"| node_n_fonts
node_n_init -->|"exports"| node_n_main
node_n_setup -->|"declares"| node_n_requirements

click node_n_client "https://github.com/vsoch/codeart/blob/master/codeart/client.py"
click node_n_main "https://github.com/vsoch/codeart/blob/master/codeart/main.py"
click node_n_nlp "https://github.com/vsoch/codeart/blob/master/codeart/nlp.py"
click node_n_utils "https://github.com/vsoch/codeart/blob/master/codeart/utils.py"
click node_n_namer "https://github.com/vsoch/codeart/blob/master/codeart/namer.py"
click node_n_colors "https://github.com/vsoch/codeart/blob/master/codeart/colors.py"
click node_n_graphics "https://github.com/vsoch/codeart/blob/master/codeart/graphics.py"
click node_n_template "https://github.com/vsoch/codeart/blob/master/codeart/static/template.html"
click node_n_codeart_html "https://github.com/vsoch/codeart/blob/master/codeart/static/codeart.html"
click node_n_tree_html "https://github.com/vsoch/codeart/blob/master/codeart/static/tree.html"
click node_n_grid_html "https://github.com/vsoch/codeart/blob/master/codeart/static/interactive-grid.html"
click node_n_d3 "https://github.com/vsoch/codeart/blob/master/codeart/static/js/d3.v3.js"
click node_n_fonts "https://github.com/vsoch/codeart/tree/master/codeart/fonts"
click node_n_init "https://github.com/vsoch/codeart/blob/master/codeart/__init__.py"
click node_n_setup "https://github.com/vsoch/codeart/blob/master/setup.py"
click node_n_requirements "https://github.com/vsoch/codeart/blob/master/requirements.txt"

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_n_client toneBlue
class node_n_main,node_n_nlp,node_n_utils,node_n_namer toneAmber
class node_n_colors,node_n_graphics toneMint
class node_n_template,node_n_codeart_html,node_n_tree_html,node_n_grid_html,node_n_d3,node_n_fonts toneRose
class node_n_init,node_n_setup,node_n_requirements toneIndigo
```

## Components

### CLI / entrypoints

User-facing ways to start the library and generate artifacts.

- [CLI](https://github.com/vsoch/codeart/blob/master/codeart/client.py): entrypoint · Command-line interface for generating code art artifacts. · `codeart/client.py`

### Analysis core

Repository ingestion, tokenization, grouping, and embedding generation.

- [CodeBase](https://github.com/vsoch/codeart/blob/master/codeart/main.py): orchestrator · Main programmatic API that ingests code, trains models, and exposes outputs. · `codeart/main.py`
- [Tokenize](https://github.com/vsoch/codeart/blob/master/codeart/nlp.py): nlp pipeline · Extracts code terms and prepares token streams for embedding training. · `codeart/nlp.py`
- [Groupers](https://github.com/vsoch/codeart/blob/master/codeart/utils.py): grouping helpers · Reusable grouping logic such as partitioning by year or other custom rules. · `codeart/utils.py`
- [Naming](https://github.com/vsoch/codeart/blob/master/codeart/namer.py): artifact naming · Derives stable names for generated files and outputs. · `codeart/namer.py`

### Rendering

Transforms vectors and color data into images, text art, and HTML views.

- [Colors](https://github.com/vsoch/codeart/blob/master/codeart/colors.py): color mapping · Converts embedding vectors into RGB lookups and color statistics. · `codeart/colors.py`
- [Graphics](https://github.com/vsoch/codeart/blob/master/codeart/graphics.py): renderer · Turns vectors and colors into images, galleries, gradients, and text art. · `codeart/graphics.py`

### Static assets

Bundled templates, JavaScript, and fonts used in generated output.

- [Template](https://github.com/vsoch/codeart/blob/master/codeart/static/template.html): html template · Base HTML template for generated browser views. · `codeart/static/template.html`
- [Gallery HTML](https://github.com/vsoch/codeart/blob/master/codeart/static/codeart.html): html view · Prebuilt HTML view for rendered code art galleries. · `codeart/static/codeart.html`
- [Tree HTML](https://github.com/vsoch/codeart/blob/master/codeart/static/tree.html): html view · Static tree-style browser view for generated output. · `codeart/static/tree.html`
- [Grid HTML](https://github.com/vsoch/codeart/blob/master/codeart/static/interactive-grid.html): html view · Interactive grid view for comparing generated artifacts. · `codeart/static/interactive-grid.html`
- [D3](https://github.com/vsoch/codeart/blob/master/codeart/static/js/d3.v3.js): browser js · Client-side visualization library bundled for interactive pages. · `codeart/static/js/d3.v3.js`
- [Fonts](https://github.com/vsoch/codeart/tree/master/codeart/fonts): asset pack · Bundled fonts used by rendered images and text-based outputs. · `codeart/fonts`

### Packaging

Project metadata and distribution support.

- [Package API](https://github.com/vsoch/codeart/blob/master/codeart/__init__.py): package facade · Package-level exports for the library namespace. · `codeart/__init__.py`
- [Setup](https://github.com/vsoch/codeart/blob/master/setup.py): packaging · Distribution and installation metadata for the Python package. · `setup.py`
- [Deps](https://github.com/vsoch/codeart/blob/master/requirements.txt): dependencies · Declared Python dependencies for training and rendering. · `requirements.txt`

## Connections

- CLI → CodeBase: invokes · CLI dispatches into the main analysis API.
- CodeBase → Groupers: groups files · Repository ingestion uses grouping helpers or custom grouping logic.
- CodeBase → Tokenize: tokenizes · CodeBase prepares token streams for model training.
- CodeBase → Naming: names outputs · Generated artifacts are assigned stable names.
- CodeBase → Colors: builds vectors · Training output is transformed into vectors and color mappings.
- CodeBase → Graphics: renders · Analysis results are passed to the rendering layer.
- Tokenize → Colors: feeds tokens · Token extraction supports downstream embedding and color generation.
- Colors → Graphics: maps color · Color statistics and RGB values drive visual output.
- Graphics → Template: fills · Rendered views are assembled from shared HTML templates.
- Graphics → Gallery HTML: outputs · Gallery pages for code art are produced from the renderer.
- Graphics → Tree HTML: outputs · Tree-style browser views are produced from the renderer.
- Graphics → Grid HTML: outputs · Interactive grid views are produced from the renderer.
- Graphics → D3: uses · Interactive visualizations rely on bundled D3 scripts.
- Graphics → Fonts: uses · Image rendering uses bundled font assets.
- Package API → CodeBase: exports · Package namespace exposes the main API.
- Setup → Deps: declares · Packaging depends on the declared runtime requirements.
