Target refactor: simplify codebase structures and optimize risk parsing performance#392
Open
lalit-t0251068 wants to merge 6 commits into
Open
Target refactor: simplify codebase structures and optimize risk parsing performance#392lalit-t0251068 wants to merge 6 commits into
lalit-t0251068 wants to merge 6 commits into
Conversation
Introduces Claude Code configuration for AI-assisted development on ISRA. CLAUDE.md - Documents monorepo structure (lib/ vs app/), IPC architecture, ISO 27005 data model, validation pattern, file formats, testing, linting, and Electron security constraints — giving Claude full project context. .claude/settings.json (hooks) - PostToolUse: auto-runs ESLint --fix on any lib/**/*.js file after an edit - PreToolUse: blocks direct edits to package-lock.json .claude/agents/security-reviewer.md - Electron security specialist agent: reviews against Electron hardening rules, OWASP Desktop App Top 10, IPC input sanitization, XXE/XSS risks in xml-json/, and file path traversal in data-load/data-store/ .claude/agents/test-writer.md - Jest test generator: writes unit and integration tests for lib/src/ following existing patterns (AJV validation, round-trip load/save, handler mocking) .claude/skills/project-conventions/SKILL.md - Loads ISRA-specific conventions (data model hierarchy, IPC pattern, validation approach, URL scheme allowlist) before code generation .claude/skills/run-tests/SKILL.md - One-command skill that runs the full Jest suite with coverage for lib/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Excludes files that waste context without helping Claude understand the code: - node_modules/, dist/, coverage/ — generated/installed, not source - lib/doc/APIdocumentation/ — generated JSDoc output - app/src/asset/ images — binary files Claude cannot use - lib/test/integration/fixtures/ — large JSON/XML test data (read on demand) - doc/*.xlsx — binary Office document - package-lock.json files — auto-generated, never hand-edited Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ormance - Simplify utility counter closure by removing redundant IIFE wrapper and unused parameters. - Optimize alterRisks parsing loop by moving businessAssets and supportingAssets lookup map constructions outside the per-risk forEach loop, reducing overhead from O(N*M) to O(1) inside loop. - Streamline parser.js editName spelling corrections by replacing nested .match checks with chained .replace operations. - Remove redundant immediately invoked anonymous destructuring functions in alter-business-assets.js. - Remove redundant self-invoking function wrappers in alter-isra.js. - Clean up guaranteed-truthy ternary checks in populate-class.js. - Save full analysis in SIMPLIFICATION_PLAN.md. All 311 unit and integration tests passing successfully.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: simplify codebase structures and optimize risk parsing performance
📝 Overview
This pull request introduces a comprehensive series of codebase simplifications and performance optimizations across 6 core files within the$O(N \times M)$ parsing loop bottleneck.
libmodule. These improvements focus on removing redundant wrappers, simplifying complex syntactic patterns (such as immediately-invoked anonymous functions and nested ternaries), and resolving a high-impactAll changes strictly preserve existing functional behavior and public API contracts, verified by 100% success of the local test suite.
🚀 Key Improvements & Performance Impact
1. Risk Parsing Optimization ($O(N \times M) \rightarrow O(1)$ lookup)
lib/src/api/xml-json/alter-isra/alter-risks.js.forEachloop, the lookup mapsbusinessAssetsandsupportingAssetswere completely rebuilt from scratch on every single iteration from static input arrays. This was a classic performance hotspot for large SRA/XML datasets.2. Spelling Corrections Streamlining (Chained
.replace)lib/src/api/xml-json/parser.jseditNamehelper function relied on five separate, chained.match()checks paired with ternary expressions to sanitize XML tags..replaceoperations directly. SinceString.prototype.replacenatively returns the original string unchanged if there is no match, this removes the redundant conditional checks and matches, improving both speed and readability.3. Redundant Closure & IIFE Removals
lib/src/utility-global.js&lib/src/api/xml-json/alter-isra/alter-isra.jsutility-global.jsfrom a nested Immediately Invoked Function Expression (IIFE) with warning suppressions (no-unused-vars) into a standard CommonJS module directly exporting a cleancounterclosure.(israJSONDataCopy, xmlDataCopy) => { ... })(israJSONData, xmlData)insidealterISRAand executed the logic directly in the parent scope.4. Code Clarity & Syntax Flattening
lib/src/api/xml-json/alter-isra/alter-business-assets.js&lib/src/api/xml-json/populate-class.js(({ props }) => ({ props }))(ba)with standard ES6 destructuring and object assignment forba.businessAssetProperties.highestBAId? highestBAId: businessAssetIdwhere the variable is guaranteed to be a truthy pre-incremented number.🛠️ Verification & Test Coverage
All modifications have been validated locally using Jest:
19 passed, 19 total311 passed, 311 total📁 Files Modified
lib/src/utility-global.jslib/src/api/xml-json/parser.js.replaceineditName.lib/src/api/xml-json/alter-isra/alter-business-assets.jsbusinessAssetProperties.lib/src/api/xml-json/alter-isra/alter-isra.jslib/src/api/xml-json/alter-isra/alter-risks.jslib/src/api/xml-json/populate-class.jsSIMPLIFICATION_PLAN.md