Transform qualifying scenarios into marketing-ready use cases with: - AI-generated titles, descriptions, ROI estimates, business value - Persona/industry/category taxonomy for targeting - Browseable feed with filtering and ranking - SEO-optimized case study pages - Daily cron job for generation and ranking Database: - Add Persona, Industry, Category lookup tables - Add UseCase model with marketing content fields - Add junction tables for personas/industries/categories - Add SocialProof model for cached metrics API: - GET /api/use-cases - Global directory with filtering - GET /api/use-cases/[id] - Individual use case details - GET /api/public/users/[username]/collections/[slug]/use-cases - POST /api/cron/use-cases - Nightly generation job Frontend: - /use-cases - Global feed with persona dropdown - /use-cases/[slug] - SEO case study page - /[username]/collections/[slug]/use-cases - Collection feed - UseCasesFeed component - Sortable table component - UseCaseCaseStudy component - Full case study layout |
||
|---|---|---|
| .. | ||
| .dockerignore | ||
| Dockerfile | ||
| package.json | ||
| railway.json | ||
| README.md | ||
| server.js | ||
TPMJS Sandbox Executor Service
Isolated microservice for securely executing TPMJS npm packages using isolated-vm.
Architecture
This service runs separately from the main Next.js application to provide:
- Secure sandboxing using V8 isolates
- Resource limits (128MB memory, 10s timeout)
- Package caching for faster subsequent executions
- Isolation from main app - no risk of compromising the web app
API Endpoints
POST /execute
Execute an npm package function.
Request:
{
"packageName": "@tpmjs/createblogpost",
"functionName": "default",
"params": {
"topic": "TypeScript best practices",
"length": "medium"
}
}
Response:
{
"success": true,
"output": "Generated blog post content...",
"executionTimeMs": 1234,
"logs": []
}
GET /health
Health check endpoint.
Response:
{
"status": "healthy",
"service": "tpmjs-sandbox-executor",
"version": "1.0.0",
"memoryLimit": "128MB",
"timeout": "10000ms"
}
POST /cache/clear
Clear the npm package cache.
Environment Variables
PORT- Server port (default: 3000)PACKAGE_CACHE_DIR- Package cache directory (default: /tmp/.tpmjs-cache)ALLOWED_ORIGINS- Comma-separated list of allowed CORS origins (default: *)
Deployment
Railway
- Initialize Railway project:
railway init
- Link to existing project or create new:
railway link
- Deploy:
railway up
- Set environment variables:
railway variables set ALLOWED_ORIGINS=https://tpmjs.com,https://tpmjs-web.vercel.app
- Get the service URL:
railway domain
Local Development
npm install
npm run dev
Test locally:
curl -X POST http://localhost:3000/execute \
-H "Content-Type: application/json" \
-d '{
"packageName": "@tpmjs/createblogpost",
"params": {"topic": "TypeScript"}
}'
Security
- Runs in isolated V8 context
- 128MB memory limit per execution
- 10 second timeout
- No filesystem access from sandbox
- No network access from sandbox
- Packages cached in /tmp
Integration with Next.js
Update the Next.js API route to call this service:
// apps/web/src/app/api/tools/execute/[...slug]/route.ts
const SANDBOX_URL = process.env.SANDBOX_EXECUTOR_URL;
const response = await fetch(`${SANDBOX_URL}/execute`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
packageName,
functionName: 'default',
params
})
});
const result = await response.json();
Monitoring
Check logs:
railway logs
Monitor resource usage:
railway status