@@ -14,7 +14,12 @@ codegraph/
1414│ ├── __init__.py # Package init, version definition
1515│ ├── main.py # CLI entry point (click-based)
1616│ ├── core.py # Core graph building logic
17- │ ├── parser.py # Python source code parser
17+ │ ├── parser.py # Python token parser (legacy, used by PythonParser)
18+ │ ├── parsers/ # Pluggable language parsers
19+ │ │ ├── base.py # Parser interface
20+ │ │ ├── python_parser.py # Python parser implementation
21+ │ │ ├── rust_parser.py # Rust parser stub
22+ │ │ ├── registry.py # Parser registry / discovery
1823│ ├── utils.py # Utility functions
1924│ └── vizualyzer.py # Visualization (D3.js + matplotlib)
2025├── tests/ # Test suite
@@ -30,9 +35,25 @@ codegraph/
3035
3136## Core Components
3237
33- ### 1. Parser (` codegraph/parser.py ` )
38+ ### 1. Parser Layer (` codegraph/parsers/ ` )
3439
35- The parser uses Python's ` tokenize ` module to extract code structure from source files.
40+ Parser implementations are pluggable via a registry. Each parser exposes:
41+ - ` get_source_files() ` for language-specific file discovery
42+ - ` parse_files() ` to produce module objects
43+ - ` usage_graph() ` to build dependencies
44+ - ` get_entity_metadata() ` for entity stats
45+
46+ This allows adding new languages without changing core graph orchestration.
47+
48+ #### Python Parser (` codegraph/parsers/python_parser.py ` )
49+
50+ Uses Python's ` ast ` (and ` typed_ast ` for Python 2.x) to extract classes, functions,
51+ imports, and line ranges.
52+
53+ #### Rust Parser (` codegraph/parsers/rust_parser.py ` )
54+
55+ Currently a stub to establish extension points. The intent is to parse ` .rs ` files,
56+ extract functions/structs/impl blocks, and build dependency edges using a Rust-aware parser.
3657
3758** Key Classes:**
3859- ` _Object ` - Base class for all parsed objects (lineno, endno, name, parent)
@@ -52,16 +73,15 @@ The parser uses Python's `tokenize` module to extract code structure from source
5273
5374### 2. Core (` codegraph/core.py ` )
5475
55- The core module builds the dependency graph from parsed data.
76+ The core module orchestrates parsing and visualization by delegating language-specific
77+ work to the selected parser.
5678
5779** Key Classes:**
5880- ` CodeGraph ` - Main class that orchestrates graph building
5981
6082** Key Functions:**
61- - ` get_code_objects(paths_list) ` - Parse all files and return dict of module → objects
62- - ` get_imports_and_entities_lines() ` - Extract imports and entity line ranges
63- - ` collect_entities_usage_in_modules() ` - Find where entities are used
64- - ` search_entity_usage() ` - Check if entity is used in a line
83+ - ` usage_graph() ` - Delegates to the active parser
84+ - ` get_entity_metadata() ` - Delegates to the active parser
6585
6686** Data Flow:**
6787```
0 commit comments