# fuse441/jsonsync architecture

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

- Interactive diagram: https://gitdiagram.com/fuse441/jsonsync
- Repository: https://github.com/fuse441/jsonsync

## Overview

##### Project type and purpose
- This is a VS Code extension (“JsonSync”) that runs inside the VS Code Extension Host.
- Its purpose is to read JSON configuration files from the user’s workspace, connect to a MongoDB database, compare each JSON file against a specified MongoDB collection, and report differences in the VS Code Output panel.

##### File structure
- Top-level entries:
- extension.js – the main activation and command handler for the extension
- package.json / package-lock.json – dependencies, VS Code extension metadata, activation events, command contributions
- eslint.config.mjs, jsconfig.json – linting and editor intellisense config
- .vscodeignore – files to exclude when packaging the extension
- test/extension.test.js – unit tests for the comparison logic
- .vscode*/.gitignore/CHANGELOG.md/vsc-extension-quickstart.md – tooling and documentation
- No separate frontend/backend: the extension runs entirely in Node.js within VS Code.

##### README for additional insights
- Reads an .env file for MongoDB connection parameters and JSON folder path.
- Defines two internal arrays of collection names: arrCollection and commonCollection.
- Exposes a single command (“Compare JSON”) bound to the Command Palette.

a. Main components
- VS Code IDE (host platform)
- VS Code Extension Host (Node.js runtime)
- JsonSync Extension Module (extension.js)
- Workspace JSON Files directory (COMMON)
- .env Configuration (DATABASE_URL, DATABASE_NAME, COMMON)
- MongoDB Service (external database)
- VS Code Output Panel (UI output surface)
b. Relationships and interactions
1. User invokes “Compare JSON” command in VS Code.
2. Extension Host calls the activate() function in extension.js.
3. JsonSync module loads .env, reads workspace JSON files.
4. JsonSync opens a connection to MongoDB at DATABASE_URL, selects DATABASE_NAME.
5. For each configured collection (arrCollection + commonCollection), extension fetches documents.
6. JsonSync compares in-memory JSON file contents to MongoDB documents.
7. Results (match/no-match) are written to the Output Panel.
c. Architectural patterns and principles
- Event-driven design via VS Code’s Command API and Extension Host lifecycle
- Single responsibility: separate reading config, fetching data, diffing, and reporting
- Dependency inversion: extension.js depends on abstracted MongoDB client and file-system reader
d. Key technologies and libraries
- VS Code Extension API (vscode module)
- Node.js fs/promises for file I/O
- dotenv for loading .env
- MongoDB Node.js Driver for database operations
- Mocha/Jest (or similar) for test/extension.test.js

## Diagram (Mermaid)

```mermaid
flowchart TD
    VSCode["VS Code IDE"]:::vscode
    VSCode -->|"onCommand:jsonSync.compare"| ExtensionHost["Extension Host\n(Node.js runtime)"]:::vscode

    subgraph "Extension Host"
        JsonSync["JsonSync Extension Module"]:::extension
        PackageJSON["VS Code Extension Metadata & Activation\n(package.json)"]:::config
        Env[".env Loader"]:::extension
        Reader["JSON File Reader & Diff Engine"]:::extension
        MongoClient["MongoDB Client Integration"]:::extension
        Comparer["Comparer Engine"]:::extension
        Reporter["VS Code Output Panel Reporter"]:::extension

        JsonSync --> PackageJSON
        JsonSync --> Env
        JsonSync --> Reader
        JsonSync --> MongoClient
        JsonSync --> Comparer
        JsonSync --> Reporter

        Env -->|"load config"| JsonSync
        Reader -->|"JSON data"| JsonSync
        MongoClient -->|"DB query results"| JsonSync
        Comparer -->|"diff report"| Reporter
    end

    Folder["Workspace JSON Files\n(COMMON)"]:::external
    Mongo["MongoDB Service"]:::external

    Reader -->|reads| Folder
    MongoClient -->|connects| Mongo

    subgraph "Testing"
        Test["Unit Tests\n(test/extension.test.js)"]:::test
    end
    Test -.-> Reader
    Test -.-> Comparer

    Lint["Lint Config\n(eslint.config.mjs)"]:::config
    Intelli["Editor Intellisense\n(jsconfig.json)"]:::config
    Ignore["Packaging Ignore\n(.vscodeignore)"]:::config
    Docs1["README.md"]:::docs
    Docs2["CHANGELOG.md"]:::docs
    Docs3["vsc-extension-quickstart.md"]:::docs

    VSCode --> Lint
    VSCode --> Intelli
    VSCode --> Ignore
    VSCode --> Docs1
    VSCode --> Docs2
    VSCode --> Docs3

    classDef vscode fill:#add8e6,stroke:#333,stroke-width:1px
    classDef extension fill:#98fb98,stroke:#333,stroke-width:1px
    classDef external fill:#ffa500,stroke:#333,stroke-width:1px
    classDef config fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef test fill:#f4cccc,stroke:#333,stroke-width:1px
    classDef docs fill:#fff2cc,stroke:#333,stroke-width:1px

    click JsonSync "https://github.com/fuse441/jsonsync/blob/master/extension.js"
    click PackageJSON "https://github.com/fuse441/jsonsync/blob/master/package.json"
    click Test "https://github.com/fuse441/jsonsync/blob/master/test/extension.test.js"
    click Lint "https://github.com/fuse441/jsonsync/blob/master/eslint.config.mjs"
    click Intelli "https://github.com/fuse441/jsonsync/blob/master/jsconfig.json"
    click Ignore "https://github.com/fuse441/jsonsync/blob/master/.vscodeignore"
    click Docs1 "https://github.com/fuse441/jsonsync/blob/master/README.md"
    click Docs2 "https://github.com/fuse441/jsonsync/blob/master/CHANGELOG.md"
    click Docs3 "https://github.com/fuse441/jsonsync/blob/master/vsc-extension-quickstart.md"
```
