Fix:Readme
swadhinbiswas committed 8 months ago
46e08a2
1 parent eae83ca
commit 46e08a2
1 file changed
+127 -1256
Showing 1 changed file+127-1242
▼README.md
+127-1242
| @@ -4,1383 +4,254 @@ | ||
4 | 4 | <picture> |
5 | 5 | <source media="(prefers-color-scheme: dark)" srcset="public/logo-dark.png"> |
6 | 6 | <source media="(prefers-color-scheme: light)" srcset="public/logo-light.png"> |
7 | - <img src="public/logo-light.png" alt="OpenCodeHub Logo" width="400"/> | |
7 | + <img src="public/logo-light.png" alt="OpenCodeHub Logo" width="420" /> | |
8 | 8 | </picture> |
9 | - <br> | |
10 | 9 | </p> |
11 | 10 | |
12 | 11 | <p align="center"> |
13 | - <strong>The self-hosted Git platform for high-velocity teams.</strong><br> | |
14 | - Built for stacked PRs, AI code review, and enterprise security. | |
12 | + <strong>A modern self-hosted Git platform for teams that want speed, control, and clean workflows.</strong> | |
15 | 13 | </p> |
16 | 14 | |
17 | 15 | <p align="center"> |
18 | - <a href="https://www.npmjs.com/package/opencodehub-cli"><img src="https://img.shields.io/npm/v/opencodehub-cli?style=flat-square&color=bd93f9&label=CLI" alt="npm version"></a> | |
19 | - <a href="LICENSE"><img src="https://img.shields.io/github/license/swadhinbiswas/OpenCodeHub?style=flat-square&color=50fa7b" alt="License"></a> | |
20 | - <a href="https://github.com/swadhinbiswas/OpenCodeHub/actions"><img src="https://img.shields.io/github/actions/workflow/status/swadhinbiswas/OpenCodeHub/ci.yml?branch=main&style=flat-square&color=8be9fd" alt="Build Status"></a> | |
21 | - <a href="https://docker.com"><img src="https://img.shields.io/badge/docker-ready-blue?style=flat-square&logo=docker" alt="Docker"></a> | |
16 | + OpenCodeHub combines Git hosting, pull requests, issues, wiki, merge queue, automation, and a stack-first CLI in one deployable system. | |
22 | 17 | </p> |
23 | 18 | |
24 | 19 | <p align="center"> |
25 | - <a href="#-features">Features</a> • | |
26 | - <a href="#-architecture">Architecture</a> • | |
27 | - <a href="#-quick-start">Quick Start</a> • | |
28 | - <a href="#-och-cli---command-line-interface">CLI</a> • | |
29 | - <a href="#-advanced-features">Advanced Features</a> • | |
30 | - <a href="#-contributing">Contributing</a> | |
20 | + <a href="https://www.npmjs.com/package/opencodehub-cli"><img src="https://img.shields.io/npm/v/opencodehub-cli?style=flat-square&label=CLI" alt="CLI version"></a> | |
21 | + <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License"></a> | |
22 | + <a href="docs/index.md"><img src="https://img.shields.io/badge/docs-available-success?style=flat-square" alt="Docs"></a> | |
31 | 23 | </p> |
32 | 24 | |
33 | 25 | --- |
34 | 26 | |
35 | -## 🎉 Production Ready! | |
27 | +## Why OpenCodeHub | |
36 | 28 | |
37 | -**All critical security vulnerabilities are now fixed. OpenCodeHub is production-ready!** 🎊 | |
29 | +Most teams eventually hit the same pain points: | |
38 | 30 | |
39 | -✅ **Rate Limiting** - Prevents brute force attacks | |
40 | -✅ **CSRF Protection** - Cross-site request forgery defense | |
41 | -✅ **Input Validation** - SQL injection & XSS prevention | |
42 | -✅ **Hook Authentication** - Secure git operations | |
43 | -✅ **Environment Validation** - Safe configuration management | |
31 | +- PRs are too large to review quickly | |
32 | +- Tooling is split across many services | |
33 | +- Data residency and security requirements are hard to satisfy in SaaS-only setups | |
44 | 34 | |
45 | -📚 **See [DEPLOYMENT.md](DEPLOYMENT.md) for complete deployment guide** with SSL setup, Nginx configuration, monitoring, database backups, and production best practices. | |
35 | +OpenCodeHub is built for that reality: self-hosted by default, with workflows optimized for fast review cycles and scalable team collaboration. | |
46 | 36 | |
37 | +## What Is Already In This Codebase | |
47 | 38 | |
48 | -## 🚀 Features | |
39 | +These are not roadmap claims; they are implemented modules and routes in this repository. | |
49 | 40 | |
50 | -### Git Hosting & Collaboration | |
41 | +### Core platform | |
51 | 42 | |
52 | -- **Full Git Support** - SSH and HTTP/HTTPS protocols with authentication | |
53 | -- **Repository Management** - Create, fork, archive, and transfer repositories | |
54 | -- **Branch Protection** - Enforce PR requirements, approvals, and code review policies | |
55 | -- **Pull Requests** - Code review with inline comments and approval workflows | |
56 | -- **Issues & Milestones** - Bug tracking with labels, assignees, and custom fields | |
57 | -- **Wiki** - Built-in documentation with markdown support | |
58 | -- **Organizations** - Team management with role-based access control (RBAC) | |
43 | +- Git hosting over HTTP and SSH (`src/pages/git/*`, `src/lib/ssh.ts`, `src/lib/git-server.ts`) | |
44 | +- Pull requests with comments, reviews, drafts, approvals (`src/pages/[owner]/[repo]/pulls/*`) | |
45 | +- Issues, labels, milestones, and project boards (`src/pages/[owner]/[repo]/issues/*`, `src/pages/[owner]/[repo]/milestones/*`, `src/pages/[owner]/[repo]/projects/*`) | |
46 | +- Repository wiki and revision history (`src/pages/[owner]/[repo]/wiki/*`) | |
47 | +- Organizations, collaborators, repository settings, branch protection | |
59 | 48 | |
60 | -### CI/CD & Automation | |
49 | +### Delivery workflows | |
61 | 50 | |
62 | -- **GitHub Actions Compatible** - Run workflows defined in `.github/workflows/` | |
63 | -- **Self-hosted Runners** - Docker-based job execution with artifact support | |
64 | -- **Merge Queue** - Automated PR merge management with conflict detection | |
65 | -- **Webhooks** - Real-time event notifications to external services | |
66 | -- **Secrets Management** - Encrypted storage for CI/CD credentials | |
51 | +- Stacked PR workflows in web + CLI (`src/lib/stacks.ts`, `cli/src/commands/stack/index.ts`) | |
52 | +- Merge queue and conflict handling (`src/lib/merge-queue.ts`, `src/pages/[owner]/[repo]/merge-queue.astro`) | |
53 | +- GitHub Actions-style pipeline engine + runner endpoints (`src/lib/pipeline.ts`, `src/pages/api/actions/*`, `src/runner/*`) | |
54 | +- Webhooks and automation rules (`src/pages/api/repos/[owner]/[repo]/webhooks/*`, `src/lib/automations.ts`) | |
67 | 55 | |
68 | -### Security Features ✅ | |
56 | +### Security and governance | |
69 | 57 | |
70 | -- **Rate Limiting** - Prevents brute force attacks (5 login attempts per 15min) | |
71 | -- **CSRF Protection** - Double-submit cookie pattern for all state-changing operations | |
72 | -- **Input Validation** - Zod schemas prevent injection attacks | |
73 | -- **Hook Authentication** - Shared secrets protect internal git hooks | |
74 | -- **Session Management** - Automatic expiration and rotation | |
75 | -- **Audit Logging** - Complete activity tracking for compliance | |
58 | +- Rate limiting middleware (`src/middleware/rate-limit.ts`, `src/middleware.ts`) | |
59 | +- CSRF utilities (`src/middleware/csrf.ts`) | |
60 | +- Input validation layer (`src/lib/validation.ts`) | |
61 | +- MFA (TOTP), OAuth/OIDC, token management, audit surfaces (`src/pages/api/user/settings/2fa.ts`, `src/lib/oidc.ts`, `src/pages/admin/audit.astro`) | |
76 | 62 | |
77 | -### Modern Tech Stack | |
63 | +### Extensibility and APIs | |
78 | 64 | |
79 | -- **Astro + React** - Fast, modern frontend with island architecture | |
80 | -- **TailwindCSS + shadcn/ui** - Beautiful, accessible UI components | |
81 | -- **Universal Database Adapter** - PostgreSQL, MySQL, SQLite, MongoDB, Turso, PlanetScale | |
82 | -- **Flexible Storage** - Local, S3, MinIO, Google Drive, Azure Blob, R2 | |
83 | -- **Production-Ready** - Rate limiting, CSRF, input validation, error monitoring | |
84 | -- **Comprehensive Docs** - Integrated documentation site with guides and API reference | |
65 | +- REST API routes: 140+ files under `src/pages/api/` | |
66 | +- GraphQL endpoint (`src/pages/api/graphql.ts`) | |
67 | +- OpenAPI JSON endpoint (`src/pages/api/openapi.json.ts`) | |
68 | +- CLI with 20+ command groups under `cli/src/commands/` | |
85 | 69 | |
70 | +### Storage and database flexibility | |
71 | + | |
72 | +- Database adapter factory with multiple drivers (`src/db/adapter/index.ts`) | |
73 | +- Pluggable storage backends (`src/lib/storage.ts`) | |
86 | 74 | |
87 | 75 | --- |
88 | 76 | |
89 | -## 🏗 Architecture | |
77 | +## Architecture | |
90 | 78 | |
91 | 79 | <p align="center"> |
92 | - <img src="public/architecture.svg" alt="System Architecture" width="800"> | |
80 | + <img src="public/architecture.svg" alt="OpenCodeHub Architecture" width="900" /> | |
93 | 81 | </p> |
94 | 82 | |
95 | -OpenCodeHub is built on a modern, scalable architecture designed for performance and flexibility. | |
96 | - | |
97 | -- **Frontend**: Astro + React for high-performance UI. | |
98 | -- **Backend API**: tRPC + Node.js for type-safe communication. | |
99 | -- **Git Server**: Custom implementation over standard Git protocols (HTTP/SSH). | |
100 | -- **Database**: Drizzle ORM supporting PostgreSQL, MySQL, and SQLite. | |
101 | -- **Storage**: Pluggable storage system (S3, R2, G-Drive, Local). | |
83 | +OpenCodeHub is a modular monolith: one main app, optional worker/runner processes, pluggable persistence, and Git protocol handling integrated into the platform. | |
102 | 84 | |
103 | 85 | --- |
104 | 86 | |
105 | -## 📦 Quick Start | |
87 | +## Quick Start (Local) | |
106 | 88 | |
107 | 89 | ### Prerequisites |
108 | 90 | |
109 | -- **Node.js** 18+ or **Bun** 1.0+ | |
110 | -- **Database**: PostgreSQL 14+ (recommended) / MySQL 8+ / SQLite 3.35+ | |
111 | -- **Git** 2.30+ | |
112 | -- **Docker** (optional, for CI/CD runners) | |
91 | +- `Node.js >= 20` | |
92 | +- `npm` | |
93 | +- `git` | |
94 | +- `bun` (recommended; used by helper scripts like admin seeding) | |
113 | 95 | |
114 | -### Installation (5 minutes) | |
96 | +### 1) Clone and install | |
115 | 97 | |
116 | 98 | ```bash |
117 | -# 1. Clone the repository | |
118 | 99 | git clone https://github.com/swadhinbiswas/OpencodeHub.git |
119 | 100 | cd OpenCodeHub |
120 | - | |
121 | -# 2. Install dependencies | |
122 | 101 | npm install |
123 | -# or | |
124 | -bun install | |
125 | - | |
126 | -# 3. Set up environment | |
127 | -cp .env.example .env | |
128 | - | |
129 | -# 4. Configure your .env file (see Configuration section) | |
130 | -nano .env # Set at minimum: JWT_SECRET, SESSION_SECRET, INTERNAL_HOOK_SECRET, SITE_URL | |
131 | - | |
132 | -# 5. Run database migrations | |
133 | -npm run db:push | |
134 | -# or generate migrations for version control: | |
135 | -npm run db:generate | |
136 | - | |
137 | -# 6. Seed an admin user | |
138 | -bun run scripts/seed-admin.ts | |
139 | -# Enter username, email, password when prompted | |
140 | - | |
141 | -# 7. Start development server | |
142 | -npm run dev | |
143 | -# Application available at http://localhost:3000 | |
144 | 102 | ``` |
145 | 103 | |
146 | -### Using Docker (Recommended for Production) | |
104 | +### 2) Configure environment | |
147 | 105 | |
148 | 106 | ```bash |
149 | -# 1. Clone and configure | |
150 | -git clone https://github.com/swadhinbiswas/OpencodeHub.git | |
151 | -cd OpenCodeHub | |
152 | 107 | cp .env.example .env |
153 | - | |
154 | -# 2. Edit .env with production values (see Production Deployment section) | |
155 | - | |
156 | -# 3. Start services | |
157 | -docker-compose up -d | |
158 | - | |
159 | -# 4. Create admin user | |
160 | -docker-compose exec app bun run scripts/seed-admin.ts | |
161 | - | |
162 | -# Access at http://localhost:3000 | |
163 | -``` | |
164 | - | |
165 | - | |
166 | -## 🎯 OCH CLI - Command Line Interface | |
167 | - | |
168 | -Powerful CLI for stack-first PR workflows. | |
169 | - | |
170 | -### Installation | |
171 | - | |
172 | -```bash | |
173 | -# Install globally | |
174 | -npm install -g opencodehub-cli | |
175 | - | |
176 | -# Or use with npx | |
177 | -npx opencodehub-cli | |
178 | - | |
179 | -# Verify installation | |
180 | -och --version | |
181 | -``` | |
182 | - | |
183 | -### Quick Setup | |
184 | - | |
185 | -```bash | |
186 | -# 1. Login to your OpenCode Hub instance | |
187 | -och auth login --url https://git.yourcompany.com | |
188 | - | |
189 | -# 2. Navigate to your repository | |
190 | -cd your-repo | |
191 | - | |
192 | -# 3. Initialize | |
193 | -och init --url https://git.yourcompany.com | |
194 | -``` | |
195 | - | |
196 | -### CLI Commands Reference | |
197 | - | |
198 | -**Authentication:** | |
199 | - | |
200 | -```bash | |
201 | -och auth login # Interactive login | |
202 | -och auth login --token TOKEN # Login with token | |
203 | -och auth logout # Logout | |
204 | -och auth whoami # Show current user | |
205 | -``` | |
206 | - | |
207 | -**Stack Management:** | |
208 | - | |
209 | -```bash | |
210 | -och stack create \u003cname\u003e # Create new stacked branch | |
211 | -och stack view # View current stack (alias: ls) | |
212 | -och stack submit # Push and create PRs | |
213 | -och stack submit --draft # Create as draft PRs | |
214 | -och stack sync # Rebase stack on latest | |
215 | -och stack reorder # Reorder branches in stack | |
216 | -``` | |
217 | - | |
218 | -**Repository:** | |
219 | - | |
220 | -```bash | |
221 | -och init # Initialize repo for OpenCodeHub | |
222 | -och sync # Bidirectional sync with remote | |
223 | -och status # Show stack status (alias: st) | |
224 | -``` | |
225 | - | |
226 | - | |
227 | -## 🚀 Advanced Features | |
228 | - | |
229 | -### 📚 Stacked Pull Requests | |
230 | - | |
231 | -**Ship faster by breaking large features into reviewable chunks.** | |
232 | - | |
233 | -#### Why Stacked PRs? | |
234 | - | |
235 | -- **Faster Reviews**: Smaller, focused PRs get reviewed quicker | |
236 | -- **Parallel Development**: Build on unmerged PRs while waiting for review | |
237 | -- **Clean History**: Each PR represents one logical change | |
238 | -- **Risk Reduction**: Deploy incrementally, rollback easily | |
239 | - | |
240 | -#### How It Works | |
241 | - | |
242 | - | |
243 | -<br> | |
244 | - | |
245 | -Each PR builds on the previous one. When #123 merges, #124 automatically rebases. | |
246 | - | |
247 | -#### Creating a Stack | |
248 | - | |
249 | -**Using CLI:** | |
250 | - | |
251 | -```bash | |
252 | -# 1. Create base branch | |
253 | -git checkout -b feature/auth | |
254 | -git commit -m "Add user table schema" | |
255 | -och stack create auth-schema | |
256 | - | |
257 | -# 2. Create stacked branch | |
258 | -och stack create auth-service | |
259 | -git commit -m "Add authentication service" | |
260 | - | |
261 | -# 3. Create final layer | |
262 | -och stack create auth-ui | |
263 | -git commit -m "Add login UI" | |
264 | - | |
265 | -# 4. Submit entire stack | |
266 | -och stack submit | |
267 | -``` | |
268 | - | |
269 | -**Using Web UI:** | |
270 | - | |
271 | -1. Create first PR normally | |
272 | -2. When creating second PR, select "Stack on PR #123" | |
273 | -3. System tracks dependencies automatically | |
274 | - | |
275 | -#### Stack Features | |
276 | - | |
277 | -✅ **Auto-Rebasing**: When base PR merges, dependent PRs rebase automatically | |
278 | -✅ **Dependency Visualization**: See entire stack in PR view | |
279 | -✅ **Smart Merge Queue**: Merges in correct order | |
280 | -✅ **Conflict Detection**: Alerts on rebase conflicts | |
281 | - | |
282 | - | |
283 | -### 🤖 AI Code Review | |
284 | - | |
285 | -**Get instant feedback from AI reviewers powered by GPT-4 or Claude.** | |
286 | - | |
287 | -#### Setup | |
288 | - | |
289 | -**1. Configure AI Provider:** | |
290 | - | |
291 | -```env | |
292 | -# In .env | |
293 | -AI_PROVIDER=openai # or anthropic | |
294 | -OPENAI_API_KEY=sk-... | |
295 | -# or | |
296 | -ANTHROPIC_API_KEY=sk-ant-... | |
297 | 108 | ``` |
298 | 109 | |
299 | -**2. Enable for Repository:** | |
300 | -Navigate to **Repository → Settings → AI Review** | |
301 | - | |
302 | -- ✅ Enable AI Review | |
303 | -- Set review triggers (on PR open, on push, manual) | |
304 | -- Configure review rules | |
305 | - | |
306 | -#### What AI Reviews Catch | |
307 | - | |
308 | -🔍 **Security Vulnerabilities** | |
309 | - | |
310 | -- SQL injection risks | |
311 | -- XSS vulnerabilities | |
312 | -- Authentication bypasses | |
313 | -- Secrets in code | |
110 | +For local development, SQLite defaults in `.env.example` are enough to start. | |
314 | 111 | |
315 | -⚡ **Performance Issues** | |
316 | - | |
317 | -- N+1 queries | |
318 | -- Inefficient algorithms | |
319 | -- Memory leaks | |
320 | -- Blocking operations | |
321 | - | |
322 | -📝 **Code Quality** | |
323 | - | |
324 | -- Best practice violations | |
325 | -- Code smells | |
326 | -- Incomplete error handling | |
327 | -- Missing documentation | |
328 | - | |
329 | -🐛 **Potential Bugs** | |
330 | - | |
331 | -- Null pointer exceptions | |
332 | -- Race conditions | |
333 | -- Off-by-one errors | |
334 | -- Logic flaws | |
335 | - | |
336 | -#### Using AI Review | |
337 | - | |
338 | -**Automatic (Recommended):** | |
339 | -AI review runs automatically on every PR based on configured triggers. | |
340 | - | |
341 | -**Manual:** | |
112 | +### 3) Initialize database | |
342 | 113 | |
343 | 114 | ```bash |
344 | -# Via CLI | |
345 | -och review ai \u003cPR_NUMBER\u003e | |
346 | - | |
347 | -# Via web UI: Click "Request AI Review" button on PR | |
348 | -``` | |
349 | - | |
350 | -#### Review Output | |
351 | - | |
352 | -AI provides: | |
353 | - | |
354 | -- **Severity Score**: Critical / High / Medium / Low / Info | |
355 | -- **Specific Line Comments**: Inline code suggestions | |
356 | -- **Summary Report**: Overall code quality assessment | |
357 | -- **Fix Suggestions**: Actionable improvements | |
358 | - | |
359 | -**Example:** | |
360 | - | |
361 | -```text | |
362 | -🔴 CRITICAL: SQL Injection Vulnerability | |
363 | -File: src/api/users.ts:45 | |
364 | -Issue: User input directly concatenated into SQL query | |
365 | -Fix: Use parameterized queries or ORM | |
366 | - | |
367 | -🟡 MEDIUM: Performance Concern | |
368 | -File: src/lib/data.ts:128 | |
369 | -Issue: N+1 query in loop (1000+ iterations) | |
370 | -Fix: Use batch loading or eager loading | |
371 | -``` | |
372 | - | |
373 | - | |
374 | -### 🔀 Smart Merge Queue | |
375 | - | |
376 | -**Stack-aware merge queue with automatic conflict resolution and CI optimization.** | |
377 | - | |
378 | -#### Features | |
379 | - | |
380 | -**Stack-Aware Merging:** | |
381 | - | |
382 | -- Detects PR dependencies | |
383 | -- Merges in correct order automatically | |
384 | -- Handles entire stacks atomically | |
385 | - | |
386 | -**CI Optimization:** | |
387 | - | |
388 | -- Batches compatible PRs | |
389 | -- Runs CI once for multiple PRs | |
390 | -- Reduces CI cost by ~60% | |
391 | - | |
392 | -**Automatic Rebasing:** | |
393 | - | |
394 | -- Detects conflicts early | |
395 | -- Auto-rebases on base changes | |
396 | -- Alerts author on conflicts | |
397 | - | |
398 | -**Smart Ordering:** | |
399 | - | |
400 | -- Priority-based queue | |
401 | -- Dependency resolution | |
402 | -- Hotfix fast-tracking | |
403 | - | |
404 | -#### Using Merge Queue | |
405 | - | |
406 | -**Add to Queue:** | |
407 | - | |
408 | -```bash | |
409 | -# Via CLI | |
410 | -och queue add \u003cPR_NUMBER\u003e | |
411 | - | |
412 | -# Via Web UI | |
413 | -Click "Add to Merge Queue" button on approved PR | |
115 | +npm run db:push | |
414 | 116 | ``` |
415 | 117 | |
416 | -**Queue Status:** | |
118 | +### 4) Create an admin user | |
417 | 119 | |
418 | 120 | ```bash |
419 | -# View queue | |
420 | -och queue list | |
421 | - | |
422 | -# Output: | |
423 | -Position PR Title Status | |
424 | -1 #125 Add login UI ⏳ Running CI | |
425 | -2 #124 Auth service ⏸️ Waiting (depends on #123) | |
426 | -3 #123 Database schema ✅ Ready to merge | |
427 | -``` | |
428 | - | |
429 | -**How It Works:** | |
430 | - | |
431 | -1. **PR Added**: Queue analyzes dependencies | |
432 | -2. **Position Assigned**: Ordered by priority and dependencies | |
433 | -3. **CI Running**: Runs tests in parallel where possible | |
434 | -4. **Auto-Merge**: Merges when ready, rebases dependents | |
435 | -5. **Notification**: Author notified on completion | |
436 | - | |
437 | -#### Queue Configuration | |
438 | - | |
439 | -**Repository → Settings → Merge Queue:** | |
440 | - | |
441 | -- **Require CI**: Only merge if all checks pass | |
442 | -- **Batch Window**: Wait time to batch PRs (default: 5min) | |
443 | -- **Max Batch Size**: Max PRs to merge together (default: 3) | |
444 | -- **Auto-Rebase**: Rebase on conflicts vs. remove from queue | |
445 | - | |
446 | - | |
447 | -### 📊 Developer Metrics | |
448 | - | |
449 | -**Track team velocity, review efficiency, and identify bottlenecks.** | |
450 | - | |
451 | -#### Available Metrics | |
452 | - | |
453 | -**PR Velocity:** | |
454 | - | |
455 | -- PRs merged per week | |
456 | -- Average time to merge | |
457 | -- Stack success rate | |
458 | -- Review cycle time | |
459 | - | |
460 | -**Review Efficiency:** | |
461 | - | |
462 | -- Average review time | |
463 | -- Reviews per day | |
464 | -- Review quality score | |
465 | -- Reviewer responsiveness | |
466 | - | |
467 | -**Team Performance:** | |
468 | - | |
469 | -- Lines changed per PR | |
470 | -- PR size distribution | |
471 | -- Revert rate | |
472 | -- CI success rate | |
473 | - | |
474 | -**Stack Metrics:** | |
475 | - | |
476 | -- % PRs that use stacks | |
477 | -- Average stack depth | |
478 | -- Stack merge success rate | |
479 | -- Time saved vs. monolithic PRs | |
480 | - | |
481 | -#### Viewing Metrics | |
482 | - | |
483 | -**Personal Dashboard:** | |
484 | - | |
485 | -```text | |
486 | -/metrics/me | |
487 | -``` | |
488 | - | |
489 | -**Team Dashboard (Admin):** | |
490 | - | |
491 | -```text | |
492 | -/admin/metrics | |
121 | +bun run scripts/seed-admin.ts | |
493 | 122 | ``` |
494 | 123 | |
495 | -**Via CLI:** | |
124 | +### 5) Start development server | |
496 | 125 | |
497 | 126 | ```bash |
498 | -och metrics show | |
499 | -och metrics show --user @username | |
500 | -och metrics show --repo owner/repo | |
501 | -``` | |
502 | - | |
503 | -#### Example Metrics View | |
504 | - | |
505 | -```text | |
506 | -📊 Your Metrics (Last 30 Days) | |
507 | - | |
508 | -PR Velocity | |
509 | -├─ PRs Merged ━━━━━━━━━━━━━━ 24 (+12%) | |
510 | -├─ Avg Time to Merge ━━━━━━━━━━━━━━ 8.2 hours (-3h) | |
511 | -└─ Stack Usage ━━━━━━━━━━━━━━ 65% (+15%) | |
512 | - | |
513 | -Review Efficiency | |
514 | -├─ Reviews Given ━━━━━━━━━━━━━━ 18 | |
515 | -├─ Avg Review Time ━━━━━━━━━━━━━━ 22 min | |
516 | -└─ Approval Rate ━━━━━━━━━━━━━━ 94% | |
517 | -``` | |
518 | - | |
519 | - | |
520 | -### 💬 Slack Notifications | |
521 | - | |
522 | -**Get actionable PR notifications directly in Slack.** | |
523 | - | |
524 | -#### Setup | |
525 | - | |
526 | -**1. Create Slack App:** | |
527 | - | |
528 | -1. Go to https://api.slack.com/apps | |
529 | -2. Create New App → From Scratch | |
530 | -3. Add OAuth Scopes: | |
531 | - - `chat:write` | |
532 | - - `chat:write.public` | |
533 | - - `users:read` | |
534 | -4. Install to workspace | |
535 | - | |
536 | -**2. Connect to OpenCodeHub:** | |
537 | -Navigate to **Admin → Integrations → Slack** | |
538 | - | |
539 | -``` | |
540 | -Workspace Name: Your Team | |
541 | -Bot Token: xoxb-... | |
542 | -Signing Secret: ... | |
543 | -``` | |
544 | - | |
545 | -**3. Map Channels:** | |
546 | -**Repository → Settings → Slack** | |
547 | - | |
548 | -``` | |
549 | -#engineering → All PR events | |
550 | -#deployments → Merges only | |
551 | -#security → Security findings | |
552 | -``` | |
553 | - | |
554 | -**4. Map Users (Optional):** | |
555 | -Users can link their Slack account: | |
556 | -**Settings → Integrations → Connect Slack** | |
557 | - | |
558 | -#### Notification Types | |
559 | - | |
560 | -**PR Events:** | |
561 | - | |
562 | -- 🎉 PR opened | |
563 | -- ✅ PR approved | |
564 | -- 🔀 PR merged | |
565 | -- ❌ PR closed | |
566 | -- 💬 Review requested | |
567 | -- 🔴 Changes requested | |
568 | - | |
569 | -**CI/CD Events:** | |
570 | - | |
571 | -- ✅ Build passed | |
572 | -- ❌ Build failed | |
573 | -- 🚀 Deployment started | |
574 | -- ✅ Deployment successful | |
575 | - | |
576 | -**Code Review:** | |
577 | - | |
578 | -- 🤖 AI review completed | |
579 | -- 🔍 Security issue found | |
580 | -- ⚠️ Performance concern | |
581 | - | |
582 | -**Merge Queue:** | |
583 | - | |
584 | -- ⏭️ Added to queue | |
585 | -- ✅ Merged from queue | |
586 | -- ⚠️ Removed (conflict) | |
587 | - | |
588 | -#### Interactive Actions | |
589 | - | |
590 | -Notifications include action buttons: | |
591 | - | |
592 | -``` | |
593 | -[swadhin] opened PR#125: Add login UI | |
594 | -Stack: #123 → #124 → #125 • files →32 • LoC +420/-18 | |
595 | - | |
596 | -[Approve] [Request Changes] [View PR] [Add to Queue] | |
127 | +npm run dev | |
597 | 128 | ``` |
598 | 129 | |
599 | -Click buttons to: | |
600 | - | |
601 | -- Approve/reject directly from Slack | |
602 | -- Request changes with comment | |
603 | -- Add to merge queue | |
604 | -- View full PR | |
605 | - | |
606 | -#### Discord & Microsoft Teams | |
607 | - | |
608 | -OpenCodeHub also supports incoming webhooks for Discord and Microsoft Teams. | |
609 | - | |
610 | -**Setup:** | |
611 | -1. **Repository → Settings → Webhooks** | |
612 | -2. Create a new webhook | |
613 | -3. Select **Discord** or **Microsoft Teams** as the type | |
614 | -4. Paste your webhook URL | |
615 | -5. Select triggers (PR events, Push events, etc.) | |
130 | +App URL: `http://localhost:3000` | |
616 | 131 | |
617 | 132 | --- |
618 | 133 | |
619 | -## 💡 Workflow Examples | |
620 | - | |
621 | -### Example 1: Complete Stacked PR Flow | |
134 | +## Quick Start (Docker Compose) | |
622 | 135 | |
623 | 136 | ```bash |
624 | -# 1. Start new feature | |
625 | -git checkout main | |
626 | -git pull | |
627 | -git checkout -b feature/user-profiles | |
628 | - | |
629 | -# 2. First PR: Database layer | |
630 | -git add migrations/ | |
631 | -git commit -m "Add user profile tables" | |
632 | -och stack create profile-db | |
633 | -och stack submit | |
634 | - | |
635 | -# → Creates PR #301 | |
636 | - | |
637 | -# 3. Second PR: Backend API | |
638 | -git add src/api/profiles/ | |
639 | -git commit -m "Add profile API" | |
640 | -och stack create profile-api | |
641 | -och stack submit | |
642 | - | |
643 | -# → Creates PR #302 (stacked on #301) | |
644 | - | |
645 | -# 4. Third PR: Frontend | |
646 | -git add src/pages/profile/ | |
647 | -git commit -m "Add profile UI" | |
648 | -och stack create profile-ui | |
649 | -och stack submit | |
650 | - | |
651 | -# → Creates PR #303 (stacked on #302) | |
652 | - | |
653 | -# 5. View stack | |
654 | -och stack view | |
655 | -``` | |
656 | - | |
657 | -**Output:** | |
658 | - | |
137 | +cp .env.example .env | |
138 | +docker-compose up -d | |
659 | 139 | ``` |
660 | -📚 Current Stack | |
661 | 140 | |
662 | -main (base) | |
663 | - └─ #301: profile-db ✅ Approved | |
664 | - └─ #302: profile-api 🔍 In Review | |
665 | - └─ #303: profile-ui ⏳ AI Review Running | |
666 | -``` | |
141 | +Default Docker app URL: `http://localhost:4321` | |
667 | 142 | |
668 | -### Example 2: Using AI Review + Merge Queue | |
143 | +Optional admin user creation: | |
669 | 144 | |
670 | 145 | ```bash |
671 | -# 1. Create PR | |
672 | -git push origin feature-branch | |
673 | - | |
674 | -# 2. Request AI review | |
675 | -och review ai 304 | |
676 | - | |
677 | -# 3. Fix AI suggestions | |
678 | -# ... make changes based on review ... | |
679 | -git commit -m "Fix security issues from AI review" | |
680 | -git push | |
681 | - | |
682 | -# 4. Get human review | |
683 | -# Team reviews via web UI | |
684 | - | |
685 | -# 5. Add to merge queue when approved | |
686 | -och queue add 304 | |
687 | - | |
688 | -# Queue handles: | |
689 | -# - Waiting for CI | |
690 | -# - Merging when ready | |
691 | -# - Notifying on Slack | |
692 | -``` | |
693 | - | |
694 | -### Example 3: Team Collaboration | |
695 | - | |
696 | -```bash | |
697 | -# Developer A: Creates base | |
698 | -git checkout -b api/payments | |
699 | -# ... implements payment models ... | |
700 | -git commit -m "Add payment models" | |
701 | -git push | |
702 | - | |
703 | -# Developer B: Builds on A's work (before merge!) | |
704 | -git checkout api/payments | |
705 | -git checkout -b api/payment-processing | |
706 | -# ... implements payment processing ... | |
707 | -git commit -m "Add payment processing" | |
708 | -git push | |
709 | -# Create PR stacked on A's PR | |
710 | - | |
711 | -# Developer C: Builds on B's work | |
712 | -git checkout api/payment-processing | |
713 | -git checkout -b ui/payment-form | |
714 | -# ... implements payment UI ... | |
715 | -``` | |
716 | - | |
717 | -**Result**: 3 parallel PRs, all reviewed separately, merged in order. | |
718 | - | |
719 | - | |
720 | -## 📖 Additional Resources | |
721 | - | |
722 | -- **Full CLI Reference**: `cli/README.md` | |
723 | -- **API Documentation**: `/api/docs` | |
724 | -- **Stacked PR Guide**: `/docs#stacked-prs` | |
725 | -- **Slack Integration Guide**: `/docs#slack` | |
726 | - | |
727 | - | |
728 | -## ⚙️ Configuration | |
729 | - | |
730 | -### Critical Environment Variables | |
731 | - | |
732 | -These **MUST** be set before deploying to production: | |
733 | - | |
734 | -```env | |
735 | -# Security (CRITICAL - Generate strong secrets!) | |
736 | -JWT_SECRET=<run: openssl rand -hex 32> | |
737 | -SESSION_SECRET=<run: openssl rand -hex 32> | |
738 | -INTERNAL_HOOK_SECRET=<run: openssl rand -hex 32> | |
739 | - | |
740 | -# Application URLs (CRITICAL) | |
741 | -SITE_URL=https://your-domain.com # Must be HTTPS in production | |
742 | -PORT=3000 | |
743 | -HOST=0.0.0.0 | |
744 | - | |
745 | -# CI/CD Runner Security (CRITICAL) | |
746 | -# Must match the secret used by your runners | |
747 | -RUNNER_SECRET=<run: openssl rand -hex 32> | |
748 | -``` | |
749 | - | |
750 | -### Database Configuration | |
751 | - | |
752 | -**PostgreSQL (Recommended for Production):** | |
753 | - | |
754 | -```env | |
755 | -DATABASE_DRIVER=postgres | |
756 | -DATABASE_URL=postgresql://user:password@localhost:5432/opencodehub | |
757 | -``` | |
758 | - | |
759 | -**MySQL:** | |
760 | - | |
761 | -```env | |
762 | -DATABASE_DRIVER=mysql | |
763 | -DATABASE_URL=mysql://user:password@localhost:3306/opencodehub | |
764 | -``` | |
765 | - | |
766 | -**SQLite (Development Only):** | |
767 | - | |
768 | -```env | |
769 | -DATABASE_DRIVER=sqlite | |
770 | -DATABASE_URL=./data/opencodehub.db | |
771 | -``` | |
772 | - | |
773 | -### Storage Configuration | |
774 | - | |
775 | -Storage can be configured via Admin Panel (`/admin/storage`) or environment variables: | |
776 | - | |
777 | -**Local Storage:** | |
778 | - | |
779 | -```env | |
780 | -STORAGE_TYPE=local | |
781 | -STORAGE_PATH=./data/storage | |
782 | -``` | |
783 | - | |
784 | -**S3/MinIO/R2:** | |
785 | - | |
786 | -```env | |
787 | -STORAGE_TYPE=s3 | |
788 | -STORAGE_BUCKET=opencodehub | |
789 | -STORAGE_REGION=us-east-1 | |
790 | -STORAGE_ENDPOINT=https://s3.amazonaws.com | |
791 | -S3_ACCESS_KEY=your-access-key | |
792 | -S3_SECRET_KEY=your-secret-key | |
793 | -``` | |
794 | - | |
795 | -**Google Drive (via Admin Panel):** | |
796 | - | |
797 | -- Navigate to `/admin/storage` | |
798 | -- Select "Google Drive" | |
799 | -- Enter Client ID, Secret, and Refresh Token | |
800 | -- Test connection before saving | |
801 | - | |
802 | -### Security Configuration | |
803 | - | |
804 | -**Rate Limiting:** | |
805 | - | |
806 | -```env | |
807 | -RATE_LIMIT_AUTH=5 # Login attempts per 15 minutes | |
808 | -RATE_LIMIT_API=100 # API requests per minute | |
809 | -RATE_LIMIT_GIT=200 # Git operations per minute | |
810 | -RATE_LIMIT_SKIP_DEV=false # Never skip in production | |
811 | -``` | |
812 | - | |
813 | -**CSRF Protection:** | |
814 | - | |
815 | -```env | |
816 | -CSRF_SKIP_DEV=false # Never skip in production | |
817 | -``` | |
818 | - | |
819 | -### Optional Services | |
820 | - | |
821 | -**Email (SMTP):** | |
822 | - | |
823 | -```env | |
824 | -SMTP_HOST=smtp.example.com | |
825 | -SMTP_PORT=587 | |
826 | ||
827 | -SMTP_PASSWORD=your-smtp-password | |
828 | ||
829 | -``` | |
830 | - | |
831 | -**Redis (Caching & Sessions):** | |
832 | - | |
833 | -```env | |
834 | -REDIS_URL=redis://localhost:6379 | |
835 | -``` | |
836 | - | |
837 | -**Error Monitoring (Sentry):** | |
838 | - | |
839 | -```env | |
840 | -SENTRY_DSN=https://... | |
841 | -ENABLE_TRACING=true | |
146 | +docker-compose exec app bun run scripts/seed-admin.ts | |
842 | 147 | ``` |
843 | 148 | |
844 | 149 | --- |
845 | 150 | |
846 | -## 🔒 Security | |
847 | - | |
848 | -OpenCodeHub implements **production-grade security** out of the box: | |
849 | - | |
850 | -### Implemented Security Features | |
851 | - | |
852 | -✅ **Authentication & Authorization** | |
853 | - | |
854 | -- JWT-based sessions with automatic expiration | |
855 | -- Bcrypt password hashing (10 rounds) | |
856 | -- 2FA/TOTP support | |
857 | -- Role-based access control (RBAC) | |
151 | +## Production Notes | |
858 | 152 | |
859 | -✅ **Attack Prevention** | |
153 | +Before production deployment, set strong values for at least: | |
860 | 154 | |
861 | -- **Rate Limiting**: Prevents brute force (5 login attempts per 15min) | |
862 | -- **CSRF Protection**: Double-submit cookie pattern on all state-changing operations | |
863 | -- **Input Validation**: Zod schemas prevent SQL injection and XSS | |
864 | -- **XSS Sanitization**: Markdown rendered with `rehype-sanitize` | |
155 | +- `JWT_SECRET` | |
156 | +- `SESSION_SECRET` | |
157 | +- `INTERNAL_HOOK_SECRET` | |
158 | +- `CRON_SECRET` | |
159 | +- `RUNNER_SECRET` | |
160 | +- `AI_CONFIG_ENCRYPTION_KEY` | |
161 | +- `SITE_URL` (HTTPS) | |
865 | 162 | |
866 | -✅ **Operational Security** | |
163 | +Useful references: | |
867 | 164 | |
868 | -- **Audit Logging**: All admin actions logged to database | |
869 | -- **Hook Authentication**: Git hooks protected with shared secrets | |
870 | -- **Session Management**: Automatic cleanup and rotation | |
871 | -- **Environment Validation**: Startup checks for missing/weak secrets | |
872 | - | |
873 | -### Security Best Practices | |
874 | - | |
875 | -1. **Always use HTTPS** in production (Let's Encrypt recommended) | |
876 | -2. **Rotate secrets** regularly (especially after team changes) | |
877 | -3. **Enable 2FA** for all admin accounts | |
878 | -4. **Monitor audit logs** for suspicious activity | |
879 | -5. **Keep dependencies updated**: Run `npm audit` weekly | |
880 | - | |
881 | -### Reporting Security Issues | |
882 | - | |
883 | -Please report security vulnerabilities to **[email protected]**. Do not create public issues. | |
165 | +- `DEPLOYMENT.md` | |
166 | +- `docs/administration/deployment.md` | |
167 | +- `docs/administration/security.md` | |
884 | 168 | |
885 | 169 | --- |
886 | 170 | |
887 | -## 🚀 Production Deployment | |
888 | - | |
889 | -### Pre-Deployment Checklist | |
890 | - | |
891 | -Before going live, ensure: | |
892 | - | |
893 | -- [ ] **Secrets**: All secrets generated with `openssl rand -hex 32` | |
894 | -- [ ] **HTTPS**: SSL certificate configured (Let's Encrypt recommended) | |
895 | -- [ ] **Database**: PostgreSQL with backups enabled | |
896 | -- [ ] **Storage**: S3/R2 configured (not local filesystem) | |
897 | -- [ ] **Monitoring**: Error tracking (Sentry) and APM configured | |
898 | -- [ ] **Rate Limits**: Configured for expected traffic | |
899 | -- [ ] **Admin Account**: Created via `bun run scripts/seed-admin.ts` | |
900 | -- [ ] **Environment Validation**: Test with `bun run src/lib/env-validation.ts` | |
901 | -- [ ] **Database Migrations**: Generated with `npm run db:generate` | |
902 | - | |
903 | -### Production Environment Variables | |
904 | - | |
905 | -```env | |
906 | -# Application | |
907 | -NODE_ENV=production | |
908 | -SITE_URL=https://git.yourcompany.com | |
909 | -PORT=3000 | |
910 | - | |
911 | -# Security (CRITICAL - Generate with: openssl rand -hex 32) | |
912 | -JWT_SECRET=<64-char-random-hex> | |
913 | -SESSION_SECRET=<64-char-random-hex> | |
914 | -INTERNAL_HOOK_SECRET=<64-char-random-hex> | |
915 | - | |
916 | -# Database (Use connection pooling) | |
917 | -DATABASE_DRIVER=postgres | |
918 | -DATABASE_URL=postgresql://user:password@db-host:5432/opencodehub?pool_timeout=30 | |
919 | - | |
920 | -# Storage (Use cloud storage) | |
921 | -STORAGE_TYPE=s3 | |
922 | -STORAGE_BUCKET=opencodehub-prod | |
923 | -STORAGE_REGION=us-east-1 | |
924 | - | |
925 | -# Rate Limiting (Adjust based on traffic) | |
926 | -RATE_LIMIT_AUTH=5 | |
927 | -RATE_LIMIT_API=200 | |
928 | -RATE_LIMIT_GIT=500 | |
929 | - | |
930 | -# Monitoring | |
931 | -SENTRY_DSN=https://your-sentry-dsn | |
932 | -LOG_LEVEL=info | |
933 | - | |
934 | -# Features | |
935 | -ENABLE_REGISTRATION=true # Set false for invite-only | |
936 | -``` | |
937 | - | |
938 | -### Docker Production Deployment | |
939 | - | |
940 | -```yaml | |
941 | -# docker-compose.prod.yml | |
942 | -version: "3.8" | |
943 | - | |
944 | -services: | |
945 | - app: | |
946 | - image: opencodehub:latest | |
947 | - restart: always | |
948 | - ports: | |
949 | - - "3000:3000" | |
950 | - env_file: .env.production | |
951 | - depends_on: | |
952 | - - postgres | |
953 | - - redis | |
954 | - volumes: | |
955 | - - ./data:/app/data | |
956 | - healthcheck: | |
957 | - test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"] | |
958 | - interval: 30s | |
959 | - timeout: 10s | |
960 | - retries: 3 | |
961 | - | |
962 | - postgres: | |
963 | - image: postgres:15-alpine | |
964 | - restart: always | |
965 | - environment: | |
966 | - POSTGRES_DB: opencodehub | |
967 | - POSTGRES_USER: opencodehub | |
968 | - POSTGRES_PASSWORD: <strong-password> | |
969 | - volumes: | |
970 | - - postgres_data:/var/lib/postgresql/data | |
971 | - | |
972 | - redis: | |
973 | - image: redis:7-alpine | |
974 | - restart: always | |
975 | - | |
976 | -volumes: | |
977 | - postgres_data: | |
978 | -``` | |
171 | +## Common Commands | |
979 | 172 | |
980 | 173 | ```bash |
981 | -# Deploy | |
982 | -docker-compose -f docker-compose.prod.yml up -d | |
983 | - | |
984 | -# Monitor logs | |
985 | -docker-compose -f docker-compose.prod.yml logs -f app | |
986 | - | |
987 | -# Health check | |
988 | -curl https://git.yourcompany.com/api/health | |
989 | -``` | |
990 | - | |
991 | -### Reverse Proxy (Nginx) | |
992 | - | |
993 | -```nginx | |
994 | -server { | |
995 | - listen 443 ssl http2; | |
996 | - server_name git.yourcompany.com; | |
997 | - | |
998 | - ssl_certificate /path/to/cert.pem; | |
999 | - ssl_certificate_key /path/to/key.pem; | |
1000 | - | |
1001 | - location / { | |
1002 | - proxy_pass http://localhost:3000; | |
1003 | - proxy_set_header Host $host; | |
1004 | - proxy_set_header X-Real-IP $remote_addr; | |
1005 | - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
1006 | - proxy_set_header X-Forwarded-Proto $scheme; | |
1007 | - } | |
1008 | - | |
1009 | - # Git operations (larger timeouts) | |
1010 | - location ~ ^/[^/]+/[^/]+\.git/ { | |
1011 | - proxy_pass http://localhost:3000; | |
1012 | - proxy_read_timeout 300s; | |
1013 | - proxy_send_timeout 300s; | |
1014 | - proxy_buffer_size 128k; | |
1015 | - proxy_buffers 4 256k; | |
1016 | - } | |
1017 | -} | |
1018 | -``` | |
1019 | - | |
1020 | -### Database Backups | |
1021 | - | |
1022 | -```bash | |
1023 | -# PostgreSQL backup script (cron daily) | |
1024 | -#!/bin/bash | |
1025 | -pg_dump -U opencodehub opencodehub | gzip > /backups/opencodehub-$(date +\%Y\%m\%d).sql.gz | |
1026 | - | |
1027 | -# Retain last 30 days | |
1028 | -find /backups -name "opencodehub-*.sql.gz" -mtime +30 -delete | |
1029 | -``` | |
1030 | - | |
1031 | - | |
1032 | -## 📚 API Documentation | |
1033 | - | |
1034 | -### Authentication | |
1035 | - | |
1036 | -All authenticated endpoints require a session cookie or `Authorization: Bearer <token>` header. | |
1037 | - | |
1038 | -**Register:** | |
1039 | - | |
1040 | -```bash | |
1041 | -POST /api/auth/register | |
1042 | -Content-Type: application/json | |
1043 | - | |
1044 | -{ | |
1045 | - "username": "johndoe", | |
1046 | - "email": "[email protected]", | |
1047 | - "password": "SecureP@ssw0rd", | |
1048 | - "displayName": "John Doe" | |
1049 | -} | |
1050 | - | |
1051 | -# Response: 201 Created | |
1052 | -{ | |
1053 | - "user": { "id": "...", "username": "johndoe", ... }, | |
1054 | - "token": "eyJ...", | |
1055 | - "expiresAt": "2026-01-08T00:00:00Z" | |
1056 | -} | |
1057 | -``` | |
1058 | - | |
1059 | -**Login:** | |
1060 | - | |
1061 | -```bash | |
1062 | -POST /api/auth/login | |
1063 | -Content-Type: application/json | |
1064 | - | |
1065 | -{ | |
1066 | - "login": "[email protected]", # username or email | |
1067 | - "password": "SecureP@ssw0rd" | |
1068 | -} | |
1069 | - | |
1070 | -# With 2FA: | |
1071 | -{ | |
1072 | - "login": "[email protected]", | |
1073 | - "password": "SecureP@ssw0rd", | |
1074 | - "totpCode": "123456" | |
1075 | -} | |
1076 | -``` | |
1077 | - | |
1078 | -### Repositories | |
1079 | - | |
1080 | -**Create Repository:** | |
1081 | - | |
1082 | -```bash | |
1083 | -POST /api/repos | |
1084 | -Authorization: Bearer <token> | |
1085 | -Content-Type: application/json | |
1086 | - | |
1087 | -{ | |
1088 | - "name": "my-project", | |
1089 | - "description": "My awesome project", | |
1090 | - "visibility": "public" # public, private, internal | |
1091 | -} | |
1092 | -``` | |
1093 | - | |
1094 | -**Branch Protection:** | |
1095 | - | |
1096 | -```bash | |
1097 | -POST /api/repos/{repoId}/branch-protection | |
1098 | -Authorization: Bearer <token> | |
1099 | -Content-Type: application/json | |
1100 | - | |
1101 | -{ | |
1102 | - "pattern": "main", | |
1103 | - "requiresPr": true, | |
1104 | - "requiredApprovals": 2, | |
1105 | - "dismissStaleReviews": true | |
1106 | -} | |
1107 | -``` | |
1108 | - | |
1109 | -### Admin Endpoints | |
1110 | - | |
1111 | -**List Users (Admin Only):** | |
1112 | - | |
1113 | -```bash | |
1114 | -GET /admin/users?q=search&page=1 | |
1115 | -Cookie: och_session=... | |
1116 | -``` | |
1117 | - | |
1118 | -**Update Storage Config (Admin Only):** | |
1119 | - | |
1120 | -```bash | |
1121 | -POST /api/admin/config/storage | |
1122 | -Cookie: och_session=... | |
1123 | -Content-Type: application/json | |
1124 | - | |
1125 | -{ | |
1126 | - "type": "s3", | |
1127 | - "bucket": "my-bucket", | |
1128 | - "region": "us-east-1", | |
1129 | - ... | |
1130 | -} | |
1131 | -``` | |
174 | +# App lifecycle | |
175 | +npm run dev | |
176 | +npm run build | |
177 | +npm run preview | |
1132 | 178 | |
1133 | -### Rate Limits | |
179 | +# Code quality and tests | |
180 | +npm run lint | |
181 | +npm run typecheck | |
182 | +npm run test | |
183 | +npm run test:coverage | |
1134 | 184 | |
1135 | -All endpoints return rate limit headers: | |
185 | +# Database | |
186 | +npm run db:generate | |
187 | +npm run db:migrate | |
188 | +npm run db:push | |
189 | +npm run db:studio | |
1136 | 190 | |
1137 | -```http | |
1138 | -X-RateLimit-Limit: 100 | |
1139 | -X-RateLimit-Remaining: 95 | |
1140 | -X-RateLimit-Reset: 2026-01-01T15:30:00Z | |
1141 | -Retry-After: 30 (when rate limited) | |
191 | +# Optional background processes | |
192 | +npm run worker:start | |
193 | +npm run runner:start | |
194 | +npm run git:start | |
1142 | 195 | ``` |
1143 | 196 | |
1144 | -**Full API documentation:** `/api/docs` (OpenAPI spec coming soon) | |
1145 | - | |
1146 | 197 | --- |
1147 | 198 | |
1148 | -## 🔧 Usage Guide | |
199 | +## OpenCodeHub CLI | |
1149 | 200 | |
1150 | -### Creating Your First Repository | |
201 | +The companion CLI is published as `opencodehub-cli` and implemented in `cli/`. | |
1151 | 202 | |
1152 | -1. **Log in** to your account | |
1153 | -2. Click the **+** button → **New Repository** | |
1154 | -3. Fill in details: | |
1155 | - - **Name**: alphanumeric, hyphens, underscores | |
1156 | - - **Description**: Optional | |
1157 | - - **Visibility**: public/private | |
1158 | -4. Click **Create Repository** | |
1159 | - | |
1160 | -### Cl | |
1161 | - | |
1162 | -oning Repositories | |
1163 | - | |
1164 | -**SSH (Recommended):** | |
1165 | - | |
1166 | -```bash | |
1167 | -# Add your SSH key in Settings → SSH Keys | |
1168 | -git clone [email protected]:username/repo.git | |
1169 | -``` | |
1170 | - | |
1171 | -**HTTPS:** | |
203 | +Install and test: | |
1172 | 204 | |
1173 | 205 | ```bash |
1174 | -git clone https://your-domain.com/username/repo.git | |
1175 | -# Username: your-username | |
1176 | -# Password: your-password or personal access token | |
1177 | -``` | |
1178 | - | |
1179 | -### Setting Up Branch Protection | |
1180 | - | |
1181 | -1. Navigate to **Repository → Settings → Branches** | |
1182 | -2. Click **Add Rule** | |
1183 | -3. Configure: | |
1184 | - - **Pattern**: `main` or `release/*` | |
1185 | - - **Require PR**: ✅ | |
1186 | - - **Required Approvals**: 2 | |
1187 | - - **Dismiss Stale Reviews**: ✅ | |
1188 | -4. **Save Rule** | |
1189 | - | |
1190 | -### CI/CD Workflows | |
1191 | - | |
1192 | -Create `.github/workflows/ci.yml`: | |
1193 | - | |
1194 | -```yaml | |
1195 | -name: CI | |
1196 | - | |
1197 | -on: | |
1198 | - push: | |
1199 | - branches: [main, develop] | |
1200 | - pull_request: | |
1201 | - branches: [main] | |
1202 | - | |
1203 | -jobs: | |
1204 | - test: | |
1205 | - runs-on: ubuntu-latest | |
1206 | - steps: | |
1207 | - - uses: actions/checkout@v4 | |
1208 | - | |
1209 | - - name: Setup Node.js | |
1210 | - uses: actions/setup-node@v4 | |
1211 | - with: | |
1212 | - node-version: "20" | |
1213 | - | |
1214 | - - name: Install | |
1215 | - run: npm ci | |
1216 | - | |
1217 | - - name: Test | |
1218 | - run: npm test | |
1219 | - | |
1220 | - - name: Build | |
1221 | - run: npm run build | |
1222 | - | |
1223 | - - name: Upload Artifacts | |
1224 | - uses: actions/upload-artifact@v3 | |
1225 | - with: | |
1226 | - name: dist | |
1227 | - path: dist/ | |
1228 | -``` | |
1229 | - | |
1230 | - | |
1231 | -## 🐛 Troubleshooting | |
1232 | - | |
1233 | -### Common Issues | |
1234 | - | |
1235 | -**"Rate limit exceeded" on login:** | |
1236 | - | |
1237 | -- Default: 5 attempts per 15 minutes | |
1238 | -- Solution: Wait 15 minutes or adjust `RATE_LIMIT_AUTH` in `.env` | |
1239 | - | |
1240 | -**"CSRF token validation failed":** | |
1241 | - | |
1242 | -- Ensure cookies are enabled | |
1243 | -- Check `SITE_URL` matches your actual domain | |
1244 | -- Verify HTTPS in production | |
1245 | - | |
1246 | -**"Unauthorized" on git hooks:** | |
1247 | - | |
1248 | -- Check `INTERNAL_HOOK_SECRET` is set | |
1249 | -- Verify hooks have correct secret in curl headers | |
1250 | -- Re-run `git init` on repositories to reinstall hooks | |
1251 | - | |
1252 | -**Database connection errors:** | |
1253 | - | |
1254 | -- Verify `DATABASE_URL` format | |
1255 | -- Check database server is running | |
1256 | -- Ensure user has correct permissions | |
1257 | - | |
1258 | -**Storage upload fails:** | |
1259 | - | |
1260 | -- Test connection in `/admin/storage` | |
1261 | -- Verify S3 credentials and bucket permissions | |
1262 | -- Check firewall rules for external storage | |
1263 | - | |
1264 | -### Debug Mode | |
1265 | - | |
1266 | -```env | |
1267 | -# Enable detailed logging | |
1268 | -LOG_LEVEL=debug | |
1269 | -NODE_ENV=development | |
1270 | - | |
1271 | -# View logs | |
1272 | -tail -f data/logs/opencodehub.log | |
206 | +npm install -g opencodehub-cli | |
207 | +och --help | |
1273 | 208 | ``` |
1274 | 209 | |
1275 | -### Health Check | |
210 | +Typical flow: | |
1276 | 211 | |
1277 | 212 | ```bash |
1278 | -curl http://localhost:3000/api/health | |
1279 | - | |
1280 | -# Response: | |
1281 | -{ | |
1282 | - "status": "ok", | |
1283 | - "checks": { | |
1284 | - "database": "ok", | |
1285 | - "storage": "ok", | |
1286 | - "redis": "ok" // if configured | |
1287 | - }, | |
1288 | - "uptime": 123456, | |
1289 | - "version": "1.0.0" | |
1290 | -} | |
213 | +och auth login --url http://localhost:3000 | |
214 | +och init --url http://localhost:3000 | |
215 | +och stack create feature/auth-step-1 | |
216 | +och stack submit | |
217 | +och queue list | |
1291 | 218 | ``` |
1292 | 219 | |
1293 | 220 | --- |
1294 | 221 | |
1295 | -## 🗺️ Roadmap | |
1296 | - | |
1297 | -We are constantly improving OpenCodeHub to make it the ultimate self-hosted development platform. | |
1298 | - | |
1299 | -### Q2 2026: Advanced AI Agents | |
222 | +## Documentation Map | |
1300 | 223 | |
1301 | -- [ ] **Auto-Fix Agents**: Autonomous agents that can silently fix lint errors and simple bugs. | |
1302 | -- [ ] **Test Generation**: Automatically generate unit and integration tests for new code. | |
1303 | - | |
1304 | -### Q3 2026: Federation & Social | |
1305 | - | |
1306 | -- [ ] **ActivityPub Support**: Follow users and repositories across different OpenCodeHub instances. | |
1307 | -- [ ] **Federated Merge Requests**: Cross-instance collaboration (like Email but better). | |
1308 | - | |
1309 | -### Q4 2026: Ecosystem Expansion | |
1310 | - | |
1311 | -- [ ] **Mobile App**: Native iOS and Android apps for reviewing code on the go. | |
1312 | -- [ ] **IDE Extensions**: dedicated VS Code and JetBrains plugins. | |
224 | +- Platform docs: `docs/` | |
225 | +- Docs site source: `docs-site/` | |
226 | +- API docs entry: `docs/api/rest-api.md` | |
227 | +- CLI reference: `docs/reference/cli-commands.md` | |
228 | +- Contribution guide: `CONTRIBUTING.md` | |
1313 | 229 | |
1314 | 230 | --- |
1315 | 231 | |
1316 | -## 🤝 Contributing | |
1317 | - | |
1318 | -We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. | |
1319 | - | |
1320 | -### Development Setup | |
232 | +## Project Maturity | |
1321 | 233 | |
1322 | -```bash | |
1323 | -# Fork and clone | |
1324 | -git clone https://github.com/swadhinbiswas/OpencodeHub.git | |
1325 | -cd OpencodeHub | |
1326 | - | |
1327 | -# Install dependencies | |
1328 | -bun install | |
1329 | - | |
1330 | -# Run in development | |
1331 | -bun run dev | |
1332 | - | |
1333 | -# Run tests | |
1334 | -bun test | |
1335 | - | |
1336 | -# Lint | |
1337 | -bun run lint | |
1338 | -``` | |
234 | +OpenCodeHub is active and evolving. Core collaboration features are functional, while some advanced areas are still being expanded. | |
1339 | 235 | |
1340 | -### Submitting Changes | |
236 | +Tracking documents: | |
1341 | 237 | |
1342 | -1. Create a feature branch (`git checkout -b feature/amazing-feature`) | |
1343 | -2. Make your changes | |
1344 | -3. Add tests | |
1345 | -4. Run `bun test` and `bun run lint` | |
1346 | -5. Commit (`git commit -m 'Add amazing feature'`) | |
1347 | -6. Push (`git push origin feature/amazing-feature`) | |
1348 | -7. Open a Pull Request | |
238 | +- `doc/feature_audit.md` | |
239 | +- `doc/missing_implementation_tracker.md` | |
240 | +- `github-issues-checklist.md` | |
1349 | 241 | |
1350 | 242 | --- |
1351 | 243 | |
1352 | -## 📄 License | |
1353 | - | |
1354 | -MIT License - see [LICENSE](LICENSE) for details. | |
244 | +## Contributing | |
1355 | 245 | |
246 | +Contributions are welcome. | |
1356 | 247 | |
1357 | -## 🙏 Acknowledgments | |
248 | +1. Fork the repository | |
249 | +2. Create a branch | |
250 | +3. Run lint/tests | |
251 | +4. Open a pull request | |
1358 | 252 | |
1359 | -- [Astro](https://astro.build/) - Web framework | |
1360 | -- [shadcn/ui](https://ui.shadcn.com/) - UI components | |
1361 | -- [Drizzle ORM](https://orm.drizzle.team/) - Database toolkit | |
1362 | -- [simple-git](https://github.com/steveukx/git-js) - Git operations | |
1363 | -- [Monaco Editor](https://microsoft.github.io/monaco-editor/) - Code editor | |
1364 | -- [Zod](https://zod.dev/) - Schema validation | |
253 | +See `CONTRIBUTING.md` for development workflow and standards. | |
1365 | 254 | |
255 | +## License | |
1366 | 256 | |
1367 | -<p align="center"> | |
1368 | - <strong>Made with ❤️ for the open source community</strong> | |
1369 | - <br> | |
1370 | - <a href="https://github.com/swadhinbiswas/OpencodeHub/issues">Report Bug</a> • | |
1371 | - <a href="https://github.com/swadhinbiswas/OpencodeHub/issues">Request Feature</a> | |
1372 | -</p> | |
257 | +MIT. See `LICENSE`. | |
1373 | 258 | |