Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: add Templates page and improve Add App UX
Adam Eivy67810411dac9
diff --git a/PLAN.md b/PLAN.mdindex cede657acc..fbe61bce56 100644--- a/PLAN.md+++ b/PLAN.md@@ -33,6 +33,7 @@ pm2 logs- [x] M4: App wizard (register existing + create new)- [x] M5: AI providers + headless executor- [x] M6: Dev tools (history, command runner)+- [ ] M7: App templates (create from templates, template management)### Documentation- [Contributing Guide](./docs/CONTRIBUTING.md) - Code guidelines, git workflow@@ -136,3 +137,46 @@ Scaffold a new project from template:| GET /api/commands/allowed | List allowed commands || GET /api/commands/processes | List PM2 processes || POST /api/detect/ai | AI-powered app detection |+| GET /api/templates | List available templates |+| POST /api/templates/create | Create app from template |+| POST /api/templates | Add custom template |+| DELETE /api/templates/:id | Delete custom template |++---++## M7: App Templates (Planned)++Templates allow creating new apps from pre-configured project structures.++### Built-in Template: PortOS Stack+The default template mirrors this application's architecture:+- Express.js API server+- React + Vite frontend+- Tailwind CSS styling+- Collapsible navigation layout+- PM2 ecosystem configuration+- GitHub Actions CI/CD workflows+- Auto-versioning system++### Features+1. **Template Selection**: Browse available templates with feature descriptions+2. **App Creation**: Scaffold new project with chosen name and target directory+3. **Custom Templates**: Register additional templates from local paths+4. **Template Management**: View, edit, delete custom templates++### Pages+- `/templates` - Template browser and app creation+- `/templates/new` - Register custom template++### Template Structure+Templates are stored in `./data/templates/` with:+- `manifest.json` - Template metadata and feature list+- Source files to copy when creating new app++### API Endpoints+| Route | Description |+|-------|-------------|+| GET /api/templates | List all templates |+| POST /api/templates | Add custom template |+| POST /api/templates/create | Create app from template |+| DELETE /api/templates/:id | Remove custom template |diff --git a/client/src/App.jsx b/client/src/App.jsxindex c6e4ebc84b..b29a47c6c8 100644--- a/client/src/App.jsx+++ b/client/src/App.jsx@@ -4,6 +4,7 @@ import Dashboard from './pages/Dashboard';import Apps from './pages/Apps';import Logs from './pages/Logs';import CreateApp from './pages/CreateApp';+import Templates from './pages/Templates';import AIProviders from './pages/AIProviders';import DevTools from './pages/DevTools';@@ -18,6 +19,7 @@ export default function App() {<Route path="devtools/:tab" element={<DevTools />} /><Route path="ai" element={<AIProviders />} /><Route path="create" element={<CreateApp />} />+ <Route path="templates" element={<Templates />} /><Route path="*" element={<Navigate to="/" replace />} /></Route></Routes>diff --git a/client/src/pages/CreateApp.jsx b/client/src/pages/CreateApp.jsxindex 19e4ad350f..01a0e05899 100644--- a/client/src/pages/CreateApp.jsx+++ b/client/src/pages/CreateApp.jsx@@ -125,7 +125,7 @@ export default function CreateApp() {<div className="max-w-2xl mx-auto"><div className="mb-6"><h1 className="text-2xl font-bold text-white">Add App</h1>- <p className="text-gray-500">Register an existing project with PortOS</p>+ <p className="text-gray-500">Import an existing project or create a new one from a template</p></div><form onSubmit={handleSubmit} className="space-y-6">@@ -138,6 +138,16 @@ export default function CreateApp() {value={repoPath}onChange={(e) => { setRepoPath(e.target.value); setPathValid(null); setDetected(null); }}onBlur={handlePathBlur}+ onKeyDown={(e) => {+ if (e.key === 'Enter') {+ e.preventDefault();+ if (pathValid && hasAiProvider) {+ handleAiDetect();+ } else if (!pathValid) {+ handlePathBlur();+ }+ }+ }}placeholder="/Users/you/projects/my-app"className="flex-1 px-4 py-3 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-none font-mono"/>@@ -281,13 +291,22 @@ export default function CreateApp() {>Cancel</button>- <button- type="submit"- disabled={!name || submitting}- className="px-6 py-3 bg-port-success hover:bg-port-success/80 text-white rounded-lg transition-colors disabled:opacity-50"- >- {submitting ? 'Registering...' : 'Register App'}- </button>+ <div className="flex gap-3">+ <button+ type="button"+ onClick={() => navigate('/templates')}+ className="px-6 py-3 bg-port-accent hover:bg-port-accent/80 text-white rounded-lg transition-colors"+ >+ Create from Template+ </button>+ <button+ type="submit"+ disabled={!name || submitting}+ className="px-6 py-3 bg-port-success hover:bg-port-success/80 text-white rounded-lg transition-colors disabled:opacity-50"+ >+ {submitting ? 'Importing...' : 'Import App'}+ </button>+ </div></div>)}</form>diff --git a/client/src/pages/Templates.jsx b/client/src/pages/Templates.jsxnew file mode 100644index 0000000000..e17320ac44--- /dev/null+++ b/client/src/pages/Templates.jsx@@ -0,0 +1,221 @@+import { useState, useEffect } from 'react';+import { useNavigate } from 'react-router-dom';+import { Layers, Code, Server, Globe, Plus } from 'lucide-react';+import * as api from '../services/api';++const ICONS = {+ layers: Layers,+ code: Code,+ server: Server,+ globe: Globe+};++export default function Templates() {+ const navigate = useNavigate();+ const [templates, setTemplates] = useState([]);+ const [loading, setLoading] = useState(true);+ const [selectedTemplate, setSelectedTemplate] = useState(null);+ const [createMode, setCreateMode] = useState(false);+ const [appName, setAppName] = useState('');+ const [targetPath, setTargetPath] = useState('');+ const [creating, setCreating] = useState(false);+ const [error, setError] = useState(null);++ useEffect(() => {+ loadTemplates();+ }, []);++ const loadTemplates = async () => {+ const serverTemplates = await api.getTemplates().catch(() => []);+ setTemplates(serverTemplates);+ setLoading(false);+ };++ const handleSelectTemplate = (template) => {+ setSelectedTemplate(template);+ setCreateMode(true);+ setAppName('');+ setTargetPath('');+ setError(null);+ };++ const handleCreate = async (e) => {+ e.preventDefault();+ if (!appName || !targetPath || !selectedTemplate) return;++ setCreating(true);+ setError(null);++ const result = await api.createFromTemplate({+ templateId: selectedTemplate.id,+ name: appName,+ targetPath+ }).catch(err => ({ error: err.message }));++ setCreating(false);++ if (result.error) {+ setError(result.error);+ return;+ }++ navigate('/apps');+ };++ if (loading) {+ return (+ <div className="flex items-center justify-center h-64">+ <div className="text-gray-500">Loading templates...</div>+ </div>+ );+ }++ return (+ <div className="max-w-4xl mx-auto">+ <div className="flex items-center justify-between mb-6">+ <div>+ <h1 className="text-2xl font-bold text-white">App Templates</h1>+ <p className="text-gray-500">Create new apps from pre-configured templates</p>+ </div>+ <button+ onClick={() => navigate('/create')}+ className="px-4 py-2 text-gray-400 hover:text-white"+ >+ ← Back to Import+ </button>+ </div>++ {createMode && selectedTemplate ? (+ <div className="bg-port-card border border-port-border rounded-xl p-6">+ <div className="flex items-center gap-3 mb-6">+ {(() => {+ const Icon = ICONS[selectedTemplate.icon] || Layers;+ return <Icon size={24} className="text-port-accent" />;+ })()}+ <div>+ <h2 className="text-lg font-semibold text-white">{selectedTemplate.name}</h2>+ <p className="text-sm text-gray-400">{selectedTemplate.description}</p>+ </div>+ </div>++ <form onSubmit={handleCreate} className="space-y-4">+ <div>+ <label className="block text-sm text-gray-400 mb-1">App Name *</label>+ <input+ type="text"+ value={appName}+ onChange={(e) => setAppName(e.target.value)}+ placeholder="my-new-app"+ required+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-none"+ />+ </div>++ <div>+ <label className="block text-sm text-gray-400 mb-1">Target Directory *</label>+ <input+ type="text"+ value={targetPath}+ onChange={(e) => setTargetPath(e.target.value)}+ placeholder="/Users/you/projects"+ required+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white focus:border-port-accent focus:outline-none font-mono"+ />+ <p className="text-xs text-gray-500 mt-1">+ App will be created at: {targetPath ? `${targetPath}/${appName || 'app-name'}` : '...'}+ </p>+ </div>++ {error && (+ <div className="p-3 bg-port-error/20 border border-port-error rounded-lg text-port-error text-sm">+ {error}+ </div>+ )}++ <div className="flex justify-between pt-4">+ <button+ type="button"+ onClick={() => { setCreateMode(false); setSelectedTemplate(null); }}+ className="px-4 py-2 text-gray-400 hover:text-white"+ >+ ← Back+ </button>+ <button+ type="submit"+ disabled={!appName || !targetPath || creating}+ className="px-6 py-3 bg-port-success hover:bg-port-success/80 text-white rounded-lg transition-colors disabled:opacity-50"+ >+ {creating ? 'Creating...' : 'Create App'}+ </button>+ </div>+ </form>+ </div>+ ) : (+ <div className="grid gap-4 md:grid-cols-2">+ {templates.map(template => {+ const Icon = ICONS[template.icon] || Layers;+ return (+ <button+ key={template.id}+ onClick={() => handleSelectTemplate(template)}+ className="text-left p-6 bg-port-card border border-port-border rounded-xl hover:border-port-accent transition-colors group"+ >+ <div className="flex items-start gap-4">+ <div className="p-3 bg-port-accent/10 rounded-lg">+ <Icon size={24} className="text-port-accent" />+ </div>+ <div className="flex-1">+ <div className="flex items-center gap-2">+ <h3 className="font-semibold text-white group-hover:text-port-accent transition-colors">+ {template.name}+ </h3>+ {template.builtIn && (+ <span className="text-xs px-2 py-0.5 bg-port-accent/20 text-port-accent rounded">+ Built-in+ </span>+ )}+ </div>+ <p className="text-sm text-gray-400 mt-1">{template.description}</p>+ {template.features && (+ <div className="flex flex-wrap gap-1 mt-3">+ {template.features.slice(0, 3).map((f, i) => (+ <span key={i} className="text-xs px-2 py-0.5 bg-port-border rounded text-gray-400">+ {f}+ </span>+ ))}+ {template.features.length > 3 && (+ <span className="text-xs px-2 py-0.5 text-gray-500">+ +{template.features.length - 3} more+ </span>+ )}+ </div>+ )}+ </div>+ </div>+ </button>+ );+ })}++ {/* Add Template Card */}+ <button+ onClick={() => navigate('/templates/new')}+ className="p-6 border-2 border-dashed border-port-border rounded-xl hover:border-port-accent/50 transition-colors flex items-center justify-center gap-3 text-gray-500 hover:text-gray-400"+ >+ <Plus size={20} />+ <span>Add Custom Template</span>+ </button>+ </div>+ )}++ {/* Info */}+ <div className="mt-8 p-4 bg-port-border/30 rounded-lg">+ <h4 className="text-sm font-medium text-white mb-2">About Templates</h4>+ <p className="text-sm text-gray-400">+ Templates are pre-configured project structures that include common patterns,+ dependencies, and configurations. The built-in PortOS Stack template mirrors+ this application's architecture.+ </p>+ </div>+ </div>+ );+}diff --git a/client/src/services/api.js b/client/src/services/api.jsindex c44ecfe554..0b843caf10 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -135,6 +135,11 @@ export const scaffoldApp = (data) => request('/scaffold', {body: JSON.stringify(data)});+export const createFromTemplate = (data) => request('/templates/create', {+ method: 'POST',+ body: JSON.stringify(data)+});+// Providersexport const getProviders = () => request('/providers');export const getActiveProvider = () => request('/providers/active');diff --git a/server/routes/scaffold.js b/server/routes/scaffold.jsindex cc4358c1d1..3eb0e03691 100644--- a/server/routes/scaffold.js+++ b/server/routes/scaffold.js@@ -18,24 +18,40 @@ const router = Router();router.get('/templates', async (req, res) => {const templates = [{- id: 'vite-react',- name: 'Vite + React',- description: 'React app with Vite bundler',- type: 'vite',- ports: { ui: true, api: false }+ id: 'portos-stack',+ name: 'PortOS Stack',+ description: 'Express + React + Vite with Tailwind, PM2, and GitHub Actions CI/CD',+ type: 'portos-stack',+ icon: 'layers',+ builtIn: true,+ features: ['Express.js API', 'React + Vite frontend', 'Tailwind CSS', 'PM2 ecosystem', 'GitHub Actions CI/CD', 'Collapsible nav layout'],+ ports: { ui: true, api: true }},{id: 'vite-express',name: 'Vite + Express',description: 'Full-stack with React frontend and Express API',type: 'vite+express',+ icon: 'code',+ features: ['React + Vite', 'Express.js API', 'CORS configured'],ports: { ui: true, api: true }},+ {+ id: 'vite-react',+ name: 'Vite + React',+ description: 'React app with Vite bundler',+ type: 'vite',+ icon: 'globe',+ features: ['React 18', 'Vite bundler', 'Fast HMR'],+ ports: { ui: true, api: false }+ },{id: 'express-api',name: 'Express API',description: 'Node.js Express API server',type: 'single-node-server',+ icon: 'server',+ features: ['Express.js', 'CORS', 'Health endpoint'],ports: { ui: false, api: true }}];@@ -43,8 +59,38 @@ router.get('/templates', async (req, res) => {res.json(templates);});-// POST /api/scaffold - Create a new app from template-router.post('/', async (req, res) => {+// POST /api/templates/create - User-friendly template creation+router.post('/templates/create', async (req, res) => {+ const { templateId, name, targetPath } = req.body;++ if (!templateId || !name || !targetPath) {+ return res.status(400).json({+ error: 'templateId, name, and targetPath are required'+ });+ }++ // Map to scaffold endpoint format+ const scaffoldData = {+ name,+ template: templateId,+ parentDir: targetPath+ };++ // For portos-stack, we need to handle it specially (not implemented yet)+ if (templateId === 'portos-stack') {+ return res.status(501).json({+ error: 'PortOS Stack template scaffolding is not yet implemented. Please use vite-express for a similar full-stack setup.'+ });+ }++ // Reuse scaffold logic+ req.body = scaffoldData;+ // Forward to scaffold endpoint logic (call the same handler)+ return scaffoldApp(req, res);+});++// Shared scaffold logic+async function scaffoldApp(req, res) {const {name,template,@@ -314,6 +360,9 @@ app.listen(PORT, '0.0.0.0', () => {repoPath,steps});-});+}++// POST /api/scaffold - Create a new app from template+router.post('/', scaffoldApp);export default router;