POST /api/threads
Create a new conversation thread
POST
Authentication
Required: JWT Bearer token JWT Claims Extraction (Lines 72-91):Request Body
Thread titleValidation: None (controller accepts null or any string, Line 94)Default: null allowed (service may generate default title)Max Length: Not enforced by API contract
Response
UUID identifier for created thread
Owner UUID (matches authenticated user)
Thread title (as provided or service-generated)
Default visibility (implementation-defined, likely
"private")ISO8601 UTC timestamp
ISO8601 UTC timestamp
Side Effects
Database Mutations (Lines 92-94):-
users table UPSERT (Lines 83-92):
- Timing: Happens before thread creation
- Purpose: Ensures
userstable row exists (FK constraint requirement) - Idempotent: UPSERT operation
- Failure: Would bubble to 500 error
-
threads table INSERT (Line 94):
- INSERT new thread row
- Sets
user_id = userIdfrom JWT - Sets
visibilityto default value (service-defined) - Generates
thread_idUUID - Sets
created_atandupdated_attimestamps
Permissions
Who Can Create:- Any authenticated user
- Thread
user_idset to authenticated user’s UUID - Cannot create threads for other users
Validation
Title Validation (Line 94):- null allowed
- Empty string allowed
- Whitespace-only allowed
- No length constraints enforced by controller
- MUST be valid GUID from JWT
- MUST exist in JWT claims
- Returns 401 if missing or invalid
Authorization
Creation Rights:- Authenticated user can create unlimited threads
- No quota enforcement by controller
- Set by service (not specified in controller)
- Assumed default:
"private"
Edge Cases
- Null title: Allowed, service may generate default (Line 94)
- Empty title: Allowed
- Very long title: Not validated by controller (database column limit may apply)
- Duplicate title: Allowed (titles not unique)
- User doesn’t exist in database: Synced before creation (Lines 92)
- User sync fails: 500 error (blocks thread creation)
Error Conditions
| Code | HTTP | Cause | Controller Line |
|---|---|---|---|
| N/A | 401 | JWT missing or invalid | Middleware |
| N/A | 401 | User ID claim missing/invalid | 78-81 |
THREAD_CREATE_ERROR | 500 | User sync failure | 98-106 |
THREAD_CREATE_ERROR | 500 | Thread creation failure | 98-106 |
THREAD_CREATE_ERROR | 500 | Database constraint violation | 98-106 |
- All exceptions return 500
- Error message exposed to client
Behavioral Guarantees
Atomicity: Not enforced by controller code- User sync and thread creation not wrapped in transaction
- User sync failure blocks thread creation
- Thread creation failure leaves user synced (not rolled back)
- Each call creates new thread (even with same title)
- No deduplication logic
Database Schema Dependencies
Foreign Key:threads.user_id → users.id
Constraint Enforcement: User must exist before thread creation (Line 92)