Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dev.vars.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AI_EXTRACTOR=mock

# Auth (local dev: leave SESSION_SECRET unset to auto-login as the local user)
# Set a local session secret to enable sign-in.
SESSION_SECRET=
TURNSTILE_SECRET_KEY=
88 changes: 16 additions & 72 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,28 @@
# CardCap Deployment
# Deploy CardCap to Cloudflare

## Canonical Project Path
The Worker serves the React app and its API from one hostname. [cloudflare.config.ts](cloudflare.config.ts) defines the deployment target and bindings.

`C:\Users\codyl\Desktop\csiOS\Projects\CARDCAP`
## Configure your environment

Use this folder for future development, commits, and deploys. The earlier Codex `outputs\cardcap-app` folder is historical.
1. Install Node.js 24, run `npm ci`, and authenticate with `npx cf auth login`.
2. In the deployment configuration, set your Cloudflare account, Worker name, custom domain, and `PUBLIC_ORIGIN`. Use the HTTPS origin for the domain where users will open sign-in links.
3. Create a D1 database and R2 bucket in your account. Update the database ID and bucket name, enable Workers AI and Browser Run, and configure the rate-limit bindings for your Worker.
4. Verify a sending domain in Cloudflare Email Service. Set `SENDER_EMAIL` and the email binding’s allowed sender to the same address.
5. Configure a Turnstile widget for the app hostname. Set the public `TURNSTILE_SITE_KEY` in the configuration and store its paired `TURNSTILE_SECRET_KEY` and a randomly generated `SESSION_SECRET` as Worker secrets. Rotating the session secret signs users out.

## Live Beta
## Migrate and deploy

- URL: `https://cc.csi.run`
- Worker name: `cardcap`
- D1 database: `cardcap-db`
- D1 database ID: `d3a74ece-fba4-4d92-a167-dfa21998c9ab`
- R2 bucket: `cardcap-card-images`
Review the pending [D1 migrations](migrations/) against the intended database. Replace `DATABASE_ID` below with its ID. The apply command runs all pending migrations in the directory.

## Secrets

The Worker expects these secrets to be configured in Cloudflare:

- `SESSION_SECRET` (32+ random characters; rotating it signs everyone out)
Sign-in links are sent through the native Cloudflare EMAIL binding from `cardcap@notify.copperstateit.com`. The domain must be verified for Email Sending.
- `TURNSTILE_SECRET_KEY` (paired with the public `TURNSTILE_SITE_KEY` var in wrangler.jsonc)

`BETA_ACCESS_CODE` is retired and should be deleted from the Worker.

Do not commit secret values. Local development secrets belong in `.dev.vars`, which is ignored by git.

## Historical first-deploy instructions for magic-link auth

1. Snapshot: `npx wrangler d1 export cardcap-db --remote --output backup-2026-06-09.sql`
2. Fresh start (wipes pre-auth beta data): `npx wrangler d1 execute cardcap-db --remote --command "DELETE FROM extraction_jobs; DELETE FROM contacts; DELETE FROM users;"`
3. Apply migrations: `npx wrangler d1 migrations apply cardcap-db --remote`
4. Create a Turnstile widget in the Cloudflare dashboard (Managed mode, hostname `cardcap.codylecates.workers.dev`); paste the site key into `TURNSTILE_SITE_KEY` in `wrangler.jsonc`, then `npx wrangler secret put TURNSTILE_SECRET_KEY`
5. `npx wrangler secret put SESSION_SECRET`
6. Verify the configured sender domain in Cloudflare Email Service
7. `npx wrangler secret delete BETA_ACCESS_CODE`
8. `npm run build && npx wrangler deploy`
9. Smoke: `/api/health` returns `ok`; full sign-in round-trip from a phone; check a corporate-style inbox's spam folder for the link; upload one card and confirm `extractionMode: "openai"`; download the iContact CSV and test-import it into iContact.

## Local Development

```powershell
npm ci
npm run dev
```

Open `http://127.0.0.1:5173/`.

## Verification

```powershell
npm test
npm run lint
npm run build
```

The build script removes generated local env files from `.cloudflare/output`.

## Deploy

```powershell
npx cf auth whoami
```sh
npm run deploy -- --dry-run
npx cf d1 migrations list DATABASE_ID
npx cf d1 migrations apply DATABASE_ID
npm run deploy
```

If Cloudflare auth expires:

```powershell
npx cf auth login
```

## Production Smoke Test

After deployment, verify:

```powershell
Invoke-RestMethod -Uri 'https://cc.csi.run/api/health'
```
The deploy script builds the app and uploads it using the Cloudflare CLI. It expects the configured resources to exist.

Expected: JSON with `ok: true` and `extractor: cloudflare`.
## Verify the release

For full upload testing, unlock with the beta session, upload a real card image, confirm `extractionMode` is `cloudflare`, then delete the temporary contact.
Check that `/api/health` returns `ok: true`. Sign in on the deployed hostname, capture a sample contact, and confirm its details in a CSV export.
64 changes: 12 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,23 @@
# CardCap

Phone-first business card capture for turning card photos into a searchable mini-CRM.
Turn business cards, email signatures, and business websites into contacts you can import into your CRM.

## What Works Now
[Open CardCap](https://cc.csi.run/)

- Open the app on desktop or phone-size browser.
- Sign in with a one-time email link (magic link); each user has a private contact list.
- Tap Add Cards to take a photo or upload card images.
- Store uploaded images in the local Cloudflare R2 binding.
- Store contacts in the local Cloudflare D1 database.
- Review the source card beside or above editable contact fields.
- Save searchable contacts with email, phone, website, map, notes, tags, status, and next step.
- Export CSV, vCard, JSON, standalone HTML, or an iContact-ready CSV for email-marketing imports.
- Extract card photos with Cloudflare Workers AI, or use mock photo extraction locally. Paste a signature, business details, or a website to review and save a contact.
- Abuse guards: Turnstile on sign-in, per-minute rate limits, and a 25-cards/day extraction quota per user.
## From source to contact

## Local Development
- **Photograph a business card** or upload several card images after an event. Review names, companies, and phone numbers alongside the originals.
- **Paste an email signature** from your inbox. Check the suggested fields and save the contact.
- **Enter a business domain.** CardCap looks for a contact page and shows the source so you can verify the details before saving.

```powershell
npm install
npm run dev -- --host 127.0.0.1
```
The dashboard shows recent imports, processing activity, errors, and contacts that need review. Search your collection, add follow-up notes, and export it as CSV, iContact CSV, vCard, JSON, or HTML.

Then open:
## Sign in

```text
http://127.0.0.1:5173/
```
Choose **Use email link** for a one-time sign-in link. If you prefer a password, sign in once and choose **Account → Set password**.

Health check:
## Project

```powershell
Invoke-WebRequest -UseBasicParsing http://127.0.0.1:5173/api/health
```
CardCap uses React and TypeScript on Cloudflare Workers. Workers AI extracts contact details, D1 stores contacts, and R2 stores card images.

## Verification

```powershell
npm run lint
npm test
npm run build
npm run deploy -- --dry-run
```

## Cloudflare extraction in development

Sign in with `npx cf auth login`. The Worker uses the remote AI binding for photo and text extraction and the Browser Run binding for website lookup. Set `AI_EXTRACTOR=cloudflare` in `.dev.vars` for live photo extraction or `AI_EXTRACTOR=mock` for local photo fixtures.

## Auth in Local Dev

- Leave `SESSION_SECRET` unset in `.dev.vars` to auto-sign-in as the local user (no email needed).
- Set `SESSION_SECRET` to any 32+ character string to exercise the real magic-link flow. Sign-in links use the Cloudflare EMAIL binding.
- `TURNSTILE_SECRET_KEY` unset means the Turnstile check is skipped locally.

## Production deployment

The `cardcap` Cloudflare Worker serves the app and API. Its production bindings are defined in `cloudflare.config.ts`. Contacts use D1 and photos use R2. The D1 CLI uses the existing `./migrations` directory.

```powershell
npm run deploy -- --dry-run
npm run deploy
```
[Contacts and exports](docs/contacts.md) · [Local development](docs/development.md) · [Deployment](DEPLOYMENT.md)
24 changes: 24 additions & 0 deletions docs/contacts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Contacts and exports

## Capture and review

| Source | What to expect |
| --- | --- |
| Business card photos | Choose **Upload business cards** and select one or more images. CardCap adds the contacts for review and can merge matching cards. |
| Website | Choose **Add a domain**. Review the suggested contact alongside the source page, then save it. A company name is enough when the site lists no individual. |
| Email signature or copied text | Choose **Paste an email signature** and paste the relevant lines. Review the draft before saving. |
| Existing contact file | Use **Import** to bring in CSV, vCard, or JSON contacts. The import summary shows new and merged records. |

In the dashboard’s contact list, choose **Show → Needs review** to find records that need attention. Open a contact to correct its fields, add notes or a next step, and mark it reviewed.

## Choose an export

**Export** downloads your account’s collection, including contacts outside the current search or filter.

| Format | Use |
| --- | --- |
| CSV | Import into a CRM or spreadsheet. Includes contact details, tags, status, next step, and notes. When the collection includes text or website captures, it also includes source URL and capture time columns. |
| iContact CSV | Import into iContact using its column names. The first phone goes in Phone and additional numbers go in Notes. |
| vCard | Import into an address book. |
| JSON | Work with structured contact records. |
| HTML | Browse a standalone contact list. |
37 changes: 37 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Local development

Use Node.js 24 and npm. From the repository root, install dependencies and run the unit tests.

```sh
npm ci
npm test
```

## Run the app

For interactive development, configure your own Cloudflare resources and sender as described in the [deployment guide](../DEPLOYMENT.md). Copy [.dev.vars.example](../.dev.vars.example) to `.dev.vars` and set a local `SESSION_SECRET` for sign-in. Use a Turnstile site key and secret appropriate to your development hostname when testing email links.

```sh
npx cf auth login
npm run dev -- --host 127.0.0.1
```

Open the local address printed by Vite. Set `AI_EXTRACTOR=mock` for fixture-based photo extraction. Pasted text and website lookup use remote Cloudflare bindings.

## Verify changes

```sh
npm run lint
npm run build
npm run test:e2e
```

For a browser walkthrough without a production account, run the Playwright suites. They launch a local test server with disposable data and simulated email delivery.

```sh
npx playwright install chromium
npm run test:browser
npm run test:browser:access
```

The [GitHub Actions workflow](../.github/workflows/checks.yml) lists the full set of release checks.
Loading
Loading