Skip to content

Phase 1: Foundation — CRM, contacts, team, import, agent flag, audit#1

Merged
Kilbas merged 33 commits into
mainfrom
phase-1-foundation
Apr 29, 2026
Merged

Phase 1: Foundation — CRM, contacts, team, import, agent flag, audit#1
Kilbas merged 33 commits into
mainfrom
phase-1-foundation

Conversation

@Kilbas
Copy link
Copy Markdown
Owner

@Kilbas Kilbas commented Apr 29, 2026

Summary

Implements all 25 tasks of Phase 1 per the design spec and implementation plan.

What ships

Stack: Next.js 16 (App Router) + TypeScript + Tailwind + Prisma 7 + PostgreSQL 16 + Auth.js v5 (Argon2id) + Vitest + Playwright + GitHub Actions.

Core features:

  • Workspace + 3-role model (owner / admin / member) with partial unique index enforcing one owner per workspace
  • Contacts with full schema, role-scoped visibility, soft delete, and dedup constraints (partial unique index on active rows)
  • Excel template generator + parser + import server action splitting rows into 4 buckets (new / skipped_own / colleague_warning / rejected), with file-hash duplicate detection
  • Invitation links with configurable expiry (default 30 days, optional permanent), 256-bit cryptographic tokens, acceptance flow
  • Agent-flag toggle with FOR UPDATE conflict detection — prevents two team members from running the LLM agent on the same blogger simultaneously (safety-critical, exhaustively unit-tested)
  • Audit log on every mutation (auth, contacts, users, invitations, agent flag, imports) with admin-only UI + filters

8 UI screens: Login, Contacts list, Contact detail, Excel import, Import report, Team management, Invitation acceptance, Audit log.

Deploy: Multi-stage Dockerfile + production docker-compose.yml + .env.example + README quickstart.

Test plan

  • CI green on phase-1-foundation (lint, typecheck, unit tests, e2e)
  • 4 e2e tests pass: sanity homepage, auth redirect, owner sign-in + import, invitation flow
  • Unit tests cover: contact dedup constraints, contact visibility, invitations (5 cases), Excel parser (4 cases), Excel template (2 cases), Instagram normalizer (9 cases), import logic (6 cases), agent-flag conflict detection (6 cases), audit coverage
  • Manual smoke test: docker compose up -d → log in with seeded owner → import sample Excel → verify report buckets → activate agent flag → check audit log

Out of scope (future phases)

Phase 2: briefs + LLM-generated outreach emails + sending engine.
Phase 3: inbox polling + response classification + buckets.
Phase 4: closed-loop negotiation agent.
Phase 5: public-profile scraping for style adaptation.
Phase 6: Instagram DM channel.

Notable adaptations from plan

  • Plan was written for Prisma 5/6; project uses Prisma 7 with the new prisma.config.ts + @prisma/adapter-pg driver-adapter pattern.
  • React 19's useActionState (instead of deprecated useFormState).
  • Auth.js v5 reads AUTH_SECRET / AUTH_URL (was NEXTAUTH_*).
  • Migrations are deployed via prisma migrate deploy in CI (not db push) so the manually-appended partial unique indexes apply.

Kilbas and others added 30 commits April 28, 2026 18:28
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds Prisma 7 with PostgreSQL, a docker-compose dev environment,
and the PrismaClient singleton. Uses prisma.config.ts (Prisma 7
requirement) with pg adapter and dotenv for .env auto-loading.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds CI pipeline with Postgres service, Prisma 7 env handling (writes
apps/web/.env before Prisma commands), lint, typecheck, unit tests,
schema push, and Playwright E2E tests. Includes phase-1-foundation in
push triggers to enable CI on this branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add full initial schema with Workspace, User (Role enum, soft-delete,
unique email per workspace), Contact, Invitation, ImportBatch, and
AuditEvent models. Migration includes a manually-appended partial unique
index enforcing one owner per workspace (users_workspace_id_role_owner_idx).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Install next-auth@beta (v5), @auth/prisma-adapter, zod
- Add Auth.js Prisma adapter tables (Account, Session, VerificationToken) with migration auth_tables
- Configure Auth.js v5 with JWT session strategy and Credentials provider backed by Argon2id password verification
- Add session type augmentation for role and workspaceId in next-auth.d.ts
- Mount /api/auth/[...nextauth] route handler
- Build login page using React 19 useActionState with server action

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add auth-gated (dashboard) route group with AppShell sidebar/header, LogoutButton client component, SessionProvider wrapper, contacts placeholder page, and e2e redirect test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds prisma/seed.ts that bootstraps the first workspace and owner account
on a fresh DB, with idempotency guard. Seed config moved to prisma.config.ts
(Prisma 7 style). Adds tsx devDependency to run the TypeScript seed script.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Expand Contact and ImportBatch from stubs to full models, add
contacts_full migration with partial unique index enforcing one active
contact per (workspace, owner, email), configure Vitest dotenv setup,
and add contact uniqueness integration tests (2 passing).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements listContactsForUser, getContactForUser, softDeleteContact, and
updateContact with owner/admin seeing all contacts, members seeing only
their own. 3 unit tests verify visibility rules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add contacts list page with role-scoped table, and detail page with
inline edit form and soft-delete action (Task 12).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements createInvitation, acceptInvitation, revokeInvitation, and listInvitations
with admin/owner role gating, token generation, expiry enforcement, and idempotency
checks. All 5 unit tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add parseImportFile() and ParsedRow type to lib/excel.ts, with header
validation and empty-row filtering. Includes 4 unit tests (TDD).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Expand AuditEvent schema with action, entityType, entityId, payload columns
- Add audit_full_columns migration
- Implement performImport with own-duplicate skip, colleague-overlap warning,
  email/instagram validation, file SHA-256 hashing, and audit trail
- Implement findPriorImportBatch for re-import detection
- 6 unit tests covering all dedup and validation branches

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Kilbas and others added 3 commits April 29, 2026 17:33
Implements activateAgent/deactivateAgent server functions using a
serializable transaction with FOR UPDATE to prevent concurrent
double-activation of the same influencer by different team members.
Adds AgentToggle client component, /api/contacts/[id]/agent route,
and replaces the read-only checkbox in the contacts list.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds writeAudit helper and wires audit events into all mutations:
contacts (updated/deleted), users (role_changed/deactivated),
invitations (invited/joined/revoked), and auth (login/failed_login).
Adds /audit admin page with actor/action filters and a coverage test
verifying all 6 mutation action types are recorded.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- globalSetup resets + re-seeds DB before every Playwright run (deterministic owner@test.com / test1234)
- import-flow and invitation-flow e2e specs; all 4 tests pass
- seed.ts honours ADMIN_INIT_PASSWORD env override
- Multi-stage production Dockerfile (deps → builder → runner)
- docker-compose.yml for production (separate from docker-compose.dev.yml)
- .env.example gains DB_PASSWORD for production compose
- README.md with quick-start, dev setup, and test instructions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Kilbas Kilbas merged commit bd45a5b into main Apr 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant