CoolFace
Apppublic

2008robocode-crypto/code-generation-system

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
API.md491 linesDownload Raw Back to root
1# API Documentation2 3## REST API Endpoints4 5### Base URL6```7http://localhost:50008```9 10### Authentication11Currently, the API is unauthenticated (for demo purposes).12 13---14 15## Endpoints16 17### 1. Generate Configuration18 19**Endpoint**: `POST /api/generate`20 21**Description**: Generate a complete application configuration from a natural language prompt.22 23**Request Body**:24```json25{26  "prompt": "Build a CRM with login, contacts, dashboard, and role-based access"27}28```29 30**Query Parameters**: None31 32**Headers**:33```34Content-Type: application/json35```36 37**Response (Success)**:38```json39{40  "success": true,41  "config": {42    "app_name": "CRM",43    "app_description": "...",44    "database_schema": [...],45    "api_schema": [...],46    "ui_schema": [...],47    "auth_config": {...},48    "roles": [...],49    "business_logic": {...}50  },51  "execution_log": {52    "timestamp": "2026-05-06T07:52:40.123456",53    "stages": {...}54  },55  "executable_report": {56    "is_executable": true,57    "errors": [],58    "warnings": [],59    "simulation_log": [...]60  },61  "is_executable": true62}63```64 65**Response (Error)**:66```json67{68  "success": false,69  "error": "Prompt is required"70}71```72 73**Status Codes**:74- `200`: Successful generation75- `400`: Bad request (invalid prompt)76- `500`: Server error77 78**Constraints**:79- Prompt length: max 2,000 characters80- Rate limit: None (local deployment)81 82**Example**:83```bash84curl -X POST http://localhost:5000/api/generate \85  -H "Content-Type: application/json" \86  -d '{"prompt":"Build a todo app with users, tasks, and sharing"}'87```88 89---90 91### 2. Validate Configuration92 93**Endpoint**: `POST /api/validate`94 95**Description**: Validate an existing configuration against schema rules.96 97**Request Body**:98```json99{100  "config": {101    "app_name": "MyApp",102    "app_description": "...",103    "database_schema": [...],104    ...105  }106}107```108 109**Response (Success)**:110```json111{112  "success": true,113  "is_executable": true,114  "report": {115    "is_executable": true,116    "errors": [],117    "warnings": [],118    "simulation_log": [119      "✓ Database table 'users' initialized",120      "✓ API endpoint 'GET /api/users' registered",121      ...122    ],123    "total_checks": 12124  }125}126```127 128**Response (Error)**:129```json130{131  "success": false,132  "error": "Internal server error"133}134```135 136**Status Codes**:137- `200`: Validation complete (executable or not)138- `400`: Bad request (invalid config)139- `500`: Server error140 141---142 143### 3. Get Recent Requests144 145**Endpoint**: `GET /api/recent`146 147**Description**: Get list of recent generation requests (last 10).148 149**Query Parameters**: None150 151**Response**:152```json153{154  "recent": [155    {156      "timestamp": "2026-05-06T07:52:40.123456",157      "prompt": "Build a CRM with login, contacts, dashboard...",158      "success": true,159      "executable": true160    },161    ...162  ]163}164```165 166**Status Codes**:167- `200`: Success168 169---170 171### 4. Get Example Generation172 173**Endpoint**: `GET /api/example`174 175**Description**: Get a pre-generated example configuration.176 177**Query Parameters**: None178 179**Response**:180```json181{182  "prompt": "Build a CRM with login, contacts, dashboard, role-based access...",183  "config": {...},184  "executable": true185}186```187 188**Status Codes**:189- `200`: Success190 191---192 193### 5. Health Check194 195**Endpoint**: `GET /api/health`196 197**Description**: Check if the API is running and get system status.198 199**Query Parameters**: None200 201**Response**:202```json203{204  "status": "healthy",205  "timestamp": "2026-05-06T07:52:40.123456",206  "total_requests": 15207}208```209 210**Status Codes**:211- `200`: Healthy212- `503`: Service unavailable213 214---215 216## Error Responses217 218### Common Error Codes219 220**400 - Bad Request**221```json222{223  "error": "Prompt is required"224}225```226 227**413 - Payload Too Large**228```json229{230  "error": "Prompt is too long (max 2000 chars)"231}232```233 234**404 - Not Found**235```json236{237  "error": "Not found"238}239```240 241**500 - Internal Server Error**242```json243{244  "error": "Internal server error"245}246```247 248---249 250## Configuration Object Format251 252### Top-Level Fields253 254```json255{256  "app_name": "string",257  "app_description": "string",258  "database_schema": [...],259  "api_schema": [...],260  "ui_schema": [...],261  "auth_config": {...},262  "roles": [...],263  "business_logic": {...},264  "validation_metadata": {...}265}266```267 268### Database Schema269 270```json271{272  "name": "users",273  "fields": [274    {275      "name": "id",276      "type": "string",277      "required": true,278      "description": "User ID"279    },280    {281      "name": "email",282      "type": "email",283      "required": true,284      "validation_rules": {285        "unique": true286      }287    }288  ],289  "primary_key": "id",290  "relations": {291    "role_id": "roles"292  },293  "indexes": ["id", "email"]294}295```296 297### API Schema298 299```json300{301  "path": "/api/users",302  "method": "GET",303  "description": "Get list of users",304  "request_body": {305    "page": {306      "name": "page",307      "type": "number",308      "required": false309    }310  },311  "response_body": {312    "users": {313      "name": "users",314      "type": "array",315      "required": true316    }317  },318  "required_role": "user",319  "validation_rules": ["Pagination required", "Min page size: 10"]320}321```322 323### UI Schema324 325```json326{327  "path": "/users",328  "title": "Users Page",329  "components": [330    {331      "name": "header",332      "type": "header"333    },334    {335      "name": "user-table",336      "type": "table",337      "fields": ["id", "name", "email", "role"]338    }339  ],340  "required_role": "user",341  "data_source": "/api/users"342}343```344 345### Auth Config346 347```json348{349  "type": "jwt",350  "secret_key": "your-secret-key",351  "expiry": 3600,352  "refresh_token_expiry": 86400,353  "algorithm": "HS256"354}355```356 357### Roles358 359```json360[361  {362    "name": "admin",363    "permissions": ["read_all", "write_all", "delete_all", "manage_users"],364    "description": "Administrator with full access"365  },366  {367    "name": "user",368    "permissions": ["read_own", "write_own", "delete_own"],369    "description": "Regular user with personal access"370  }371]372```373 374---375 376## Code Examples377 378### Python (requests)379 380```python381import requests382import json383 384# Generate configuration385response = requests.post(386    'http://localhost:5000/api/generate',387    json={388        'prompt': 'Build a CRM with contacts, dashboard, and analytics'389    }390)391 392config = response.json()393 394if config['success']:395    print(f"Generated: {config['config']['app_name']}")396    print(f"Executable: {config['is_executable']}")397    print(json.dumps(config['config'], indent=2))398```399 400### JavaScript (fetch)401 402```javascript403const prompt = "Build a CRM with contacts, dashboard, and analytics";404 405const response = await fetch('http://localhost:5000/api/generate', {406  method: 'POST',407  headers: {408    'Content-Type': 'application/json'409  },410  body: JSON.stringify({ prompt })411});412 413const data = await response.json();414 415if (data.success) {416  console.log('Generated:', data.config.app_name);417  console.log('Executable:', data.is_executable);418  console.log(JSON.stringify(data.config, null, 2));419}420```421 422### cURL423 424```bash425# Generate config426curl -X POST http://localhost:5000/api/generate \427  -H "Content-Type: application/json" \428  -d '{429    "prompt": "Build a CRM with contacts, dashboard, and analytics"430  }' | jq .431 432# Health check433curl http://localhost:5000/api/health | jq .434 435# Get recent requests436curl http://localhost:5000/api/recent | jq .437 438# Get example439curl http://localhost:5000/api/example | jq .440```441 442---443 444## Rate Limiting445 446Currently disabled. For production deployment, implement:447- 100 requests/minute per IP448- 10,000 requests/day per API key449- Exponential backoff on rate limit errors (429)450 451---452 453## Webhooks (Future)454 455Support for event notifications:456- `generation.started`457- `generation.completed`458- `generation.failed`459- `validation.warning`460 461---462 463## Version History464 465### v1.0 (Current)466- Basic generation pipeline467- Validation and repair468- REST API469- Web interface470 471### v1.1 (Planned)472- Advanced LLM selection473- Extended schema types474- Webhook support475- Rate limiting476 477### v2.0 (Future)478- Direct app scaffolding479- Framework selection480- Deployment integration481 482---483 484## Support485 486For API issues or questions:4871. Check ARCHITECTURE.md for system design4882. Review quickstart.py for examples4893. Run evaluation framework for diagnostics4904. Check execution logs in API responses491