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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
---
sidebar_position: 3
displayed_sidebar: developersSidebar
---

# Quick Start Guide

## Three Services

This project runs three separate services. Launch all three at once with `./start-all.sh`:

| Service | Port (Local) | Live URL | Description |
|---------|--------------|----------|-------------|
| ** Open Navigator** (`web_app`) | 5173 | [www.communityone.com](https://www.communityone.com) | **Main application** β€” search, filters, heatmap, data exploration |
| ** Documentation** (`web_docs`) | 3000 | [www.communityone.com/docs](https://www.communityone.com/docs) | Docusaurus site with complete guides and tutorials |
| ** API Backend** (`api`) | 8001 | [www.communityone.com/api/docs](https://www.communityone.com/api/docs) | FastAPI server with AI agents |

> ** LIVE DEMO:** Visit **[www.communityone.com](https://www.communityone.com)** to use the hosted application.
>
> ** LOCAL DEV:** After running `./start-all.sh`, visit **http://localhost:5173**.

## Prerequisites

- Python 3.11+
- Node.js 18+
- A local Postgres warehouse on `localhost:5433` (databases `open_navigator` and `openstates`) β€” see [Configuration](#configuration) below
- **PostgreSQL client tools 17** (`psql`, `pg_dump`, `pg_restore`) β€” **recommended version**.
 The local warehouse server runs PG 16, but a **17** client dumps it *and* the (PG 16/17)
 Neon serving DB, and reads both dump formats. Keep `pg_dump` and `pg_restore` on the
 **same major version** (β‰₯ any server you back up) to avoid `unsupported version` errors.
- Docker (optional β€” only for the containerized deployment)

## Installation

### Option 1: Start Everything at Once (Recommended)

```bash
# Clone repository
git clone https://github.com/getcommunityone/open-navigator.git
cd open-navigator

# Install dependencies
./install.sh # Python backend (creates .venv + .env from template)
cd web_app && npm install && cd .. # React app
cd web_docs && npm install && cd .. # Documentation

# Start all three services in tmux
./start-all.sh
```

`start-all.sh` auto-installs the `web_app`/`web_docs` `node_modules` if they're missing,
so the two `npm install` steps above are optional on first run.

### Option 2: Using Makefile

```bash
# Install
make install # Python backend
make install-web_app # React app
make install-docs # Documentation

# Start all services
make start-all

# …or individually:
make dev # API only
make dev-web_app # React app only
make dev-docs # Docs only
```

### Option 3: Manual Setup

```bash
# Python backend
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

# Optional: Spark + Delta Lake (only if you'll run Databricks/Spark scripts).
# Requires a Java runtime (e.g. `sudo apt install openjdk-17-jre-headless`).
# pip install -r requirements-spark.txt

# React app + documentation
cd web_app && npm install && cd ..
cd web_docs && npm install && cd ..

# Configure environment (see Configuration below)
cp .env.example .env

# Start services in separate terminals:
source .venv/bin/activate && python main.py serve # Terminal 1 β€” API (8001)
cd web_app && npm run dev # Terminal 2 β€” App (5173)
cd web_docs && npm start # Terminal 3 β€” Docs (3000)
```

### Option 4: Windows (PowerShell)

The `.sh` scripts and the `make` targets are Unix-oriented (`start-all.sh` uses
`tmux`, which Windows lacks). Use the PowerShell equivalents instead β€” they create
the same `.venv`, install from the same `requirements.txt`, and launch the same three
services, each in its own window:

```powershell
# From the repo root, in PowerShell:
.\install.ps1 # Python backend: creates .venv, installs deps, seeds .env
cd web_app; npm install; cd ..
cd web_docs; npm install; cd ..
.\start-all.ps1 # API (8001) + App (5173) + Docs (3000), one window each
```

If you see *"running scripts is disabled on this system"*, PowerShell's execution
policy is blocking the script. Either allow local scripts once for your user:

```powershell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
```

…or run each script without changing the policy:

```powershell
powershell -ExecutionPolicy Bypass -File .\install.ps1
powershell -ExecutionPolicy Bypass -File .\start-all.ps1
```

> **Warning Don't use `uv sync` to set up the backend on any OS.** The root
> `pyproject.toml` is a **uv workspace** whose members are only `packages/*`, so
> `uv sync` installs those workspace libraries but **not** the top-level
> `requirements.txt` β€” leaving out the dev tooling (`pytest`, `black`, `ruff`) and
> runtime deps like `yt-dlp`. Install the backend from `requirements.txt`
> (`.\install.ps1`, `./install.sh`, or `pip install -r requirements.txt`), which is
> the complete set. `uv sync` is only for working *inside* the `packages/*`
> libraries.

> **Tesseract / OCR on Windows:** `install.ps1` installs Tesseract via `winget`
> (or Chocolatey) when available; otherwise grab the
> [UB-Mannheim build](https://github.com/UB-Mannheim/tesseract/wiki). OCR is
> optional β€” the app runs without it.

## Configuration

`.env.example` is organized in tiers so you only set what you actually use.
Copy it to `.env` and fill in values as needed:

```bash
cp .env.example .env
```

### Required (minimum to run locally)

The site needs exactly **one** variable to boot. It points the API at the
already-running local Postgres warehouse on port `5433`, and the API reads it for
both the civic-data warehouse and the auth/user tables:

```bash
NEON_DATABASE_URL_DEV=postgresql://postgres:password@localhost:5433/open_navigator
```

The web app (`5173`) and docs (`3000`) need no env vars to boot. With just the line
above, `./start-all.sh` brings up all three services.

### Optional for local development

Set these only for the features that need them β€” the site runs without all of them:

```bash
# OAuth login (omit a provider to disable just that login button)
FRONTEND_URL=http://localhost:5173
API_BASE_URL=http://localhost:8001
# GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET, HUGGINGFACE_CLIENT_ID / _SECRET, etc.

# Stable JWT signing across restarts (auto-generated if unset)
# JWT_SECRET_KEY=$(openssl rand -hex 32)

# Bill / legislator / vote features (restore the Open States dump first)
# OPENSTATES_DATABASE_URL=postgresql://postgres:postgres@localhost:5433/openstates
```

### Data-source API keys (ingestion only)

Keys such as `OPENAI_API_KEY`, the `GEMINI_API_KEY_*` pool, `CENSUS_API_KEY`, and the
other source keys are needed **only** to run the ingestion/enrichment pipelines that
populate the warehouse β€” not to view the site.

### Deployment

`HF_TOKEN` / `HF_ORGANIZATION` (HuggingFace Spaces), `NEON_DATABASE_URL` (production
Neon), and the `DATABRICKS_*` variables are for deployment only and are not needed for
local development.

> See [`.env.example`](https://github.com/getcommunityone/open-navigator/blob/main/.env.example)
> for the full, commented list of every variable across all five tiers.

## Restore the Database

The three services give you the UI, but the app shows no civic data until you load a
warehouse snapshot into the local Postgres on `localhost:5433`. Restoring a shared dump
is far faster than rebuilding every dbt model from scratch.

**If you have the [Google Drive backup folder](#google-drive-folder-one-time-setup) synced**, it's one command:

```bash
make restore VERSION=snapshot-20260609 # dev only
```

**No local symlink?** Browse shared snapshots at
[open-navigator-backups on Google Drive](https://drive.google.com/drive/folders/1yQSHMI-lk36Zm3_RZJfO7qCgRXqxC9ur?usp=sharingWeWe),
download the `.dump` files, then restore manually (below).

```bash
# Create the DB if needed, then restore (rebuilds the `public` serving schema the API reads):
PGPASSWORD=password createdb -h localhost -p 5433 -U postgres open_navigator 2>/dev/null || true
PGPASSWORD=password pg_restore -h localhost -p 5433 -U postgres -d open_navigator \
 --clean --if-exists open_navigator.dump
```

The API serves the **`public`** schema in `open_navigator` by default (`API_DB_SCHEMA=public`).
After the restore, refresh http://localhost:5173 β€” search, maps, and the heatmap will be populated.

> **Restore only into a local/dev warehouse β€” never into a production database.**

## Access Points

** Local development:**
- ** Main App:** http://localhost:5173
- ** Documentation:** http://localhost:3000
- ** API Docs:** http://localhost:8001/docs

** Live application:**
- ** Open Navigator:** https://www.communityone.com
- ** Documentation:** https://www.communityone.com/docs
- ** API Docs:** https://www.communityone.com/api/docs

## Stop Services

```bash
./stop-all.sh
# or
make stop-all
```

## Running the System

### Start the API Server

```bash
# Using the virtual environment
source .venv/bin/activate
python main.py serve

# Or using make
make run
```

Visit http://localhost:8001 for the API and http://localhost:8001/docs for interactive documentation.

## Common Commands

```bash
# Activate virtual environment (required for all commands)
source .venv/bin/activate

# Start API server
python main.py serve

# Run with auto-reload (development)
python main.py serve --reload

# Check system status
python main.py status

# Run tests
pytest

# Or using make
make test
```

## Troubleshooting

### "ModuleNotFoundError: No module named 'click'"

You need to activate the virtual environment first:

```bash
source .venv/bin/activate
```

### "Tesseract binary not found" or OCR errors

The `install.sh` script automatically installs tesseract-ocr on Linux (via apt) and macOS (via brew). If it failed or you're on a different system, install manually:

**Linux (Debian/Ubuntu):**
```bash
sudo apt-get update && sudo apt-get install -y tesseract-ocr
```

**macOS:**
```bash
brew install tesseract
```

**Verify installation:**
```bash
tesseract --version
```

OCR is optional but enables text extraction from scanned PDFs and images.

### "error: externally-managed-environment"

Don't use `pip install` directly. Use the virtual environment:

```bash
# Create venv if not exists
python3 -m venv .venv

# Activate it
source .venv/bin/activate

# Now install
pip install -r requirements.txt
```

### Permission denied when running install.sh

```bash
chmod +x install.sh
./install.sh
```

## Releases & Data Versioning

Open Navigator follows [Semantic Versioning](https://semver.org/) (`MAJOR.MINOR.PATCH`).
**Every release is tied to a Postgres backup** so that a given version of the code can
always be paired with the warehouse state it was built and tested against.

Given a version `MAJOR.MINOR.PATCH` (e.g. `1.4.2`):

| Bump | When | Example |
| --------- | ------------------------------------------------------------------------------- | --------------- |
| **MAJOR** | Breaking API/schema change, dropped table or endpoint, incompatible dbt model | `1.4.2 β†’ 2.0.0` |
| **MINOR** | New data source, new endpoint, new dbt mart, backward-compatible feature | `1.4.2 β†’ 1.5.0` |
| **PATCH** | Bug fix, data backfill, doc change, no schema or contract change | `1.4.2 β†’ 1.4.3` |

A release bundles three things at the same version number:

1. **Code** β€” a git tag (`vMAJOR.MINOR.PATCH`).
2. **Schema/marts** β€” the dbt models as built at that tag.
3. **Data** β€” a Postgres backup snapshot stored off-machine (see [Database Backups](#database-backups) below).

## Database Backups

Backup and restore are Makefile targets β€” no manual `pg_dump`/`pg_restore` needed. Each
stamps the dump files with version/date/git SHA and syncs them off-machine through Google
Drive. Pick the scope that fits β€” and note that **two of the three are free of personal
user data**:

| Command | Scope | Personal user data? |
| --- | --- | --- |
| `make backup VERSION=v1.5.0` | **Full** β€” entire `open_navigator` warehouse (bronze/gold/staging/intermediate/public) **+** `openstates`. Self-contained; ~170 GB. | Warning **Yes** β€” includes the `user`/auth/social tables. Keep private. |
| `make backup-neon VERSION=v1.5.0` | **Neon serving** (recommended) β€” dumps the production Neon serving DB; civic data as standalone materialized tables. Small (~0.5 GB). | Yes **No** |
| `make backup-public VERSION=v1.5.0` | **Local public** β€” dumps only the local `public` serving schema; civic views + `event_documents`. | Yes **No** (personal tables excluded) |
| `make restore VERSION=v1.5.0` | Restore the full backup into the local warehouse. **Dev only.** | β€” |
| `make restore-neon VERSION=v1.5.0` | Restore a Neon snapshot into a separate local db (`open_navigator_serving`). **Dev only.** | β€” |
| `make restore-public VERSION=v1.5.0` | Restore the local `public` schema (needs `gold` present). **Dev only.** | β€” |

The `VERSION` label decides **where the dump is filed** inside the backup folder:

- A **semver tag** (`v1.5.0`) β†’ `open-navigator-backups/releases/v1.5.0/` β€” for tagged releases.
- **Any other label** (e.g. `2026-06-09`, `snapshot-20260609`) β†’ `open-navigator-backups/snapshots/<label>/` β€” for ad-hoc point-in-time backups.

`restore*` searches **both** folders, so you restore with the same label you backed up with
regardless of which one it landed in. Exact commands live in the
[`backup` targets in the Makefile](https://github.com/getcommunityone/open-navigator/blob/main/Makefile).

### Backing up the serving data without user PII

To share or version the public civic data **without** shipping personal user information
(accounts, OAuth state, social graph, feed prefs, saved locations), use one of the
PII-free targets. Both exclude the same app/runtime tables that the Neon serving DB never
mirrors (`user`, `contact_oauth_state`, `social_follows`, `user_lens_prefs`,
`user_locations`, `user_signal_prefs`, `meeting_document_gap_cache`).

**`make backup-neon` (recommended).** Dumps the production Neon serving DB
(`NEON_DATABASE_URL` from `.env`). That DB is **civic-only by construction** β€” the
`sync_public_to_neon.py` loader never copies the user/auth tables β€” and its serving objects
are real **materialized tables**, so the dump is standalone (no dependency on `gold`):

```bash
make backup-neon VERSION=snapshot-20260609 # writes one small neon_serving_*.dump, no PII
```

`pg_dump` is read-only, so this is safe to run against prod. Restore into a **separate
local** database (never prod) and optionally point the API at it for a PII-free local
serving instance:

```bash
make restore-neon VERSION=snapshot-20260609 # β†’ local db open_navigator_serving (dev only)
```

The Neon dump is taken with `--no-owner --no-privileges`, and `restore-neon` restores with
`--role=$(PG_USER)`, so all objects end up owned by your **local** `postgres` user β€” not the
Neon role. (Same for `make backup-public`.)

**`make backup-public`.** Dumps the local `public` schema with the personal tables
excluded β€” civic views + `event_documents` only. It does **not** include the Postgres
extensions (`pg_trgm`, `btree_gin`, …) that live in `public`, so restoring it never drops
them and `gold`'s indexes stay safe. Because the views reference `gold`, restore it onto a
warehouse that already has `gold`:

```bash
make backup-public VERSION=snapshot-20260609 # local public, personal tables excluded
```

> **Restore only into a local/dev warehouse β€” never into a production database.** The full
> `make backup` is the only one that contains user accounts; treat its dumps as private and
> do not share them via a public Drive link.

> **Client version.** The backup targets auto-select the newest PostgreSQL client under
> `/usr/lib/postgresql/*/bin` (so a PG 17 `pg_dump` is used for the PG 17 Neon server even
> when your `PATH` still points at PG 16). Install PG 17 client tools (see
> [Prerequisites](#prerequisites)). Override the choice if needed with
> `make backup-neon VERSION=… PG_BIN=/usr/lib/postgresql/17/bin/` (or `PG_BIN=` to force `PATH`).

### Google Drive folder (one-time setup)

`make backup` writes into a folder synced by **Google Drive for Desktop**, reached in WSL
through a symlink named `open-navigator-backups` in the repo root.

**Shared team folder:**
[open-navigator-backups on Google Drive](https://drive.google.com/drive/folders/1m1kCoY5oM9xlnKKi9u2wfgaXVaKZSWwp?usp=sharing)
(Anyone with the link can view snapshots under `releases/` and `snapshots/`).

Set up the local symlink once per machine:

```bash
# One command (mounts I:, updates /etc/fstab, creates the folder, links the symlink):
make setup-backup-drive

# Or manually:
# 1. Google Drive for Desktop must be running on Windows (so I:\My Drive is accessible).
# 2. Mount I: into WSL and make it persist across restarts:
sudo mkdir -p /mnt/i && sudo mount -t drvfs 'I:' /mnt/i
echo 'I: /mnt/i drvfs defaults 0 0' | sudo tee -a /etc/fstab
# 3. Create the Drive folder and link it into the repo (the symlink is gitignored):
mkdir -p "/mnt/i/My Drive/open-navigator-backups"
ln -sfn "/mnt/i/My Drive/open-navigator-backups" open-navigator-backups
# 4. Verify:
test -d open-navigator-backups/ && echo "Yes Drive backup folder ready"
```

> Different Drive letter? `make setup-backup-drive DRIVE_LETTER=H` (or swap `I:` / `/mnt/i`
> in the manual steps). No Drive for Desktop? Point `BACKUP_DIR`
> at any folder and sync it with [`rclone`](https://rclone.org/drive/) instead.

### Create a backup

With the [Google Drive folder](#google-drive-folder-one-time-setup) in place, dump both
databases with one command. Pick any label β€” a semver tag for a release, or a date for an
ad-hoc snapshot:

```bash
make backup VERSION=snapshot-20260609
```

This stages the dumps on local disk, copies them into
`open-navigator-backups/snapshots/snapshot-20260609/` (a non-`v` label files under
`snapshots/`; each filename stamped with the version, date, and git SHA), and Google Drive
for Desktop syncs them off-machine automatically. Confirm they landed:

```bash
ls open-navigator-backups/snapshots/snapshot-20260609/
# open_navigator_snapshot-20260609_20260609_a1b2c3d.dump
# openstates_snapshot-20260609_20260609_a1b2c3d.dump
```

### Share a snapshot with a collaborator

1. Run `make backup VERSION=<label>`.
2. After Google Drive syncs, confirm the dumps appear under
 [`snapshots/<label>/`](https://drive.google.com/drive/folders/1m1kCoY5oM9xlnKKi9u2wfgaXVaKZSWwp?usp=sharing)
 in the shared [open-navigator-backups](https://drive.google.com/drive/folders/1m1kCoY5oM9xlnKKi9u2wfgaXVaKZSWwp?usp=sharing)
 folder (or `releases/<label>/` for semver tags).
3. Collaborators with folder access run `make restore VERSION=<label>` when their
 [local symlink](#google-drive-folder-one-time-setup) points at the same Drive tree;
 otherwise they download the `.dump` files from the shared folder and restore manually
 (see [Restore the Database](#restore-the-database)).

For a tagged release, also push the matching git tag and record the snapshot path + SHA in
the [Release History](development/release-history.md) (shared folder:
[open-navigator-backups](https://drive.google.com/drive/folders/1m1kCoY5oM9xlnKKi9u2wfgaXVaKZSWwp?usp=sharing)):

```bash
git tag -a v1.5.0 -m "feat: add grants.gov opportunities to search" && git push origin v1.5.0
```

## Next Steps

1. Configure your `.env` file (see [Configuration](#configuration) β€” only `NEON_DATABASE_URL_DEV` is required)
2. Start all three services: `./start-all.sh`
3. Open the app at http://localhost:5173
4. Check out the interactive API docs: http://localhost:8001/docs

For more details, see the main [README.md](https://github.com/getcommunityone/open-navigator/blob/main/README.md).