# jagi/meteor-astronomy architecture

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

- Interactive diagram: https://gitdiagram.com/jagi/meteor-astronomy
- Repository: https://github.com/jagi/meteor-astronomy

## Overview

##### Project type and purpose
- This is an open‑source Meteor package (“jagi:astronomy”) that implements an Object‑Document Mapper (ODM) / Model Layer for Meteor/MongoDB.
- Its goal is to let developers define schemas, automatically validate, transform and persist Mongo documents, and extend them with behaviors, events, methods, indexes, validators, etc.

##### High‑level architecture
- Entry point: lib/main.js – registers the package with Meteor and loads the core.
- Core layer: lib/core
- class.js – class-definition engine
- module.js – module registry & loader
- config.js, ejson.js, reserved_keywords.js – global settings & EJSON integration
- Extension modules: lib/modules
- behaviors, events, fields, helpers, indexes, methods, storage, validators
- each module plugs into the class lifecycle via hooks and contributes static methods, instance methods, schemas, Meteor methods, etc.
- Data layer
- Meteor’s Mongo.Collection & DDP
- Storage module orchestrates inserts/updates/removes via Meteor methods or direct calls
- Tests & packaging: test/ and .npm/package – ensure correctness and NPM publication metadata

- Core registry & hook pipeline as the heart of the system
- Module’s role in the pipeline
- How data flows from application code through classes, modules, storage, and into MongoDB

## Diagram (Mermaid)

```mermaid
flowchart TB
    AppCode["Application Code"]:::external
    AstronomyAPI["Astronomy API"]:::api
    subgraph "Core Layer"
        ClassEngine["Class-definition Engine"]:::core
        ModuleLoader["Module Registry & Hook Pipeline"]:::core
        Config["Global Settings (config.js)"]:::core
        EJSON["EJSON Integration (ejson.js)"]:::core
        Reserved["Reserved Keywords (reserved_keywords.js)"]:::core
    end
    subgraph "Hook Pipeline"
        Behaviors["Behaviors Module"]:::module
        Events["Events Module"]:::module
        Fields["Fields Module"]:::module
        Helpers["Helpers Module"]:::module
        Indexes["Indexes Module"]:::module
        Methods["Methods Module"]:::module
        Storage["Storage Module"]:::module
        Validators["Validators Module"]:::module
    end
    MeteorRuntime["Meteor Runtime (Client & Server)"]:::runtime
    MongoDB["MongoDB"]:::db

    AppCode -->|"Class.create/findOne"| AstronomyAPI
    AstronomyAPI -->|"entry: lib/main.js"| ClassEngine
    AstronomyAPI -->|loads| ModuleLoader
    AstronomyAPI -->|loads| Config
    AstronomyAPI -->|loads| EJSON
    AstronomyAPI -->|loads| Reserved

    ModuleLoader -->|"applyDefinition/initClass/initSchema"| Behaviors
    Behaviors --> Events
    Events --> Fields
    Fields --> Helpers
    Helpers --> Indexes
    Indexes --> Methods
    Methods --> Storage
    Storage --> Validators

    Validators -->|"instance.save()/validate()"| Storage
    Storage -->|"CRUD via Mongo.Collection"| MeteorRuntime
    MeteorRuntime -->|"DDP"| MongoDB

    click AstronomyAPI "https://github.com/jagi/meteor-astronomy/blob/v2/lib/main.js"
    click ClassEngine "https://github.com/jagi/meteor-astronomy/blob/v2/lib/core/class.js"
    click ModuleLoader "https://github.com/jagi/meteor-astronomy/blob/v2/lib/core/module.js"
    click Config "https://github.com/jagi/meteor-astronomy/blob/v2/lib/core/config.js"
    click EJSON "https://github.com/jagi/meteor-astronomy/blob/v2/lib/core/ejson.js"
    click Reserved "https://github.com/jagi/meteor-astronomy/blob/v2/lib/core/reserved_keywords.js"
    click Behaviors "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/behaviors/module.js"
    click Events "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/events/module.js"
    click Fields "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/fields/module.js"
    click Helpers "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/helpers/module.js"
    click Indexes "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/indexes/module.js"
    click Methods "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/methods/module.js"
    click Storage "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/storage/module.js"
    click Validators "https://github.com/jagi/meteor-astronomy/blob/v2/lib/modules/validators/module.js"

    classDef core fill:#cce5ff,stroke:#0366d6,color:#000
    classDef module fill:#d4edda,stroke:#28a745,color:#000
    classDef runtime fill:#e2e3e5,stroke:#6c757d,color:#000
    classDef db fill:#ffe5b4,stroke:#d39e00,color:#000
    classDef api fill:#cfe2ff,stroke:#2b6cb0,color:#000
    classDef external fill:#f8d7da,stroke:#721c24,color:#000
```
