# fusionstrings/swiss-eph architecture

> Architecture diagram of the GitHub repository fusionstrings/swiss-eph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fusionstrings/swiss-eph
- Repository: https://github.com/fusionstrings/swiss-eph

## Overview

This repository provides Swiss Ephemeris astronomical calculations through native Rust bindings and a WebAssembly interface for JavaScript/TypeScript runtimes. The principal JS workflow loads a WASM module, constructs a calculation facade, marshals inputs through linear memory, calls exported ephemeris functions, and returns typed results. Domain capabilities include date/time conversion, planetary positions, houses, eclipses, and related astronomical calculations. Rust also exposes raw FFI and a safer idiomatic API. WASI emulation enables module execution across runtimes; detailed Rust internals and unsampled subsystems are represented only where documented.

Main entry points: [`src/main.ts`](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts) (Calculation API), [`crates/swiss-eph/src/lib.rs`](https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph/src/lib.rs) (Raw FFI), [`src/loader.ts`](https://github.com/fusionstrings/swiss-eph/blob/creation/src/loader.ts) (Module Loader), [`src/wasi.ts`](https://github.com/fusionstrings/swiss-eph/blob/creation/src/wasi.ts) (WASI Services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_js["JavaScript WASM API"]
  node_loader["Module Loader<br/>[loader.ts]"]
  node_facade["Calculation API<br/>[main.ts]"]
  node_heap["Memory Marshaling<br/>[heap.ts]"]
  node_bindings["Export Signatures<br/>[api.ts]"]
  node_date["Date Conversion<br/>[main.ts]"]
  node_positions["Planet Positions<br/>[main.ts]"]
  node_houses["Houses &amp; Angles<br/>[main.ts]"]
  node_eclipses["Eclipse Calculations<br/>[main.ts]"]
  node_astronomy["Other Calculations<br/>[main.ts]"]
end

subgraph group_runtime["WASM Runtime"]
  node_wasi["WASI Services<br/>[wasi.ts]"]
  node_wasm{{"Swiss Ephemeris WASM"}}
  node_ephe[("Ephemeris Data<br/>[lib.rs]")]
end

subgraph group_rust["Rust Bindings"]
  node_ffi["Raw FFI<br/>[lib.rs]"]
  node_safe["Safe Rust API<br/>[safe.rs]"]
end

node_user(("JS/TS Caller"))

node_user -->|"loads API"| node_loader
node_loader -->|"constructs"| node_facade
node_facade -->|"initializes"| node_wasi
node_facade -->|"marshals memory"| node_heap
node_facade -->|"uses signatures"| node_bindings
node_facade -->|"calls exports"| node_wasm
node_wasi -->|"provides imports"| node_wasm
node_wasm -.->|"exports bindings"| node_ffi
node_safe -->|"wraps calls"| node_ffi
node_facade -->|"converts dates"| node_date
node_facade -->|"calculates positions"| node_positions
node_facade -->|"calculates houses"| node_houses
node_facade -->|"calculates eclipses"| node_eclipses
node_facade -->|"calculates phenomena"| node_astronomy
node_ffi -.->|"uses ephemeris"| node_ephe

click node_loader "https://github.com/fusionstrings/swiss-eph/blob/creation/src/loader.ts"
click node_facade "https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts"
click node_heap "https://github.com/fusionstrings/swiss-eph/blob/creation/src/heap.ts"
click node_bindings "https://github.com/fusionstrings/swiss-eph/blob/creation/src/generated/api.ts"
click node_wasi "https://github.com/fusionstrings/swiss-eph/blob/creation/src/wasi.ts"
click node_ephe "https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph-data/src/lib.rs"
click node_ffi "https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph/src/lib.rs"
click node_safe "https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph/src/safe.rs"
click node_date "https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts"
click node_positions "https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts"
click node_houses "https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts"
click node_eclipses "https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts"
click node_astronomy "https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_facade,node_heap,node_bindings,node_date,node_positions,node_houses,node_eclipses,node_astronomy toneBlue
class node_wasi,node_wasm,node_ephe toneAmber
class node_ffi,node_safe toneMint
class node_user toneIndigo
```

## Components

### JavaScript WASM API

- [Module Loader](https://github.com/fusionstrings/swiss-eph/blob/creation/src/loader.ts): `src/loader.ts`
- [Calculation API](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts): `src/main.ts`
- [Memory Marshaling](https://github.com/fusionstrings/swiss-eph/blob/creation/src/heap.ts): `src/heap.ts`
- [Export Signatures](https://github.com/fusionstrings/swiss-eph/blob/creation/src/generated/api.ts): `src/generated/api.ts`
- [Date Conversion](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts): `src/main.ts`
- [Planet Positions](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts): `src/main.ts`
- [Houses & Angles](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts): `src/main.ts`
- [Eclipse Calculations](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts): `src/main.ts`
- [Other Calculations](https://github.com/fusionstrings/swiss-eph/blob/creation/src/main.ts): `src/main.ts`

### WASM Runtime

- [WASI Services](https://github.com/fusionstrings/swiss-eph/blob/creation/src/wasi.ts): `src/wasi.ts`
- **Swiss Ephemeris WASM**
- [Ephemeris Data](https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph-data/src/lib.rs): `crates/swiss-eph-data/src/lib.rs`

### Rust Bindings

- [Raw FFI](https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph/src/lib.rs): `crates/swiss-eph/src/lib.rs`
- [Safe Rust API](https://github.com/fusionstrings/swiss-eph/blob/creation/crates/swiss-eph/src/safe.rs): `crates/swiss-eph/src/safe.rs`

### Other components

- **JS/TS Caller**

## Connections

- JS/TS Caller → Module Loader: loads API (evidence: `README.md`)
- Module Loader → Calculation API: constructs (evidence: `src/loader.ts`)
- Calculation API → WASI Services: initializes (evidence: `src/main.ts`)
- Calculation API → Memory Marshaling: marshals memory (evidence: `src/main.ts`)
- Calculation API → Export Signatures: uses signatures (evidence: `src/main.ts`)
- Calculation API → Swiss Ephemeris WASM: calls exports (evidence: `src/main.ts`)
- WASI Services → Swiss Ephemeris WASM: provides imports
- Swiss Ephemeris WASM → Raw FFI: exports bindings
- Safe Rust API → Raw FFI: wraps calls (evidence: `crates/swiss-eph/src/safe.rs`)
- Calculation API → Date Conversion: converts dates (evidence: `README.md`)
- Calculation API → Planet Positions: calculates positions (evidence: `README.md`)
- Calculation API → Houses & Angles: calculates houses (evidence: `README.md`)
- Calculation API → Eclipse Calculations: calculates eclipses (evidence: `src/main.ts`)
- Calculation API → Other Calculations: calculates phenomena (evidence: `src/main.ts`)
- Raw FFI → Ephemeris Data: uses ephemeris
