Backend
Services
Services Overview

Services Overview

The service layer contains the business logic of the application. Services orchestrate repositories, handle business rules, and integrate with external APIs.

Core Services

User Service (user_service.go)

Manages user-related business logic:

  • User profile management
  • Social media integration
  • User connections
  • Profile enrichment
  • User recommendations

Key Methods:

  • GetUserByID() - Get user by ID
  • GetUserByTelegramID() - Get user by Telegram ID
  • UpdateUserSocials() - Update social media usernames
  • GetRecommendedUsers() - Get user recommendations
  • EnrichUserProfile() - Enrich user profile with social data

Event Service (event_service.go)

Handles event management:

  • Event CRUD operations
  • Event filtering and search
  • Event status management
  • Event approval workflow

Key Methods:

  • CreateEvent() - Create a new event
  • UpdateEvent() - Update event details
  • GetEventBySlug() - Get event by slug
  • ListEvents() - List events with filters
  • GetEventWithAttendees() - Get event with attendee list

Event Attendee Service (event_attendee_service.go)

Manages event attendance:

  • Registration for events
  • Attendance tracking
  • Waitlist management

Key Methods:

  • RegisterForEvent() - Register user for event
  • CancelAttendance() - Cancel event attendance
  • CheckAttendance() - Check if user is attending
  • GetEventAttendees() - Get list of attendees

Quest Service (quest_service.go)

Handles quest system logic:

  • Quest creation and management
  • Task completion tracking
  • Progress calculation
  • Leaderboard generation
  • Quest registration approval

Key Methods:

  • CreateQuest() - Create a new quest
  • StartQuest() - User starts a quest
  • CompleteTask() - Complete a quest task
  • GetUserProgress() - Get user's quest progress
  • GetLeaderboard() - Get quest leaderboard
  • ApproveTask() - Admin approves task completion
  • RejectTask() - Admin rejects task completion

Notification Service (notification_service.go)

Manages user notifications:

  • Creating notifications
  • Sending notifications
  • Notification status tracking

Key Methods:

  • CreateNotification() - Create a notification
  • GetUserNotifications() - Get user's notifications
  • MarkAsClicked() - Mark notification as clicked
  • MarkAsDismissed() - Mark notification as dismissed

Notification Job Service (notification_job_service.go)

Handles bulk and scheduled notifications:

  • Bulk notification sending
  • Scheduled notifications
  • Job status tracking
  • Background worker processing

Key Methods:

  • CreateNotificationJob() - Create a notification job
  • SendBulkNotification() - Send bulk notifications
  • StartWorker() - Start background worker
  • ProcessNotificationJob() - Process a notification job

Conference Service (conference_service.go)

Manages conferences:

  • Conference CRUD operations
  • Conference-event relationships
  • Conference agenda management

Key Methods:

  • CreateConference() - Create a conference
  • GetConferenceBySlug() - Get conference by slug
  • GetConferenceWithEvents() - Get conference with events
  • UpdateConference() - Update conference details

Conference Attendee Service (conference_attendee_service.go)

Handles conference attendance:

  • Conference registration
  • Attendee management
  • Bulk attendee import

Key Methods:

  • RegisterForConference() - Register for conference
  • CancelRegistration() - Cancel registration
  • ListConferenceAttendees() - List attendees
  • BulkUploadAttendees() - Bulk import attendees

Conference Agenda Service (conference_agenda_service.go)

Manages conference agenda:

  • Agenda item CRUD
  • Agenda organization
  • Time slot management

Key Methods:

  • CreateAgendaItem() - Create agenda item
  • GetAgendaByConferenceID() - Get agenda for conference
  • UpdateAgendaItem() - Update agenda item

Speaker Service (speaker_service.go)

Manages speakers:

  • Speaker CRUD operations
  • Speaker enrichment
  • Speaker-conference mapping

Key Methods:

  • CreateSpeaker() - Create a speaker
  • GetSpeakerByID() - Get speaker by ID
  • EnrichSpeaker() - Enrich speaker with social data
  • GetConferenceSpeakers() - Get speakers for conference

Enrichment Service (enrichment_service.go)

Handles social media enrichment:

  • Twitter enrichment
  • LinkedIn enrichment
  • Crypto enrichment
  • AI-powered profile analysis

Key Methods:

  • GenerateEnrichment() - Generate enrichment for user
  • GenerateEnrichmentSync() - Synchronous enrichment
  • GenerateMultipleEnrichments() - Bulk enrichment

Verification Service (verification_service.go)

Handles task verification:

  • Twitter task verification
  • Social media proof verification
  • Automated verification logic

Key Methods:

  • VerifyTwitterTask() - Verify Twitter task completion
  • VerifyTask() - Generic task verification

Telegram Service (telegram_service.go)

Integrates with Telegram:

  • Sending messages
  • User authentication
  • Group chat integration

Key Methods:

  • SendMessage() - Send Telegram message
  • SendToGroup() - Send message to group
  • VerifyTelegramAuth() - Verify Telegram authentication

Quest Reminder Service (quest_reminder_service.go)

Manages quest reminders:

  • Reminder template management
  • Scheduled reminder sending
  • Quest progress tracking

Key Methods:

  • CreateReminderTemplate() - Create reminder template
  • SendReminder() - Send quest reminder
  • GetTemplates() - Get reminder templates

External Integration Services

Twitter Service (twitter_service.go)

Integrates with Twitter/Apify:

  • Fetching Twitter profiles
  • Fetching tweets
  • Twitter data enrichment

LinkedIn Service (linkedin_service.go)

Integrates with LinkedIn:

  • Fetching LinkedIn profiles
  • Profile data extraction

Azure Storage Service (azure_storage_service.go)

Handles Azure Blob Storage:

  • Image uploads
  • Video uploads
  • File management

Cloudflare R2 Service (cloudflare_r2_service.go)

Handles Cloudflare R2 storage:

  • Image uploads
  • Video uploads
  • CDN integration

JWT Service (jwt_service.go)

Handles JWT tokens:

  • Token generation
  • Token validation
  • Token refresh

Service Patterns

Dependency Injection

Services receive dependencies through constructors:

func NewUserService(
    userRepo repositories.UserRepository,
    connectionRepo *repositories.ConnectionRepository,
    // ... other dependencies
) *UserService {
    return &UserService{
        userRepo: userRepo,
        connectionRepo: connectionRepo,
        // ...
    }
}

Error Handling

Services return domain-specific errors:

if err != nil {
    return nil, fmt.Errorf("failed to create user: %w", err)
}

Transaction Management

Services handle database transactions when needed:

tx := s.db.Begin()
// ... operations
tx.Commit()

Service Responsibilities

  1. Business Logic: Implement business rules and validations
  2. Orchestration: Coordinate multiple repositories
  3. External Integration: Communicate with external APIs
  4. Data Transformation: Transform data between layers
  5. Error Handling: Handle and transform errors appropriately