How didit-protocol/didit-full-demo works
Project type and purpose
• This is a full‑stack Next.js application (“didit‑full‑demo”) showcasing a vanilla implementation of the Didit Identity Verification flow.
• It combines a React‑based frontend (Next.js App Router + UI components), backend API routes (NextAuth for auth, custom registration and verification endpoints), a database (Prisma + SQLite by default), and integration with the external Didit identity service (via REST and webhooks).
File structure
• Top‑level config & scripts:
• next.config.mjs, tsconfig.json, postcss.config.mjs, tailwind.config.ts
• .env.example for environment variables (CLIENT_ID, CLIENT_SECRET, SHARED_SECRET_KEY, WEBHOOK_URL)
• Prisma folder: schema.prisma defines User and VerificationSession models
• src/app: contains Next.js pages and API route handlers under /api
• /api/auth/[...nextauth]/route.ts – NextAuth authentication with Didit OAuth provider
• /api/register/route.ts – user registration
• /api/verification/route.ts – starts a new verification session
• /api/verification/webhook/route.ts – receives Didit webhook callbacks
• client‑rendered pages: /signin, /register, /callback, plus root layout and global CSS
• src/components & src/components/ui: reusable React UI primitives (buttons, forms, dialogs)
• src/lib: business logic and integrations
• auth.ts – session checks, protected‑route logic
• diditAuth.ts – HTTP client / helper to call Didit API
• prisma.ts – Prisma client instantiation
• utils.ts – misc utilities
• src/middleware.ts – route protection, e.g. guard pages requiring auth
• src/types – TypeScript type augmentations (NextAuth, custom types)
README for additional insights
• Describes environment setup, Prisma models, and the verification flow:
1. User signs up → User record (isVerified=false)
2. App creates a VerificationSession (status = NOT_STARTED)
3. Frontend redirects user to Didit hosted workflow
4. Didit calls back via webhook to update VerificationSession.status
5. On “Approved,” app sets User.isVerified = true
• Shows how Prisma migrations and client generation are used
a. Frontend (React/Next.js App Router pages & UI components)
b. Backend (Next.js API routes + business logic in src/lib)
c. Database (Prisma Client + underlying SQLite or production database)
d. NextAuth Authentication Layer (OAuth handshake + session store)
e. External Didit Service (REST API calls to initiate verification + webhooks for status updates)
f. Webhook Tunnel (e.g., ngrok in dev)
Relationships and interactions
• User’s browser ↔ Next.js SSR/CSR pages
• Browser → POST /api/register → Backend creates User in DB
• Browser → POST /api/verification → Backend creates VerificationSession in DB & obtains Didit workflow URL
• Browser → Didit hosted pages (external domain)
• Didit → webhook → POST /api/verification/webhook → Backend updates VerificationSession status and, on success, sets User.isVerified
• NextAuth handlers under /api/auth handle login, session cookies, JWT storage (DB relations via Prisma)
• Any authenticated page uses middleware.ts and auth.ts logic to guard content
Architectural patterns and design principles
• Monolithic repository but modularized into clear “layers”: presentation (components + pages), API (route handlers), data (Prisma ORM), external integration (DiditAuth), and cross‑cutting concerns (auth, middleware, utilities).
• Next.js App Router pattern: file‑based routing for pages & API.
• MVC‑lite: route handlers act as controllers talking to the model (Prisma) and rendering views (JSON or next pages).
• Event‑driven update via webhooks for asynchronous verification updates.
Technologies, frameworks, and libraries to annotate
• Next.js 13 (App Router) + React + TypeScript
• NextAuth.js for OAuth and session management
• Prisma ORM + SQLite (dev) or Postgres/MySQL in production
• Tailwind CSS for styling
• Didit Identity Verification external API + webhooks
• ngrok (or equivalent) for local webhook tunneling
Detailed checklist
• Each major folder (src/app, src/api, src/lib, prisma) corresponds to a component or layer
• NextAuth as a subcomponent of API with its own data store relations (sessions, accounts)
• Middleware.ts as a gating mechanism between Frontend pages and API endpoints (authentication guard)
• If desired, annotate the UI component library as a shared resource under Frontend