Thanks to visit codestin.com
Credit goes to github.com

Skip to content

stitchsages/connex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Connex

A 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.

πŸš€ Features

Backend (Go)

  • HTTP API using net/http and chi router
  • JSON-based REST endpoints with comprehensive error handling
  • JWT-based authentication with role support and CSRF protection
  • PostgreSQL integration using sqlx with migrations
  • Redis caching and session management
  • WebSocket support with authentication, rate limiting, and room-based messaging
  • Static file serving with SPA fallback for React Router
  • Server-side rendering hooks for future SSR implementation
  • Background job processing with asynq
  • Comprehensive monitoring with Prometheus, OpenTelemetry, and health checks
  • Security-first approach with rate limiting, input validation, and security headers

Frontend

  • Modern responsive UI with CSS Grid and Flexbox
  • Real-time chat via WebSocket connections
  • Authentication system with JWT token management
  • SPA architecture with client-side routing support
  • Static file serving from Go backend
  • SSR-ready templates for future server-side rendering
  • Admin Dashboard with glassmorphic design and real-time monitoring

Infrastructure

  • Docker containerization with multi-stage builds
  • Docker Compose for development and production
  • Load testing with k6 and comprehensive test suites
  • Security scanning with automated vulnerability detection
  • CI/CD ready with comprehensive testing and deployment scripts

πŸ—οΈ Project Structure

connex/
β”œβ”€β”€ cmd/                    # Application entry points
β”‚   └── server/
β”‚       └── main.go        # Main server with WebSocket and static file support
β”œβ”€β”€ internal/              # Application logic
β”‚   β”œβ”€β”€ api/              # HTTP handlers and WebSocket
β”‚   β”‚   β”œβ”€β”€ auth/         # Authentication handlers
β”‚   β”‚   β”œβ”€β”€ user/         # User management
β”‚   β”‚   β”œβ”€β”€ websocket/    # WebSocket handler with rooms and messaging
β”‚   β”‚   └── ssr/          # Server-side rendering hooks
β”‚   β”œβ”€β”€ service/          # Business logic
β”‚   β”œβ”€β”€ db/               # Database access & migrations
β”‚   β”œβ”€β”€ middleware/       # HTTP middleware (security, logging, etc.)
β”‚   β”œβ”€β”€ job/              # Background tasks
β”‚   └── config/           # Configuration management
β”œβ”€β”€ pkg/                  # Shared libraries
β”‚   β”œβ”€β”€ hash/             # Password hashing
β”‚   β”œβ”€β”€ jwt/              # JWT utilities
β”‚   └── logger/           # Structured logging
β”œβ”€β”€ web/                  # Frontend application
β”‚   β”œβ”€β”€ public/           # Static assets (served by Go)
β”‚   β”‚   β”œβ”€β”€ index.html    # Main SPA with WebSocket chat
β”‚   β”‚   └── admin.html    # Admin dashboard with glassmorphic UI
β”‚   └── src/              # Frontend source code
β”œβ”€β”€ tests/                # Comprehensive test suites
β”œβ”€β”€ scripts/              # Build and deployment scripts
β”œβ”€β”€ Dockerfile            # Multi-stage container build
β”œβ”€β”€ docker-compose.yml    # Development environment
β”œβ”€β”€ docker-compose.prod.yml # Production environment
β”œβ”€β”€ Makefile              # Build automation
└── README.md             # This file

πŸ› οΈ Requirements

  • Go >= 1.24.3
  • PostgreSQL >= 14
  • Redis >= 6
  • Docker (optional, for containerized setup)
  • Node.js >= 18 (for frontend development)

πŸš€ Quick Start

1. Clone and Setup

git clone https://github.com/wdarrenww/connex.git
cd connex

2. Environment Configuration

Create a .env file based on env.example:

cp env.example .env

Configure your environment variables:

# Server
PORT=8080
ENV=development

# Database
DATABASE_URL=postgres://user:password@localhost:5432/connex?sslmode=disable

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0

# JWT
JWT_SECRET=your-super-secret-jwt-key-32-chars-minimum

# CSRF (base64-encoded 32-byte key)
CSRF_AUTH_KEY=your-base64-encoded-32-byte-csrf-key

# OpenTelemetry
OTEL_ENABLED=true
OTEL_ENDPOINT=http://localhost:14268/api/traces

3. Install Dependencies

# Backend dependencies
go mod tidy

# Frontend dependencies (if developing frontend)
cd web
npm install

4. Start Services

Option A: Docker Compose (Recommended)

# Start all services (PostgreSQL, Redis, Jaeger, Prometheus, Grafana)
make dev-docker

# In another terminal, start the Go application
make run

Option B: Manual Setup

# Start PostgreSQL and Redis manually
# Then run the application
make run

5. Access the Application

πŸ”Œ WebSocket API

The application includes a comprehensive WebSocket implementation at /ws:

Connection

// Connect with JWT authentication
const ws = new WebSocket(`ws://localhost:8080/ws?token=${jwtToken}`);

Message Types

// Chat message
{
  "type": "chat",
  "data": "Hello, world!",
  "timestamp": "2025-07-03T21:58:45.123Z"
}

// Join room
{
  "type": "auth",
  "data": {
    "room": "general"
  }
}

// Ping/Pong (automatic)
{
  "type": "ping",
  "data": {},
  "timestamp": "2025-07-03T21:58:45.123Z"
}

Features

  • Authentication: JWT token validation
  • Rate Limiting: 10 connections per minute per IP
  • Room Support: Join/leave chat rooms
  • Message Broadcasting: Send to all clients or specific rooms
  • Automatic Ping/Pong: Connection health monitoring
  • Error Handling: Comprehensive error responses

πŸ“ Static File Serving

The application serves static files from web/public/:

  • Static Assets: /static/* - CSS, JS, images, etc.
  • SPA Fallback: Any unknown route serves index.html for React Router
  • Security: Proper cache headers and security middleware

Frontend Build

# Build frontend (if using a build tool)
cd web
npm run build

# Copy build output to public directory
cp -r dist/* public/

πŸ” Security Features

Authentication & Authorization

  • JWT-based authentication with secure token handling
  • Password hashing with bcrypt
  • CSRF protection on state-changing requests
  • Role-based access control

Input Validation & Sanitization

  • Comprehensive input validation for all endpoints
  • XSS protection with content filtering
  • SQL injection prevention
  • Request size limiting (1MB default)

Security Headers

  • Content Security Policy (CSP)
  • X-Content-Type-Options
  • X-Frame-Options
  • X-XSS-Protection
  • Modern security headers (COEP, COOP, etc.)

Rate Limiting

  • IP-based rate limiting for authentication endpoints
  • WebSocket connection rate limiting
  • Configurable limits and time windows

πŸ§ͺ Testing

Run All Tests

# Unit tests
make test

# Integration tests
make test-integration

# Security tests
make security-test-comprehensive

# Load tests
make load-test

Test Coverage

make test-coverage

πŸ“Š Monitoring & Observability

Metrics

  • Prometheus metrics at /metrics
  • Custom application metrics
  • Database and Redis monitoring

Tracing

  • OpenTelemetry integration
  • Jaeger for distributed tracing
  • Request tracing middleware

Health Checks

  • /health - Basic health check
  • /health/detailed - Comprehensive health status
  • /ready - Readiness probe

🐳 Docker Deployment

Development

docker-compose up --build

Production

docker-compose -f docker-compose.prod.yml up --build

Production Features

  • Multi-stage builds for smaller images
  • Security hardening
  • Resource limits
  • Health checks
  • Graceful shutdown

πŸ”§ Development

Code Quality

# Format code
make fmt

# Lint code
make lint

# Run security scans
make security-all

Database Migrations

# Run migrations
make migrate-up

# Rollback migrations
make migrate-down

Background Jobs

# Start job worker
go run ./cmd/worker

# Enqueue jobs via API
curl -X POST http://localhost:8080/api/jobs/email

πŸš€ Production Deployment

Environment Variables

Ensure all production environment variables are set:

# Required for production
ENV=production
JWT_SECRET=<secure-32-char-minimum>
CSRF_AUTH_KEY=<base64-encoded-32-byte-key>
DATABASE_URL=<production-database-url>
REDIS_PASSWORD=<redis-password>

Security Checklist

  • Change default passwords
  • Configure HTTPS/TLS
  • Set up proper CORS origins
  • Configure rate limiting for production
  • Set up monitoring and alerting
  • Regular security scans
  • Database backups
  • Log aggregation

πŸ“š API Endpoints

Authentication

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login

Users

  • GET /api/users/me - Get current user
  • PUT /api/users/me - Update current user
  • DELETE /api/users/me - Delete current user

Admin (Protected)

  • GET /api/admin/dashboard - Dashboard overview data
  • GET /api/admin/users - User management data
  • GET /api/admin/analytics - Analytics and reporting
  • GET /api/admin/system - System status and health
  • GET /api/admin/logs - System logs
  • GET /api/admin/metrics - System metrics

Health & Monitoring

  • GET /health - Basic health check
  • GET /health/detailed - Detailed health status
  • GET /ready - Readiness probe
  • GET /metrics - Prometheus metrics

WebSocket

  • GET /ws - WebSocket endpoint

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For support and questions:

  • Create an issue on GitHub
  • Check the documentation
  • Review the security audit report

Built with ❀️ using Go, WebSockets, and modern web technologies

About

Advanced HTTP/2 server in Go

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published