Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Database
DATABASE_URL="file:./dev.db"

# Server
PORT=3001
NODE_ENV=development

# CORS
CORS_ORIGIN=http://localhost:3000

# API (single-user mode - optional auth token)
API_KEY=your-api-key-here

28 changes: 28 additions & 0 deletions server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Dependencies
node_modules/

# Build output
dist/

# Environment variables
.env
.env.local

# Database
*.db
*.db-journal
prisma/migrations/

# Logs
logs/
*.log
npm-debug.log*

# IDE
.vscode/
.idea/

# OS
.DS_Store
Thumbs.db

124 changes: 124 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# CodeGen Server - Agentic Profiles Backend

Backend TypeScript server for the CodeGen Agentic Profiles System, providing REST APIs for dynamic template management, profile configuration, MCP tool integration, and multi-sandbox orchestration.

## Features

- **Profile Management**: Full CRUD for agentic profiles with role assignment, tools, skills, and templates
- **Dynamic Templates**: Database-backed template system (replacing static chainTemplates.ts)
- **MCP Tool Catalog**: Browse, configure, and deploy MCP tools with step-by-step instructions
- **Task Templates**: Pre-settable workflow configurations
- **Sandbox Manager**: Multi-sandbox context isolation and deployment configuration
- **Context Application Engine**: Merge profiles + templates + variables into executable agent contexts

## Tech Stack

- **Runtime**: Node.js 18+ with TypeScript
- **Framework**: Express.js
- **Database**: SQLite (development) / PostgreSQL (production-ready)
- **ORM**: Prisma
- **Validation**: Zod
- **Testing**: Vitest

## Quick Start

```bash
# Install dependencies
npm install

# Setup database
cp .env.example .env
npx prisma generate
npx prisma migrate dev --name init

# Seed initial data (MCP tools, etc.)
npm run db:seed

# Start development server
npm run dev
```

Server runs on `http://localhost:3001`

## API Endpoints

### Profiles
- `GET /api/profiles` - List all profiles
- `GET /api/profiles/:id` - Get profile by ID
- `POST /api/profiles` - Create profile
- `PUT /api/profiles/:id` - Update profile
- `DELETE /api/profiles/:id` - Delete profile
- `GET /api/profiles/active/current` - Get active profile
- `POST /api/profiles/:id/activate` - Set active profile

### Templates
- `GET /api/templates` - List all templates
- `POST /api/templates` - Create template
- `POST /api/templates/import` - Import from external source (e.g., davila7/claude-code-templates)

### MCP Tools
- `GET /api/mcp-tools` - List MCP tool catalog
- `GET /api/mcp-tools/:id` - Get tool with deployment instructions

### Context Application
- `POST /api/context/apply` - Generate agent run payload from profile + template + variables

## Database Schema

See `prisma/schema.prisma` for complete schema. Key models:
- **Profile**: Core profile configuration
- **Template**: Dynamic templates with variables
- **McpTool**: MCP tool catalog with deployment instructions
- **TaskTemplate**: Pre-configured workflows
- **Sandbox**: Sandbox configuration per profile
- Junction tables for many-to-many relationships

## Development

```bash
# Type checking
npm run typecheck

# Linting
npm run lint

# Tests
npm test

# Build
npm run build

# Prisma Studio (DB GUI)
npm run prisma:studio
```

## Environment Variables

```env
DATABASE_URL=file:./dev.db
PORT=3001
NODE_ENV=development
CORS_ORIGIN=http://localhost:3000
API_KEY=optional-api-key-for-single-user-mode
```

## Deployment

Ready for deployment to:
- Docker/Docker Compose
- Kubernetes
- Serverless platforms (with PostgreSQL)
- Traditional VPS/cloud servers

## Next Steps

1. Implement template CRUD routes
2. Add template importer for davila7/claude-code-templates
3. Seed MCP tool catalog
4. Build context application engine
5. Add E2E tests with Playwright

## License

MIT

41 changes: 41 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@codegen/server",
"version": "0.1.0",
"description": "Backend server for CodeGen Agentic Profiles System",
"main": "dist/index.js",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"test": "vitest",
"test:watch": "vitest --watch",
"lint": "eslint src --ext .ts",
"typecheck": "tsc --noEmit",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev",
"prisma:studio": "prisma studio",
"db:seed": "tsx src/db/seed.ts"
},
"keywords": ["codegen", "ai", "agents", "profiles", "templates"],
"author": "Zeeeepa",
"license": "MIT",
"dependencies": {
"@prisma/client": "^5.22.0",
"cors": "^2.8.5",
"express": "^4.21.2",
"helmet": "^8.0.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
"eslint": "^9.17.0",
"prisma": "^5.22.0",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"vitest": "^2.1.8"
}
}
175 changes: 175 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Prisma schema for CodeGen Agentic Profiles System

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

// Core profile model matching frontend schema
model Profile {
id String @id @default(uuid())
name String
role String // researcher, developer, analyst, qa-engineer, devops, security, api-manager, custom
description String?
isActive Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relationships
profileTools ProfileTool[]
profileMcpTools ProfileMcpTool[]
profileSkills ProfileSkill[]
profileTemplates ProfileTemplate[]
sandboxes Sandbox[]

@@map("profiles")
}

// Dynamic template system - replaces static chainTemplates.ts
model Template {
id String @id @default(uuid())
name String @unique
category String? // e.g., "research", "development", "analysis"
description String?
systemPrompt String?
userPrompt String?
variables String // JSON array of variable names: ["query", "context", ...]
tags String? // JSON array: ["parallel", "sequential", ...]
version Int @default(1)
isPublic Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relationships
profileTemplates ProfileTemplate[]

@@map("templates")
}

// Task templates (pre-settable, selectable workflows)
model TaskTemplate {
id String @id @default(uuid())
name String @unique
description String?
steps String // JSON array of step definitions
config String? // JSON configuration
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@map("task_templates")
}

// MCP tool catalog with deployment instructions
model McpTool {
id String @id @default(uuid())
name String @unique
description String?
repoUrl String?
docsUrl String?
installCommands String? // JSON array of commands
runCommands String? // JSON array of commands
envVarsSchema String? // JSON schema for required env vars
healthcheck String? // Command to verify installation
instructions String? // Markdown deployment guide
version String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relationships
profileMcpTools ProfileMcpTool[]

@@map("mcp_tools")
}

// Plugin/skill definitions
model Skill {
id String @id @default(uuid())
name String @unique
description String?
type String? // e.g., "command", "hook", "plugin"
content String? // Skill implementation or reference
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relationships
profileSkills ProfileSkill[]

@@map("skills")
}

// Sandbox configuration for multi-sandbox isolation
model Sandbox {
id String @id @default(uuid())
profileId String
name String
setupCommands String? // JSON array of setup commands
env String? // JSON object of environment variables
status String @default("pending") // pending, ready, error
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

// Relationships
profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)

@@map("sandboxes")
}

// Junction tables for many-to-many relationships

model ProfileTool {
id String @id @default(uuid())
profileId String
toolName String
config String? // JSON configuration for this tool
createdAt DateTime @default(now())

profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)

@@unique([profileId, toolName])
@@map("profile_tools")
}

model ProfileMcpTool {
id String @id @default(uuid())
profileId String
mcpToolId String
config String? // JSON configuration
createdAt DateTime @default(now())

profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
mcpTool McpTool @relation(fields: [mcpToolId], references: [id], onDelete: Cascade)

@@unique([profileId, mcpToolId])
@@map("profile_mcp_tools")
}

model ProfileSkill {
id String @id @default(uuid())
profileId String
skillId String
createdAt DateTime @default(now())

profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
skill Skill @relation(fields: [skillId], references: [id], onDelete: Cascade)

@@unique([profileId, skillId])
@@map("profile_skills")
}

model ProfileTemplate {
id String @id @default(uuid())
profileId String
templateId String
createdAt DateTime @default(now())

profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)

@@unique([profileId, templateId])
@@map("profile_templates")
}

7 changes: 7 additions & 0 deletions server/src/api/routes/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Router } from 'express';
const router = Router();

// TODO: Implement routes
router.get('/', (_req, res) => res.json([]));

export default router;
Loading