bởi Kai

A TypeScript/Express backend block that handles the full identity and personalization pipeline for AI-driven SaaS apps: JWT-based auth with hashed session tokens, user profiles with onboarding completion tracking, media metadata storage, intake questionnaire upserts, and deterministic style-profile generation from preferences and answers. Built on SQLite via `better-sqlite3` with an idempotent schema, it exposes clean REST endpoints under `/api/users/me` and `/api/admin`, and accepts enrichment from an external AI Vision Plugin via a dedicated `/style-profile/visual-analysis` endpoint without taking any direct AI provider dependency itself. Licensed under the Tetrees License.
Backend 31RG is a reusable TypeScript backend block that handles the full identity and personalization pipeline for AI-driven SaaS or commerce applications. It covers user authentication, profile and preference management, media record tracking, intake questionnaire storage, and deterministic style-profile generation — all without calling any external AI provider.
This block is designed to integrate cleanly with a companion AI Vision Style Analysis Plugin Block (sold separately), which enriches style profiles via a single POST endpoint. The backend itself remains stateless with respect to AI dependencies and ships as a fully functional standalone service.
Backend only. No frontend screens are included.
completion scoring (percent + missing[]) for onboarding checklistsquestion_key; supports strings, numbers, booleans, arrays, and nullbetter-sqlite3; no migration tooling required| Layer | Technology |
|---|---|
| Runtime | Node.js |
| Language | TypeScript (ts-node for dev) |
| Framework | Express |
| Database | SQLite via better-sqlite3 |
| Auth | SHA-256 hashed bearer tokens |
| Build | tsc |
npm install
npm run dev # Development mode with ts-node, auto-seeds on first boot
# Or build and run
npm run build && npm start
curl -s http://localhost:3000/api/health
# => {"status":"ok","block":"identity-personalization-backend"}
| Variable | Default | Purpose |
|---|---|---|
PORT | 3000 | HTTP listen port |
BACKEND_DB_PATH | ./data/app.db | SQLite file path; use :memory: for tests |
BACKEND_SKIP_SEED | (unset) | Set to 1 to skip demo data seeding on boot |
Auto-seeded on boot (idempotent — existing rows are never overwritten):
| Role | Password | |
|---|---|---|
| user | user@example.com | demoPass123 |
| admin | user@example.com | adminPass123 |
Base URL: http://localhost:3000
Auth header (all authenticated routes): Authorization: Bearer <session.token>
Error format: { "error": "...", "field": "..." } with 400, 401, 403, or 404 as appropriate.
/api/auth| Method | Path | Auth Required | Purpose |
|---|---|---|---|
POST | /api/auth/signup | No | Create user and open initial session |
POST | /api/auth/login | No | Email + password → session token |
POST | /api/auth/logout | Yes | Revoke the supplied token |
GET | /api/auth/me | Yes | Return current authenticated user |
# Signup
curl -s -X POST http://localhost:3000/api/auth/signup \
-H 'content-type: application/json' \
-d '{"email":"alice@example.com","password":"wonder123","full_name":"Alice"}'
# Login
curl -s -X POST http://localhost:3000/api/auth/login \
-H 'content-type: application/json' \
-d '{"email":"user@example.com","password":"demoPass123"}'
# Current user
curl -s http://localhost:3000/api/auth/me \
-H "Authorization: Bearer $TOKEN"
# Logout
curl -s -X POST http://localhost:3000/api/auth/logout \
-H "Authorization: Bearer $TOKEN"
/api/users/me| Method | Path | Purpose |
|---|---|---|
GET | /api/users/me/profile | Profile + completion object { percent, missing[] } |
PUT | /api/users/me/profile | Update full_name, avatar_url, phone |
GET | /api/users/me/preferences | Body and style preferences |
PUT | /api/users/me/preferences | Partial update of preferences |
# Get profile with completion score
curl -s http://localhost:3000/api/users/me/profile \
-H "Authorization: Bearer $TOKEN"
# Update preferences (all fields optional)
curl -s -X PUT http://localhost:3000/api/users/me/preferences \
-H "Authorization: Bearer $TOKEN" \
-H 'content-type: application/json' \
-d '{
"height": 175, "weight": 70, "preferred_size": "M",
"style_preferences": ["minimalist","smart_casual"],
"color_preferences": ["navy","white","olive"],
"budget_min": 50, "budget_max": 250
}'
/api/users/me/mediaStores metadata only — wire your own storage provider (S3, Cloudinary, etc.) and POST the resulting URL here.
| Method | Path | Purpose |
|---|---|---|
GET | /api/users/me/media | List user media records (descending) |
POST | /api/users/me/media | Save a media record |
DELETE | /api/users/me/media/:media_id | Delete a media record |
Constraints:
file_type: image/jpeg, image/png, image/webp, image/giffile_size: 10 MBupload_purpose: reference, avatar, wardrobecurl -s -X POST http://localhost:3000/api/users/me/media \
-H "Authorization: Bearer $TOKEN" \
-H 'content-type: application/json' \
-d '{
"file_url": "https://cdn.example.com/ref.png",
"file_type": "image/png",
"file_size": 50000,
"upload_purpose": "reference"
}'
/api/users/me/intakeAnswers are upserted by question_key — resubmitting the same key overwrites the previous value.
| Method | Path | Purpose |
|---|---|---|
GET | /api/users/me/intake | List all answers (sorted by key) |
POST | /api/users/me/intake | Save or overwrite a batch of answers |
Recognized keys used by the style-profile generator:
question_key | Type | Maps to |
|---|---|---|
style_keywords | string[] | style_tags |
vibe | string or string[] | style_tags |
occasions | string[] | occasion_tags |
favorite_colors | string[] | color_tags |
avoid_styles | string[] | avoid_tags |
avoid_colors | string[] | avoid_tags |
fit_preference | 'slim' | 'regular' | 'relaxed' | fit_preference |
Any other question_key is stored but ignored by the generator.
curl -s -X POST http://localhost:3000/api/users/me/intake \
-H "Authorization: Bearer $TOKEN" \
-H 'content-type: application/json' \
-d '{
"answers": [
{ "question_key": "style_keywords", "answer_value": ["clean","modern"] },
{ "question_key": "fit_preference", "answer_value": "regular" },
{ "question_key": "occasions", "answer_value": ["work","date_night"] }
]
}'
/api/users/me/style-profile| Method | Path | Purpose |
|---|---|---|
POST | /api/users/me/style-profile/generate | (Re)generate style profile deterministically |
GET | /api/users/me/style-profile | Read current style profile (or null) |
POST | /api/users/me/style-profile/visual-analysis | Plugin endpoint — enrich with vision analysis results |
# Generate
curl -s -X POST http://localhost:3000/api/users/me/style-profile/generate \
-H "Authorization: Bearer $TOKEN"
# Read
curl -s http://localhost:3000/api/users/me/style-profile \
-H "Authorization: Bearer $TOKEN"
# Plugin enrichment (called by AI Vision Style Analysis Plugin Block)
curl -s -X POST http://localhost:3000/api/users/me/style-profile/visual-analysis \
-H "Authorization: Bearer $TOKEN" \
-H 'content-type: application/json' \
-d '{
"summary": "Predominantly cool tones with structured silhouettes.",
"style_tags": ["tailored"],
"color_tags": ["charcoal"],
"occasion_tags": [],
"avoid_tags": []
}'
Generation behavior:
fit_preference comes from the intake key or falls back to a BMI heuristicvisual_analysis_summary is preserved across regenerationsgenerate multiple times with the same inputs produces identical output/api/adminRequires a bearer token for a user with role === 'admin'.
| Method | Path | Purpose |
|---|---|---|
GET | /api/admin/users?limit=&offset=&status= | Paginated user list with profile_completion per user |
GET | /api/admin/users/:user_id | Full user detail (profile, prefs, media, intake, style profile) |
PATCH | /api/admin/users/:user_id/status | Set active or disabled; disabling revokes all sessions |
GET | /api/admin/style-profiles?limit=&offset= | List all style profiles (most recent first) |
GET | /api/admin/style-profiles/:user_id | Single style profile by user ID |
# List users
curl -s "http://localhost:3000/api/admin/users?limit=50" \
-H "Authorization: Bearer $ADMIN_TOKEN"
# Disable a user (also revokes their sessions)
curl -s -X PATCH "http://localhost:3000/api/admin/users/$USER_ID/status" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H 'content-type: application/json' \
-d '{"status":"disabled"}'
The AI Vision Style Analysis Plugin Block (sold separately) integrates via a single endpoint contract:
GET /api/users/me/mediaPOST /api/users/me/style-profile/visual-analysisThe backend additively merges plugin-supplied tags into the existing style profile (deduped, never destructive) and stores the summary string. The original generated_at timestamp is preserved. This backend block has no AI provider dependency and functions fully without the plugin.
getDb() for Postgres in production)Tetrees License
Khởi chạy sandbox cách ly và chạy phía máy chủ — không cần cài đặt cục bộ.
Lần kiểm định sandbox đã hoàn tất và đường chạy được phát hiện đã đạt yêu cầu.
This Express backend / api completed archive review with strong static results. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Quy trình avcp-2026-08-04.1 · SHA-256 39ff197e6467c41e…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Đã đánh giá 4 thg 8, 2026
Hướng dẫn cài đặt đầy đủ và prompt tích hợp sẽ mở khóa sau khi mua.
Đưa sản phẩm này thẳng vào AI IDE, trình tạo web hoặc cloud IDE của bạn.
Kết nối Tetrees với AI IDE tương thích để liệt kê sản phẩm bạn sở hữu và nhận ZIP đã xác minh mà không cấp quyền tải lên của người bán.
19 đánh giá
Saved me a ton of time. Dropped this automation setup straight into the workflow; even the tricky env setup was explained well. Five stars, would recommend to my team.
Shipped with this same week. Setup was a single command and it ran first try, and docs were clear enough that I never had to open an issue. Would buy from this seller again.
Worth every point. Zero mystery dependencies, everything is documented, and the README covered every config I needed.
Genuinely impressed. Picked up "Backend - Identity&Personalization Block" for a client workflow — Zero mystery dependencies, everything is documented. Highly recommend.
Punches well above its price. As someone who automates these all day, no spaghetti — the folder layout is sane.
Punches well above its price. Components are cleanly separated and easy to extend, and examples matched the actual API, which is rare.
Saved me a ton of time. Used "Backend - Identity&Personalization Block" to automate my workflow and it cut days off the build.
Punches well above its price. Picked up this automation setup for a client workflow — No spaghetti — the folder layout is sane. Would buy from this seller again.
Shipped with this same week. Picked up "Backend - Identity&Personalization Block" for a client workflow — No spaghetti — the folder layout is sane. No regrets.
Better than I expected. As someone who automates these all day, setup was a single command and it ran first try. Highly recommend.
Sign in to join the discussion
Loading discussion…