How vsoch/codeart works
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: graphics.py Graphics · main.py CodeBase · colors.py Colors · nlp.py Tokenize
Components 16
CLI / entrypoints
User-facing ways to start the library and generate artifacts.
- CLI · Command-line interface for generating code art artifacts.
codeart/client.py
Analysis core
Repository ingestion, tokenization, grouping, and embedding generation.
- CodeBase · Main programmatic API that ingests code, trains models, and exposes outputs.
codeart/main.py - Tokenize · Extracts code terms and prepares token streams for embedding training.
codeart/nlp.py - Groupers · Reusable grouping logic such as partitioning by year or other custom rules.
codeart/utils.py - 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.
Static assets
Bundled templates, JavaScript, and fonts used in generated output.
- Template · Base HTML template for generated browser views.
codeart/static/template.html - Gallery HTML · Prebuilt HTML view for rendered code art galleries.
codeart/static/codeart.html - Tree HTML · Static tree-style browser view for generated output.
codeart/static/tree.html - Grid HTML · Interactive grid view for comparing generated artifacts.
codeart/static/interactive-grid.html - D3 · Client-side visualization library bundled for interactive pages.
codeart/static/js/d3.v3.js - Fonts · Bundled fonts used by rendered images and text-based outputs.
codeart/fonts
Packaging
Project metadata and distribution support.
- Package API · Package-level exports for the library namespace.
codeart/__init__.py - Setup · Distribution and installation metadata for the Python package.
setup.py - Deps · Declared Python dependencies for training and rendering.
requirements.txt
Connections 16
- 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.