# zennoptionxct/am-reverse architecture

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

- Interactive diagram: https://gitdiagram.com/zennoptionxct/am-reverse
- Repository: https://github.com/zennoptionxct/am-reverse

## Overview

AlightMotion Premium Activate provides a CLI and web interface for email magic-link sign-in and premium verification. The main web flow sends a link, accepts the returned link, authenticates the user, requests premium verification, and reports the outcome; the CLI also supports refreshing a saved session and viewing saved sessions. The map includes the web API, CLI, and statistics state. The web page’s detailed request wiring was not sampled, so its connection to the API is based on the README’s description of the web workflow.

Main entry points: [`am.js`](https://github.com/zennoptionxct/am-reverse/blob/main/am.js) (CLI), [`app/api/route.js`](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/route.js) (API Router), [`lib/auth.js`](https://github.com/zennoptionxct/am-reverse/blob/main/lib/auth.js) (Auth Client), [`app/api/verify-link/route.js`](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/verify-link/route.js) (Verify Link)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User Interfaces"]
  node_webui["Web UI<br/>[index.html]"]
  node_cli["CLI<br/>[am.js]"]
end

subgraph group_web["Web API"]
  node_server["HTTP Server<br/>[server.js]"]
  node_api["API Router<br/>[route.js]"]
  node_status["Status Route<br/>[route.js]"]
  node_send["Send Link<br/>[route.js]"]
  node_verify["Verify Link<br/>[route.js]"]
  node_statsroute["Stats Route<br/>[route.js]"]
end

subgraph group_auth["Authentication"]
  node_authlib["Auth Client<br/>[auth.js]"]
  node_errors["Error Mapping<br/>[errors.js]"]
end

subgraph group_state["Local State"]
  node_statslib["Stats Logic<br/>[stats.js]"]
  node_statsfile[("Stats File<br/>[stats.json]")]
  node_sessions[("CLI Sessions<br/>[am.js]")]
end

node_user(("User"))
node_identity{{"Firebase Identity"}}
node_tokens{{"Firebase Tokens"}}
node_purchase{{"Purchase Verification"}}

node_user -->|"uses"| node_webui
node_user -->|"runs"| node_cli
node_webui -->|"sends requests"| node_server
node_server -->|"mounts API"| node_api
node_api -->|"dispatches"| node_status
node_api -->|"dispatches"| node_send
node_api -->|"dispatches"| node_verify
node_api -->|"dispatches"| node_statsroute
node_send -->|"requests link"| node_authlib
node_send -->|"formats errors"| node_errors
node_verify -->|"authenticates, verifies"| node_authlib
node_verify -->|"formats errors"| node_errors
node_verify -->|"updates or reads"| node_statslib
node_statsroute -->|"reads counts"| node_statslib
node_statslib -->|"reads and writes"| node_statsfile
node_authlib -->|"requests sign-in"| node_identity
node_authlib -->|"submits verification"| node_purchase
node_authlib -->|"refreshes token"| node_tokens
node_cli -->|"requests sign-in"| node_identity
node_cli -->|"submits verification"| node_purchase
node_cli -->|"refreshes token"| node_tokens
node_cli -->|"reads and writes"| node_sessions

click node_webui "https://github.com/zennoptionxct/am-reverse/blob/main/public/index.html"
click node_cli "https://github.com/zennoptionxct/am-reverse/blob/main/am.js"
click node_server "https://github.com/zennoptionxct/am-reverse/blob/main/server.js"
click node_api "https://github.com/zennoptionxct/am-reverse/blob/main/app/api/route.js"
click node_status "https://github.com/zennoptionxct/am-reverse/blob/main/app/api/status/route.js"
click node_send "https://github.com/zennoptionxct/am-reverse/blob/main/app/api/send-link/route.js"
click node_verify "https://github.com/zennoptionxct/am-reverse/blob/main/app/api/verify-link/route.js"
click node_statsroute "https://github.com/zennoptionxct/am-reverse/blob/main/app/api/stats/route.js"
click node_authlib "https://github.com/zennoptionxct/am-reverse/blob/main/lib/auth.js"
click node_errors "https://github.com/zennoptionxct/am-reverse/blob/main/lib/errors.js"
click node_statslib "https://github.com/zennoptionxct/am-reverse/blob/main/lib/stats.js"
click node_statsfile "https://github.com/zennoptionxct/am-reverse/blob/main/data/stats.json"
click node_sessions "https://github.com/zennoptionxct/am-reverse/blob/main/am.js"

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_webui,node_cli,node_user toneBlue
class node_server,node_api,node_status,node_send,node_verify,node_statsroute toneAmber
class node_authlib,node_errors toneMint
class node_statslib,node_statsfile,node_sessions toneRose
class node_identity,node_tokens,node_purchase toneIndigo
```

## Components

### User Interfaces

- [Web UI](https://github.com/zennoptionxct/am-reverse/blob/main/public/index.html): `public/index.html`
- [CLI](https://github.com/zennoptionxct/am-reverse/blob/main/am.js): `am.js`

### Web API

- [HTTP Server](https://github.com/zennoptionxct/am-reverse/blob/main/server.js): `server.js`
- [API Router](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/route.js): `app/api/route.js`
- [Status Route](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/status/route.js): `app/api/status/route.js`
- [Send Link](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/send-link/route.js): `app/api/send-link/route.js`
- [Verify Link](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/verify-link/route.js): `app/api/verify-link/route.js`
- [Stats Route](https://github.com/zennoptionxct/am-reverse/blob/main/app/api/stats/route.js): `app/api/stats/route.js`

### Authentication

- [Auth Client](https://github.com/zennoptionxct/am-reverse/blob/main/lib/auth.js): `lib/auth.js`
- [Error Mapping](https://github.com/zennoptionxct/am-reverse/blob/main/lib/errors.js): `lib/errors.js`

### Local State

- [Stats Logic](https://github.com/zennoptionxct/am-reverse/blob/main/lib/stats.js): `lib/stats.js`
- [Stats File](https://github.com/zennoptionxct/am-reverse/blob/main/data/stats.json): `data/stats.json`
- [CLI Sessions](https://github.com/zennoptionxct/am-reverse/blob/main/am.js): `am.js`

### Other components

- **User**
- **Firebase Identity**
- **Firebase Tokens**
- **Purchase Verification**

## Connections

- User → Web UI: uses
- User → CLI: runs
- Web UI → HTTP Server: sends requests
- HTTP Server → API Router: mounts API
- API Router → Status Route: dispatches
- API Router → Send Link: dispatches
- API Router → Verify Link: dispatches
- API Router → Stats Route: dispatches
- Send Link → Auth Client: requests link
- Send Link → Error Mapping: formats errors
- Verify Link → Auth Client: authenticates, verifies
- Verify Link → Error Mapping: formats errors
- Verify Link → Stats Logic: updates or reads
- Stats Route → Stats Logic: reads counts
- Stats Logic → Stats File: reads and writes
- Auth Client → Firebase Identity: requests sign-in
- Auth Client → Purchase Verification: submits verification
- Auth Client → Firebase Tokens: refreshes token
- CLI → Firebase Identity: requests sign-in
- CLI → Purchase Verification: submits verification
- CLI → Firebase Tokens: refreshes token
- CLI → CLI Sessions: reads and writes
