# nitishrajput01/date-plugin-vanilla architecture

> Architecture diagram of the GitHub repository nitishrajput01/date-plugin-vanilla, 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/nitishrajput01/date-plugin-vanilla
- Repository: https://github.com/nitishrajput01/date-plugin-vanilla

## Overview

##### Project type and purpose
- This is a tiny, chainable, zero-dependency date formatting and difference-calculator plugin published to npm.
- It exposes three main APIs:
- formatDate() – one-off formatter
- GetFormattedDate() – chainable builder for adding days/months then retrieving a date
- getDiffBetweenDates() – computes difference in seconds/minutes/hours/days/months/years

##### File structure
- Top-level files:
- package.json/package-lock.json – npm metadata & dependencies
- README.md – documentation & usage
- .gitignore/.npmignore – VCS & packaging rules
- LICENSE – MIT license
- src/ directory:
- babel.config.js – Babel configuration for transpile targets
- index.ts – exports the public API and ties together modules
- timezone.ts – internal utility for parsing/formats/locales/timezones
- index.test.ts – unit tests for core functionality
- tsconfig.json – TypeScript compiler settings

##### README for additional insights
- Confirms supported features (formatting, chaining, diff calculation)
- Mentions upcoming locale/timezone support extensions

##### Main components
a. Public API layer
- formatDate() function
- GetFormattedDate class (chainable methods: addDays(), addMonths(), .date)
- getDiffBetweenDates() function
b. Core utilities
- timezone.ts – parsing, locale, timezone handling stubbed now, extended later
- internal date math functions (add/subtract, diff calculations)
c. Build & distribution pipeline
- TypeScript compiler (tsconfig.json)
- Babel transpiler (babel.config.js)
- npm packaging (package.json, .npmignore)
d. Test harness
- index.test.ts (Jest or similar)
e. External consumer
- Any Node or browser application that imports the plugin

##### Relationships and interactions
- The Public API layer calls into Core utilities to perform formatting, date arithmetic, and diff calculations.
- On code change, the source is fed through the TypeScript compiler → Babel → bundled module → published to npm.
- Tests import the built (or TS) modules to validate behavior before release.
- End-user code imports the published module and drives the Public API.

##### Architectural patterns & design principles
- Modular layering: clear separation between API, utility modules, and build pipeline
- Chainable / fluent interface for GetFormattedDate
- Single Responsibility Principle: each module handles one concern (formatting vs. parsing vs. differences)
- Extensible: timezone module can be swapped/enhanced to support more locales/timezones

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% API Layer
    subgraph "API Layer"
        direction TB
        formatDate["formatDate()"]:::code
        GetFormattedDate["GetFormattedDate()"]:::code
        getDiffBetweenDates["getDiffBetweenDates()"]:::code
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        TimezoneUtil["timezone.ts"]:::code
        DateMath["Date Math Functions"]:::code
    end

    %% Build Pipeline
    subgraph "Build Pipeline"
        direction TB
        TSCompiler["TypeScript Compiler"]:::pipeline
        Babel["Babel Transpiler"]:::pipeline
        subgraph "npm Packaging"
            direction TB
            pkgMeta["package.json"]:::pipeline
            npmIgnore[".npmignore"]:::pipeline
        end
    end

    %% Test Suite
    subgraph "Test Suite"
        direction TB
        UnitTests["index.test.ts"]:::pipeline
    end

    %% Published Module
    PublishedModule["Published Module"]:::pipeline

    %% External Consumer
    ConsumerApp["Consumer Application"]:::consumer

    %% Relationships
    formatDate -->|"uses"| TimezoneUtil
    formatDate -->|"uses"| DateMath
    GetFormattedDate -->|"uses"| DateMath
    getDiffBetweenDates -->|"uses"| DateMath

    %% Build/Test flows
    formatDate -.->|transpiles| TSCompiler
    TimezoneUtil -.->|transpiles| TSCompiler
    DateMath -.->|transpiles| TSCompiler

    TSCompiler -->|"transpiles to"| Babel
    Babel -->|"bundles"| pkgMeta
    Babel -->|"bundles"| npmIgnore
    Babel -->|"produces"| PublishedModule

    UnitTests -.->|"tests"| formatDate
    UnitTests -.->|"tests"| GetFormattedDate
    UnitTests -.->|"tests"| getDiffBetweenDates
    UnitTests -.->|"tests"| TimezoneUtil
    UnitTests -.->|"tests"| DateMath

    PublishedModule -->|"imports from npm"| ConsumerApp

    %% Click Events
    click formatDate "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/src/index.ts"
    click GetFormattedDate "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/src/index.ts"
    click getDiffBetweenDates "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/src/index.ts"
    click TimezoneUtil "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/src/timezone.ts"
    click TSCompiler "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/tsconfig.json"
    click Babel "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/src/babel.config.js"
    click pkgMeta "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/package.json"
    click npmIgnore "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/.npmignore"
    click UnitTests "https://github.com/nitishrajput01/date-plugin-vanilla/blob/main/src/index.test.ts"

    %% Styles
    classDef code fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef pipeline fill:#DFF2BF,stroke:#4F8A10,color:#4F8A10
    classDef consumer fill:#FFE4B5,stroke:#D2691E,color:#D2691E
```
