|
| 1 | +# Hierarchy API Documentation |
| 2 | + |
| 3 | +This directory contains the complete API documentation for the Devlog Hierarchy API endpoints. |
| 4 | + |
| 5 | +## Quick Links |
| 6 | + |
| 7 | +- **OpenAPI Specification**: [hierarchy-api.yaml](./hierarchy-api.yaml) |
| 8 | +- **Usage Examples**: [examples.md](./examples.md) |
| 9 | +- **Integration Guide**: See below |
| 10 | + |
| 11 | +## Overview |
| 12 | + |
| 13 | +The Hierarchy API manages the 5-level organizational structure: |
| 14 | + |
| 15 | +``` |
| 16 | +Organization |
| 17 | +└── Projects (Git repositories) |
| 18 | + └── Machines (Development environments) |
| 19 | + └── Workspaces (VS Code windows) |
| 20 | + └── ChatSessions (AI conversations) |
| 21 | + └── AgentEvents (Time-series events) |
| 22 | +``` |
| 23 | + |
| 24 | +## API Endpoints |
| 25 | + |
| 26 | +### Machines |
| 27 | +- `POST /api/machines` - Create/update machine |
| 28 | +- `GET /api/machines` - List all machines |
| 29 | +- `GET /api/machines/{id}` - Get machine details |
| 30 | + |
| 31 | +### Workspaces |
| 32 | +- `POST /api/workspaces` - Create/update workspace |
| 33 | +- `GET /api/workspaces/{workspaceId}` - Get workspace by VS Code ID |
| 34 | + |
| 35 | +### Projects |
| 36 | +- `GET /api/projects/{id}/hierarchy` - Get project hierarchy tree |
| 37 | +- `GET /api/projects/{id}/events` - Get filtered events |
| 38 | + |
| 39 | +### Chat Sessions |
| 40 | +- `POST /api/chat-sessions` - Create/update session |
| 41 | +- `GET /api/chat-sessions/{sessionId}/events` - Get session events |
| 42 | + |
| 43 | +### Events |
| 44 | +- `POST /api/events/batch` - Batch create events (max 1000) |
| 45 | +- `GET /api/events/stream` - Real-time event stream (SSE) |
| 46 | + |
| 47 | +### Health |
| 48 | +- `GET /api/health` - Health check |
| 49 | + |
| 50 | +## Authentication |
| 51 | + |
| 52 | +Currently, the API does not require authentication in development mode. Production deployment will use JWT tokens or API keys. |
| 53 | + |
| 54 | +## Rate Limiting |
| 55 | + |
| 56 | +- Standard requests: 100 requests/minute |
| 57 | +- Batch events: 10 requests/minute |
| 58 | +- Event stream: 1 concurrent connection per filter combination |
| 59 | + |
| 60 | +## Error Handling |
| 61 | + |
| 62 | +All errors return a consistent format: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "error": "Human-readable error message", |
| 67 | + "details": "Optional additional details" |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +Common HTTP status codes: |
| 72 | +- `200` - Success |
| 73 | +- `201` - Created (batch events) |
| 74 | +- `400` - Bad Request (validation error) |
| 75 | +- `404` - Not Found |
| 76 | +- `500` - Internal Server Error |
| 77 | + |
| 78 | +## Viewing the Specification |
| 79 | + |
| 80 | +### Using Swagger UI |
| 81 | + |
| 82 | +1. Install Swagger UI: |
| 83 | +```bash |
| 84 | +npm install -g swagger-ui |
| 85 | +``` |
| 86 | + |
| 87 | +2. Serve the specification: |
| 88 | +```bash |
| 89 | +swagger-ui serve hierarchy-api.yaml |
| 90 | +``` |
| 91 | + |
| 92 | +3. Open http://localhost:8080 in your browser |
| 93 | + |
| 94 | +### Using Redoc |
| 95 | + |
| 96 | +1. Install Redoc CLI: |
| 97 | +```bash |
| 98 | +npm install -g redoc-cli |
| 99 | +``` |
| 100 | + |
| 101 | +2. Generate static HTML: |
| 102 | +```bash |
| 103 | +redoc-cli bundle hierarchy-api.yaml -o docs.html |
| 104 | +``` |
| 105 | + |
| 106 | +3. Open `docs.html` in your browser |
| 107 | + |
| 108 | +### Online Viewers |
| 109 | + |
| 110 | +Upload `hierarchy-api.yaml` to: |
| 111 | +- [Swagger Editor](https://editor.swagger.io/) |
| 112 | +- [Redocly](https://redocly.github.io/redoc/) |
| 113 | + |
| 114 | +## Development |
| 115 | + |
| 116 | +### Running Tests |
| 117 | + |
| 118 | +```bash |
| 119 | +# Run all API tests |
| 120 | +RUN_INTEGRATION_TESTS=true pnpm test |
| 121 | + |
| 122 | +# Run specific test suite |
| 123 | +RUN_INTEGRATION_TESTS=true pnpm test hierarchy-api.test.ts |
| 124 | +``` |
| 125 | + |
| 126 | +### Test Server |
| 127 | + |
| 128 | +Start the development server: |
| 129 | + |
| 130 | +```bash |
| 131 | +pnpm dev:web |
| 132 | +``` |
| 133 | + |
| 134 | +The API will be available at http://localhost:3200/api |
| 135 | + |
| 136 | +## Integration Examples |
| 137 | + |
| 138 | +See [examples.md](./examples.md) for detailed integration examples including: |
| 139 | + |
| 140 | +- Go collector integration |
| 141 | +- JavaScript/TypeScript clients |
| 142 | +- Python clients |
| 143 | +- curl examples |
| 144 | + |
| 145 | +## Changelog |
| 146 | + |
| 147 | +### v1.0.0 (2025-10-31) |
| 148 | +- Initial release |
| 149 | +- Machine, workspace, project, session, and event endpoints |
| 150 | +- Real-time event streaming via SSE |
| 151 | +- Comprehensive filtering and validation |
0 commit comments