mirror of
https://github.com/bitbaum/datacat.git
synced 2026-12-04 05:48:00 +01:00
* feat(auth): every way in, on @bitbaum/accountkit, keeping every account
Sign-in offered email and password and Continue with OrangeCat, on
next-auth. It now runs on AccountKit's runtime and screens: email and
password, the emailed sign-in link, passkeys, two-step codes, recovery,
OrangeCat and the shared sign-in (Google, Apple, GitHub, X, Facebook), each
shown once configured. /account holds passkeys, two-step codes, the
password, sign-in methods and deletion. next-auth, the hand-rolled
OrangeCat resolver and the unused /api/v1/auth/{login,register} are gone.
Every account is kept. The Prisma migration 20261101120000 adds
AccountKit's tables (auth_ prefix, modelled in schema.prisma so Prisma
never proposes dropping them) and imports each person under the same id:
the bcrypt / $bs1$ hash (legacyBcrypt) and the OrangeCat link keyed on the
sub, with AccountKit's own placeholder for a person without an address.
A trigger mirrors anyone the old server creates during the cutover. It is
re-runnable and refuses addresses that collide once lower-cased.
/api/v1/* takes the session cookie or the API token /api/account mints in
the format the Express backend verifies. The session key is
BETTER_AUTH_SECRET, or derived from the secret the box already holds.
CI: a new browser-smoke job rehearses the import twice (counts, no Prisma
drift) and drives Chromium through an imported account signing in with
its old password, sign-up, sign-out, a refused wrong password, sign-in,
recovery through the reset link, both API auth paths and every way in at
320, 390 and 1280px.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* test(browser): give the first article visit on next dev a compile-sized wait
The shared-article suite runs on next dev, which compiles a route on its
first visit. The account route (better-auth, pg) now compiles beside the
article for the header, so the first click can outlast the default 5s.
A production server answers at once; the account journey checks that.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
* ci: re-run checks on the latest head
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9
---------
Co-authored-by: Claude <noreply@anthropic.com>
5.0 KiB
5.0 KiB
Backend Setup Documentation
Current Status: ✅ COMPLETE
Date: August 7, 2025
Environment: Development
Architecture: Node.js + tRPC + PostgreSQL + Redis + Docker
Services Successfully Running
1. PostgreSQL Database
- Port: 5433 (external), 5432 (internal)
- Container: formular-postgres
- Status: ✅ Healthy
- Connection: postgresql://formbuilder:devpassword@localhost:5433/formbuilder
- Features: Prisma ORM, comprehensive schema with users, forms, submissions, LLM analysis
2. Redis Cache & Job Queue
- Port: 6380 (external), 6379 (internal)
- Container: formular-redis
- Status: ✅ Healthy
- Connection: redis://localhost:6380
- Features: Caching, background job processing with Bull
3. Backend API Service
- Port: 5001
- Technology: Node.js + Express + tRPC
- Status: ✅ Running
- Endpoints:
- Health:
http://localhost:5001/ - tRPC API:
http://localhost:5001/api/trpc - REST API:
http://localhost:5001/api/v1
- Health:
Key Backend Features
Database Schema (Prisma)
- Users & Organizations: Multi-tenant support
- Forms: Dynamic schema, versioning, sharing controls
- Submissions: Data collection with metadata
- LLM Analysis: AI-powered form analysis
- Background Jobs: Async processing
- Accounts: the frontend signs people in with
@bitbaum/accountkitand mints the API token this backend verifies (frontend/src/server/auth/api-token.ts)
API Architecture
- Primary: tRPC for type-safe API calls
- Secondary: REST API for backward compatibility
- WebSocket: Real-time features ready
- Authentication: JWT (
JWT_SECRET), minted by the frontend
Background Processing
- Queue System: Bull + Redis
- Job Types: LLM analysis, email notifications, data export
- Processors: Automatic job processing
Successful Tests
Database Connectivity ✅
# PostgreSQL Test
docker exec formular-postgres psql -U formbuilder -d formbuilder -c "SELECT current_user;"
# Result: formbuilder user connected
# Redis Test
docker exec formular-redis redis-cli ping
# Result: PONG
API Endpoints ✅
# Health Check
curl http://localhost:5001/
# Result: {"message":"Formular Backend API","version":"2.0.0","status":"running"}
# tRPC Endpoint
curl http://localhost:5001/api/trpc
# Result: tRPC server responding correctly
Quick Start Commands
Start Environment
# 1. Start database services
docker-compose up -d postgres redis
# 2. Start backend API
cd backend
DATABASE_URL="postgresql://formbuilder:devpassword@localhost:5433/formbuilder" node index.js
Check Status
# Check Docker services
docker-compose ps
# Test API
curl http://localhost:5001/
Architecture Benefits
For CEO Learning:
- Microservices: Each service runs independently
- Type Safety: tRPC provides end-to-end TypeScript
- Scalability: Redis for caching, background jobs
- Database: PostgreSQL with complex relationships
- Real-time: WebSocket support for live features
Production Ready:
- Health checks on all services
- Database migrations with Prisma
- Job queue for async processing
- Multi-tenant architecture
- Security middleware ready
Next Steps Available:
- Connect Frontend: Integrate tRPC with Next.js frontend
- Authentication: done in the frontend (
@bitbaum/accountkit) - Form Submission: Connect form builder to backend
- LLM Integration: Activate AI analysis features
- Real-time Features: Enable WebSocket functionality
✅ AUTHENTICATION SYSTEM FULLY TESTED & WORKING
Authentication Test Results (All Passed):
- User Registration: ✅ Creates users with encrypted passwords
- User Login: ✅ Validates credentials and generates JWT tokens
- Protected Routes: ✅ Validates JWT tokens for secure endpoints
- Token Verification: ✅ Endpoint validates token authenticity
- Security: ✅ Rejects invalid tokens and credentials
- Database Integration: ✅ Prisma ORM working with PostgreSQL
Authentication Endpoints Tested:
POST /api/v1/auth/register - User registration ✅
POST /api/v1/auth/login - User authentication ✅
GET /api/v1/auth/profile - Protected user profile ✅
GET /api/v1/auth/verify - Token validation ✅
GET /api/v1/forms - Protected forms endpoint ✅
Backend Security Features:
- Password Hashing: Bcrypt with 12 salt rounds
- JWT Tokens: 24-hour expiration, stateless auth
- Auth Middleware: Protects sensitive endpoints
- Input Validation: Prevents malformed requests
- Error Handling: Proper HTTP status codes
Test Evidence:
✅ Registration: 201 Created with JWT token
✅ Login: 200 OK with user data and token
✅ Profile Access: 200 OK with authenticated user data
✅ Invalid Token: 401 Unauthorized (correctly rejected)
✅ Invalid Credentials: 401 Unauthorized (correctly rejected)
Status: Backend services are fully operational with COMPLETE AUTHENTICATION SYSTEM ready for frontend integration.