# How the pieces fit

Tidepool is three small parts: a fetcher that downloads station constants once a year, a predictor that turns them into heights, and the apps that draw the curve.

## Data flow

```mermaid
flowchart LR
    NOAA[(NOAA CO-OPS)] -->|yearly constants| Fetch[Fetcher]
    Fetch --> Store[(Station store)]
    Store --> Predict[Predictor]
    Predict --> Web[Web app]
    Predict --> CLI[Command line]
    Web --> Cache[(Offline cache)]
```

The predictor is pure: same constants and same time range in, same numbers out. That makes it easy to test against NOAA's own published tables.

## Opening a station on the phone

```mermaid
sequenceDiagram
    participant U as You
    participant A as App
    participant C as Offline cache
    participant S as Station store
    U->>A: Tap "Port Calloway"
    A->>C: Constants cached?
    alt cached
        C-->>A: Constants
    else not cached
        A->>S: GET /v2/stations/9414290
        S-->>A: Constants
        A->>C: Save
    end
    A->>A: Predict 7 days
    A-->>U: Draw the curve
```

## Release states

```mermaid
stateDiagram-v2
    [*] --> Draft
    Draft --> Review: pull request
    Review --> Draft: changes requested
    Review --> Frozen: merged before freeze
    Frozen --> Released: tag vX.Y.0
    Released --> [*]
```

## Where the code lives

| Folder | What's in it |
| --- | --- |
| `fetch/` | Downloader and the yearly cron job |
| `predict/` | The harmonic sum, node factors, turn finder |
| `web/` | The site and the offline cache |
| `cli/` | The `tidepool` command |
