Skip to content
kimashii-danPublic

About

The Event Management API makes organizing and managing events simple and efficient.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

74 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Event Hub

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.

Go Version Docker

πŸ“‹ Table of Contents

Features

  • 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

Architecture

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

Tech Stack

  • 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

Quick Start

Prerequisites

  • Docker & Docker Compose (v20.10+)
  • Git
  • Go 1.21+ (for local development)

Setup & Run

# 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

Environment Configuration

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_PASSWORD and JWT_SECRET in production!

πŸ“š API Documentation

Base URL

http://localhost:8000

Authentication

Most endpoints require JWT authentication. Include the token in the Authorization header:

Authorization: Bearer <your_jwt_token>

Core Endpoints

Authentication

Method Endpoint Description Auth Required
POST /auth/register Register new user No
POST /auth/login Login and get JWT token No

Events

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)

Registrations

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

Users

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

Notifications

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

API Examples

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"
}

Query Parameters for Event Filtering

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

Error Responses

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

πŸ›  Development

Local Development Setup

# 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

Project Structure Explained

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)

Code Style Guidelines

  • 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)

Database Migrations

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

πŸ§ͺ Testing

Running Tests

# 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

Test Structure

  • Unit Tests: Test individual functions with mocked dependencies

    • Located in tests/unit/
    • Mock database and external dependencies
    • Fast execution, no external services required
  • Integration Tests: Test complete workflows with real database

    • Located in tests/integration/
    • Use test database (separate from production)
    • Test full request/response cycles

Writing Tests

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)
}

πŸ“¦ Docker Commands

# 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

Daily Workflow

# 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

About

The Event Management API makes organizing and managing events simple and efficient.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages