Skip to content

Architecture Overview

This document provides an overview of the internal architecture of Code Context Analyzer.


๐Ÿงฑ High-Level Components

The project is composed of several modular layers:

User CLI (cca)
   โ†“
Source Resolver (local path or GitHub URL)
   โ†“
File Discovery (discover_files)
   โ†“
Language Parsers (Python, JS)
   โ†“
Formatter (structured summary)
   โ†“
CLI Output (terminal or clipboard)

๐Ÿ“ Directory Structure

code_context_analyzer/
โ”œโ”€โ”€ /
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ analyzer/
โ”‚   โ”œโ”€โ”€ clipboard.py
โ”‚   โ”œโ”€โ”€ discovery.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ analyzer\parsers/
โ”‚   โ”œโ”€โ”€ base.py
โ”‚   โ”œโ”€โ”€ js_parser.py
โ”‚   โ”œโ”€โ”€ python_parser.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ cli/
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ dto/
โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ formatters/
โ”‚   โ”œโ”€โ”€ base.py
โ”‚   โ”œโ”€โ”€ default.py
โ”‚   โ”œโ”€โ”€ factory.py
โ”‚   โ”œโ”€โ”€ html_formatter.py
โ”‚   โ”œโ”€โ”€ json_formatter.py
โ”‚   โ”œโ”€โ”€ yaml_formatter.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ repo_system/
โ”‚   โ”œโ”€โ”€ handler.py
โ”‚   โ”œโ”€โ”€ session.py
โ”‚   โ””โ”€โ”€ __init__.py
โ””โ”€โ”€ utils/
    โ”œโ”€โ”€ dto_converter.py
    โ”œโ”€โ”€ temp_dir.py
    โ””โ”€โ”€ __init__.py

๐Ÿ”„ Process Flow

  1. User invokes CLI

The user runs:

cca <source> --ignore <some, ingore, patterns>
  1. RepositoryHandler resolves the source

  2. If local path: it validates the directory

  3. If GitHub URL: it clones the repo to a temp dir

  4. walks through the directory

  5. Yields paths and their inferred language

  6. Filters based on extension, test files, max files

  7. Parsers process each file

  8. Python parser uses ast to find classes, functions, constants

  9. JS parser uses regex to extract functions/classes

  10. Formatter builds structured output

  11. Outputs hierarchy based on folder/module structure

  12. Optional truncation

  13. Output sent to terminal or clipboard

  14. If --no-clipboard is passed, summary is copied automatically


๐Ÿ”Œ Extensibility

To add support for a new language:

  1. Create a new parser in parsers/ (e.g. go_parser.py)
  2. Implement the ParserProtocol
  3. Register the parser in registry

Example:

from .go_parser import GoParser

registry = {
    "python": PythonParser(),
    "js": JSParser(),
    "go": GoParser(),  # new
}

๐Ÿงช Testing and Maintenance

  • All modules are designed to be testable independently
  • Temp directories are safely handled via context manager
  • CLI arguments can be tested via unit or integration tests

For detailed module documentation, see Module Reference.