From c222fbb1689fdc3b716cdcab9e858d456087e57f Mon Sep 17 00:00:00 2001 From: SURYANSH-RAI Date: Sat, 17 Oct 2026 12:21:46 +0530 Subject: [PATCH 01/69] database migration and Keyclock added as sigin process --- .dockerignore | 25 + .env.example | 81 +- .github/workflows/ci.yml | 152 + .github/workflows/deploy.yml | 270 + .gitignore | 124 +- ReadMe.md | 153 +- app/api/lookup-email/route.js | 34 - app/auth/callback/page.jsx | 15 - app/login/page.jsx | 9 - app/page.jsx | 9 - apps/web/Dockerfile | 67 + .../events/[eventSlug]/analytics/page.tsx | 29 + .../events/[eventSlug]/matching/page.tsx | 29 + .../[orgSlug]/events/[eventSlug]/page.tsx | 48 + .../events/[eventSlug]/roster/page.tsx | 37 + .../orgs/[orgSlug]/events/new/page.tsx | 26 + .../orgs/[orgSlug]/events/page.tsx | 21 + .../e/[eventSlug]/connections/page.tsx | 44 + .../e/[eventSlug]/matches/page.tsx | 54 + .../app/(participant)/e/[eventSlug]/page.tsx | 47 + .../e/[eventSlug]/profile/page.tsx | 52 + .../e/[eventSlug]/search/SearchForm.tsx | 66 + .../e/[eventSlug]/search/page.tsx | 14 + {app => apps/web/app}/MatchApp.jsx | 84 +- apps/web/app/actions/intro.actions.ts | 76 + apps/web/app/actions/match.actions.ts | 61 + apps/web/app/actions/organizer.actions.ts | 73 + apps/web/app/actions/participant.actions.ts | 58 + apps/web/app/api/auth/google/start/route.js | 64 + apps/web/app/api/auth/logout/route.js | 33 + apps/web/app/api/auth/lookup/route.js | 57 + apps/web/app/api/auth/otp/request/route.js | 90 + apps/web/app/api/auth/otp/verify/route.js | 79 + apps/web/app/api/domains/route.js | 17 + apps/web/app/api/health/ready/route.js | 45 + apps/web/app/api/health/route.js | 21 + {app => apps/web/app}/api/match/route.js | 148 +- apps/web/app/api/me/route.js | 46 + apps/web/app/api/webhooks/.gitkeep | 0 apps/web/app/auth/callback/route.js | 135 + {app => apps/web/app}/icon.png | Bin {app => apps/web/app}/layout.jsx | 0 {app => apps/web/app}/login.jsx | 227 +- apps/web/app/login/page.jsx | 28 + apps/web/app/page.jsx | 7 + apps/web/components/organizer/.gitkeep | 0 apps/web/components/participant/.gitkeep | 0 apps/web/components/ui/.gitkeep | 0 apps/web/eslint.config.mjs | 29 + apps/web/lib/safe-return-to.ts | 18 + apps/web/lib/session.ts | 66 + apps/web/middleware.ts | 16 + apps/web/next.config.mjs | 38 + apps/web/package.json | 27 + {public => apps/web/public}/logo.png | Bin .../src/application/ports/candidate-cache.ts | 4 + .../application/ports/embedding-provider.ts | 3 + .../src/application/ports/event-repository.ts | 42 + .../src/application/ports/intro-repository.ts | 9 + .../web/src/application/ports/llm-provider.ts | 6 + .../src/application/ports/match-repository.ts | 6 + .../web/src/application/ports/notification.ts | 4 + .../ports/participant-repository.ts | 16 + .../web/src/application/ports/rate-limiter.ts | 3 + .../application/use-cases/compute-matches.ts | 5 + .../application/use-cases/get-my-matches.ts | 5 + .../src/application/use-cases/manage-event.ts | 41 + .../application/use-cases/request-intro.ts | 27 + .../application/use-cases/respond-to-intro.ts | 26 + .../application/use-cases/reveal-contact.ts | 8 + .../use-cases/search-participants.ts | 12 + .../application/use-cases/share-venue-zone.ts | 19 + .../use-cases/upsert-participant.ts | 11 + apps/web/src/composition/container.ts | 41 + .../src/domain/connection/connection.rules.ts | 6 + .../domain/connection/intro-request.entity.ts | 38 + .../web/src/domain/matching/match-strategy.ts | 15 + apps/web/src/domain/matching/pipeline.ts | 87 + .../scorers/complementarity.scorer.ts | 12 + .../domain/matching/scorers/domain.scorer.ts | 13 + .../domain/matching/scorers/intent.scorer.ts | 11 + .../domain/matching/scorers/jaccard.scorer.ts | 14 + .../web/src/domain/matching/scorers/scorer.ts | 25 + .../matching/scorers/semantic.scorer.ts | 18 + .../matching/scorers/seniority.scorer.ts | 11 + .../specifications/intent-compatible.spec.ts | 10 + .../matching/specifications/specification.ts | 3 + .../matching/specifications/visible.spec.ts | 8 + .../matching/stages/intent-filter.stage.ts | 11 + .../matching/stages/llm-rerank.stage.ts | 25 + .../domain/matching/stages/persist.stage.ts | 9 + .../domain/matching/stages/retrieve.stage.ts | 50 + .../src/domain/matching/stages/score.stage.ts | 33 + .../src/domain/matching/stages/topk.stage.ts | 7 + apps/web/src/domain/participant/intent.ts | 32 + .../domain/participant/participant.entity.ts | 75 + apps/web/src/domain/shared/tenant-context.ts | 16 + apps/web/src/domain/shared/value-objects.ts | 20 + .../cache/postgres-candidate-cache.ts | 20 + .../cache/postgres-rate-limiter.ts | 22 + .../cache/upstash-candidate-cache.ts | 50 + .../notifications/realtime.notifier.ts | 25 + .../src/infrastructure/postgres/event.repo.ts | 75 + .../src/infrastructure/postgres/intro.repo.ts | 101 + .../src/infrastructure/postgres/match.repo.ts | 84 + .../postgres/participant.repo.ts | 159 + .../providers/gemini-embedding.provider.ts | 30 + .../providers/gemini-llm.provider.ts | 57 + .../providers/local-bge.provider.ts | 23 + .../providers/provider-registry.ts | 18 + .../src/infrastructure/resilience/bulkhead.ts | 1 + .../resilience/circuit-breaker.ts | 1 + .../web/src/infrastructure/supabase/client.ts | 1 + apps/web/src/lib/auth.ts | 35 + apps/web/src/lib/excel-importer.ts | 66 + apps/web/tsconfig.json | 24 + apps/web/types/database.types.ts | 2 + backend/authcallback.jsx | 64 - database/import-attendees.js | 112 - database/schema.sql | 60 - docker-compose.yml | 153 + docs/BRIDGE_ENGINE_PIPELINE.md | 35 + docs/BRIDGE_ENGINE_PIPELINE_TEXT_DIAGRAM.md | 58 + docs/Bridge-Engine-Pipeline.svg | 195 + docs/END_TO_END_FLOW.md | 86 + docs/END_TO_END_FLOW_TEXT_DIAGRAM.md | 59 + docs/IMG-20260625-WA0014.jpg.jpeg | Bin 0 -> 83863 bytes docs/PRODUCTION_ROADMAP.md | 96 + docs/PROJECT_STRUCTURE.md | 62 + docs/roadmap_revised.md | 220 + infra/docker/keycloak.Dockerfile | 31 + infra/docker/migrate.Dockerfile | 23 + infra/docker/worker.Dockerfile | 19 + infra/postgres/init/01-create-keycloak-db.sql | 6 + infra/terraform/alb.tf | 218 + infra/terraform/autoscaling.tf | 140 + infra/terraform/database.tf | 103 + infra/terraform/ecs.tf | 516 + infra/terraform/iam.tf | 199 + infra/terraform/monitoring.tf | 216 + infra/terraform/network.tf | 213 + infra/terraform/outputs.tf | 113 + infra/terraform/secrets.tf | 64 + infra/terraform/terraform.tfvars.example | 46 + infra/terraform/variables.tf | 301 + infra/terraform/versions.tf | 33 + keycloak/realm-export.json | 108 + next.config.mjs | 4 - package-lock.json | 9566 +++++++++++------ package.json | 51 +- packages/auth/package.json | 18 + packages/auth/src/config.ts | 100 + packages/auth/src/index.ts | 50 + packages/auth/src/keycloak.ts | 363 + packages/auth/src/otp.ts | 135 + packages/auth/src/session.ts | 154 + packages/auth/tsconfig.json | 8 + packages/db/migrations/0001_init.sql | 44 + .../db/migrations/0002_login_challenges.sql | 31 + .../db/migrations/0003_events_matching.sql | 134 + packages/db/package.json | 20 + packages/db/src/client.ts | 104 + packages/db/src/ensure-database.ts | 80 + packages/db/src/index.ts | 13 + packages/db/src/is-main.ts | 20 + packages/db/src/migrate.ts | 103 + packages/db/src/repositories/attendees.ts | 148 + packages/db/src/repositories/events.ts | 157 + .../db/src/repositories/login-challenges.ts | 128 + packages/db/src/repositories/matches.ts | 43 + packages/db/src/repositories/matching-jobs.ts | 48 + packages/db/src/seed.ts | 144 + packages/db/src/types.ts | 52 + packages/db/tsconfig.json | 8 + packages/db/workers/embed.worker.ts | 22 + packages/db/workers/match.worker.ts | 17 + packages/db/workers/worker.ts | 24 + packages/email/package.json | 17 + packages/email/src/client.ts | 101 + packages/email/src/index.ts | 5 + packages/email/src/templates/login-email.ts | 153 + packages/email/tsconfig.json | 8 + tests/integration/login-challenge.test.ts | 156 + tests/unit/attendees.test.ts | 36 + tests/unit/auth-redirect.test.ts | 20 + tests/unit/auth-routes.test.ts | 135 + tests/unit/login-email.test.ts | 49 + tests/unit/otp.test.ts | 65 + tests/unit/session.test.ts | 88 + tools/bootstrap-organization.ts | 58 + tools/import-attendees.ts | 156 + theme_update.cjs => tools/theme_update.cjs | 0 tools/wait-for-keycloak.ts | 21 + tsconfig.base.json | 28 + turbo.json | 33 + vitest.config.ts | 23 + 196 files changed, 17028 insertions(+), 4042 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy.yml delete mode 100644 app/api/lookup-email/route.js delete mode 100644 app/auth/callback/page.jsx delete mode 100644 app/login/page.jsx delete mode 100644 app/page.jsx create mode 100644 apps/web/Dockerfile create mode 100644 apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/analytics/page.tsx create mode 100644 apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/matching/page.tsx create mode 100644 apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/page.tsx create mode 100644 apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/roster/page.tsx create mode 100644 apps/web/app/(organizer)/orgs/[orgSlug]/events/new/page.tsx create mode 100644 apps/web/app/(organizer)/orgs/[orgSlug]/events/page.tsx create mode 100644 apps/web/app/(participant)/e/[eventSlug]/connections/page.tsx create mode 100644 apps/web/app/(participant)/e/[eventSlug]/matches/page.tsx create mode 100644 apps/web/app/(participant)/e/[eventSlug]/page.tsx create mode 100644 apps/web/app/(participant)/e/[eventSlug]/profile/page.tsx create mode 100644 apps/web/app/(participant)/e/[eventSlug]/search/SearchForm.tsx create mode 100644 apps/web/app/(participant)/e/[eventSlug]/search/page.tsx rename {app => apps/web/app}/MatchApp.jsx (95%) create mode 100644 apps/web/app/actions/intro.actions.ts create mode 100644 apps/web/app/actions/match.actions.ts create mode 100644 apps/web/app/actions/organizer.actions.ts create mode 100644 apps/web/app/actions/participant.actions.ts create mode 100644 apps/web/app/api/auth/google/start/route.js create mode 100644 apps/web/app/api/auth/logout/route.js create mode 100644 apps/web/app/api/auth/lookup/route.js create mode 100644 apps/web/app/api/auth/otp/request/route.js create mode 100644 apps/web/app/api/auth/otp/verify/route.js create mode 100644 apps/web/app/api/domains/route.js create mode 100644 apps/web/app/api/health/ready/route.js create mode 100644 apps/web/app/api/health/route.js rename {app => apps/web/app}/api/match/route.js (69%) create mode 100644 apps/web/app/api/me/route.js create mode 100644 apps/web/app/api/webhooks/.gitkeep create mode 100644 apps/web/app/auth/callback/route.js rename {app => apps/web/app}/icon.png (100%) rename {app => apps/web/app}/layout.jsx (100%) rename {app => apps/web/app}/login.jsx (65%) create mode 100644 apps/web/app/login/page.jsx create mode 100644 apps/web/app/page.jsx create mode 100644 apps/web/components/organizer/.gitkeep create mode 100644 apps/web/components/participant/.gitkeep create mode 100644 apps/web/components/ui/.gitkeep create mode 100644 apps/web/eslint.config.mjs create mode 100644 apps/web/lib/safe-return-to.ts create mode 100644 apps/web/lib/session.ts create mode 100644 apps/web/middleware.ts create mode 100644 apps/web/next.config.mjs create mode 100644 apps/web/package.json rename {public => apps/web/public}/logo.png (100%) create mode 100644 apps/web/src/application/ports/candidate-cache.ts create mode 100644 apps/web/src/application/ports/embedding-provider.ts create mode 100644 apps/web/src/application/ports/event-repository.ts create mode 100644 apps/web/src/application/ports/intro-repository.ts create mode 100644 apps/web/src/application/ports/llm-provider.ts create mode 100644 apps/web/src/application/ports/match-repository.ts create mode 100644 apps/web/src/application/ports/notification.ts create mode 100644 apps/web/src/application/ports/participant-repository.ts create mode 100644 apps/web/src/application/ports/rate-limiter.ts create mode 100644 apps/web/src/application/use-cases/compute-matches.ts create mode 100644 apps/web/src/application/use-cases/get-my-matches.ts create mode 100644 apps/web/src/application/use-cases/manage-event.ts create mode 100644 apps/web/src/application/use-cases/request-intro.ts create mode 100644 apps/web/src/application/use-cases/respond-to-intro.ts create mode 100644 apps/web/src/application/use-cases/reveal-contact.ts create mode 100644 apps/web/src/application/use-cases/search-participants.ts create mode 100644 apps/web/src/application/use-cases/share-venue-zone.ts create mode 100644 apps/web/src/application/use-cases/upsert-participant.ts create mode 100644 apps/web/src/composition/container.ts create mode 100644 apps/web/src/domain/connection/connection.rules.ts create mode 100644 apps/web/src/domain/connection/intro-request.entity.ts create mode 100644 apps/web/src/domain/matching/match-strategy.ts create mode 100644 apps/web/src/domain/matching/pipeline.ts create mode 100644 apps/web/src/domain/matching/scorers/complementarity.scorer.ts create mode 100644 apps/web/src/domain/matching/scorers/domain.scorer.ts create mode 100644 apps/web/src/domain/matching/scorers/intent.scorer.ts create mode 100644 apps/web/src/domain/matching/scorers/jaccard.scorer.ts create mode 100644 apps/web/src/domain/matching/scorers/scorer.ts create mode 100644 apps/web/src/domain/matching/scorers/semantic.scorer.ts create mode 100644 apps/web/src/domain/matching/scorers/seniority.scorer.ts create mode 100644 apps/web/src/domain/matching/specifications/intent-compatible.spec.ts create mode 100644 apps/web/src/domain/matching/specifications/specification.ts create mode 100644 apps/web/src/domain/matching/specifications/visible.spec.ts create mode 100644 apps/web/src/domain/matching/stages/intent-filter.stage.ts create mode 100644 apps/web/src/domain/matching/stages/llm-rerank.stage.ts create mode 100644 apps/web/src/domain/matching/stages/persist.stage.ts create mode 100644 apps/web/src/domain/matching/stages/retrieve.stage.ts create mode 100644 apps/web/src/domain/matching/stages/score.stage.ts create mode 100644 apps/web/src/domain/matching/stages/topk.stage.ts create mode 100644 apps/web/src/domain/participant/intent.ts create mode 100644 apps/web/src/domain/participant/participant.entity.ts create mode 100644 apps/web/src/domain/shared/tenant-context.ts create mode 100644 apps/web/src/domain/shared/value-objects.ts create mode 100644 apps/web/src/infrastructure/cache/postgres-candidate-cache.ts create mode 100644 apps/web/src/infrastructure/cache/postgres-rate-limiter.ts create mode 100644 apps/web/src/infrastructure/cache/upstash-candidate-cache.ts create mode 100644 apps/web/src/infrastructure/notifications/realtime.notifier.ts create mode 100644 apps/web/src/infrastructure/postgres/event.repo.ts create mode 100644 apps/web/src/infrastructure/postgres/intro.repo.ts create mode 100644 apps/web/src/infrastructure/postgres/match.repo.ts create mode 100644 apps/web/src/infrastructure/postgres/participant.repo.ts create mode 100644 apps/web/src/infrastructure/providers/gemini-embedding.provider.ts create mode 100644 apps/web/src/infrastructure/providers/gemini-llm.provider.ts create mode 100644 apps/web/src/infrastructure/providers/local-bge.provider.ts create mode 100644 apps/web/src/infrastructure/providers/provider-registry.ts create mode 100644 apps/web/src/infrastructure/resilience/bulkhead.ts create mode 100644 apps/web/src/infrastructure/resilience/circuit-breaker.ts create mode 100644 apps/web/src/infrastructure/supabase/client.ts create mode 100644 apps/web/src/lib/auth.ts create mode 100644 apps/web/src/lib/excel-importer.ts create mode 100644 apps/web/tsconfig.json create mode 100644 apps/web/types/database.types.ts delete mode 100644 backend/authcallback.jsx delete mode 100644 database/import-attendees.js delete mode 100644 database/schema.sql create mode 100644 docker-compose.yml create mode 100644 docs/BRIDGE_ENGINE_PIPELINE.md create mode 100644 docs/BRIDGE_ENGINE_PIPELINE_TEXT_DIAGRAM.md create mode 100644 docs/Bridge-Engine-Pipeline.svg create mode 100644 docs/END_TO_END_FLOW.md create mode 100644 docs/END_TO_END_FLOW_TEXT_DIAGRAM.md create mode 100644 docs/IMG-20260625-WA0014.jpg.jpeg create mode 100644 docs/PRODUCTION_ROADMAP.md create mode 100644 docs/PROJECT_STRUCTURE.md create mode 100644 docs/roadmap_revised.md create mode 100644 infra/docker/keycloak.Dockerfile create mode 100644 infra/docker/migrate.Dockerfile create mode 100644 infra/docker/worker.Dockerfile create mode 100644 infra/postgres/init/01-create-keycloak-db.sql create mode 100644 infra/terraform/alb.tf create mode 100644 infra/terraform/autoscaling.tf create mode 100644 infra/terraform/database.tf create mode 100644 infra/terraform/ecs.tf create mode 100644 infra/terraform/iam.tf create mode 100644 infra/terraform/monitoring.tf create mode 100644 infra/terraform/network.tf create mode 100644 infra/terraform/outputs.tf create mode 100644 infra/terraform/secrets.tf create mode 100644 infra/terraform/terraform.tfvars.example create mode 100644 infra/terraform/variables.tf create mode 100644 infra/terraform/versions.tf create mode 100644 keycloak/realm-export.json delete mode 100644 next.config.mjs create mode 100644 packages/auth/package.json create mode 100644 packages/auth/src/config.ts create mode 100644 packages/auth/src/index.ts create mode 100644 packages/auth/src/keycloak.ts create mode 100644 packages/auth/src/otp.ts create mode 100644 packages/auth/src/session.ts create mode 100644 packages/auth/tsconfig.json create mode 100644 packages/db/migrations/0001_init.sql create mode 100644 packages/db/migrations/0002_login_challenges.sql create mode 100644 packages/db/migrations/0003_events_matching.sql create mode 100644 packages/db/package.json create mode 100644 packages/db/src/client.ts create mode 100644 packages/db/src/ensure-database.ts create mode 100644 packages/db/src/index.ts create mode 100644 packages/db/src/is-main.ts create mode 100644 packages/db/src/migrate.ts create mode 100644 packages/db/src/repositories/attendees.ts create mode 100644 packages/db/src/repositories/events.ts create mode 100644 packages/db/src/repositories/login-challenges.ts create mode 100644 packages/db/src/repositories/matches.ts create mode 100644 packages/db/src/repositories/matching-jobs.ts create mode 100644 packages/db/src/seed.ts create mode 100644 packages/db/src/types.ts create mode 100644 packages/db/tsconfig.json create mode 100644 packages/db/workers/embed.worker.ts create mode 100644 packages/db/workers/match.worker.ts create mode 100644 packages/db/workers/worker.ts create mode 100644 packages/email/package.json create mode 100644 packages/email/src/client.ts create mode 100644 packages/email/src/index.ts create mode 100644 packages/email/src/templates/login-email.ts create mode 100644 packages/email/tsconfig.json create mode 100644 tests/integration/login-challenge.test.ts create mode 100644 tests/unit/attendees.test.ts create mode 100644 tests/unit/auth-redirect.test.ts create mode 100644 tests/unit/auth-routes.test.ts create mode 100644 tests/unit/login-email.test.ts create mode 100644 tests/unit/otp.test.ts create mode 100644 tests/unit/session.test.ts create mode 100644 tools/bootstrap-organization.ts create mode 100644 tools/import-attendees.ts rename theme_update.cjs => tools/theme_update.cjs (100%) create mode 100644 tools/wait-for-keycloak.ts create mode 100644 tsconfig.base.json create mode 100644 turbo.json create mode 100644 vitest.config.ts diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f160b66 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +.git +.github +node_modules +**/node_modules +**/.next +**/dist +.next + +# env files must never bake into an image — ECS injects them at runtime +.env +.env.* +!.env.example + +# PII — never goes into an image +*.xlsx + +docs +infra/terraform/.terraform +infra/terraform/*.tfstate* +**/*.log +**/.DS_Store +.gemini-cache.json +README.md +ReadMe.md +LICENSE diff --git a/.env.example b/.env.example index c4705f3..5607942 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,75 @@ -# Copy this file to .env.local and fill in your values -# Supabase — get these from your Supabase project settings > API -NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url -NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key +# ============================================================== +# Copy to .env and fill in. docker-compose reads .env automatically. +# Nothing here is exposed to the browser — there are no NEXT_PUBLIC_* vars. +# ============================================================== -# Service key — NEVER expose this to the browser, server/scripts only -SUPABASE_SERVICE_KEY=your_supabase_service_role_key +# ── App ─────────────────────────────────────────────────────── +# Public origin. Must match the Keycloak client's redirect URI. +APP_BASE_URL=http://localhost:3000 +WEB_PORT=3000 +DEFAULT_EVENT_SLUG=demo -# Gemini API — server-side only, never prefix with NEXT_PUBLIC_ -GEMINI_API_KEY=your_gemini_api_key_here +# Encrypts the session cookie. REQUIRED, min 32 chars. +# openssl rand -base64 48 +SESSION_SECRET= + +# ── Postgres ────────────────────────────────────────────────── +POSTGRES_USER=matchmaker +POSTGRES_PASSWORD=matchmaker +POSTGRES_DB=matchmaker +POSTGRES_PORT=5432 + +# Used by scripts run on the HOST (migrate/seed/import). +# Inside docker-compose the host is `postgres`, not `localhost`. +DATABASE_URL=postgres://matchmaker:matchmaker@localhost:5432/matchmaker +DATABASE_SSL=disable + +# ── Keycloak ────────────────────────────────────────────────── +KEYCLOAK_PORT=8080 +KEYCLOAK_PUBLIC_URL=http://localhost:8080 +KEYCLOAK_ADMIN=admin +KEYCLOAK_ADMIN_PASSWORD=admin + +# Issuer as the BROWSER sees it — also the expected `iss` claim. +KEYCLOAK_ISSUER=http://localhost:8080/realms/match-maker +# Issuer as the APP CONTAINER sees it. Only differs inside docker-compose. +KEYCLOAK_INTERNAL_ISSUER=http://keycloak:8080/realms/match-maker +KEYCLOAK_CLIENT_ID=match-maker-web +KEYCLOAK_CLIENT_SECRET=dev-client-secret-change-me +KEYCLOAK_GOOGLE_IDP_ALIAS=google + +# ── Google sign-in ──────────────────────────────────────────── +# From Google Cloud Console > APIs & Services > Credentials. +# Authorised redirect URI must be: +# http://localhost:8080/realms/match-maker/broker/google/endpoint +# Leave blank to develop with the e-mail-code path only. +GOOGLE_CLIENT_ID= +GOOGLE_CLIENT_SECRET= + +# ── Resend (login e-mails) ──────────────────────────────────── +RESEND_API_KEY= +EMAIL_FROM=Mr. Bridge + +# With no RESEND_API_KEY, print login e-mails to the server log instead of +# sending them. Local development only — never set this in a deployed +# environment, or logins will silently never arrive. +EMAIL_DEV_FALLBACK=true + +# Code + magic-link lifetime and throttling. +OTP_TTL_SECONDS=600 +OTP_MAX_PER_WINDOW=5 +OTP_RATE_WINDOW_SECONDS=900 + +# ── Gemini (matchmaking) ────────────────────────────────────── +GEMINI_API_KEY= +GEMINI_LLM_MODEL=gemini-3.8-flash +EMBEDDING_PROVIDER=gemini +# Optional self-hosted BGE endpoint, used when EMBEDDING_PROVIDER=local. +LOCAL_BGE_URL= +# Optional shared Redis retrieval cache. Docker uses PostgreSQL when these are blank. +UPSTASH_REDIS_REST_URL= +UPSTASH_REDIS_REST_TOKEN= + +# ── Local convenience ───────────────────────────────────────── +# Seed demo attendees after migrating. Never enable against production. +SEED_ON_MIGRATE=true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5b24733 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,152 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +# A new push supersedes an in-flight run on the same branch. +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +env: + NODE_VERSION: "22" + +jobs: + quality: + name: Lint, typecheck & unit tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: npm + + - run: npm ci + + - name: Typecheck + run: npm run typecheck + + - name: Lint + run: npm run lint + + - name: Unit tests + run: npx vitest run tests/unit + + integration: + name: Integration tests + runs-on: ubuntu-latest + + services: + postgres: + image: pgvector/pgvector:pg16 + env: + POSTGRES_USER: matchmaker + POSTGRES_PASSWORD: matchmaker + POSTGRES_DB: matchmaker + ports: + - 5432:5432 + options: >- + --health-cmd "pg_isready -U matchmaker" + --health-interval 5s + --health-timeout 5s + --health-retries 20 + + env: + DATABASE_URL: postgres://matchmaker:matchmaker@localhost:5432/matchmaker + DATABASE_SSL: disable + SESSION_SECRET: ci-session-secret-long-enough-for-validation-x + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: npm + + - run: npm ci + + # The suite calls migrate() itself, so this only proves the runner works + # standalone — the way the deploy pipeline invokes it. + - name: Apply migrations + run: npm run db:migrate + + - name: Integration tests + run: npx vitest run tests/integration + + build: + name: Build images + runs-on: ubuntu-latest + needs: [quality] + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + # Build only — publishing happens in deploy.yml, and only from main. + - name: Build web image + uses: docker/build-push-action@v6 + with: + context: . + file: apps/web/Dockerfile + push: false + load: false + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build migrate image + uses: docker/build-push-action@v6 + with: + context: . + file: infra/docker/migrate.Dockerfile + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build worker image + uses: docker/build-push-action@v6 + with: + context: . + file: infra/docker/worker.Dockerfile + push: false + load: false + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build Keycloak image + uses: docker/build-push-action@v6 + with: + context: . + file: infra/docker/keycloak.Dockerfile + push: false + cache-from: type=gha + cache-to: type=gha,mode=max + + terraform: + name: Terraform validate + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: "1.9.8" + + - name: Format check + run: terraform fmt -check -recursive + working-directory: infra/terraform + + # No backend, no credentials — this only checks the configuration parses + # and is internally consistent. + - name: Init (no backend) + run: terraform init -backend=false + working-directory: infra/terraform + + - name: Validate + run: terraform validate + working-directory: infra/terraform diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f7bcde0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,270 @@ +name: Deploy to ECS + +on: + push: + branches: [main] + workflow_dispatch: + inputs: + deploy_keycloak: + description: "Also rebuild and roll out Keycloak" + type: boolean + default: false + +# Never let two deploys race for the same service. +concurrency: + group: deploy-production + cancel-in-progress: false + +permissions: + # Required to fetch the OIDC token that assumes the AWS deploy role. + id-token: write + contents: read + +env: + AWS_REGION: ${{ vars.AWS_REGION || 'ap-south-1' }} + ECS_CLUSTER: ${{ vars.ECS_CLUSTER || 'match-maker-prod-cluster' }} + ECS_WEB_SERVICE: ${{ vars.ECS_WEB_SERVICE || 'match-maker-prod-web' }} + ECS_WORKER_SERVICE: ${{ vars.ECS_WORKER_SERVICE || 'match-maker-prod-worker' }} + ECS_KEYCLOAK_SERVICE: ${{ vars.ECS_KEYCLOAK_SERVICE || 'match-maker-prod-keycloak' }} + MIGRATE_TASK_FAMILY: ${{ vars.MIGRATE_TASK_FAMILY || 'match-maker-prod-migrate' }} + +jobs: + # Re-run the fast checks against the exact commit being shipped, so a green + # PR that raced with another merge cannot deploy a broken main. + verify: + name: Verify + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: "22" + cache: npm + - run: npm ci + - run: npm run typecheck + - run: npx vitest run tests/unit + + build-and-push: + name: Build & push images + runs-on: ubuntu-latest + needs: [verify] + outputs: + image_tag: ${{ steps.meta.outputs.tag }} + steps: + - uses: actions/checkout@v4 + + - name: Derive image tag + id: meta + # The commit SHA is the tag. `latest` also moves, but every deploy is + # pinned to an immutable tag so a rollback is just a re-deploy of one. + run: echo "tag=${GITHUB_SHA::12}" >> "$GITHUB_OUTPUT" + + - uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - uses: aws-actions/amazon-ecr-login@v2 + id: ecr + + - uses: docker/setup-buildx-action@v3 + + - name: Build & push web + uses: docker/build-push-action@v6 + with: + context: . + file: apps/web/Dockerfile + push: true + tags: | + ${{ steps.ecr.outputs.registry }}/match-maker-prod/web:${{ steps.meta.outputs.tag }} + ${{ steps.ecr.outputs.registry }}/match-maker-prod/web:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build & push migrate + uses: docker/build-push-action@v6 + with: + context: . + file: infra/docker/migrate.Dockerfile + push: true + tags: | + ${{ steps.ecr.outputs.registry }}/match-maker-prod/migrate:${{ steps.meta.outputs.tag }} + ${{ steps.ecr.outputs.registry }}/match-maker-prod/migrate:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build & push worker + uses: docker/build-push-action@v6 + with: + context: . + file: infra/docker/worker.Dockerfile + push: true + tags: | + ${{ steps.ecr.outputs.registry }}/match-maker-prod/worker:${{ steps.meta.outputs.tag }} + ${{ steps.ecr.outputs.registry }}/match-maker-prod/worker:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build & push Keycloak + if: inputs.deploy_keycloak + uses: docker/build-push-action@v6 + with: + context: . + file: infra/docker/keycloak.Dockerfile + push: true + tags: | + ${{ steps.ecr.outputs.registry }}/match-maker-prod/keycloak:${{ steps.meta.outputs.tag }} + ${{ steps.ecr.outputs.registry }}/match-maker-prod/keycloak:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + migrate: + name: Run migrations + runs-on: ubuntu-latest + needs: [build-and-push] + steps: + - uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + # Migrations run BEFORE the new tasks roll out, so they must be + # backwards-compatible with the version currently serving traffic. + - name: Run migration task and wait + run: | + set -euo pipefail + + TASK_ARN=$(aws ecs run-task \ + --cluster "$ECS_CLUSTER" \ + --task-definition "$MIGRATE_TASK_FAMILY" \ + --launch-type FARGATE \ + --network-configuration "awsvpcConfiguration={subnets=[${{ secrets.PRIVATE_SUBNET_IDS }}],securityGroups=[${{ secrets.TASK_SECURITY_GROUP_ID }}],assignPublicIp=DISABLED}" \ + --query 'tasks[0].taskArn' --output text) + + echo "Migration task: $TASK_ARN" + aws ecs wait tasks-stopped --cluster "$ECS_CLUSTER" --tasks "$TASK_ARN" + + EXIT_CODE=$(aws ecs describe-tasks --cluster "$ECS_CLUSTER" --tasks "$TASK_ARN" \ + --query 'tasks[0].containers[0].exitCode' --output text) + REASON=$(aws ecs describe-tasks --cluster "$ECS_CLUSTER" --tasks "$TASK_ARN" \ + --query 'tasks[0].stoppedReason' --output text) + + echo "Exit code: $EXIT_CODE ($REASON)" + if [ "$EXIT_CODE" != "0" ]; then + echo "::error::Migration failed — aborting deploy. Check /ecs/match-maker-prod/migrate." + exit 1 + fi + + deploy: + name: Roll out + runs-on: ubuntu-latest + needs: [build-and-push, migrate] + steps: + - uses: actions/checkout@v4 + + - uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_ARN }} + aws-region: ${{ env.AWS_REGION }} + + - name: Pin web task definition to the new image + id: taskdef + run: | + set -euo pipefail + TAG="${{ needs.build-and-push.outputs.image_tag }}" + REGISTRY="$(aws sts get-caller-identity --query Account --output text).dkr.ecr.${AWS_REGION}.amazonaws.com" + + aws ecs describe-task-definition \ + --task-definition "$(aws ecs describe-services --cluster "$ECS_CLUSTER" --services "$ECS_WEB_SERVICE" --query 'services[0].taskDefinition' --output text)" \ + --query 'taskDefinition' > taskdef.json + + # Strip the server-managed fields that RegisterTaskDefinition rejects, + # then point the container at the immutable tag. + jq --arg IMAGE "$REGISTRY/match-maker-prod/web:$TAG" ' + .containerDefinitions[0].image = $IMAGE + | del(.taskDefinitionArn, .revision, .status, .requiresAttributes, + .compatibilities, .registeredAt, .registeredBy, .deregisteredAt) + ' taskdef.json > new-taskdef.json + + NEW_ARN=$(aws ecs register-task-definition \ + --cli-input-json file://new-taskdef.json \ + --query 'taskDefinition.taskDefinitionArn' --output text) + + echo "arn=$NEW_ARN" >> "$GITHUB_OUTPUT" + echo "Registered $NEW_ARN" + + - name: Update web service + run: | + aws ecs update-service \ + --cluster "$ECS_CLUSTER" \ + --service "$ECS_WEB_SERVICE" \ + --task-definition "${{ steps.taskdef.outputs.arn }}" \ + --query 'service.deployments[0].id' --output text + + - name: Pin worker task definition to the new image + id: worker-taskdef + run: | + set -euo pipefail + TAG="${{ needs.build-and-push.outputs.image_tag }}" + REGISTRY="$(aws sts get-caller-identity --query Account --output text).dkr.ecr.${AWS_REGION}.amazonaws.com" + + aws ecs describe-task-definition \ + --task-definition "$(aws ecs describe-services --cluster "$ECS_CLUSTER" --services "$ECS_WORKER_SERVICE" --query 'services[0].taskDefinition' --output text)" \ + --query 'taskDefinition' > worker-taskdef.json + + jq --arg IMAGE "$REGISTRY/match-maker-prod/worker:$TAG" ' + .containerDefinitions[0].image = $IMAGE + | del(.taskDefinitionArn, .revision, .status, .requiresAttributes, + .compatibilities, .registeredAt, .registeredBy, .deregisteredAt) + ' worker-taskdef.json > new-worker-taskdef.json + + NEW_ARN=$(aws ecs register-task-definition \ + --cli-input-json file://new-worker-taskdef.json \ + --query 'taskDefinition.taskDefinitionArn' --output text) + echo "arn=$NEW_ARN" >> "$GITHUB_OUTPUT" + echo "Registered $NEW_ARN" + + - name: Update worker service + run: | + aws ecs update-service \ + --cluster "$ECS_CLUSTER" \ + --service "$ECS_WORKER_SERVICE" \ + --task-definition "${{ steps.worker-taskdef.outputs.arn }}" \ + --query 'service.deployments[0].id' --output text + + - name: Force Keycloak rollout + if: inputs.deploy_keycloak + run: | + aws ecs update-service \ + --cluster "$ECS_CLUSTER" \ + --service "$ECS_KEYCLOAK_SERVICE" \ + --force-new-deployment >/dev/null + + # The service's deployment circuit breaker rolls back automatically on + # failure; this makes the workflow reflect that outcome. + - name: Wait for the service to stabilise + run: | + aws ecs wait services-stable --cluster "$ECS_CLUSTER" --services "$ECS_WEB_SERVICE" "$ECS_WORKER_SERVICE" + echo "Web and worker deployments are stable." + + - name: Smoke test + run: | + set -euo pipefail + URL="${{ vars.APP_BASE_URL }}" + if [ -z "$URL" ]; then + echo "APP_BASE_URL variable not set — skipping smoke test." + exit 0 + fi + + echo "Checking $URL/api/health/ready" + for attempt in 1 2 3 4 5; do + if curl -fsS --max-time 15 "$URL/api/health/ready" | tee /tmp/ready.json; then + echo + exit 0 + fi + echo "attempt $attempt failed; retrying in 10s" + sleep 10 + done + + echo "::error::Readiness check never passed after deploy." + exit 1 diff --git a/.gitignore b/.gitignore index 5ea9339..22f52aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,126 @@ # dependencies -/node_modules +node_modules /.pnp .pnp.js # next.js -/.next/ -/out/ +.next/ +out/ +next-env.d.ts # production /build +dist/ -# misc -.DS_Store +# turbo +.turbo + +# typescript +*.tsbuildinfo + +# vercel +.vercel + +# test output +coverage/ +test-results/ +playwright-report/ +blob-report/ + +# --------------------------------------------------------------------------- +# Secrets — never commit +# --------------------------------------------------------------------------- + +# env files — .env.example is the only one committed +.env +.env.* +!.env.example + +# keys and certificates *.pem +*.key +*.crt +*.cer +*.p12 +*.pfx +*.jks +*.keystore +id_rsa* +id_ed25519* -# debug -npm-debug.log* +# downloaded cloud / OAuth credentials +credentials.json +client_secret*.json +service-account*.json +*.secret +secrets/ -# env files -.env*.local +# Keycloak user exports contain password hashes (realm-export.json stays) +keycloak/*-users-*.json + +# local compose overrides often carry real credentials +docker-compose.override.yml +compose.override.yml + +# terraform +infra/terraform/.terraform/ +infra/terraform/*.tfstate +infra/terraform/*.tfstate.* +infra/terraform/*.tfvars +!infra/terraform/*.tfvars.example +infra/terraform/*.tfplan +infra/terraform/.terraform.lock.hcl +infra/terraform/override.tf +infra/terraform/*_override.tf +.terraformrc +terraform.rc +crash.log +crash.*.log + +# --------------------------------------------------------------------------- +# Attendee data (PII) and database dumps — never commit +# --------------------------------------------------------------------------- +*.xlsx +*.xls +*.csv +*.dump +*.backup +*.sql.gz +backups/ # gemini file cache .gemini-cache.json -# attendee data (PII — never commit) -*.xlsx +# --------------------------------------------------------------------------- +# Logs, caches and temp files +# --------------------------------------------------------------------------- +*.log +logs/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +.eslintcache +.cache/ +*.pid +*.seed +*.tmp +*.temp +tmp/ +temp/ -# vercel -.vercel +# editors and IDEs +.idea/ +.vscode/* +!.vscode/extensions.json +*.swp +*.swo +*~ +.claude/settings.local.json -# typescript -*.tsbuildinfo -next-env.d.ts +# OS files +.DS_Store +Thumbs.db +ehthumbs.db +desktop.ini +$RECYCLE.BIN/ diff --git a/ReadMe.md b/ReadMe.md index dda2ada..981a7cb 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,22 +1,131 @@ -User enters phone / email - │ - ▼ -Check registered_attendees table in Supabase - │ - ┌────┴────┐ -Not found Found - │ │ - ▼ ┌────┴────────┐ -Block Phone Email - │ │ - ▼ ▼ - Supabase OTP Supabase Google OAuth - (via Twilio) (redirect → callback) - │ │ - ▼ ▼ - Verify OTP Verify email matches - │ registered_attendees - └────┬────┘ - ▼ - onAuthSuccess() - → Load matchmaking app \ No newline at end of file +# Mr. Bridge + +Mr. Bridge is a multi event networking and matchmaking app. Organizers create events, import attendee rosters, configure intents and venue zones, and open registration. Attendees claim an invited roster entry, complete a profile, discover ranked matches, and request introductions. Contact details appear only after the other attendee accepts. + +The implementation follows the architecture described in [docs/PROJECT_STRUCTURE.md](docs/PROJECT_STRUCTURE.md). The [end-to-end flow](docs/END_TO_END_FLOW.md) and [matching pipeline](docs/BRIDGE_ENGINE_PIPELINE.md) docs show the product journeys. + +See the [production roadmap](docs/PRODUCTION_ROADMAP.md) for authentication findings, the invited-account signup policy, Google setup, and remaining work ordered by implementation effort. + +## Architecture + +| Area | Responsibility | +| --- | --- | +| `apps/web/app` | Next.js pages, route handlers, and server actions | +| `apps/web/src/domain` | Participant, intent, connection, and matching rules | +| `apps/web/src/application` | Use cases and ports | +| `apps/web/src/infrastructure` | PostgreSQL repositories, Gemini/BGE providers, notifications, and rate limiting | +| `apps/web/src/composition` | Binds ports to adapters | +| `packages/db` | PostgreSQL pool, migrations, repositories, demo seed, and async job queue | +| `packages/auth`, `packages/email` | Keycloak/OIDC and passwordless e-mail services | +| `infra/docker` | Web, migration, and queue-worker images | +| `infra/terraform` | AWS ECS, RDS, networking, and monitoring | + +The Next.js app, shared packages, migrations, and worker run from one npm workspace. Docker builds use the repository root as their context so workspace packages are available to each image. + +## Run the local stack + +Requirements: Node.js 22+, npm, and Docker Compose. + +1. Copy `.env.example` to `.env`. +2. Set `SESSION_SECRET` to a random value of at least 32 characters. In PowerShell: + + ```powershell + [Convert]::ToBase64String([Security.Cryptography.RandomNumberGenerator]::GetBytes(48)) + ``` + +3. Start the app and its dependencies: + + ```bash + npm run docker:up + ``` + +Compose starts the Next.js app, Keycloak, PostgreSQL with pgvector, a one-shot migration/demo-seed task, and the embedding/matching worker. The app is at `http://localhost:3000`; Keycloak is at `http://localhost:8080`. + +The demo event is `http://localhost:3000/e/demo`. The organizer dashboard is `http://localhost:3000/orgs/ai-community-lucknow/events/demo`. + +Demo attendee accounts are already on the seeded roster. Use a listed attendee's phone number, such as `+919876543210`, and enter the e-mail code. With no `RESEND_API_KEY`, local e-mail delivery is printed in the web logs: + +```bash +docker compose logs -f web +``` + +The organizer account is `organizer@example.com` / `+919876543209`. Google sign-in requires Google OAuth credentials in `.env`; e-mail-code sign-in works without them. Gemini is optional for local use; without `GEMINI_API_KEY`, the app uses its built-in profile and intent scoring. + +```bash +npm run docker:logs +npm run docker:down +``` + +`docker compose down` keeps the PostgreSQL volume. The schema and demo roster are re-applied safely when the stack starts again. + +## Local development without Docker + +Install workspace dependencies and start PostgreSQL/Keycloak separately, or use Compose for those services. `.env` is loaded by migration and import commands; Next.js loads `.env` itself. + +```bash +npm install +npm run db:migrate +npm run db:seed +npm run dev +``` + +## Organizer and roster setup + +Organizers can create an event from `/orgs//events/new`, import `.xlsx` or `.xls` attendee rosters from the event's Roster page, configure profile intents and venue zones, and start matching from the Matching page. + +For a new production database, first import the attendee identities, create the organization and its first event, then associate the roster with that event: + +```bash +npm run db:import -- attendees.xlsx --no-event +npm run org:init -- "AI Community" ai-community organizer@example.com "Summer Meetup" summer-meetup +npm run db:import -- attendees.xlsx summer-meetup +``` + +The first command imports the global attendee directory so the organizer account exists. The bootstrap command grants that account organization and event owner access. The last command attaches imported attendees to the event. These commands use `DATABASE_URL` from `.env`. + +## Workspace commands + +| Command | Purpose | +| --- | --- | +| `npm run dev` | Run the Next.js app in development | +| `npm run build` | Build workspace packages and the app | +| `npm run typecheck` | Type-check all workspaces | +| `npm run lint` | Run ESLint | +| `npm test` | Run unit and integration suites | +| `npm run db:migrate` | Apply pending PostgreSQL migrations | +| `npm run db:seed` | Upsert demo roster, organization, event, and organizer | +| `npm run db:import -- [event-slug]` | Import attendee rows and optionally attach them to an event | +| `npm run keycloak:wait` | Wait for the configured Keycloak realm to respond | +| `npm run docker:up` | Build images and start the local Compose stack | + +`DATABASE_URL` should point at `localhost` for commands run on the host. Compose sets the service hostname `postgres` inside containers. + +## Environment variables + +See `.env.example` for the full list. The main settings are: + +| Variable | Purpose | +| --- | --- | +| `SESSION_SECRET` | Encrypts application session cookies; required | +| `DATABASE_URL` | PostgreSQL connection string | +| `KEYCLOAK_ISSUER`, `KEYCLOAK_CLIENT_ID`, `KEYCLOAK_CLIENT_SECRET` | OIDC configuration | +| `RESEND_API_KEY` | Sends passwordless e-mail; local fallback logs codes when unset | +| `GEMINI_API_KEY` | Enables Gemini profile embeddings and LLM reranking | +| `DEFAULT_EVENT_SLUG` | Event used by the `/` redirect | +| `SEED_ON_MIGRATE` | Seeds demo data in the local stack; leave false in production | + +## Docker and deployment + +Build from the repository root: + +```bash +docker build -f apps/web/Dockerfile . +docker build -f infra/docker/migrate.Dockerfile . +docker build -f infra/docker/worker.Dockerfile . +``` + +The GitHub workflows type-check the workspace, build the container images, apply database migrations, and deploy the web and worker services to ECS. Terraform configuration is under `infra/terraform`; deployment secrets are injected through AWS Secrets Manager. + +## License + +MIT. See [LICENSE](LICENSE). diff --git a/app/api/lookup-email/route.js b/app/api/lookup-email/route.js deleted file mode 100644 index 050d9ab..0000000 --- a/app/api/lookup-email/route.js +++ /dev/null @@ -1,34 +0,0 @@ -import { NextResponse } from "next/server"; -import { createClient } from "@supabase/supabase-js"; - -const supabase = createClient( - process.env.SUPABASE_URL, - process.env.SUPABASE_SERVICE_KEY -); - -export async function POST(req) { - try { - const { phone } = await req.json(); - if (!phone) return NextResponse.json({ error: "Phone required" }, { status: 400 }); - - // Normalize to E.164 - const digits = phone.replace(/\D/g, ""); - const normalized = - digits.length === 10 ? `+91${digits}` : - digits.length === 12 && digits.startsWith("91") ? `+${digits}` : - phone.startsWith("+") ? phone.trim() : `+${digits}`; - - const { data, error } = await supabase - .from("registered_attendees") - .select("email, name") - .eq("phone", normalized) - .maybeSingle(); - - if (error) return NextResponse.json({ error: "Lookup failed" }, { status: 500 }); - if (!data?.email) return NextResponse.json({ registered: false }, { status: 200 }); - - return NextResponse.json({ registered: true, email: data.email, name: data.name }); - } catch { - return NextResponse.json({ error: "Internal server error" }, { status: 500 }); - } -} diff --git a/app/auth/callback/page.jsx b/app/auth/callback/page.jsx deleted file mode 100644 index 5f52c18..0000000 --- a/app/auth/callback/page.jsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client"; - -import AuthCallback from "../../../backend/authcallback.jsx"; -import { useRouter } from "next/navigation"; - -export default function CallbackPage() { - const router = useRouter(); - - return ( - router.push("/")} - onAuthFail={() => router.push("/login")} - /> - ); -} diff --git a/app/login/page.jsx b/app/login/page.jsx deleted file mode 100644 index 2e6606b..0000000 --- a/app/login/page.jsx +++ /dev/null @@ -1,9 +0,0 @@ -"use client"; - -import Login from "../login.jsx"; -import { useRouter } from "next/navigation"; - -export default function LoginPage() { - const router = useRouter(); - return router.push("/")} />; -} diff --git a/app/page.jsx b/app/page.jsx deleted file mode 100644 index 9b79457..0000000 --- a/app/page.jsx +++ /dev/null @@ -1,9 +0,0 @@ -"use client"; - -import dynamic from "next/dynamic"; - -const MatchApp = dynamic(() => import("./MatchApp"), { ssr: false }); - -export default function Page() { - return ; -} diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile new file mode 100644 index 0000000..e5ad9a0 --- /dev/null +++ b/apps/web/Dockerfile @@ -0,0 +1,67 @@ +# syntax=docker/dockerfile:1.7 +# ============================================================== +# Mr. Bridge web — multi-stage build for ECS Fargate. +# Build context is the MONOREPO ROOT, not apps/web: +# docker build -f apps/web/Dockerfile . +# ============================================================== + +ARG NODE_VERSION=22-alpine + +# ── deps ────────────────────────────────────────────────────── +# Only manifests are copied here, so this layer is reused across +# source-only changes and npm ci runs from cache. +FROM node:${NODE_VERSION} AS deps +WORKDIR /repo + +COPY package.json package-lock.json ./ +COPY apps/web/package.json apps/web/ +COPY packages/db/package.json packages/db/ +COPY packages/auth/package.json packages/auth/ +COPY packages/email/package.json packages/email/ + +RUN --mount=type=cache,target=/root/.npm \ + npm ci --include=dev + +# ── builder ─────────────────────────────────────────────────── +FROM node:${NODE_VERSION} AS builder +WORKDIR /repo + +COPY --from=deps /repo/node_modules ./node_modules +COPY . . + +# Next.js inlines NEXT_PUBLIC_* at build time. This app has none — every secret +# is read at runtime — which is why no build-time secrets are needed here. +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NODE_ENV=production + +RUN npm run build --workspace=@match-maker/web + +# ── runner ──────────────────────────────────────────────────── +FROM node:${NODE_VERSION} AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV PORT=3000 +ENV HOSTNAME=0.0.0.0 + +# Run unprivileged. The node image already ships a `node` user (uid 1000). +RUN apk add --no-cache curl + +# `output: "standalone"` traced exactly the files the server needs, including +# the workspace packages and their hoisted dependencies. With +# outputFileTracingRoot set to the repo root, the bundle is emitted under +# apps/web/.next/standalone but keeps the monorepo's directory shape inside. +COPY --from=builder --chown=node:node /repo/apps/web/.next/standalone ./ +COPY --from=builder --chown=node:node /repo/apps/web/.next/static ./apps/web/.next/static +COPY --from=builder --chown=node:node /repo/apps/web/public ./apps/web/public + +USER node +EXPOSE 3000 + +# ECS/ALB health checks hit this. `/api/health` is intentionally dependency-free +# so a database blip doesn't cause the load balancer to kill healthy tasks. +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \ + CMD curl -fsS http://127.0.0.1:3000/api/health || exit 1 + +CMD ["node", "apps/web/server.js"] diff --git a/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/analytics/page.tsx b/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/analytics/page.tsx new file mode 100644 index 0000000..ea60a5e --- /dev/null +++ b/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/analytics/page.tsx @@ -0,0 +1,29 @@ +import Link from "next/link"; +import { requireOrganizerEvent } from "@/src/lib/auth"; + +export default async function AnalyticsPage({ params }: { params: Promise<{ orgSlug: string; eventSlug: string }> }) { + const { orgSlug, eventSlug } = await params; + const { event, container } = await requireOrganizerEvent(orgSlug, eventSlug); + const analytics = await container.events.analytics(event.id); + const completion = analytics.roster ? Math.round(analytics.profiles / analytics.roster * 100) : 0; + return
+ +

Event analytics

+

{event.name} · {event.status}

+
+ + + + + +
+
; +} + +function Card({ label, value, note }: { label: string; value: number | string; note?: string }) { + return
{label}{value}{note && {note}}
; +} + +const shell = { minHeight: "100vh", maxWidth: 1000, margin: "0 auto", padding: "36px 24px", color: "#f4f4f5" } as const; +const grid = { display: "grid", gridTemplateColumns: "repeat(auto-fit,minmax(190px,1fr))", gap: 14, marginTop: 28 } as const; +const card = { display: "grid", gap: 10, padding: 20, background: "#151519", border: "1px solid #333", borderRadius: 12 } as const; diff --git a/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/matching/page.tsx b/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/matching/page.tsx new file mode 100644 index 0000000..e8b4050 --- /dev/null +++ b/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/matching/page.tsx @@ -0,0 +1,29 @@ +import Link from "next/link"; +import { computeEventMatchesAction } from "../../../../../../actions/organizer.actions"; +import { requireOrganizerEvent } from "@/src/lib/auth"; + +export default async function MatchingPage({ params, searchParams }: { + params: Promise<{ orgSlug: string; eventSlug: string }>; + searchParams: Promise<{ queued?: string }>; +}) { + const { orgSlug, eventSlug } = await params; + const query = await searchParams; + const { event, container } = await requireOrganizerEvent(orgSlug, eventSlug); + const analytics = await container.events.analytics(event.id); + const action = computeEventMatchesAction.bind(null, orgSlug, eventSlug); + return
+ +

Matching pipeline

+

Embeddings and ranked matches run in the background for profiles already completed.

+ {query.queued &&

Queued profile matching for {query.queued} attendee(s).

} +
+
{analytics.profiles} completed profiles
{analytics.matches} saved match results
+
+
+ {event.status !== "open" &&

Registration is currently {event.status}. Starting matching opens the event to participants.

} +
; +} + +const shell = { minHeight: "100vh", maxWidth: 900, margin: "0 auto", padding: "36px 24px", color: "#f4f4f5" } as const; +const card = { display: "flex", justifyContent: "space-between", flexWrap: "wrap", gap: 20, alignItems: "center", padding: 24, background: "#151519", border: "1px solid #333", borderRadius: 12, marginTop: 24 } as const; +const button = { border: 0, borderRadius: 8, padding: 14, background: "#f59e0b", color: "#0a0a0e", fontWeight: 700, cursor: "pointer" } as const; diff --git a/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/page.tsx b/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/page.tsx new file mode 100644 index 0000000..1d7627a --- /dev/null +++ b/apps/web/app/(organizer)/orgs/[orgSlug]/events/[eventSlug]/page.tsx @@ -0,0 +1,48 @@ +import Link from "next/link"; +import { updateEventAction } from "../../../../../actions/organizer.actions"; +import { requireOrganizerEvent } from "@/src/lib/auth"; + +export default async function EventDashboardPage({ params }: { params: Promise<{ orgSlug: string; eventSlug: string }> }) { + const { orgSlug, eventSlug } = await params; + const { event, container } = await requireOrganizerEvent(orgSlug, eventSlug); + const analytics = await container.events.analytics(event.id); + const action = updateEventAction.bind(null, orgSlug, eventSlug); + return
+ ORGANIZER · {event.organization_name} +

{event.name}

+

{event.description}

+ +
+ + + + +
+

Event setup

+
+ +