{"id":29354319,"url":"https://github.com/wdarrenww/connex","last_synced_at":"2025-07-09T03:13:15.348Z","repository":{"id":302747019,"uuid":"1013480640","full_name":"wdarrenww/connex","owner":"wdarrenww","description":"HTTP/2 server in Go","archived":false,"fork":false,"pushed_at":"2025-07-04T02:21:20.000Z","size":10374,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-04T03:19:27.858Z","etag":null,"topics":["go","golang","http","http-2","http-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wdarrenww.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-04T01:27:42.000Z","updated_at":"2025-07-04T02:21:23.000Z","dependencies_parsed_at":"2025-07-04T03:29:44.791Z","dependency_job_id":null,"html_url":"https://github.com/wdarrenww/connex","commit_stats":null,"previous_names":["wdarrenww/connex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wdarrenww/connex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdarrenww%2Fconnex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdarrenww%2Fconnex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdarrenww%2Fconnex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdarrenww%2Fconnex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wdarrenww","download_url":"https://codeload.github.com/wdarrenww/connex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdarrenww%2Fconnex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264384430,"owners_count":23599617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","http","http-2","http-server"],"created_at":"2025-07-09T03:13:05.985Z","updated_at":"2025-07-09T03:13:15.339Z","avatar_url":"https://github.com/wdarrenww.png","language":"Go","readme":"# Connex\n\nA comprehensive full-stack web application built with Go backend and modern frontend technologies. Features include real-time WebSocket communication, secure authentication, static file serving, and server-side rendering capabilities.\n\n## 🚀 Features\n\n### Backend (Go)\n- **HTTP API** using `net/http` and `chi` router\n- **JSON-based REST endpoints** with comprehensive error handling\n- **JWT-based authentication** with role support and CSRF protection\n- **PostgreSQL integration** using `sqlx` with migrations\n- **Redis caching** and session management\n- **WebSocket support** with authentication, rate limiting, and room-based messaging\n- **Static file serving** with SPA fallback for React Router\n- **Server-side rendering hooks** for future SSR implementation\n- **Background job processing** with asynq\n- **Comprehensive monitoring** with Prometheus, OpenTelemetry, and health checks\n- **Security-first approach** with rate limiting, input validation, and security headers\n\n### Frontend\n- **Modern responsive UI** with CSS Grid and Flexbox\n- **Real-time chat** via WebSocket connections\n- **Authentication system** with JWT token management\n- **SPA architecture** with client-side routing support\n- **Static file serving** from Go backend\n- **SSR-ready templates** for future server-side rendering\n- **Admin Dashboard** with glassmorphic design and real-time monitoring\n\n### Infrastructure\n- **Docker containerization** with multi-stage builds\n- **Docker Compose** for development and production\n- **Load testing** with k6 and comprehensive test suites\n- **Security scanning** with automated vulnerability detection\n- **CI/CD ready** with comprehensive testing and deployment scripts\n\n## 🏗️ Project Structure\n\n```\nconnex/\n├── cmd/                    # Application entry points\n│   └── server/\n│       └── main.go        # Main server with WebSocket and static file support\n├── internal/              # Application logic\n│   ├── api/              # HTTP handlers and WebSocket\n│   │   ├── auth/         # Authentication handlers\n│   │   ├── user/         # User management\n│   │   ├── websocket/    # WebSocket handler with rooms and messaging\n│   │   └── ssr/          # Server-side rendering hooks\n│   ├── service/          # Business logic\n│   ├── db/               # Database access \u0026 migrations\n│   ├── middleware/       # HTTP middleware (security, logging, etc.)\n│   ├── job/              # Background tasks\n│   └── config/           # Configuration management\n├── pkg/                  # Shared libraries\n│   ├── hash/             # Password hashing\n│   ├── jwt/              # JWT utilities\n│   └── logger/           # Structured logging\n├── web/                  # Frontend application\n│   ├── public/           # Static assets (served by Go)\n│   │   ├── index.html    # Main SPA with WebSocket chat\n│   │   └── admin.html    # Admin dashboard with glassmorphic UI\n│   └── src/              # Frontend source code\n├── tests/                # Comprehensive test suites\n├── scripts/              # Build and deployment scripts\n├── Dockerfile            # Multi-stage container build\n├── docker-compose.yml    # Development environment\n├── docker-compose.prod.yml # Production environment\n├── Makefile              # Build automation\n└── README.md             # This file\n```\n\n## 🛠️ Requirements\n\n- **Go** \u003e= 1.24.3\n- **PostgreSQL** \u003e= 14\n- **Redis** \u003e= 6\n- **Docker** (optional, for containerized setup)\n- **Node.js** \u003e= 18 (for frontend development)\n\n## 🚀 Quick Start\n\n### 1. Clone and Setup\n\n```bash\ngit clone https://github.com/wdarrenww/connex.git\ncd connex\n```\n\n### 2. Environment Configuration\n\nCreate a `.env` file based on `env.example`:\n\n```bash\ncp env.example .env\n```\n\nConfigure your environment variables:\n\n```env\n# Server\nPORT=8080\nENV=development\n\n# Database\nDATABASE_URL=postgres://user:password@localhost:5432/connex?sslmode=disable\n\n# Redis\nREDIS_HOST=localhost\nREDIS_PORT=6379\nREDIS_PASSWORD=\nREDIS_DB=0\n\n# JWT\nJWT_SECRET=your-super-secret-jwt-key-32-chars-minimum\n\n# CSRF (base64-encoded 32-byte key)\nCSRF_AUTH_KEY=your-base64-encoded-32-byte-csrf-key\n\n# OpenTelemetry\nOTEL_ENABLED=true\nOTEL_ENDPOINT=http://localhost:14268/api/traces\n```\n\n### 3. Install Dependencies\n\n```bash\n# Backend dependencies\ngo mod tidy\n\n# Frontend dependencies (if developing frontend)\ncd web\nnpm install\n```\n\n### 4. Start Services\n\n#### Option A: Docker Compose (Recommended)\n\n```bash\n# Start all services (PostgreSQL, Redis, Jaeger, Prometheus, Grafana)\nmake dev-docker\n\n# In another terminal, start the Go application\nmake run\n```\n\n#### Option B: Manual Setup\n\n```bash\n# Start PostgreSQL and Redis manually\n# Then run the application\nmake run\n```\n\n### 5. Access the Application\n\n- **Web Application**: http://localhost:8080\n- **Admin Dashboard**: http://localhost:8080/admin\n- **API Documentation**: http://localhost:8080/api/health\n- **Metrics**: http://localhost:8080/metrics\n- **Grafana**: http://localhost:3000 (admin/admin)\n- **Jaeger**: http://localhost:16686\n\n## 🔌 WebSocket API\n\nThe application includes a comprehensive WebSocket implementation at `/ws`:\n\n### Connection\n\n```javascript\n// Connect with JWT authentication\nconst ws = new WebSocket(`ws://localhost:8080/ws?token=${jwtToken}`);\n```\n\n### Message Types\n\n```javascript\n// Chat message\n{\n  \"type\": \"chat\",\n  \"data\": \"Hello, world!\",\n  \"timestamp\": \"2025-07-03T21:58:45.123Z\"\n}\n\n// Join room\n{\n  \"type\": \"auth\",\n  \"data\": {\n    \"room\": \"general\"\n  }\n}\n\n// Ping/Pong (automatic)\n{\n  \"type\": \"ping\",\n  \"data\": {},\n  \"timestamp\": \"2025-07-03T21:58:45.123Z\"\n}\n```\n\n### Features\n\n- **Authentication**: JWT token validation\n- **Rate Limiting**: 10 connections per minute per IP\n- **Room Support**: Join/leave chat rooms\n- **Message Broadcasting**: Send to all clients or specific rooms\n- **Automatic Ping/Pong**: Connection health monitoring\n- **Error Handling**: Comprehensive error responses\n\n## 📁 Static File Serving\n\nThe application serves static files from `web/public/`:\n\n- **Static Assets**: `/static/*` - CSS, JS, images, etc.\n- **SPA Fallback**: Any unknown route serves `index.html` for React Router\n- **Security**: Proper cache headers and security middleware\n\n### Frontend Build\n\n```bash\n# Build frontend (if using a build tool)\ncd web\nnpm run build\n\n# Copy build output to public directory\ncp -r dist/* public/\n```\n\n## 🔐 Security Features\n\n### Authentication \u0026 Authorization\n- JWT-based authentication with secure token handling\n- Password hashing with bcrypt\n- CSRF protection on state-changing requests\n- Role-based access control\n\n### Input Validation \u0026 Sanitization\n- Comprehensive input validation for all endpoints\n- XSS protection with content filtering\n- SQL injection prevention\n- Request size limiting (1MB default)\n\n### Security Headers\n- Content Security Policy (CSP)\n- X-Content-Type-Options\n- X-Frame-Options\n- X-XSS-Protection\n- Modern security headers (COEP, COOP, etc.)\n\n### Rate Limiting\n- IP-based rate limiting for authentication endpoints\n- WebSocket connection rate limiting\n- Configurable limits and time windows\n\n## 🧪 Testing\n\n### Run All Tests\n\n```bash\n# Unit tests\nmake test\n\n# Integration tests\nmake test-integration\n\n# Security tests\nmake security-test-comprehensive\n\n# Load tests\nmake load-test\n```\n\n### Test Coverage\n\n```bash\nmake test-coverage\n```\n\n## 📊 Monitoring \u0026 Observability\n\n### Metrics\n- Prometheus metrics at `/metrics`\n- Custom application metrics\n- Database and Redis monitoring\n\n### Tracing\n- OpenTelemetry integration\n- Jaeger for distributed tracing\n- Request tracing middleware\n\n### Health Checks\n- `/health` - Basic health check\n- `/health/detailed` - Comprehensive health status\n- `/ready` - Readiness probe\n\n## 🐳 Docker Deployment\n\n### Development\n\n```bash\ndocker-compose up --build\n```\n\n### Production\n\n```bash\ndocker-compose -f docker-compose.prod.yml up --build\n```\n\n### Production Features\n- Multi-stage builds for smaller images\n- Security hardening\n- Resource limits\n- Health checks\n- Graceful shutdown\n\n## 🔧 Development\n\n### Code Quality\n\n```bash\n# Format code\nmake fmt\n\n# Lint code\nmake lint\n\n# Run security scans\nmake security-all\n```\n\n### Database Migrations\n\n```bash\n# Run migrations\nmake migrate-up\n\n# Rollback migrations\nmake migrate-down\n```\n\n### Background Jobs\n\n```bash\n# Start job worker\ngo run ./cmd/worker\n\n# Enqueue jobs via API\ncurl -X POST http://localhost:8080/api/jobs/email\n```\n\n## 🚀 Production Deployment\n\n### Environment Variables\n\nEnsure all production environment variables are set:\n\n```bash\n# Required for production\nENV=production\nJWT_SECRET=\u003csecure-32-char-minimum\u003e\nCSRF_AUTH_KEY=\u003cbase64-encoded-32-byte-key\u003e\nDATABASE_URL=\u003cproduction-database-url\u003e\nREDIS_PASSWORD=\u003credis-password\u003e\n```\n\n### Security Checklist\n\n- [ ] Change default passwords\n- [ ] Configure HTTPS/TLS\n- [ ] Set up proper CORS origins\n- [ ] Configure rate limiting for production\n- [ ] Set up monitoring and alerting\n- [ ] Regular security scans\n- [ ] Database backups\n- [ ] Log aggregation\n\n## 📚 API Endpoints\n\n### Authentication\n- `POST /api/auth/register` - User registration\n- `POST /api/auth/login` - User login\n\n### Users\n- `GET /api/users/me` - Get current user\n- `PUT /api/users/me` - Update current user\n- `DELETE /api/users/me` - Delete current user\n\n### Admin (Protected)\n- `GET /api/admin/dashboard` - Dashboard overview data\n- `GET /api/admin/users` - User management data\n- `GET /api/admin/analytics` - Analytics and reporting\n- `GET /api/admin/system` - System status and health\n- `GET /api/admin/logs` - System logs\n- `GET /api/admin/metrics` - System metrics\n\n### Health \u0026 Monitoring\n- `GET /health` - Basic health check\n- `GET /health/detailed` - Detailed health status\n- `GET /ready` - Readiness probe\n- `GET /metrics` - Prometheus metrics\n\n### WebSocket\n- `GET /ws` - WebSocket endpoint\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests for new functionality\n5. Run the test suite\n6. Submit a pull request\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🆘 Support\n\nFor support and questions:\n- Create an issue on GitHub\n- Check the documentation\n- Review the security audit report\n\n---\n\n**Built with ❤️ using Go, WebSockets, and modern web technologies**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdarrenww%2Fconnex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwdarrenww%2Fconnex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdarrenww%2Fconnex/lists"}