loqatevars
Version:
Locate JavaScript files with 'const' or 'process.env' usage in LLM-generated codebases
25 lines (17 loc) • 1.86 kB
Markdown
# Architecture
This project, `loqatevars`, is a Node.js command-line tool designed to analyze JavaScript codebases. Its primary function is to identify files that contain `const` variable declarations and `process.env` usage.
The architecture is composed of three main layers:
1. **Command-Line Interface (CLI)**: The entry point for user interaction is [`cli.js`](cli.js). It is responsible for parsing command-line arguments, handling user commands (`scan`, `detailed`, `help`), and displaying the final output to the console.
2. **Core Logic Library**: The core functionality resides in the `lib/` directory, specifically within [`lib/utils.js`](lib/utils.js). This module contains the functions responsible for:
* Traversing the file system to find relevant files.
* Reading file contents.
* Parsing JavaScript code into an Abstract Syntax Tree (AST) using the `acorn` library.
* Analyzing the AST to detect `const` declarations (while intelligently ignoring those used for `require` statements) and `process.env` access.
3. **Module Entry Point**: The [`index.js`](index.js) file serves as the main entry point for the `npm` package. It exposes the core scanning functions (`findMatchingFiles` and `findMatchingFilesDetailed`) for programmatic use in other projects.
## Data Flow
The typical data flow is as follows:
1. A user executes a command via the `loqatevars` CLI.
2. [`cli.js`](cli.js) parses the arguments and invokes the corresponding function from [`lib/utils.js`](lib/utils.js).
3. The function in [`lib/utils.js`](lib/utils.js) scans the target directory, reads files, and analyzes their content.
4. The results are returned to [`cli.js`](cli.js), which then formats and prints the output to the user.
Configuration, such as directories to ignore, is managed in [`config/localVars.js`](config/localVars.js).