RankLens
Officialby agentfirsthq
README.md
<p align="center">
<img src="apps/web/public/logo.svg" alt="RankLens" height="56">
</p>
<h3 align="center">App Store keyword rankings for your apps and every competitor. Self-hosted on Cloudflare.</h3>
<p align="center">
Tracks the full top 200 for every keyword in every storefront, once a day,<br>
and serves it to a dashboard and to your agent over MCP. No API keys, no subscription.
</p>
<p align="center">
<a href="LICENSE"><img src="https://img.shields.io/github/license/agentfirsthq/ranklens?color=111111" alt="MIT license"></a>
<img src="https://img.shields.io/badge/Cloudflare-Workers%20%2B%20D1-111111" alt="Cloudflare Workers + D1">
<img src="https://img.shields.io/badge/MCP-6%20tools-111111" alt="MCP server with 6 tools">
<img src="https://img.shields.io/badge/platform-iOS%20App%20Store-111111" alt="iOS App Store">
</p>
<p align="center">
<a href="#deploy"><b>Deploy</b></a> ·
<a href="#add-apps-and-keywords"><b>Keywords</b></a> ·
<a href="#dashboard"><b>Dashboard</b></a> ·
<a href="#use-it-from-your-agent"><b>MCP</b></a> ·
<a href="#rest-api"><b>API</b></a> ·
<a href="#try-the-demo"><b>Demo</b></a>
</p>
<p align="center">
<picture>
<source media="(prefers-color-scheme: light)" srcset=".github/dashboard-light.webp">
<img src=".github/dashboard-dark.webp" alt="RankLens dashboard: KPIs, rank distribution and the keyword table" width="900">
</picture>
</p>
## Why
ASO tools charge per keyword and show you one position: yours. One App Store search already returns the whole top 200, so RankLens keeps all of it. From the same request you get:
- **Your position** for every keyword in every storefront, with the 7-day change.
- **Every competitor** in the top 200 and how they moved over 1, 7 and 30 days.
- **Opportunities**: keywords where you sit outside the top 10 while competitors hold the top 5.
- **History** you own, in your own D1 database.
Collection is slow and cheap by design: one Apple request per keyword × storefront per day, rate-limited by `RPM` (2 per minute by default).
## Deploy
You need a Cloudflare account, Node 24+ and pnpm.
```bash
git clone https://github.com/agentfirsthq/ranklens.git
cd ranklens
pnpm install
# 1. Create the database, then put its id into wrangler.jsonc → d1_databases[0].database_id
npx wrangler d1 create ranklens
# 2. Apply the schema
pnpm db:migrate:remote
# 3. Set the access token. It guards the dashboard, /api, /mcp and /admin.
npx wrangler secret put ADMIN_TOKEN
# 4. Point VITE_SITE_URL in apps/web/.env at your Worker URL (canonical and link previews)
# 5. Build the dashboard and deploy
pnpm build
pnpm run deploy
```
Open the Worker URL and sign in with the token. The cron starts collecting on its own.
## Add apps and keywords
Describe your apps in a JSON file (see [`config.example.json`](config.example.json)) and POST it:
```json
{
"storefronts": ["US", "GB"],
"apps": [
{
"url": "https://apps.apple.com/us/app/your-app/id1234567890",
"storefronts": ["US", "GB", "CA"],
"keywords": [
"habit tracker",
"daily planner",
{ "term": "gewohnheitstracker", "storefronts": ["DE", "AT"] }
]
}
]
}
```
```bash
curl -X POST https://<worker>.workers.dev/admin/seed \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d @config.json
```
- `url` can be any App Store link; the `id…` is extracted. The name is looked up from Apple when omitted.
- Storefronts are ISO country codes (`US`, `GB`, `DE`, `JP`, …). On iOS, ranking is per storefront, not per language.
- The closest list wins: a keyword's own `storefronts`, then the app's, then the top-level default. A keyword shared by two apps is fetched once per storefront.
- Seeding only adds. Rename, re-target and remove keywords in the dashboard's **Keywords** panel or through the endpoints below.
```bash
# Add keywords (lowercased; existing ones gain the storefronts)
curl -X POST https://<worker>.workers.dev/admin/apps/<appId>/keywords \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
-d '{"terms":["mileage log","gps mileage"],"storefronts":["US","GB"]}'
# Set the exact storefronts, optionally renaming
curl -X PUT "https://<worker>.workers.dev/admin/apps/<appId>/keywords/mileage%20log" \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "Content-Type: application/json" \
-d '{"term":"mileage logbook","storefronts":["US"]}'
# Stop tracking
curl -X DELETE "https://<worker>.workers.dev/admin/apps/<appId>/keywords/mileage%20log" \
-H "Authorization: Bearer $ADMIN_TOKEN"
# Collect now instead of waiting for cron (up to 20 pairs per call)
curl -X POST "https://<worker>.workers.dev/admin/collect?n=10" \
-H "Authorization: Bearer $ADMIN_TOKEN"
# → {"collected":10,"failed":0,"rateLimited":false}
```
Rank history is attached to the keyword text: renaming starts a fresh history, deleting keeps the old one.
## Dashboard
It answers one question: where do my apps rank today, and what moved this week?
- **KPIs** compared with 7 days ago: keywords in the top 10, average position, keywords that moved, keywords ranked in the top 200.
- **Where you rank**: position buckets (top 3, 4–10, 11–50, 51–200, not ranked). Click a bucket to filter the table.
- **Rankings and Opportunities** tabs with filtering and sortable columns. Click a keyword to see its full top 200 and the week's movers.
- **Keywords panel**: paste a list to add many keywords for chosen storefronts, click one to rename it or change its storefronts, delete with Undo.
- **Settings**: theme, row density, visible storefronts.
- Light and dark themes, works down to 375 px. Color means status only: green is top 10 or rising, red is falling.
## Use it from your agent
RankLens is an MCP server at `/mcp` (Streamable HTTP, JSON-RPC over POST). Add it to Claude Code:
```bash
claude mcp add --transport http ranklens https://<worker>.workers.dev/mcp \
--header "Authorization: Bearer $ADMIN_TOKEN"
```
| Tool | Returns |
|---|---|
| `list_apps` | tracked apps and keyword counts |
| `app_rankings` | positions, 7-day change, apps above you |
| `keyword_board` | the full top 200 for a keyword, with changes |
| `movers` | biggest risers and fallers over N days |
| `opportunities` | keywords where you are outside the top N while competitors hold the top 5 |
| `collection_status` | total, complete and pending pairs for a day |
All tools are read-only. Then ask things like *"which keywords did we lose in GB this week, and who took them?"*
## REST API
Every endpoint needs `Authorization: Bearer $ADMIN_TOKEN`.
| Endpoint | Returns |
|---|---|
| `GET /api/apps` | tracked apps with per-storefront keyword counts |
| `GET /api/apps/:id/rankings?country=US` | positions and 7-day change |
| `GET /api/apps/:id/keywords` | tracked keywords and their storefronts |
| `GET /api/apps/:id/report.md` | a Markdown report |
| `GET /api/keywords/:term/board?country=US` | the full top 200 |
| `GET /api/movers?keyword=…&country=US` | risers and fallers |
| `GET /api/opportunities/:id` | keywords worth pushing |
| `GET /api/status` | today's collection progress |
## How it works
```
Cron (every minute) ──► Durable Object "Collector" (pinned to eeur)
│ RPM requests per tick
▼
itunes.apple.com/search?term=<kw>&country=<cc>&entity=software&limit=200
│
▼
D1: one snapshot = up to 200 positions
│
┌────────────────┼────────────────┐
▼ ▼ ▼
Dashboard REST /api MCP /mcp
```
- **Apple rate limits.** iTunes Search answers most Cloudflare locations with 429, so fetching runs in one Durable Object pinned to `eeur`. A 429 ends the tick without spending the pair's retries. If 429s come back (`wrangler tail` shows `iTunes search 429`), change the location hint and the object name in `apps/worker/src/collector.ts` together.
- **Storage.** About 1,500 pairs a day is ~300k rows/day. Daily detail is kept for 90 days, then only Mondays; `RETENTION_DAYS` is the hard limit.
- **Throughput.** Requests per day equal the number of unique keyword × storefront pairs. `RPM=2` gives ~2,880 a day; raise it gradually, up to about 20.
- **Security.** One token guards reads and writes and is compared in constant time. Only `/health` and the static dashboard shell are public. The dashboard ships a strict CSP and refuses to be framed. Rotate the token with `npx wrangler secret put ADMIN_TOKEN`.
## Try the demo
`demo/` is a static build of the same dashboard with generated data. No install, no Cloudflare:
```bash
cd demo
python3 -m http.server 5182
# → http://localhost:5182 (?theme=light or ?theme=dark)
```
Rebuild it after changing the UI: `pnpm --filter @ranklens/web build:demo`.
## Develop locally
```bash
# terminal 1: Worker + local D1 on :8787
pnpm db:migrate
npx wrangler dev --test-scheduled --var ADMIN_TOKEN:dev
# terminal 2: Vite on :5182, proxying /api, /admin and /mcp to :8787
pnpm dev
```
Fire one collection tick without waiting for cron (each tick makes `RPM` Apple requests):
```bash
curl "http://localhost:8787/cdn-cgi/handler/scheduled?cron=*+*+*+*+*"
```
`/__scheduled` does not work here: the SPA fallback answers it before the Worker does.
## Project layout
```
ranklens/
wrangler.jsonc Worker, D1, Durable Object, static assets, cron
shared/api.ts types shared by the Worker and the dashboard
apps/worker/
migrations/ D1 schema
src/index.ts Hono routes and auth
src/collector.ts Durable Object that fetches from Apple
src/db.ts queries, seeding, keyword editing
src/mcp.ts MCP server
apps/web/ Vite + React 19 + Tailwind v4 + shadcn/ui dashboard
demo/ static demo build
```
## Limits
- iOS only. Google Play needs a proxy or a third-party API and is not included.
- Apple returns at most 200 results, so anything below 200 reads as "not ranked".
- Positions come from the public iTunes Search API. They track the App Store's search order closely but are not Apple's official ranking data.
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues