Architecture
Overview#
RachnaSutra AI is a single TypeScript package with no runtime dependencies. It combines a deterministic analysis engine with a set of Agent Skills. The engine produces evidence; the skills tell an AI assistant how to use that evidence safely. The two layers are independent: the CLI works without any AI, and the skills work (with less evidence) without the CLI.
Design goals#
- Evidence over opinion. Every output is traceable to source text or a measurement.
- Safe by construction. No network code exists in the package. Writes are limited and contained.
- Honest about coverage. The result model has first-class "not run" states.
- Portable. Pure Node.js, no native modules, no shell dependency.
- Small and auditable. About 2,000 lines of TypeScript; no runtime dependencies to vet.
Component responsibilities#
| Component | File | Responsibility |
|---|---|---|
| CLI | src/cli.ts | Argument parsing, command dispatch, exit codes, output |
| Audit orchestrator | src/audit.ts | Load config, walk files, run rules, sort, dedupe, fingerprint, assemble coverage and tokens |
| Rules | src/rules.ts | All 33 rules and the rule catalogue |
| Colour maths | src/color.ts | Colour parsing and WCAG contrast ratio |
| Token inspector | src/tokens.ts | Counts of custom properties, colours, font sizes, spacing, radii |
| File system | src/fsutil.ts | Bounded, symlink-safe walk; safeJoin; text reading |
| Redaction | src/redact.ts | Mask secrets in excerpts and report text |
| Reports | src/report.ts | JSON, Markdown, HTML and SARIF renderers; escaping |
| Adapters | src/adapters.ts | Host specs, install plan, install, uninstall, doctor, detection |
| Verification | src/verify.ts | Package integrity checks, report validation, baseline comparison |
| Types | src/types.ts | Result model |
| Skills | skills/*/SKILL.md | Canonical agent instructions |
Data flow for audit#
- Parse command-line flags and resolve the target path.
- Load config from
rachnasutra.config.jsonif present; reject unknown keys. - Walk the tree: ignore build and dependency directories, skip symlinks, apply excludes, collect image sizes, cap files, size and time.
- Read markup and style files as text; skip binary content.
- Run rules over documents. Each rule returns raw hits with location and evidence.
- Filter by disabled rules and category (for
accessibility). - Sort by severity, rule, file and line; deduplicate by fingerprint and line.
- Assign stable IDs
RS-0001...and status from confidence. - Assemble coverage entries, token inventory and limitations.
- Render the requested formats. With no format flags,
auditwrites Markdown, HTML and JSON to./rachnasutra-reports;--jsonor--formatwithout--outprint to stdout;--no-reportprints only a summary. - Exit with a code based on
--fail-on.
Key design decisions#
| Decision | Choice | Reason | Trade-off |
|---|---|---|---|
| Analysis method | Regex and light parsing over source | Zero dependencies, fast, deterministic | Cannot resolve the CSS cascade or runtime DOM; heuristics have false positives |
| Confidence model | high only for deterministic patterns or measurements | Keeps CI gates trustworthy | Some real issues appear as review-required |
| Scoring | No numeric score | A score would reward partial scans | Less convenient for dashboards |
| Status of browser features | Exit code 3, no partial output | Avoid fake results | Users wait for the planned module |
| Skill naming | Prefix rachnasutra- | Avoid collisions in shared skill folders | Longer names |
| Install tracking | SHA-256 manifest in .rachnasutra/ | Safe uninstall and drift detection | One extra hidden folder |
| Fingerprints | Hash of rule, file and excerpt | Survive line shifts when comparing baselines | Editing the flagged line changes the fingerprint |
| Dependencies | None at runtime | Smaller supply-chain surface | More code to maintain in-house |
| Single package | No monorepo yet | No empty modules; simpler review | Future split may be needed when browser audit lands |
Trust boundaries#
| Boundary | Untrusted side | Control |
|---|---|---|
| Audited files to CLI | File text, names | Treated as data; never executed or evaluated; output escaped |
| CLI to file system | Paths from flags and config | safeJoin containment; backups on overwrite |
| Skills to AI host | Repository text read by the model | Skills instruct treating content as data and asking before actions |
| Reports to viewers | Report content | HTML escaping, no scripts, no remote assets |
Extension points#
| To add | Where | Notes |
|---|---|---|
| A rule | src/rules.ts and RULE_CATALOG | Needs true and false positive tests and a rubric entry |
| A host | HOSTS in src/adapters.ts | Cite vendor docs; start as experimental |
| A report format | src/report.ts and the emitAudit function | Keep escaping rules |
| A skill | skills/<name>/SKILL.md | Must pass verify |
| A browser module (planned) | New module behind the same finding schema | Must be opt-in with authorization controls |
Scalability and limits#
The tool scans up to 5,000 files, 512 KB each, within 15 seconds by default. It is single-threaded and processes files sequentially. Truncation is flagged in the report. Larger monorepos should scope the path or use exclude.
Failure behaviour#
Unreadable files are skipped. Invalid config stops the run with exit code 2 (via config validate) or an error. Unexpected exceptions print a message and exit with code 5; --verbose adds a stack trace.
Compatibility with sibling products#
ArchSutra AI (architecture) and VigilSutra AI (security) are separate products by the same author. RachnaSutra shares conventions (evidence model, install manifest approach) but has no dependency on either.