From 0c59030696d187fa52d7244b2e59cc864f2d3673 Mon Sep 17 00:00:00 2001 From: shanoysinc Date: Tue, 29 Sep 2026 17:10:57 -0500 Subject: [PATCH 1/3] docs updated --- docs/architecture-and-environments.md | 93 ++++++++++++ docs/handoff-known-considerations.md | 73 ++++++++++ docs/integrations-overview.md | 197 ++++++++++++++++++++++++++ 3 files changed, 363 insertions(+) create mode 100644 docs/architecture-and-environments.md create mode 100644 docs/handoff-known-considerations.md create mode 100644 docs/integrations-overview.md diff --git a/docs/architecture-and-environments.md b/docs/architecture-and-environments.md new file mode 100644 index 000000000..6b35fbf48 --- /dev/null +++ b/docs/architecture-and-environments.md @@ -0,0 +1,93 @@ +# Architecture, Environments & Maintenance + +This document covers what each app does, how local development differs from +production, and the day-to-day maintenance workflows (migrations, queue +inspection). For integration details, see +[`integrations-overview.md`](./integrations-overview.md). For known risks, +see [`handoff-known-considerations.md`](./handoff-known-considerations.md). + +## Core services + +Oyster is a Turborepo monorepo with three deployable apps sharing a +`packages/core` business-logic layer. + +### `apps/member-profile` + +The member-facing app. This is where ColorStack members manage their +profile, browse/apply to opportunities, use the "Ask AI" Slack chatbot +integration, do resume reviews, track gamification points, and go through +onboarding. Runs 2 replicas in production. + +### `apps/admin-dashboard` + +The internal ops tool used by the ColorStack team — reviewing member +applications, managing companies/schools, running events, editing gamification +activities, managing feature flags, and inspecting/managing BullMQ queues +directly (`/bull` route, owner-role only). This is the main place an +engineer would go to operate the system without touching the database or +Redis directly. + +### `apps/api` + +No user-facing UI. Runs all background job processing (BullMQ workers) and +handles webhook callbacks from external services (e.g. the LinkedIn/Google +OAuth callback, Slack events). Runs 3 replicas in production — this is the +service most directly implicated in the BullMQ outage documented in +`handoff-known-considerations.md`, since more replicas means more workers +pulling from the same queues. + +### `packages/core` + +Shared business logic used by all three apps — this is where most feature +code actually lives (modules like `slack/`, `apify.ts`, `location/`, +`notifications/`, etc., referenced throughout `integrations-overview.md`). + +## Environments + +| | Local development | Production | +|---|---|---| +| Postgres | Docker container (`docker-compose.yml`), port 5433, throwaway data | Railway-managed Postgres | +| Redis | Docker container, port 6380 | Railway-managed Redis (`roundhouse.proxy.rlwy.net` per last incident review) | +| Apps | Run directly via `bun dev` on your machine | Deployed to Railway, 1 service per app | +| Auth | OTP login is bypassed — any 6-digit code works | Real OTP delivery via Postmark/SMTP | +| Integrations | Mostly unconfigured by default (see `.env.example` files); only enable what a feature you're working on needs | Fully configured (assuming credentials are valid — some are unverified, see `integrations-overview.md`) | + +Full local setup steps are in [`CONTRIBUTING.md`](../CONTRIBUTING.md) +("Getting Started") — `bun install` → `bun env:setup` → `bun dx:up` → +`bun db:migrate` → `bun db:seed` → `bun dev`. There's also a `postgres-test` +container (port 5434) used for the test suite, separate from the dev +database. + +## Deployment + +All three apps deploy to **Railway**, auto-triggered on push to `main` — there +is no separate staging environment visible in the repo's config +(`apps/*/railway.json`). Each app's `railway.json` defines its build command +(which includes running `bun db:migrate` against `DATABASE_PUBLIC_URL` as +part of the build step) and start command. Since migrations run as part of +every app's build, **a migration only needs to exist in one deploy** — it'll +run whichever app happens to build/deploy first after being merged. + +## Maintenance workflows + +- **Running a migration:** `bun db:migrate` locally; in production this + happens automatically as part of the Railway build step above. See + [`how-to-implement-a-database-migration.md`](./how-to-implement-a-database-migration.md) + for how to write one. +- **Inspecting/managing BullMQ queues:** the admin dashboard has a built-in + UI for this at `/bull` (owner role required) — lists queues, lets you view + individual jobs, manually add jobs, and manage repeatable jobs + (`apps/admin-dashboard/app/routes/_dashboard.bull.*`). This is the + first place to check when investigating the job backlog described in + `handoff-known-considerations.md`, rather than needing direct Redis + access. +- **Inspecting the database directly:** `bun prisma:studio` opens Prisma + Studio against your local database for browsing/editing rows. +- **Feature flags:** managed through the admin dashboard's feature-flags + route, not via a config file or third-party service. + +## Cross-references + +- Local dev setup (already documented): [`CONTRIBUTING.md`](../CONTRIBUTING.md) +- Integration details: [`integrations-overview.md`](./integrations-overview.md) +- Known risks/escalation areas: [`handoff-known-considerations.md`](./handoff-known-considerations.md) diff --git a/docs/handoff-known-considerations.md b/docs/handoff-known-considerations.md new file mode 100644 index 000000000..8284c92c3 --- /dev/null +++ b/docs/handoff-known-considerations.md @@ -0,0 +1,73 @@ +# Key Dependencies, Known Technical Considerations & Escalation Areas + +This document is intended for the incoming team taking over Oyster +development. It covers what the codebase depends on, what has caused problems +in the past, and what to be careful with as usage grows (particularly with +the planned student-contribution feature). + +## Key Dependencies + +### Runtime & data layer + +- **Node.js / Bun** — Bun is used for scripts and package management; apps run + on Node. +- **TypeScript** across the whole monorepo (Turborepo-managed workspaces). +- **PostgreSQL** — primary datastore, queried via **Kysely** (type-safe SQL + builder, not a full ORM). Migrations live in `packages/db`. +- **Redis** — backs **BullMQ**, which handles all background/async job + processing (emails, Slack sync, onboarding, gamification, etc.). + +### Hosting + +- **Railway** hosts all three apps (`api`, `admin-dashboard`, `member-profile`) + plus the Postgres and Redis instances. Deploys are automatic on push to + `main` — there is no separate staging gate visible in the repo config + (`apps/*/railway.json`). `api` runs 3 replicas, `member-profile` runs 2. + +### External integrations + +| Service | Purpose | Status | +|---|---|---| +| Airmeet | Virtual events | Documented, active | +| Airtable | CRM (event registrations, family/members) | Documented, active | +| Cloudflare R2 | Object storage | Documented, active | +| Google OAuth | Authentication | Documented, active | +| Mailchimp | Email marketing | Documented, active | +| Pinecone | Vector database | Documented, active | +| Slack | Community home + auth | Documented, active | +| Sentry | Error monitoring | Documented, optional | +| Anthropic / OpenAI / Cohere | AI features (e.g. resume review) | Env vars present, not in the integrations doc — confirm which are live in prod | +| Apify, Google Maps, LinkedIn, Mixpanel, Postmark, SMTP, Twilio | Various | Env vars present in `apps/api/.env.example` but undocumented — likely partial/legacy; **confirm which are actually load-bearing in production before assuming any are safe to ignore** | + +The last group above is the biggest documentation gap: they have config +surface but no write-up in `docs/how-to-enable-integrations.md`, so their +current production status needs to be confirmed directly with the outgoing +team rather than assumed from the code alone. + +## Known Technical Considerations + +## Known Issues / Candidate Follow-Up Work +as of September 29, 2026 +These are lower-severity than the items above (no outage risk), but worth +surfacing during the KT session as known rough edges the incoming team may +want to prioritize early, since they affect day-to-day usability: + +- **Admin dashboard error handling** — some failures surface as an + unhandled 500 / crash rather than a friendly error state. Worth an audit of + error boundaries across `apps/admin-dashboard` routes. +- **Stale UI state after mutations** — some admin actions don't reflect + their result until the page is manually reloaded, suggesting a loader/data + revalidation isn't being triggered after certain form submissions or + actions. +- **"Ask AI" feature reliability** — the member-profile Ask AI feature + (`apps/member-profile/app/routes/_profile.ask-ai.tsx`, live at + `/ask-ai`) works correctly roughly 90% of the time; the remaining failure + cases haven't been root-caused yet. + +## Areas That May Require Escalation + +- **Worker health monitoring** — currently absent; needs design input before + scaling job volume. +- **Undocumented integrations** (AI providers, Apify, Twilio, etc.) — need + their production status confirmed; don't assume unused just because + undocumented. diff --git a/docs/integrations-overview.md b/docs/integrations-overview.md new file mode 100644 index 000000000..7ced300a9 --- /dev/null +++ b/docs/integrations-overview.md @@ -0,0 +1,197 @@ +# External Integrations — What Each One Actually Does + +This document explains what each external service is *used for* in the app — +the feature it powers and where it lives in the code. For setup instructions +(generating keys, which env vars to set), see +[`how-to-enable-integrations.md`](./how-to-enable-integrations.md). + +Services are listed alphabetically. + +### Airmeet + +**Powers:** virtual event registration and attendance sync for +Airmeet-hosted ColorStack events. + +**Code:** `packages/core/src/modules/events/airmeet.ts` + +### Airtable + +**Powers:** CRM sync — pushes event registration data and "family" +(mentorship program) data into Airtable bases used by the ops team outside +the app. + +**Code:** `packages/core/src/modules/airtable.ts` + +### Anthropic (Claude) + +**Powers:** the LLM behind several AI features — +1. the Slack "Ask AI" chatbot's answer generation (RAG over past Slack threads) +2. resume review AI feedback +3. parsing scraped job postings into structured tags +4. parsing free-text compensation offers shared in Slack into structured records + +**Code:** `packages/core/src/infrastructure/ai.ts` (`getChatCompletion`), called +from `slack/slack.ts`, `resume-reviews.ts`, `opportunities.ts`, +`compensation/offers.ts`. + +### Apify + +**Powers:** LinkedIn scraping for three features — +1. auto-filling a new "Company" record's name/logo/description when an admin + creates one from a LinkedIn slug +2. auto-filling a new "School" record the same way +3. a periodic job that syncs a member's work experience/education from their + LinkedIn profile + +**Code:** `packages/core/src/modules/apify.ts` (`isApifyConfigured()`, +`runActor`), consumers: `employment/use-cases/create-company.ts`, +`education/use-cases/save-school-if-necessary.ts`, `linkedin.ts`. + +The company-creation flow has a `isApifyConfigured()` check with a manual +fallback in the admin UI. The LinkedIn profile-sync background job doesn't +have that fallback — it throws a `ColorStackError` if the token is missing. + +### Cloudflare R2 + +**Powers:** object storage — profile photos, resumes, and other uploaded +files. + +**Code:** `packages/core/src/infrastructure/s3.ts` (`putObject`, `getObject`, +`deleteObject`), referenced from many modules across the app. + +### Cohere + +**Powers:** reranks candidate Slack threads for relevance before they're fed +to Claude as chatbot context. + +**Code:** `packages/core/src/infrastructure/ai.ts` (`rerankDocuments`, +`rerank-english-v3.0`), used in `slack/slack.ts`. A required step in the same +chatbot pipeline as Anthropic/OpenAI/Pinecone. + +### Google Maps + +**Powers:** city/location autocomplete and place-details lookup (onboarding +location field, event locations, etc.), cached in Redis for 30-90 days. + +**Code:** `packages/core/src/modules/location/location.ts` +(`getAutocompletedPlaces`, `getPlaceDetails`, `getMostRelevantLocation`). + +### Google OAuth + +**Powers:** member and admin login. + +**Code:** `packages/core/src/modules/authentication/services/google-oauth.service.ts` + +### LinkedIn (OAuth) + +**Powers:** "Sign in / apply with LinkedIn" on the public application form, as +an alternative to email/Google. + +**Code:** `packages/core/src/modules/authentication/services/linkedin-oauth.service.ts`, +callback handled in `apps/api/src/handlers/oauth.ts`. If credentials are +missing, `getLinkedInAuthUri` returns `null` and the "Login with LinkedIn" +button is hidden. + +### Mailchimp + +**Powers:** email marketing list sync — keeps members synced to a Mailchimp +audience for newsletters/campaigns. + +**Code:** `packages/core/src/modules/mailchimp.ts` + +### Mixpanel + +**Powers:** product analytics only (page views, opportunity views, LinkedIn +syncs, help requests, logins, etc.) — not a functional dependency for any +user-facing feature. + +**Code:** `packages/core/src/infrastructure/mixpanel.ts` (`track`, +`setMixpanelProfile`), called from `opportunities.ts`, `linkedin.ts`, +`resume-reviews.ts`, `peer-help.ts`, `slack/slack.ts`. + +### OpenAI + +**Powers:** text embeddings for the Slack chatbot's vector search step (embeds +the question and candidate Slack messages before retrieval). + +**Code:** `packages/core/src/infrastructure/ai.ts` (`createEmbedding`, +`text-embedding-3-small`), used in `slack/slack.ts`. + +This step is a likely contributor to the ~90% reliability issue already +flagged in [`handoff-known-considerations.md`](./handoff-known-considerations.md) — +worth checking rate limits/quota on this key. + +### Pinecone + +**Powers:** the vector store backing the Slack "Ask AI" chatbot's semantic +search over past Slack threads — stores the embeddings created via OpenAI +and is queried at answer time before results are reranked (Cohere) and +answered (Anthropic). + +**Code:** `packages/core/src/infrastructure/pinecone.ts`. Part of the same +chatbot pipeline as Anthropic/OpenAI/Cohere above. + +### Postmark + +**Powers:** production transactional email — application accepted/rejected, +one-time login codes, referral emails, resume-submission confirmations, +student anniversary/graduation/removal notices, email-changed notices. Also +used to check whether a member's email has bounced, which gates certain +application flows. + +**Code:** `packages/core/src/infrastructure/postmark.ts` (`sendEmail`, +`hasEmailBounced`), dispatched from +`notifications/use-cases/send-email.ts`. + +Worth noting: a failed send just logs to Sentry and swallows the error +rather than throwing, so emails can quietly stop sending with no loud +failure signal — the same blind spot pattern behind the BullMQ outage +already documented in +[`handoff-known-considerations.md`](./handoff-known-considerations.md). + +### Sentry + +**Powers:** error reporting sink used throughout the codebase — captures +unhandled errors/exceptions across `api`, `admin-dashboard`, and +`member-profile` for debugging production issues. + +**Code:** `packages/core/src/infrastructure/sentry.ts` (`reportException`), +called from most modules in `packages/core`. + +### Slack + +**Powers:** the community home for ColorStack members (channels, DMs), +Slack-based login, and the engine behind the "Ask AI" chatbot (ingesting +messages, triggering embeddings, and answering member questions). + +**Code:** `packages/core/src/modules/slack/` (`slack.ts`, `slack.worker.ts`, +`slack-profile.ts`, `slack.utils.ts`, `slack.types.ts`). + +### SMTP + +**Powers:** dev-only substitute for Postmark, so contributors can test the +email flow without a verified Postmark domain. + +**Code:** `packages/core/src/modules/notifications/shared/email.utils.ts` +(`getNodemailerTransporter`), selected only when `ENVIRONMENT === 'development'`. +Dev-experience dependency only — never invoked in production or test. + +### Twilio + +**Powers:** SMS notifications — a `notification.sms.send` job type and +worker handler exist and are fully wired up +(`packages/core/src/modules/notifications/twilio.ts`, +`notifications.worker.ts`, `bull.types.ts`). + +**However:** no code path anywhere in the app currently enqueues a +`notification.sms.send` job — it's built but not called from anywhere. This +looks like a dormant/shelved feature rather than dead config, but it's worth +confirming with the outgoing team whether it was intentionally shelved or a +caller was removed at some point, since the infrastructure to bring it back +already exists. + +## Cross-references + +- Setup/enablement steps: [`how-to-enable-integrations.md`](./how-to-enable-integrations.md) +- Outage risk, job backlog, and other known considerations: + [`handoff-known-considerations.md`](./handoff-known-considerations.md) From 2c503148e6c87ecb9e356659f43a2d9641cc8924 Mon Sep 17 00:00:00 2001 From: shanoysinc Date: Tue, 29 Sep 2026 17:55:03 -0500 Subject: [PATCH 2/3] docs updated --- apps/api/.env.example | 8 + apps/member-profile/.env.example | 4 + docs/architecture-and-environments.md | 13 +- docs/feature-flags.md | 60 +++++ docs/handoff-known-considerations.md | 20 +- docs/how-to-enable-integrations.md | 369 ++++++++++++++++++++++++-- docs/integrations-overview.md | 21 +- 7 files changed, 468 insertions(+), 27 deletions(-) create mode 100644 docs/feature-flags.md diff --git a/apps/api/.env.example b/apps/api/.env.example index 0683c18ba..948829c70 100644 --- a/apps/api/.env.example +++ b/apps/api/.env.example @@ -23,6 +23,7 @@ STUDENT_PROFILE_URL=http://localhost:3000 # GOOGLE_CLIENT_ID= # GOOGLE_CLIENT_SECRET= # GOOGLE_MAPS_API_KEY= +# Slack (internal/staff workspace) — Bot User OAuth Token must be xoxb- # INTERNAL_SLACK_BOT_TOKEN= # INTERNAL_SLACK_NOTIFICATIONS_CHANNEL_ID= # LINKEDIN_CLIENT_ID= @@ -41,13 +42,20 @@ STUDENT_PROFILE_URL=http://localhost:3000 # R2_PUBLIC_BUCKET_URL= # R2_SECRET_ACCESS_KEY= # SENTRY_DSN= +# Slack — token type matters (see docs/how-to-enable-integrations.md#slack). +# SLACK_ADMIN_TOKEN = User OAuth Token (xoxp-), workspace admin, NOT the bot token +# SLACK_BOT_TOKEN = Bot User OAuth Token (xoxb-) +# SLACK_SIGNING_SECRET = Basic Information → Signing Secret (no xox prefix) +# Channel IDs look like C… / team ID like T… / profile fields like Xf… # SLACK_ADMIN_TOKEN= # SLACK_BIRTHDATE_FIELD_ID= # SLACK_BIRTHDAYS_CHANNEL_ID= # SLACK_BOT_TOKEN= # SLACK_CLIENT_ID= # SLACK_CLIENT_SECRET= +# SLACK_EMOJI_CHANNEL_ID= # SLACK_FEED_CHANNEL_ID= +# SLACK_MEMBER_DIRECTORY_FIELD_ID= # SLACK_SIGNING_SECRET= # SMTP_HOST= # SMTP_PASSWORD= diff --git a/apps/member-profile/.env.example b/apps/member-profile/.env.example index 9fb16a3b2..c51e1b9c6 100644 --- a/apps/member-profile/.env.example +++ b/apps/member-profile/.env.example @@ -34,6 +34,10 @@ STUDENT_PROFILE_URL=http://localhost:3000 # R2_PUBLIC_BUCKET_URL= # R2_SECRET_ACCESS_KEY= # SENTRY_DSN= +# Slack — token type matters (see docs/how-to-enable-integrations.md#slack). +# SLACK_BOT_TOKEN = Bot User OAuth Token (xoxb-), same value as apps/api +# SLACK_TEAM_ID = workspace ID (T…) +# Channel IDs look like C… # SLACK_ANNOUNCEMENTS_CHANNEL_ID= # SLACK_BOT_TOKEN= # SLACK_CLIENT_ID= diff --git a/docs/architecture-and-environments.md b/docs/architecture-and-environments.md index 6b35fbf48..b7cc9eec0 100644 --- a/docs/architecture-and-environments.md +++ b/docs/architecture-and-environments.md @@ -3,8 +3,9 @@ This document covers what each app does, how local development differs from production, and the day-to-day maintenance workflows (migrations, queue inspection). For integration details, see -[`integrations-overview.md`](./integrations-overview.md). For known risks, -see [`handoff-known-considerations.md`](./handoff-known-considerations.md). +[`integrations-overview.md`](./integrations-overview.md). For feature flags, +see [`feature-flags.md`](./feature-flags.md). For known risks, see +[`handoff-known-considerations.md`](./handoff-known-considerations.md). ## Core services @@ -83,11 +84,13 @@ run whichever app happens to build/deploy first after being merged. access. - **Inspecting the database directly:** `bun prisma:studio` opens Prisma Studio against your local database for browsing/editing rows. -- **Feature flags:** managed through the admin dashboard's feature-flags - route, not via a config file or third-party service. - +- **Feature flags:** stored in Postgres, toggled at `/feature-flags` (owner + role). See [`feature-flags.md`](./feature-flags.md) for what each name + actually gates. ## Cross-references - Local dev setup (already documented): [`CONTRIBUTING.md`](../CONTRIBUTING.md) - Integration details: [`integrations-overview.md`](./integrations-overview.md) +- Feature flags: [`feature-flags.md`](./feature-flags.md) +- Slack setup (tokens, events, Redis session): [`how-to-enable-integrations.md`](./how-to-enable-integrations.md#slack) - Known risks/escalation areas: [`handoff-known-considerations.md`](./handoff-known-considerations.md) diff --git a/docs/feature-flags.md b/docs/feature-flags.md new file mode 100644 index 000000000..f2d225029 --- /dev/null +++ b/docs/feature-flags.md @@ -0,0 +1,60 @@ +# Feature Flags + +Feature flags live in Postgres (`feature_flags`), not in env vars or a +third-party service. Toggle them in the **Admin Dashboard → Feature Flags** +(`/feature-flags`, owner role). + +The **Name** field must match the snake_case string in the tables below +exactly (`send_slack_messages`, not `Send Slack Messages`). Display name and +description are UI-only. + +Seed data does **not** insert these rows. A fresh local DB has none, so every +flag is off until you create it and enable it. + +`isFeatureFlagEnabled` +(`packages/core/src/modules/feature-flags/queries/is-feature-flag-enabled.ts`) +returns `false` if the row is missing or `enabled` is false. + +The allowed names live in +`packages/core/src/modules/feature-flags/feature-flags.types.ts` +(`FeatureFlagName`). + +## Flags the code actually checks + +| Name | When **on** | When **off** | Code | +|---|---|---|---| +| `send_slack_messages` | `chat.postMessage` and `chat.postEphemeral` actually send (community + internal workspaces) | Those helpers return immediately — **silent no-op**. Slack tokens can be valid and nothing posts | `packages/core/src/modules/notifications/use-cases/send-slack-notification.ts`, `send-ephemeral-slack-notification.ts` | +| `slack_emoji_updates` | New custom emoji events post to `SLACK_EMOJI_CHANNEL_ID` | Emoji-added jobs do nothing | `packages/core/src/modules/slack/use-cases/send-emoji-update.ts` | +| `family_application` | Public ColorStack application (`/apply`) is open | Applicants see "application is temporarily closed" | `apps/member-profile/app/routes/_public.apply.tsx` | +| `points_page` | "Points" appears in the member-profile sidebar | Nav link is hidden. `/points` is **not** blocked if someone hits the URL | `apps/member-profile/app/routes/_profile.tsx` | + +For local Slack work, you almost always need `send_slack_messages` created and +enabled. Without it, bot replies, feed alerts, birthday posts, and internal +ops notifications will not send. + +## Names in the type union that are not checked + +These exist on `FeatureFlagName` but **no** `isFeatureFlagEnabled(...)` call +uses them. Creating/enabling them in the admin UI does nothing today: + +| Name | Likely original intent | What actually happens | +|---|---|---| +| `chatbot` | Gate Ask AI / Slack DM chatbot | `/ask-ai` and Slack chatbot jobs always run (Slack answers still need `send_slack_messages` to post) | +| `compensation` | Gate the Offers page | Offers nav and `/offers` are always available | +| `peer_help` | Gate Peer Help | Peer Help nav and `/peer-help` are always available | + +Do not assume toggling these three will hide a feature. + +## How to create one locally + +1. Log into the admin dashboard as an **owner**. +2. Open `/feature-flags` → **Create Flag**. +3. Set **Name** to one of the snake_case values above. +4. Leave it enabled if you want the feature on. + +## Cross-references + +- Slack tokens, events, and Redis session: + [`how-to-enable-integrations.md`](./how-to-enable-integrations.md#slack) +- Architecture and admin tooling: + [`architecture-and-environments.md`](./architecture-and-environments.md) diff --git a/docs/handoff-known-considerations.md b/docs/handoff-known-considerations.md index 8284c92c3..916616463 100644 --- a/docs/handoff-known-considerations.md +++ b/docs/handoff-known-considerations.md @@ -34,7 +34,7 @@ the planned student-contribution feature). | Google OAuth | Authentication | Documented, active | | Mailchimp | Email marketing | Documented, active | | Pinecone | Vector database | Documented, active | -| Slack | Community home + auth | Documented, active | +| Slack | Community home + auth + internal notifications | Documented, active — setup is credential-type-sensitive (see below) | | Sentry | Error monitoring | Documented, optional | | Anthropic / OpenAI / Cohere | AI features (e.g. resume review) | Env vars present, not in the integrations doc — confirm which are live in prod | | Apify, Google Maps, LinkedIn, Mixpanel, Postmark, SMTP, Twilio | Various | Env vars present in `apps/api/.env.example` but undocumented — likely partial/legacy; **confirm which are actually load-bearing in production before assuming any are safe to ignore** | @@ -46,6 +46,20 @@ team rather than assumed from the code alone. ## Known Technical Considerations +- **Slack credentials are not one key.** Production needs a bot token + (`xoxb-` → `SLACK_BOT_TOKEN`), a workspace-admin *user* token (`xoxp-` → + `SLACK_ADMIN_TOKEN`), a signing secret, and OpenID client id/secret. Putting + the bot token in `SLACK_ADMIN_TOKEN` (or using an `xapp-` Socket Mode token) + is the usual failure mode. See + [`how-to-enable-integrations.md`](./how-to-enable-integrations.md#slack). +- **Slack invite / deactivate depends on a browser session, not the Slack + app.** `users.admin.invite` / `setInactive` / `setRegular` read + `slack:legacy_token` (`xoxc-`) and `slack:legacy_cookie` from Redis. Nothing + in the codebase writes those keys, and they die when the admin's Slack web + session expires — invites can stop working with no env-var change. Confirm + with the outgoing team how those Redis keys are currently populated and + rotated. + ## Known Issues / Candidate Follow-Up Work as of September 29, 2026 These are lower-severity than the items above (no outage risk), but worth @@ -68,6 +82,4 @@ want to prioritize early, since they affect day-to-day usability: - **Worker health monitoring** — currently absent; needs design input before scaling job volume. -- **Undocumented integrations** (AI providers, Apify, Twilio, etc.) — need - their production status confirmed; don't assume unused just because - undocumented. + diff --git a/docs/how-to-enable-integrations.md b/docs/how-to-enable-integrations.md index 829939fe4..2e98d9b32 100644 --- a/docs/how-to-enable-integrations.md +++ b/docs/how-to-enable-integrations.md @@ -130,22 +130,359 @@ To enable the **Sentry** integration: ## Slack -To enable the **Slack** integration: +Slack is the integration people mix up most. The Slack dashboard shows several +credentials that look interchangeable, and **they are not**. Oyster needs +specific token *types* (the prefix tells you which is which), plus a handful of +channel/field IDs. -1. -2. In `/api/.env`, set the following variables: +Oyster talks to **two workspaces**: - ``` - SLACK_ADMIN_TOKEN - SLACK_BIRTHDAYS_CHANNEL_ID - SLACK_BOT_TOKEN - SLACK_CLIENT_ID - SLACK_CLIENT_SECRET - SLACK_SIGNING_SECRET - ``` +1. **Community workspace** (members) — login, events, chatbot, channel sync, + birthday posts, profile updates. +2. **Internal workspace** (staff) — ops notifications (member removed, huge + threads, etc.). This is a *separate* Slack app / bot token. -3. In `/member-profile/.env`, set the following variables: - ``` - SLACK_CLIENT_ID - SLACK_TEAM_ID - ``` +For local development, create a throwaway Slack workspace and a new Slack app. +Do not point Event Subscriptions from the production ColorStack app at your +laptop. + +Official references: + +- [Creating a Slack app](https://api.slack.com/authentication/basics) +- [Token types](https://docs.slack.dev/authentication/tokens) +- [Sign in with Slack (OpenID Connect)](https://docs.slack.dev/authentication/sign-in-with-slack) +- [Verifying requests from Slack](https://api.slack.com/authentication/verifying-requests-from-slack) + +### Which credential is which + +This is the part that usually goes wrong. Copy the value whose **name and +prefix** match the row — not whichever token is listed first on the page. + +| Env var | Must start with / look like | Where in the Slack app | Used for | +|---|---|---|---| +| `SLACK_BOT_TOKEN` | `xoxb-` | **OAuth & Permissions** → **Bot User OAuth Token** | Almost all Web API calls: post messages, read history, join channels, look up users, add reactions | +| `SLACK_ADMIN_TOKEN` | `xoxp-` | **OAuth & Permissions** → **User OAuth Token** | `users.profile.set` (update a member's Slack email / directory-link custom field). Must belong to a **workspace admin**. A bot token (`xoxb-`) will fail here | +| `SLACK_SIGNING_SECRET` | long hex string, **no** `xox` prefix | **Basic Information** → **App Credentials** → **Signing Secret** | HMAC-verifying that `/slack/events` and `/slack/shortcuts` requests actually came from Slack | +| `SLACK_CLIENT_ID` | numeric / alphanumeric, no `xox` prefix | **Basic Information** → **App Credentials** → **Client ID** | Sign in with Slack (OpenID) | +| `SLACK_CLIENT_SECRET` | hex string, no `xox` prefix | **Basic Information** → **App Credentials** → **Client Secret** | Exchanging the Slack login `code` for a token | +| `INTERNAL_SLACK_BOT_TOKEN` | `xoxb-` | Bot User OAuth Token of the **internal** Slack app | Staff-workspace notifications | + +Do **not** use: + +- **App-level tokens** (`xapp-`) — those are for Socket Mode. This app uses HTTP + webhooks, not Socket Mode. +- A bot token in `SLACK_ADMIN_TOKEN`, or a user token in `SLACK_BOT_TOKEN`. +- An incoming-webhook URL. Messages are posted via `chat.postMessage` with the + bot token. + +### 1. Create the Slack app (community workspace) + +1. Go to [https://api.slack.com/apps](https://api.slack.com/apps) → + **Create New App** → **From scratch**. +2. Name it something like `Oyster (dev)` and pick **your** workspace (not + ColorStack production, unless you are configuring prod). +3. Under **App Home**, enable the bot user (display name can be `ColorStack` / + `StackBot`). + +### 2. Bot token (`xoxb-`) — `SLACK_BOT_TOKEN` + +1. Open **OAuth & Permissions**. +2. Under **Bot Token Scopes**, add: + + - `channels:history` + - `channels:join` + - `channels:read` + - `chat:write` + - `emoji:read` + - `groups:history` + - `groups:read` + - `im:history` + - `im:read` + - `im:write` + - `mpim:history` + - `mpim:read` + - `reactions:write` + - `users:read` + - `users:read.email` + - `users.profile:read` + +3. Click **Install to Workspace** (or **Reinstall** if you added scopes after + a previous install). Scopes do nothing until you reinstall. +4. Copy **Bot User OAuth Token** — it must start with `xoxb-`. That is + `SLACK_BOT_TOKEN`. + +Invite the bot into any channel it needs to post in (feed, birthdays, emoji +updates, announcements). `conversations.join` only works for *public* +channels; private channels need a manual `/invite`. + +### 3. User / admin token (`xoxp-`) — `SLACK_ADMIN_TOKEN` + +This is **not** the same as the bot token. `users.profile.set` for *other* +users requires a **user token from a workspace admin** with +`users.profile:write`. + +1. Still on **OAuth & Permissions**, under **User Token Scopes**, add + `users.profile:write`. +2. Reinstall the app. The installing user must be a **Workspace Admin or + Owner**. +3. Copy **User OAuth Token** — it must start with `xoxp-`. That is + `SLACK_ADMIN_TOKEN`. + +If this value starts with `xoxb-`, profile updates (directory link, email +change) will fail. + +### 4. Signing secret + OAuth client credentials + +From **Basic Information** → **App Credentials**: + +- **Signing Secret** → `SLACK_SIGNING_SECRET` (used to verify Slack HTTP + requests; see `apps/api/src/handlers/slack.ts`) +- **Client ID** → `SLACK_CLIENT_ID` +- **Client Secret** → `SLACK_CLIENT_SECRET` + +### 5. Sign in with Slack (OpenID Connect) + +Login uses OpenID (`https://slack.com/openid/connect/authorize`), **not** the +legacy `identity.*` scopes and **not** the bot-install OAuth URL. + +1. On **OAuth & Permissions**, add these **User Token Scopes** (in addition to + `users.profile:write` above): + + - `openid` + - `profile` + - `email` + +2. Add a **Redirect URL**: + + - Local: `http://localhost:8080/oauth/slack` + - Production: `{API_URL}/oauth/slack` + + It must match `API_URL` exactly (see + `packages/core/src/modules/authentication/shared/oauth.utils.ts`). + +3. Reinstall after adding the OpenID scopes. + +If `SLACK_CLIENT_ID` is unset, the "Log in with Slack" button is hidden. + +### 6. Event Subscriptions + +Slack must be able to **POST** to the API. `localhost` is not reachable from +Slack's servers — for local events you need a tunnel (ngrok, Cloudflare +Tunnel, etc.) whose HTTPS origin is what you paste here. Login (step 5) works +on localhost without a tunnel; events do not. + +1. Open **Event Subscriptions** → turn **Enable Events** on. +2. **Request URL**: `{API_URL}/slack/events` + - Local-with-tunnel example: `https:///slack/events` + - Production: `https:///slack/events` +3. Slack will send a `url_verification` challenge; the API echoes it back + (`handleSlackEvent`). Keep the API running while you save this URL. +4. Under **Subscribe to bot events**, add: + + - `channel_archive` + - `channel_created` + - `channel_deleted` + - `channel_rename` + - `channel_unarchive` + - `emoji_changed` + - `message.channels` + - `message.groups` + - `message.im` + - `message.mpim` + - `reaction_added` + - `reaction_removed` + - `team_join` + - `user_profile_changed` + +These map 1:1 to `apps/api/src/handlers/slack.ts`. + +### 7. Interactivity (Ask ColorStack AI shortcut) + +1. Open **Interactivity & Shortcuts** → turn **Interactivity** on. +2. **Request URL**: `{API_URL}/slack/shortcuts` (note: this is **not** the + events URL). +3. Create a **Message Shortcut** whose **Callback ID** is exactly + `ask_colorstack_ai`. + +### 8. Channel IDs, Team ID, custom profile fields + +These are not tokens. In Slack, right-click a channel → **View channel +details** → copy **Channel ID** at the bottom (`C…`). Enable Slack's +developer mode if you don't see IDs. + +| Env var | Shape | Where it is used | +|---|---|---| +| `SLACK_TEAM_ID` | `T…` | Deep links (`slack://user?team=…`). From a channel URL (`app.slack.com/client/T…/C…`) or `auth.test` on the bot token | +| `SLACK_FEED_CHANNEL_ID` | `C…` | New-channel alerts, 250-reply alerts, event/peer-help posts | +| `SLACK_BIRTHDAYS_CHANNEL_ID` | `C…` | Daily birthday shout-outs | +| `SLACK_ANNOUNCEMENTS_CHANNEL_ID` | `C…` | Member Profile recap → announcements | +| `SLACK_EMOJI_CHANNEL_ID` | `C…` | "new emoji added" posts (also needs the `slack_emoji_updates` feature flag) | +| `INTERNAL_SLACK_NOTIFICATIONS_CHANNEL_ID` | `C…` in the **internal** workspace | Default destination for `workspace: 'internal'` notifications | +| `SLACK_BIRTHDATE_FIELD_ID` | `Xf…` | Custom Slack profile field used to backfill member birthdates | +| `SLACK_MEMBER_DIRECTORY_FIELD_ID` | `Xf…` | Custom Slack profile field that stores the Member Directory URL | + +Custom field IDs live under the workspace's **Configure profiles** / custom +fields settings, not in the Slack *app* dashboard. + +### 9. Internal workspace bot + +Create a **second** Slack app in the staff workspace (or reuse the existing +internal one in production). You only need a bot token with `chat:write` and +a notifications channel ID: + +``` +INTERNAL_SLACK_BOT_TOKEN # xoxb-… from the *internal* app +INTERNAL_SLACK_NOTIFICATIONS_CHANNEL_ID +``` + +### 10. Workspace admin APIs (invite / activate / deactivate) + +Inviting members and activating/deactivating Slack users does **not** use +`SLACK_BOT_TOKEN` or `SLACK_ADMIN_TOKEN`. Those flows call undocumented +Slack admin methods (`users.admin.invite`, `users.admin.setInactive`, +`users.admin.setRegular`) with a **browser session** from a workspace +admin. + +See `packages/core/src/modules/slack/services/slack-admin.service.ts`. The +values live in **Redis**, not `.env`. Nothing in the app writes them — you +set them by hand. You can skip this entire step in local development unless +you are working on invite/activation. + +These expire when that admin's Slack web session ends (logout, password +change, "sign out of all sessions"). Invites then fail with +`Slack legacy token or cookie not found` or Slack `invalid_auth`, with no +env-var change. Treat them like passwords: never commit them, never paste +them into Slack/GitHub. + +#### How to get the token and cookie + +You need **both**, from the **same** browser session, as a **Workspace +Admin or Owner**. Use the Slack **website** (`app.slack.com`), not the +desktop app (the desktop app does not expose these in DevTools). + +1. In Chrome (or another Chromium browser), log into the community Slack + workspace as an admin. +2. Open DevTools (`Cmd+Option+I` on Mac, `F12` on Windows) → **Network**. +3. Check **Preserve log**. Filter by `slack.com/api` (or just `api`). +4. Click around in Slack so requests fire (open a channel, load the home + tab, etc.). +5. Click any `POST` to `https://slack.com/api/...`. +6. **Token:** in **Payload** / **Form Data** / **Request**, find `token`. + It must start with `xoxc-`. Copy the whole value. +7. **Cookie:** DevTools → **Application** → **Cookies** → + `https://app.slack.com` (or `https://.slack.com`). Find the + cookie named `d`. Its value starts with `xoxd-`. Copy the value. + +The Redis cookie value is sent as the entire `Cookie` header, so it must +include the cookie **name**: + +``` +d=xoxd-...your value... +``` + +If Slack still returns `invalid_auth` / `not_authed`, also include the +`d-s` cookie from the same list: + +``` +d=xoxd-...; d-s=... +``` + +Token and cookie must be a pair from one session. If you log in again, +re-copy **both**. + +#### How to set them in Redis + +Local Redis is the `oyster-redis` Docker container (`REDIS_URL=redis://localhost:6380`). +From the repo root, with `bun dx:up` already running: + +```sh +docker exec oyster-redis redis-cli SET slack:legacy_token "xoxc-..." +docker exec oyster-redis redis-cli SET slack:legacy_cookie "d=xoxd-..." +``` + +Paste the real `xoxc-` token and `d=xoxd-...` cookie inside the quotes. Both +are `SET` — `GET` is only for checking afterwards. + +**Production** is Railway-managed Redis. Use the Redis URL from the +Railway dashboard (the `REDIS_URL` on the `api` service): + +```sh +redis-cli -u "$REDIS_URL" SET slack:legacy_token "xoxc-..." +redis-cli -u "$REDIS_URL" SET slack:legacy_cookie "d=xoxd-..." +``` + +Do not set a TTL — the code does not refresh these keys. Overwrite them +with a fresh pair whenever the session dies. + +#### Verify + +```sh +# local +docker exec oyster-redis redis-cli GET slack:legacy_token +docker exec oyster-redis redis-cli GET slack:legacy_cookie + +# production +redis-cli -u "$REDIS_URL" GET slack:legacy_token +redis-cli -u "$REDIS_URL" GET slack:legacy_cookie +``` + +You should see `xoxc-` and `d=xoxd-` respectively. Then trigger an invite +(or a deactivate) and confirm the job succeeds. + +References already in the code: + +- [users.admin.invite](https://github.com/ErikKalkoken/slackApiDoc/blob/master/users.admin.invite.md) +- [How xoxc tokens work with the `d` cookie](https://stackoverflow.com/questions/62759949/accessing-slack-api-with-chrome-authentication-token-xoxc/62777057#62777057) + + +### 11. Feature flags + +Even with valid Slack tokens, outbound messages are a silent no-op unless +these Postgres flags exist and are **enabled** (Admin Dashboard → Feature +Flags, owner role). A missing row counts as off. Seed data does not create +them. + +| Name | What it gates | +|---|---| +| `send_slack_messages` | All `chat.postMessage` / `chat.postEphemeral` (bot replies, feed, birthdays, internal notifications) | +| `slack_emoji_updates` | Posts to `SLACK_EMOJI_CHANNEL_ID` when a custom emoji is added | + +`chatbot` is listed in the TypeScript flag-name union but is **not** checked +anywhere — Ask AI / Slack DMs are not turned off by that flag. Replies still +need `send_slack_messages` on, or the bot "answers" without posting. + +Full flag list (including `family_application`, `points_page`, and unused +names): [`feature-flags.md`](./feature-flags.md). + +### 12. Env files + +In `apps/api/.env`: + +``` +INTERNAL_SLACK_BOT_TOKEN +INTERNAL_SLACK_NOTIFICATIONS_CHANNEL_ID +SLACK_ADMIN_TOKEN +SLACK_BIRTHDATE_FIELD_ID +SLACK_BIRTHDAYS_CHANNEL_ID +SLACK_BOT_TOKEN +SLACK_CLIENT_ID +SLACK_CLIENT_SECRET +SLACK_EMOJI_CHANNEL_ID +SLACK_FEED_CHANNEL_ID +SLACK_MEMBER_DIRECTORY_FIELD_ID +SLACK_SIGNING_SECRET +``` + +In `apps/member-profile/.env`: + +``` +SLACK_ANNOUNCEMENTS_CHANNEL_ID +SLACK_BOT_TOKEN +SLACK_CLIENT_ID +SLACK_FEED_CHANNEL_ID +SLACK_TEAM_ID +``` + +All of these are optional in development (`ENVIRONMENT=development`). Only +set the ones for the Slack feature you are actually testing. In production +they are required (see `apps/api/src/shared/env.ts`). diff --git a/docs/integrations-overview.md b/docs/integrations-overview.md index 7ced300a9..b1e257757 100644 --- a/docs/integrations-overview.md +++ b/docs/integrations-overview.md @@ -162,10 +162,27 @@ called from most modules in `packages/core`. **Powers:** the community home for ColorStack members (channels, DMs), Slack-based login, and the engine behind the "Ask AI" chatbot (ingesting -messages, triggering embeddings, and answering member questions). +messages, triggering embeddings, and answering member questions). Also +posts staff-facing ops notifications to a **separate internal workspace**. **Code:** `packages/core/src/modules/slack/` (`slack.ts`, `slack.worker.ts`, -`slack-profile.ts`, `slack.utils.ts`, `slack.types.ts`). +`slack-profile.ts`, `slack.utils.ts`, `slack.types.ts`), webhook handlers in +`apps/api/src/handlers/slack.ts`, Sign in with Slack in +`packages/core/src/modules/authentication/services/slack-oauth.service.ts`. + +Setup is easy to get wrong because several different credential types are +required — they are **not** interchangeable. In particular: + +- `SLACK_BOT_TOKEN` must be a **Bot User OAuth Token** (`xoxb-`) +- `SLACK_ADMIN_TOKEN` must be a **User OAuth Token** (`xoxp-`) from a + workspace admin (used only for `users.profile.set`) +- `SLACK_SIGNING_SECRET` is the app's signing secret, not a token +- Invite / activate / deactivate members use an undocumented Slack admin API + with an `xoxc-` browser session token stored in Redis + (`slack:legacy_token` + `slack:legacy_cookie`), not `.env` + +Full key-type table, scopes, event URLs, and Redis notes: +[`how-to-enable-integrations.md`](./how-to-enable-integrations.md#slack). ### SMTP From cd951f2e8668789224c3629d12a9ab2896dc172f Mon Sep 17 00:00:00 2001 From: shanoysinc Date: Wed, 30 Sep 2026 10:38:09 -0500 Subject: [PATCH 3/3] docs updated --- docs/handoff-known-considerations.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/handoff-known-considerations.md b/docs/handoff-known-considerations.md index 916616463..8143fbb5c 100644 --- a/docs/handoff-known-considerations.md +++ b/docs/handoff-known-considerations.md @@ -62,13 +62,17 @@ team rather than assumed from the code alone. ## Known Issues / Candidate Follow-Up Work as of September 29, 2026 -These are lower-severity than the items above (no outage risk), but worth -surfacing during the KT session as known rough edges the incoming team may -want to prioritize early, since they affect day-to-day usability: +These are not outage-level, but they make day-to-day use annoying. Flag them +during handoff so the new team can decide what to fix first. - **Admin dashboard error handling** — some failures surface as an - unhandled 500 / crash rather than a friendly error state. Worth an audit of - error boundaries across `apps/admin-dashboard` routes. + unhandled 500 / crash rather than a friendly error state. A common case + is missing env vars: in development those keys are optional so the app + still boots, but hitting a screen that needs them (resume books → + Airtable / Google Drive, GitHub contributors → `GITHUB_TOKEN`, student + Airtable links, etc.) throws instead of saying the integration isn't + configured. Worth an audit of error boundaries across + `apps/admin-dashboard` routes. - **Stale UI state after mutations** — some admin actions don't reflect their result until the page is manually reloaded, suggesting a loader/data revalidation isn't being triggered after certain form submissions or