You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 38802fa
Browse filesBrowse the repository at this point in the historyBrowse files
`tests/conftest.py` points `DATABASE_URL` at a **throwaway SQLite file** (never `backend/test.db`), blanks every API key, and sets `RUN_SCRAPER_INLINE=0` + `WARM_RESOURCE_CACHE=0`, all before `app` is imported — so the suite needs no database, secrets or network and gives the same answer in CI as locally. Backend CI (`.github/workflows/backend.yml`) runs it on every push/PR. Coverage today: the project video gate + cache key (`test_projects.py`, with the real titles that reached production as regressions), data freshness (`test_health.py`), the scheduler's success stamping (`test_scheduler.py`), the score's contract (`test_scoring.py`), and the booted app (`test_api.py`). Pure logic belongs in a service module where it can be tested without a request — `projects.video_cache_slug` was moved out of the endpoint for exactly that reason.
1.**`app/services/scheduler.py`** — `run_scraper_loop()` runs every 30 min (started as an asyncio task at app startup). `perform_full_scrape()` is an 8-step pipeline: sync tool registry → fetch community sources → sentiment → GitHub repo stats → score → persist snapshots → update tools → recompute. Live progress is exposed via `GET /api/v1/status`.
65
+
1.**`app/services/scheduler.py`** — `run_scraper_loop()` runs every 30 min (started as an asyncio task at app startup). `perform_full_scrape()` is an 8-step pipeline: sync tool registry → fetch community sources → sentiment → GitHub repo stats → score → persist snapshots → update tools → recompute. Live progress is exposed via `GET /api/v1/status`.`perform_full_scrape` never raises (the loop must survive) but **returns True only when the final commit landed**; the loop stamps `last_scraped_time` on success alone and otherwise increments `consecutive_failures`. It used to stamp unconditionally, so a crashed pipeline was reported as a fresh scrape and the site said "Live".
60
66
2.**`app/services/scraper.py`** — async fetchers: `fetch_github_repo_stats` (targeted per-repo, ETag caching + adaptive rate limiting), `fetch_hackernews`, `fetch_devto`, `fetch_reddit` (RSS, no auth), `fetch_tech_news` (RSS). `batch_sentiment_analysis` uses Groq (`llama-3.1-8b-instant`) — a no-op/skip when `GROQ_API_KEY` is empty.
61
-
3.**`app/services/scoring.py`** — `calculate_all_tool_scores`normalizes weighted mentions + GitHub signals into **percentile ranks (0–100)**across all tools at once (this is why scores are relative, not absolute). Also classifies growth stage, trend, learning priority, and generates recommendation text.
62
-
4.**`app/api/endpoints/mvp.py`** — the single router, mounted at `settings.API_V1_STR` (`/api/v1`). All endpoints live here: `/tools`, `/tools/{slug}`, `/tools/{slug}/history`, `/tools/{slug}/resources` (learning videos + platforms, see below), `/tools/compare`, `/tools/by-domain`, `/domains`, `/domains/{slug}/learning-path`, `/roadmaps`, `/roadmaps/{slug}` (steps hydrated with per-step tools + each tool's top video), `/progress/{summary,/{slug},toggle}` (learning progress, auth-gated), `/notifications/{subscribe,status,unsubscribe}` (daily-nudge opt-in), `/overview`, `/status`, `/health`, `/ready`, `/admin/scrape` + `/admin/send-daily-digests` (gated by `ADMIN_API_KEY`).
67
+
3.**`app/services/scoring.py`** — `calculate_all_tool_scores`scores each tool on an **absolute 0–100 scale**from its own signals only: floor-anchored log stars (60%) and forks (15%) plus community mentions saturating at 25 (25%). A tool's score does not move when an unrelated tool moves — `test_scoring.py` pins this. (This file used to say percentile ranks; `_percentile_rank` is unused.) Also classifies growth stage, trend, learning priority, and generates recommendation text.
68
+
4.**`app/api/endpoints/mvp.py`** — the single router, mounted at `settings.API_V1_STR` (`/api/v1`). All endpoints live here: `/tools`, `/tools/{slug}`, `/tools/{slug}/history`, `/tools/{slug}/resources` (learning videos + platforms, see below), `/tools/compare`, `/tools/by-domain`, `/domains`, `/domains/{slug}/learning-path`, `/roadmaps`, `/roadmaps/{slug}` (steps hydrated with per-step tools + each tool's top video), `/progress/{summary,/{slug},toggle}` (learning progress, auth-gated), `/notifications/{subscribe,status,unsubscribe}` (daily-nudge opt-in), `/overview`, `/status`, `/health` (always 200; `status` is ok/degraded/error with a `data` freshness report), `/health/data` (**503 when data is stale >2h, the scraper has failed 2+ cycles running, or nothing was ever scraped — point an uptime monitor here**; logic in `app/services/health.py:assess_freshness`), `/ready`, `/admin/scrape` + `/admin/send-daily-digests` (gated by `ADMIN_API_KEY`).
63
69
5.**`app/models/all_models.py`** — tables: `Domain`, `Tool` (now also carries `homepage`/`latest_version`/`latest_release_at` for the resource docs-link + stale-tutorial warning), `ToolSnapshot` (time series, incl. `stars`), `ToolRoadmap`, `UserProgress` (completed roadmap steps per user), `ToolResource` (cached learning videos/platforms), `NotificationPref` (daily-nudge opt-in). Roadmaps are keyed by **domain slug**. New model fields are reconciled onto existing DBs at startup by `app/db/migrate.py:ensure_columns` (additive `ALTER TABLE ADD COLUMN` only — `create_all` never adds columns to an existing table).
64
70
65
71
### Learning layer (the retention + growth product)
@@ -118,7 +124,7 @@ To grow the signal further: add more subreddits/RSS feeds, fetch HN story text (
118
124
- The app runs fine with **empty `GITHUB_TOKEN`/`GROQ_API_KEY`** (degraded: no GitHub stats, no sentiment) — don't make either a hard requirement to boot.
119
125
120
126
## Environment variables
121
-
Backend (`backend/.env`): `GITHUB_TOKEN`, `GROQ_API_KEY`, `YOUTUBE_API_KEY` (optional — enables ranked video results on `/tools/{slug}/resources`; without it the endpoint returns curated platform links and reports `videos_live: false`), `CLERK_PUBLISHABLE_KEY` (optional but required in production — the same public `pk_...` value as the frontend; when set, `/progress` verifies the Clerk session token server-side via `app/core/auth.py` and ignores any client-supplied `user_id`; when empty it falls back to a client id for local dev), `RESEND_API_KEY` + `DIGEST_FROM` + `SITE_URL` (optional — the daily learning-nudge email; empty → the `/admin/send-daily-digests` batch runs as a safe no-op and sends nothing; trigger it from an external daily cron with the `X-Admin-Key` header), `ADMIN_API_KEY` (optional), `DATABASE_URL` (auto-set by Docker; empty → SQLite). Frontend (`frontend/.env.local`): `BACKEND_ORIGIN` (where the Next server proxies `/api/v1/*` — **read at build time**; local `http://localhost:8000`, docker-compose `http://backend:8000`, prod = the public backend URL), `NEXT_PUBLIC_SITE_URL` (absolute site URL for OG/canonical/sitemap; single source `src/lib/site.ts`), `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY`, `CLERK_SECRET_KEY`. (`NEXT_PUBLIC_API_URL` was removed in favour of the proxy.)
127
+
Backend (`backend/.env`): `GITHUB_TOKEN`, `GROQ_API_KEY`, `YOUTUBE_API_KEY` (optional — enables ranked video results on `/tools/{slug}/resources`; without it the endpoint returns curated platform links and reports `videos_live: false`), `CLERK_PUBLISHABLE_KEY` (optional but required in production — the same public `pk_...` value as the frontend; when set, `/progress` verifies the Clerk session token server-side via `app/core/auth.py` and ignores any client-supplied `user_id`; when empty it falls back to a client id for local dev), `RESEND_API_KEY` + `DIGEST_FROM` + `SITE_URL` (optional — the daily learning-nudge email; empty → the `/admin/send-daily-digests` batch runs as a safe no-op and sends nothing; trigger it from an external daily cron with the `X-Admin-Key` header), `ADMIN_API_KEY` (optional), `WARM_RESOURCE_CACHE` (default `1`; `0` skips the startup video-cache warm — the test suite sets it), `DATABASE_URL` (auto-set by Docker; empty → SQLite). Frontend (`frontend/.env.local`): `BACKEND_ORIGIN` (where the Next server proxies `/api/v1/*` — **read at build time**; local `http://localhost:8000`, docker-compose `http://backend:8000`, prod = the public backend URL), `NEXT_PUBLIC_SITE_URL` (absolute site URL for OG/canonical/sitemap; single source `src/lib/site.ts`), `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY`, `CLERK_SECRET_KEY`. (`NEXT_PUBLIC_API_URL` was removed in favour of the proxy.)
122
128
123
129
## Deployment
124
130
Live (beta): **frontend on Vercel** (root `frontend`), **backend + Postgres on Render + Neon** (root `backend`, Docker). The same-origin proxy means Vercel forwards `/api/v1/*` to the Render backend — no CORS to configure. Full step-by-step (env-var tables, Clerk/scraper/cron notes, single-VPS docker-compose alternative) is in **`DEPLOY.md`**. Set `BACKEND_ORIGIN` in Vercel *before* the first build (it's baked into the rewrite), and `NEXT_PUBLIC_SITE_URL` to the real domain. The Render free tier sleeps on inactivity (~50s cold start on the first request) — expected for the beta.
0 commit comments