# novfensec/codekivy architecture

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

- Interactive diagram: https://gitdiagram.com/novfensec/codekivy
- Repository: https://github.com/novfensec/codekivy

## Overview

#### Purpose and Runtime
CodeKivy is a Visual Studio Code extension for Kivy’s KvLang (`.kv`) UI files. It provides language registration, TextMate syntax highlighting, snippets, and completion informed by Python classes/properties in the active workspace. The host runtime is VS Code’s Node.js extension API; Python is invoked for source analysis and Kivy is the target framework.

#### Extension Entry and Activation
The extension’s JavaScript controller is the VS Code-facing entry point, responsible for activation, language features, workspace integration, and invoking analysis:
- `src/extension.js`
- `package.json`

VS Code loads the extension according to manifest contributions/activation metadata in `package.json`. The controller operates on editor documents and workspace files rather than serving a web application.

#### KvLang Language Surface
KvLang editor behavior is defined through three declarative assets:
- `language-configuration.json`
- `syntaxes/kvlang.tmLanguage.json`
- `snippets/kvlang.json`

The language configuration establishes editing behavior; the TextMate grammar tokenizes `.kv` syntax for highlighting; snippets supply reusable KvLang constructs. These are independent VS Code contribution layers consumed directly by the editor.

#### Python Workspace Analysis
Python source inspection is isolated in:
- `src/parser.py`

This forms the boundary between the Node-based extension host and Python/Kivy-oriented project code. The extension scans or refreshes workspace Python files, delegates parsing to Python, and uses extracted custom widget classes and property definitions to augment completions in KvLang documents. Python availability on `PATH` is therefore a material runtime dependency; analysis quality depends on current workspace source.

#### Completion and Live Refresh Flow
Primary control flow is:
1. VS Code activates the JavaScript extension for KvLang work.
2. `src/extension.js` registers completion behavior and file/workspace listeners.
3. Python-file changes trigger workspace re-analysis through `src/parser.py`.
4. Parsed widget/property metadata is retained or refreshed in the extension host.
5. While editing `.kv` files, completion merges Kivy-oriented suggestions with discovered project-defined classes/properties.

The critical boundary is asynchronous process/data exchange between `src/extension.js` and `src/parser.py`; failures in Python discovery or parsing should degrade custom suggestions without breaking syntax highlighting or snippets.

#### Packaging and Distribution
The extension is packaged as an npm/VS Code extension project:
- `package.json`
- `package-lock.json`
- `assets`

`assets` contains marketplace-facing extension resources, including the icon referenced by project documentation. The external distribution surface is the VS Code Marketplace; Kivy itself is not bundled and must exist in the user’s Python environment.

Main entry points: [`package.json`](https://github.com/novfensec/codekivy/blob/master/package.json) (Extension Manifest), [`src/extension.js`](https://github.com/novfensec/codekivy/blob/master/src/extension.js) (Extension Controller), [`src/parser.py`](https://github.com/novfensec/codekivy/blob/master/src/parser.py) (Python Parser), [`language-configuration.json`](https://github.com/novfensec/codekivy/blob/master/language-configuration.json) (Language Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vscode["VS Code Extension"]
  node_vs_code{{"VS Code<br/>editor host"}}
  node_manifest["Extension Manifest<br/>npm manifest<br/>[package.json]"]
  node_controller["Extension Controller<br/>extension entry<br/>[extension.js]"]
  node_kv_document["KvLang Documents<br/>editor document"]
end

subgraph group_language["KvLang Contributions"]
  node_language_config["Language Configuration<br/>editing rules"]
  node_grammar["TextMate Grammar<br/>syntax grammar"]
  node_snippets["KvLang Snippets<br/>snippet catalog<br/>[kvlang.json]"]
end

subgraph group_analysis["Workspace Analysis"]
  node_workspace_python["Workspace Python Files<br/>project source"]
  node_parser["Python Parser<br/>source analyzer<br/>[parser.py]"]
  node_metadata[("Widget Metadata<br/>completion cache")]
  node_python_runtime{{"Python on PATH<br/>runtime dependency"}}
end

subgraph group_distribution["Packaging"]
  node_package_lock["Dependency Lockfile<br/>npm lockfile<br/>[package-lock.json]"]
  node_assets["Marketplace Assets<br/>extension resources"]
  node_marketplace{{"VS Code Marketplace<br/>distribution channel"}}
end

node_vs_code -->|"loads"| node_manifest
node_manifest -->|"activates"| node_controller
node_manifest -->|"contributes"| node_language_config
node_manifest -->|"contributes"| node_grammar
node_manifest -->|"contributes"| node_snippets
node_language_config -->|"editing behavior"| node_kv_document
node_grammar -->|"syntax highlighting"| node_kv_document
node_snippets -->|"snippet suggestions"| node_kv_document
node_controller -->|"registers completion"| node_kv_document
node_workspace_python -->|"change events"| node_controller
node_controller -.->|"invokes asynchronously"| node_parser
node_python_runtime -->|"executes"| node_parser
node_workspace_python -->|"analyzes"| node_parser
node_parser -->|"extracts"| node_metadata
node_metadata -->|"refreshes cache"| node_controller
node_controller -->|"merges project suggestions"| node_kv_document
node_manifest -->|"resolved dependencies"| node_package_lock
node_assets -->|"published with"| node_marketplace
node_manifest -->|"packaged and published"| node_marketplace

click node_manifest "https://github.com/novfensec/codekivy/blob/master/package.json"
click node_controller "https://github.com/novfensec/codekivy/blob/master/src/extension.js"
click node_language_config "https://github.com/novfensec/codekivy/blob/master/language-configuration.json"
click node_grammar "https://github.com/novfensec/codekivy/blob/master/syntaxes/kvlang.tmLanguage.json"
click node_snippets "https://github.com/novfensec/codekivy/blob/master/snippets/kvlang.json"
click node_parser "https://github.com/novfensec/codekivy/blob/master/src/parser.py"
click node_package_lock "https://github.com/novfensec/codekivy/blob/master/package-lock.json"
click node_assets "https://github.com/novfensec/codekivy/tree/master/assets"

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_vs_code,node_manifest,node_controller,node_kv_document toneBlue
class node_language_config,node_grammar,node_snippets toneAmber
class node_workspace_python,node_parser,node_metadata,node_python_runtime toneMint
class node_package_lock,node_assets,node_marketplace toneRose
```

## Components

### VS Code Extension

Node.js extension-host runtime.

- **VS Code**: editor host · Loads contributions and runs the extension host.
- [Extension Manifest](https://github.com/novfensec/codekivy/blob/master/package.json): npm manifest · Declares activation and language contributions. · `package.json`
- [Extension Controller](https://github.com/novfensec/codekivy/blob/master/src/extension.js): extension entry · Registers language features, listeners, and analysis calls. · `src/extension.js`
- **KvLang Documents**: editor document · Active .kv files receive completion and editor behavior.

### KvLang Contributions

Editor-consumed language assets.

- [Language Configuration](https://github.com/novfensec/codekivy/blob/master/language-configuration.json): editing rules · Defines KvLang editing behavior. · `language-configuration.json`
- [TextMate Grammar](https://github.com/novfensec/codekivy/blob/master/syntaxes/kvlang.tmLanguage.json): syntax grammar · Tokenizes KvLang for highlighting. · `syntaxes/kvlang.tmLanguage.json`
- [KvLang Snippets](https://github.com/novfensec/codekivy/blob/master/snippets/kvlang.json): snippet catalog · Provides reusable KvLang constructs. · `snippets/kvlang.json`

### Workspace Analysis

Python-backed project metadata discovery.

- **Workspace Python Files**: project source · Current source used to discover custom widgets and properties.
- [Python Parser](https://github.com/novfensec/codekivy/blob/master/src/parser.py): source analyzer · Extracts widget classes and property definitions. · `src/parser.py`
- **Widget Metadata**: completion cache · Discovered classes and properties retained by the extension host.
- **Python on PATH**: runtime dependency · Runs workspace source analysis.

### Packaging

Marketplace distribution resources.

- [Dependency Lockfile](https://github.com/novfensec/codekivy/blob/master/package-lock.json): npm lockfile · `package-lock.json`
- [Marketplace Assets](https://github.com/novfensec/codekivy/tree/master/assets): extension resources · Includes marketplace-facing resources such as the icon. · `assets`
- **VS Code Marketplace**: distribution channel

## Connections

- VS Code → Extension Manifest: loads
- Extension Manifest → Extension Controller: activates
- Extension Manifest → Language Configuration: contributes
- Extension Manifest → TextMate Grammar: contributes
- Extension Manifest → KvLang Snippets: contributes
- Language Configuration → KvLang Documents: editing behavior
- TextMate Grammar → KvLang Documents: syntax highlighting
- KvLang Snippets → KvLang Documents: snippet suggestions
- Extension Controller → KvLang Documents: registers completion
- Workspace Python Files → Extension Controller: change events
- Extension Controller → Python Parser: invokes asynchronously · Re-analysis crosses the Node-to-Python process boundary.
- Python on PATH → Python Parser: executes
- Workspace Python Files → Python Parser: analyzes
- Python Parser → Widget Metadata: extracts
- Widget Metadata → Extension Controller: refreshes cache
- Extension Controller → KvLang Documents: merges project suggestions
- Extension Manifest → Dependency Lockfile: resolved dependencies
- Marketplace Assets → VS Code Marketplace: published with
- Extension Manifest → VS Code Marketplace: packaged and published
