# lnquy/cron architecture

> Architecture diagram of the GitHub repository lnquy/cron, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lnquy/cron
- Repository: https://github.com/lnquy/cron

## Overview

##### Main Components

a. Core Library Components:
- Parser Module (parser.go)
- Expression Descriptor (cron.go)
- Localization System (locale.go)
- Options Handler (option.go)

b. CLI Application:
- hcron Command Line Interface (cmd/hcron)

##### Component Relationships

**┌─ Input Layer ─────────────┐**
- CRON Expression String  │
- Locale Selection        │
- Configuration Options   │
- ┬────────────┘
- ↓
**┌─ Core Processing ─────────────────────┐**
- ┌─ Parser ────────┐  ┌─ Descriptor ─┐ │
- Tokenization  │→ │ - Expression │ │
- Validation    │  │   Analysis   │ │
- ┘  │ - Human Text │ │
- Generation  │ │
- ┬────────┘ │
- ┼──────────┘
- ↓
**┌─ Localization Engine ──────────────┐**
- ┌─ i18n Manager ─────────────────┐ │
- 26 Language Support          │ │
- Locale-specific Formatting   │ │
- ┘ │
- ┬───────────────┘
- ↓
**┌─ Output Layer ────────────────────┐**
- Human Readable Description      │
- Localized Text                 │
- ┘

##### Important Details

a. Input Processing:
- Supported CRON formats (5-7 parts)
- Configuration options (24h format, DoW starts at one, etc.)

b. Parser Details:
- Special character support (* / , - ? L W #)
- Validation rules

c. Localization:
- 26 supported locales
- Locale selection flow

##### Implementation Notes

- Transformation flow from CRON expression to human text
- Clear separation between core library and CLI tool

##### Special Features to Highlight

- Quartz Job Scheduler compatibility
- Multiple locale support
- Various input methods for CLI (direct input, pipe, crontab file)

Remember to include a note about the project's origin as a port from cron-expression-descriptor (C#) via cRonstrue (Javascript), as this provides important context about the architecture decisions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        CronStr["CRON Expression String"]
        LocaleSelect["Locale Selection"]
        ConfigOpt["Configuration Options"]
    end

    subgraph CoreProcessing
        subgraph ParserModule
            Parser["Parser"]:::parser
            Token["Tokenization"]
            Valid["Validation"]
        end

        subgraph DescriptorModule
            Desc["Expression Descriptor"]:::descriptor
            Analysis["Expression Analysis"]
            HumanGen["Human Text Generation"]
        end
    end

    subgraph LocalizationEngine
        I18N["i18n Manager"]:::locale
        LangFiles["Language Files"]:::i18n
        LocaleFormat["Locale-specific Formatting"]
    end

    subgraph CLI
        HCron["hcron CLI"]:::cli
        DirectInput["Direct Input"]
        PipeInput["Pipe Input"]
        CrontabInput["Crontab File"]
    end

    subgraph Output
        HumanText["Human Readable Description"]
        LocalizedOutput["Localized Text"]
    end

    %% Relationships
    CronStr --> Parser
    LocaleSelect --> I18N
    ConfigOpt --> Parser

    Parser --> Token
    Token --> Valid
    Valid --> Desc
    
    Desc --> Analysis
    Analysis --> HumanGen
    HumanGen --> I18N
    
    I18N --> LangFiles
    I18N --> LocaleFormat
    LocaleFormat --> LocalizedOutput
    
    DirectInput --> HCron
    PipeInput --> HCron
    CrontabInput --> HCron
    HCron --> Parser

    %% Styling
    classDef parser fill:#90EE90
    classDef descriptor fill:#98FB98
    classDef locale fill:#FFA500
    classDef cli fill:#ADD8E6
    classDef i18n fill:#FFD700

    %% Click events
    click Parser "https://github.com/lnquy/cron/blob/master/parser.go"
    click Desc "https://github.com/lnquy/cron/blob/master/cron.go"
    click I18N "https://github.com/lnquy/cron/blob/master/locale.go"
    click HCron "https://github.com/lnquy/cron/blob/master/cmd/hcron/main.go"
    click LangFiles "https://github.com/lnquy/cron/tree/master/i18n"

    %% Legend
    subgraph Legend
        L1["Parser Components"]:::parser
        L2["Descriptor Components"]:::descriptor
        L3["Localization Components"]:::locale
        L4["CLI Components"]:::cli
        L5["Language Support"]:::i18n
    end
```
