A modern, RESTful API for event management built with Go, enabling organizers to create, manage, and publish events while users can discover and register for events.
- Secure Authentication: JWT-based authentication with role-based access control
- Event Management: Create, update, publish, and cancel events with comprehensive metadata
- User Registration: Users can register for events with capacity management
- User Profile Management: Update profile information (name, email, password)
- Notification System: Real-time notifications for users with read/unread status
- Advanced Filtering: Search and filter events by date, capacity, and status
- Pagination: Efficient data retrieval with configurable page sizes
- Docker Support: Fully containerized with Docker Compose for easy deployment
- Comprehensive Testing: Unit and integration tests for reliability
- Health Checks: Built-in endpoint for monitoring application status
Event Hub follows Clean Architecture principles with clear separation of concerns:
backend/
βββ cmd/app/ # Application entry point
βββ internal/
β βββ config/ # Configuration management
β βββ database/ # Database connection & migrations
β βββ domain/ # Domain models & business rules
β βββ handler/ # HTTP handlers (controllers)
β βββ middleware/ # HTTP middleware (auth, logging)
β βββ repository/ # Data access layer
β βββ service/ # Business logic layer
β βββ worker/ # Background job workers
β βββ cache/ # Redis caching layer
βββ pkg/ # Reusable packages
β βββ jwt/ # JWT token utilities
β βββ response/ # Standardized API responses
βββ migrations/ # Database schema migrations
βββ tests/ # Integration & unit tests
- Framework: Gin (HTTP web framework)
- Database: PostgreSQL with GORM ORM
- Cache: Redis (for event data)
- Concurrency: Goroutines & Worker Pools (async notifications)
- Authentication: JWT tokens
- Containerization: Docker & Docker Compose
- Testing: Go testing framework with testify
- Docker & Docker Compose (v20.10+)
- Git
- Go 1.21+ (for local development)
# 1. Clone the repository
git clone https://github.com/kimashii-dan/event-hub.git
cd event-hub/backend
# 2. Configure environment
cp docker/.env.example docker/.env
# Edit docker/.env with your configuration
# 3. Start the application
cd docker
docker compose up --build
Application is running at: http://localhost:8000
Create docker/.env file with the following variables:
# Database Configuration
DB_HOST=db
DB_USER=postgres
DB_PASSWORD=your_secure_password
DB_PORT=5432
DB_NAME=event_hub
# Server Configuration
SERVER_PORT=8000
# JWT Configuration
JWT_SECRET=your_jwt_secret_key_min_32_chars
JWT_EXPIRATION_TIME=24h
# Redis Configuration
REDIS_HOST=redis
REDIS_PORT=6379
Security Note: Always use strong, unique values for
DB_PASSWORDandJWT_SECRETin production!
http://localhost:8000
Most endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your_jwt_token>
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/register |
Register new user | No |
| POST | /auth/login |
Login and get JWT token | No |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /events |
Get all events (with filtering & pagination) | No |
| GET | /events/:id |
Get event by ID | No |
| POST | /events |
Create new event | Yes |
| PUT | /events/:id |
Update event | Yes (organizer only) |
| DELETE | /events/:id |
Delete event | Yes (organizer only) |
| POST | /events/:id/publish |
Publish event | Yes (organizer only) |
| POST | /events/:id/cancel |
Cancel event | Yes (organizer only) |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /registrations |
Register for event | Yes |
| GET | /registrations/my |
Get user's registrations | Yes |
| DELETE | /registrations/:id |
Cancel registration | Yes |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /users/me |
Get current user profile | Yes |
| PATCH | /users/me |
Update user profile | Yes |
| GET | /users/me/events |
Get user's created events | Yes |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /notifications/ |
Get user's notifications | Yes |
| POST | /notifications/ |
Send notification to user | Yes |
| PATCH | /notifications/:id/read |
Mark notification as read | Yes |
Register New User
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "securepass123",
"name": "John Doe"
}'
Response (201 Created)
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"email": "user@example.com",
"name": "John Doe",
"role": "user",
"created_at": "2025-12-17T10:30:00Z"
}
Login
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "securepass123"
}'
Response (200 OK)
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_at": "2025-12-18T10:30:00Z",
"user": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"email": "user@example.com",
"name": "John Doe",
"role": "user"
}
}
Create Event
curl -X POST http://localhost:8000/events \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "Tech Conference 2025",
"description": "Annual technology conference",
"start_datetime": "2025-06-15T09:00:00Z",
"end_datetime": "2025-06-15T18:00:00Z",
"location": "Convention Center, NY",
"capacity": 500
}'
Response (201 Created)
{
"id": "660e8400-e29b-41d4-a716-446655440001",
"organizer_id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Tech Conference 2025",
"description": "Annual technology conference",
"start_datetime": "2025-06-15T09:00:00Z",
"end_datetime": "2025-06-15T18:00:00Z",
"location": "Convention Center, NY",
"capacity": 500,
"status": "draft",
"created_at": "2025-12-17T10:30:00Z",
"updated_at": "2025-12-17T10:30:00Z"
}
Get Events with Filtering
# Get published events with pagination
curl "http://localhost:8000/events?page=1&page_size=10&status=published"
# Filter by date range
curl "http://localhost:8000/events?start_date_from=2025-01-01&start_date_to=2025-12-31"
# Filter by capacity
curl "http://localhost:8000/events?min_capacity=100&max_capacity=500"
Response (200 OK)
{
"data": [
{
"id": "660e8400-e29b-41d4-a716-446655440001",
"title": "Tech Conference 2025",
"status": "published",
...
}
],
"pagination": {
"page": 1,
"page_size": 10,
"total": 42,
"total_pages": 5
}
}
Register for Event
curl -X POST http://localhost:8000/registrations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"event_id": "660e8400-e29b-41d4-a716-446655440001"
}'
Response (201 Created)
{
"id": "770e8400-e29b-41d4-a716-446655440002",
"user_id": "550e8400-e29b-41d4-a716-446655440000",
"event_id": "660e8400-e29b-41d4-a716-446655440001",
"status": "confirmed",
"registered_at": "2025-12-17T10:30:00Z"
}
| Parameter | Type | Description | Example |
|---|---|---|---|
page |
integer | Page number (default: 1) | ?page=2 |
page_size |
integer | Items per page (default: 10, max: 100) | ?page_size=20 |
status |
string | Filter by status: draft, published, cancelled | ?status=published |
start_date_from |
datetime | Filter events starting from this date | ?start_date_from=2025-01-01 |
start_date_to |
datetime | Filter events starting before this date | ?start_date_to=2025-12-31 |
min_capacity |
integer | Minimum event capacity | ?min_capacity=50 |
max_capacity |
integer | Maximum event capacity | ?max_capacity=500 |
All errors follow a consistent format:
{
"error": "error_code",
"message": "Human-readable error message",
"details": {
"field": "specific_field",
"reason": "validation_failed"
}
}
Common HTTP status codes:
400- Bad Request (validation errors)401- Unauthorized (missing or invalid token)403- Forbidden (insufficient permissions)404- Not Found (resource doesn't exist)409- Conflict (duplicate resource)500- Internal Server Error
# 1. Clone repository
git clone https://github.com/kimashii-dan/event-hub.git
cd event-hub/backend
# 2. Install dependencies
go mod download
# 3. Setup local database (optional, or use Docker)
# Create PostgreSQL database named 'event_hub'
# 4. Configure environment
cp .env.example .env
# Edit .env with local database credentials
# 5. Run migrations
# Migrations run automatically on application start
# 6. Run application
go run cmd/app/main.go
backend/
βββ cmd/app/main.go # Application entry point, dependency injection
βββ internal/
β βββ config/config.go # Configuration loader (env variables)
β βββ database/postgres.go # Database connection & auto-migrations
β βββ domain/ # Business entities & DTOs
β β βββ user.go # User model, validation, DTOs
β β βββ event.go # Event model, validation, DTOs
β β βββ registration.go # Registration model, DTOs
β βββ handler/ # HTTP request handlers (controllers)
β β βββ auth_handler.go # Authentication endpoints
β β βββ event_handler.go # Event CRUD endpoints
β β βββ registration_handler.go # Registration endpoints
β β βββ user_handler.go # User profile endpoints
β βββ middleware/ # HTTP middleware
β β βββ auth.go # JWT authentication middleware
β β βββ logger.go # Request logging middleware
β βββ repository/ # Data access layer (database operations)
β β βββ user_repository.go
β β βββ event_repository.go
β β βββ registration_repository.go
β βββ service/ # Business logic layer
β βββ auth_service.go # Authentication & user management
β βββ event_service.go # Event management logic
β βββ registration_service.go # Registration logic
βββ pkg/ # Reusable packages (can be extracted)
β βββ jwt/jwt.go # JWT token generation & validation
β βββ response/response.go # Standardized API response helpers
βββ migrations/ # SQL migration files
β βββ 000001_create_users_table.up.sql
β βββ 000002_create_events_table.up.sql
β βββ 000003_create_registrations_table.up.sql
βββ tests/
βββ integration/ # Integration tests (with test DB)
βββ unit/ # Unit tests (mocked dependencies)
- Follow Clean Architecture principles
- Use meaningful variable names in English
- Write godoc comments for all exported functions and types
- Keep functions focused and small (single responsibility)
- Use dependency injection for testability
- Handle errors explicitly (no silent failures)
Migrations run automatically on application startup. To create new migrations:
# Create new migration files manually in migrations/ directory
# Follow naming convention: 000XXX_description.up.sql and 000XXX_description.down.sql
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with verbose output
go test -v ./...
# Run only unit tests
go test ./tests/unit/...
# Run only integration tests
go test ./tests/integration/...
# Generate coverage report
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
-
Unit Tests: Test individual functions with mocked dependencies
- Located in
tests/unit/ - Mock database and external dependencies
- Fast execution, no external services required
- Located in
-
Integration Tests: Test complete workflows with real database
- Located in
tests/integration/ - Use test database (separate from production)
- Test full request/response cycles
- Located in
Example test structure:
func TestEventService_CreateEvent(t *testing.T) {
// Setup
db := setupTestDB(t)
defer cleanupTestDB(db)
eventRepo := repository.NewEventRepository(db)
eventService := service.NewEventService(eventRepo)
// Test case
req := &domain.CreateEventRequest{
Title: "Test Event",
Description: "Test Description",
StartDatetime: time.Now().Add(24 * time.Hour),
EndDatetime: time.Now().Add(48 * time.Hour),
Location: "Test Location",
Capacity: 100,
}
// Execute
event, err := eventService.CreateEvent("user-123", req)
// Assert
assert.NoError(t, err)
assert.NotNil(t, event)
assert.Equal(t, "Test Event", event.Title)
assert.Equal(t, "draft", event.Status)
}
# Build and start services
docker compose up --build
# Start services in background
docker compose up -d
# Stop services
docker compose down
# View logs
docker compose logs -f
# Rebuild specific service
docker compose up --build backend
# Access database
docker compose exec db psql -U postgres -d event_hub
# Run tests in container
docker compose exec backend go test ./...
- Features:
feature/jd-user-auth - Bug fixes:
bugfix/jd-fix-login - Hotfixes:
hotfix/jd-security-patch
# Start work
git checkout main && git pull origin main
git checkout -b feature/initials-feature-name
# Finish work
git add . && git commit -m "feat: description"
git push origin feature/initials-feature-name
# Create PR on GitHub