# nrjdalal/smart-registry architecture

> Architecture diagram of the GitHub repository nrjdalal/smart-registry, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nrjdalal/smart-registry
- Repository: https://github.com/nrjdalal/smart-registry

## Overview

##### Project Type and Purpose
- This is a Node.js command-line tool (“Smart Registry”) written in TypeScript.
- Purpose: scan a codebase (registry/components folders), automatically detect dependencies and files, and generate a complete, error-free JSON registry for use by the shadcn UI ecosystem.

##### High-Level Architecture
- It’s a single-package CLI application with these major layers:
a. CLI Entry Point (bin/index.ts)
b. File System Scanner & Parser (bin/utils/files + bin/utils/resolvers)
c. Dependency & Import Analyzer (bin/utils/transformer + codemods)
d. Registry Item Builder (bin/constants + builder logic)
e. Output Writer (generates JSON under public/r or configured output)

##### Main Components and Their Interactions
- User invokes `npx smart‐registry [options]` → CLI Entry
- CLI Entry
- Parses flags (output dir, cwd, patterns)
- Calls File System Scanner
- File System Scanner
- Walks `registry/`, `components/`, or custom paths
- Collects file metadata (paths, types)
- Hands files to Dependency Analyzer
- Dependency & Import Analyzer
- Reads and parses each TypeScript/TSX file
- Extracts import statements for:
– runtime dependencies (e.g. “@radix-ui/react-dialog”)
– registry dependencies (other registry items)
- Builds a file/component dependency graph
- Registry Item Builder
- For each scanned file, consolidates:
– name, type (ui, lib, hooks, etc.)
– list of dependencies
– list of related files (with content snippets)
- Merges with any existing root `registry.json` extensions
- Output Writer
- Emits per-item JSON under `public/r/<item>.json`
- Emits a combined `public/r/registry.json`

##### Architectural Patterns & Principles
- Modular functional decomposition:
- “bin” folder holds entry points and high-level orchestration
- “bin/utils/files” for file traversal concerns
- “bin/utils/resolvers” for import resolution concerns
- Zero-Configuration defaulting: no required config file → uses convention (registry/components folder names)
- Dependency inversion: CLI parsing, file scanning, and JSON generation layers depend on abstracted utility modules

##### Technology Stack
- Node.js + TypeScript
- TSup for bundling (`tsup.config.ts`)
- Bun lockfile (`bun.lock`) supported
- GitHub Actions workflows for CI (`.github/workflows/*.yml`)
- File system: native `fs` + custom utilities
- Parser: TS AST via TypeScript compiler API (used in transformer)
- JSON I/O for final registry

- User → CLI Parser → File Scanner → Analyzer → Builder → Writer
- Green for input sources
- Blue for processing modules
- Orange for output stores
- Rectangles for code modules

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::user
    CLIEntry["CLI Entry Point"]:::process
    CLIParser["CLI Parser & Helpers"]:::process
    FileScanner["File System Scanner & Parser"]:::process
    DepAnalyzer["Dependency & Import Analyzer"]:::process
    Builder["Registry Item Builder"]:::process
    Writer["JSON Writer"]:::process
    SourceFS[(registry/, components/)]:::input
    OutputFS[(public/r)]:::output

    User --> CLIEntry
    CLIEntry --> CLIParser
    CLIParser --> FileScanner
    FileScanner --> SourceFS
    FileScanner --> DepAnalyzer
    DepAnalyzer --> Builder
    Builder --> Writer
    Writer --> OutputFS

    click CLIEntry "https://github.com/nrjdalal/smart-registry/blob/main/bin/index.ts"
    click CLIParser "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/aliases.ts"
    click CLIParser "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/get-package-manager.ts"
    click FileScanner "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/files/index.ts"
    click FileScanner "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/files/find-file.ts"
    click FileScanner "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/files/list-files.ts"
    click FileScanner "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/files/list-registry-files.ts"
    click FileScanner "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/files/get-input-registry.ts"
    click DepAnalyzer "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/resolvers/index.ts"
    click DepAnalyzer "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/resolvers/data-resolver.ts"
    click DepAnalyzer "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/resolvers/type-resolver.ts"
    click DepAnalyzer "https://github.com/nrjdalal/smart-registry/blob/main/bin/utils/transformer.ts"
    click DepAnalyzer "https://github.com/nrjdalal/smart-registry/blob/main/bin/codemods/kebab-case.ts"
    click DepAnalyzer "https://github.com/nrjdalal/smart-registry/blob/main/bin/codemods/radix.ts"
    click Builder "https://github.com/nrjdalal/smart-registry/blob/main/bin/constants/orders.ts"
    click Builder "https://github.com/nrjdalal/smart-registry/blob/main/bin/constants/regex.ts"
    click Writer "https://github.com/nrjdalal/smart-registry/blob/main/tsup.config.ts"

    classDef user fill:#999,stroke:#333,color:#fff
    classDef input fill:#cfc,stroke:#393,color:#000
    classDef process fill:#ccf,stroke:#339,color:#000
    classDef output fill:#fcf,stroke:#933,color:#000
```
