This document details the internal architecture, scan execution pipeline, rule engine schemas, and extension guide for @putervision/spc (Space Proof Code).
SPC operates as a zero-dependency static analysis pipeline built entirely on native Node.js filesystem APIs and regex pattern matching algorithms.
flowchart TD
A[CLI Entry: bin/cli.js] --> B[loadConfig: .spc.config.json]
A --> C[loadSpcIgnore: .spcignore]
B --> D[scanCodebase: lib/scanner.js]
C --> D
D --> E[loadPlugins: custom rule plugins]
E --> F[Directory Walker & File Discovery]
F --> G[Routing Engine: Match Filename & Extension]
G --> H[analyzeFile: lib/scanner.js]
H --> I[Pattern Regex Matcher]
H --> J[Function Length Counter]
H --> K[Unchecked Return Checker]
H --> L[Suppression Filter: spc-disable]
I --> M[Collect Raw Issues]
J --> M
K --> M
L --> N[Filtered Issues]
N --> O[formatResults: lib/formatter.js]
O --> P[Output: Table / JSON / MD / SARIF]
Each language and AI configuration rule engine exports a pattern configuration object:
const CustomPatterns = {
language: 'custom_lang',
category: 'security', // 'nasa' | 'security' | 'quality' | 'agent'
extensions: ['.ext1', '.ext2'], // Optional extension routing
filenames: ['Customfile', 'config.custom'], // Optional filename routing
patterns: {
rule_name: /regex_pattern/gi,
},
function_regex: /^function\s+\w+/,
ignore_functions: ['safeFunc'],
critical_functions: ['criticalFunc'],
void_return_indicator: 'void',
};
module.exports = { CustomPatterns };SPC automatically loads custom plugins placed in a project's ./plugins directory or specified via --config. A plugin is a JavaScript file exporting a pattern configuration object matching the schema above.
Example custom plugin (plugins/custom_rules.js):
module.exports = {
name: 'my_custom_plugin',
language: 'javascript',
extensions: ['.js'],
patterns: {
custom_forbidden_api: /\bforbiddenApiCall\s*\(/g,
},
};To add support for a new programming language or config file type:
- Create a new pattern module in
lib/lang/<language>.js. - Register the export in
LANGUAGE_PATTERNSinsidelib/scanner.js. - Add rule severities and URLs to
PATTERN_INFOinlib/info.js. - Add test fixtures in
test/examples/bad-example.<ext>. - Add unit test assertions in
test/scanner.test.jsandtest/patterns.test.js.