Skip to content

Latest commit

Β 

History

19 Commits

Folders and files

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

Repository files navigation

Call Center Backend - Spring Boot Application

Complete backend implementation for a Call Center system with automatic dialer (Manual, Progressive, and Predictive modes).

πŸ—οΈ Architecture

Technology Stack

  • Java 17+
  • Spring Boot 3.2+
  • Spring Data JPA (Database access)
  • Spring Security + JWT (Authentication)
  • Spring WebSocket (Real-time notifications)
  • MySQL 8.0 (Database)
  • FreeSWITCH (Telephony engine via ESL)

Project Structure

backend/
β”œβ”€β”€ src/main/java/com/callcenter/
β”‚   β”œβ”€β”€ CallCenterApplication.java          # Main application
β”‚   β”œβ”€β”€ config/                              # Configuration classes
β”‚   β”‚   β”œβ”€β”€ CorsConfig.java
β”‚   β”‚   β”œβ”€β”€ FreeSwitchConfig.java
β”‚   β”‚   β”œβ”€β”€ SecurityConfig.java
β”‚   β”‚   └── WebSocketConfig.java
β”‚   β”œβ”€β”€ controller/                          # REST Controllers
β”‚   β”‚   β”œβ”€β”€ AuthController.java
β”‚   β”‚   β”œβ”€β”€ CampaignController.java
β”‚   β”‚   β”œβ”€β”€ ContactController.java
β”‚   β”‚   β”œβ”€β”€ CallController.java
β”‚   β”‚   β”œβ”€β”€ AgentController.java
β”‚   β”‚   β”œβ”€β”€ ReportController.java
β”‚   β”‚   └── WebSocketController.java
β”‚   β”œβ”€β”€ model/                               # Entity classes
β”‚   β”‚   β”œβ”€β”€ User.java
β”‚   β”‚   β”œβ”€β”€ Campaign.java
β”‚   β”‚   β”œβ”€β”€ Contact.java
β”‚   β”‚   β”œβ”€β”€ Call.java
β”‚   β”‚   β”œβ”€β”€ AgentStatus.java
β”‚   β”‚   └── CallRecording.java
β”‚   β”œβ”€β”€ repository/                          # Data access layer
β”‚   β”‚   β”œβ”€β”€ UserRepository.java
β”‚   β”‚   β”œβ”€β”€ CampaignRepository.java
β”‚   β”‚   β”œβ”€β”€ ContactRepository.java
β”‚   β”‚   β”œβ”€β”€ CallRepository.java
β”‚   β”‚   β”œβ”€β”€ AgentStatusRepository.java
β”‚   β”‚   └── CallRecordingRepository.java
β”‚   β”œβ”€β”€ dto/                                 # Data Transfer Objects
β”‚   β”‚   β”œβ”€β”€ LoginRequest.java
β”‚   β”‚   β”œβ”€β”€ LoginResponse.java
β”‚   β”‚   β”œβ”€β”€ CallRequest.java
β”‚   β”‚   β”œβ”€β”€ CallResponse.java
β”‚   β”‚   β”œβ”€β”€ CampaignDTO.java
β”‚   β”‚   β”œβ”€β”€ ContactDTO.java
β”‚   β”‚   β”œβ”€β”€ StatisticsDTO.java
β”‚   β”‚   β”œβ”€β”€ AgentStatusDTO.java
β”‚   β”‚   └── ImportResult.java
β”‚   β”œβ”€β”€ service/                             # Business logic
β”‚   β”‚   β”œβ”€β”€ AuthService.java
β”‚   β”‚   β”œβ”€β”€ CampaignService.java
β”‚   β”‚   β”œβ”€β”€ ContactService.java
β”‚   β”‚   β”œβ”€β”€ CallService.java
β”‚   β”‚   β”œβ”€β”€ AgentService.java
β”‚   β”‚   β”œβ”€β”€ FreeSwitchService.java
β”‚   β”‚   β”œβ”€β”€ ReportService.java
β”‚   β”‚   └── WebSocketService.java
β”‚   β”œβ”€β”€ dialer/                              # Dialer implementations
β”‚   β”‚   β”œβ”€β”€ ManualDialer.java
β”‚   β”‚   β”œβ”€β”€ ProgressiveDialer.java           # Runs every 5s
β”‚   β”‚   β”œβ”€β”€ PredictiveDialer.java            # Runs every 3s
β”‚   β”‚   └── DialRatioCalculator.java
β”‚   β”œβ”€β”€ freeswitch/                          # FreeSWITCH integration
β”‚   β”‚   β”œβ”€β”€ ESLClient.java
β”‚   β”‚   β”œβ”€β”€ EventListener.java
β”‚   β”‚   β”œβ”€β”€ CommandBuilder.java
β”‚   β”‚   └── EventHandler.java
β”‚   β”œβ”€β”€ security/                            # Security components
β”‚   β”‚   β”œβ”€β”€ JwtTokenProvider.java
β”‚   β”‚   β”œβ”€β”€ JwtAuthenticationFilter.java
β”‚   β”‚   └── UserDetailsServiceImpl.java
β”‚   └── exception/                           # Exception handling
β”‚       β”œβ”€β”€ ResourceNotFoundException.java
β”‚       β”œβ”€β”€ FreeSwitchException.java
β”‚       β”œβ”€β”€ ValidationException.java
β”‚       └── GlobalExceptionHandler.java
└── src/main/resources/
    └── application.yml                      # Application configuration

πŸš€ Quick Start

Prerequisites

  1. Java 17 or higher

    java -version
  2. Maven 3.6+

    mvn -version
  3. MySQL 8.0

    mysql --version
  4. FreeSWITCH (installed and configured)

    systemctl status freeswitch

Setup Steps

1. Add FreeSWITCH ESL Dependency

CRITICAL: Add this to pom.xml before building:

<!-- FreeSWITCH ESL Client -->
<dependency>
    <groupId>org.freeswitch.esl.client</groupId>
    <artifactId>org.freeswitch.esl.client</artifactId>
    <version>0.9.2</version>
</dependency>

2. Create Database

CREATE DATABASE callcenter_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'callcenter_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON callcenter_db.* TO 'callcenter_user'@'localhost';
FLUSH PRIVILEGES;

3. Configure Application

Edit src/main/resources/application.yml:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/callcenter_db
    username: callcenter_user
    password: your_password

jwt:
  secret: change-this-to-a-secure-256-bit-secret-key-minimum-32-characters

freeswitch:
  esl:
    host: localhost
    port: 8021
    password: ClueCon

4. Build & Run

# Clean and build
mvn clean install

# Run application
mvn spring-boot:run

# Or run JAR
java -jar target/callcenter-0.0.1-SNAPSHOT.jar

Application starts on: http://localhost:8080

πŸ“‘ API Endpoints

Authentication

POST   /api/auth/login          # Login
POST   /api/auth/register       # Register user
GET    /api/auth/me             # Get current user

Campaigns

GET    /api/campaigns                 # List all (paginated)
GET    /api/campaigns/{id}            # Get campaign
POST   /api/campaigns                 # Create campaign
PUT    /api/campaigns/{id}            # Update campaign
DELETE /api/campaigns/{id}            # Delete campaign
POST   /api/campaigns/{id}/start      # Start campaign
POST   /api/campaigns/{id}/pause      # Pause campaign
POST   /api/campaigns/{id}/stop       # Stop campaign
GET    /api/campaigns/{id}/statistics # Get statistics

Contacts

GET    /api/contacts                        # List all (paginated)
GET    /api/contacts/{id}                   # Get contact
POST   /api/contacts                        # Create contact
PUT    /api/contacts/{id}                   # Update contact
DELETE /api/contacts/{id}                   # Delete contact
POST   /api/contacts/import                 # Import CSV
GET    /api/contacts/campaign/{campaignId}  # List by campaign

Calls

POST   /api/calls/make                # Make call
POST   /api/calls/{callId}/hangup     # Hangup call
POST   /api/calls/{callId}/transfer   # Transfer call
POST   /api/calls/{callId}/complete   # Complete call (add notes)
GET    /api/calls/history             # Call history
GET    /api/calls/{callId}            # Get call details
GET    /api/calls/agent/{agentId}     # Agent's calls

Agents

GET    /api/agents                        # List agents
GET    /api/agents/{id}/status            # Get agent status
POST   /api/agents/{id}/status            # Update agent status
GET    /api/agents/available              # Available agents
GET    /api/agents/{id}/status/history    # Status history

Reports

GET    /api/reports/dashboard                    # Dashboard statistics
GET    /api/reports/calls-by-hour               # Calls by hour
GET    /api/reports/calls-by-disposition        # Calls by disposition
GET    /api/reports/agent-performance           # Agent performance
GET    /api/reports/campaign-stats/{campaignId} # Campaign statistics

πŸ”Œ WebSocket Topics

Subscribe to:

  • /topic/calls - All call events
  • /topic/agents - Agent status changes
  • /topic/campaigns - Campaign updates
  • /topic/statistics - Statistics updates
  • /user/queue/messages - User-specific messages
  • /user/queue/contacts - Contact assignments

Send to:

  • /app/call.event - Send call event
  • /app/agent.status - Send agent status
  • /app/campaign.update - Send campaign update

Example WebSocket Connection:

const socket = new SockJS('http://localhost:8080/ws');
const stompClient = Stomp.over(socket);

stompClient.connect({
  'Authorization': 'Bearer ' + token
}, function(frame) {
  console.log('Connected: ' + frame);

  // Subscribe to call events
  stompClient.subscribe('/topic/calls', function(message) {
    const event = JSON.parse(message.body);
    console.log('Call event:', event);
  });

  // Subscribe to user-specific messages
  stompClient.subscribe('/user/queue/messages', function(message) {
    const data = JSON.parse(message.body);
    console.log('Message:', data);
  });
});

πŸ“ž Dialer Modes

1. Manual Dialer

  • Agent requests next contact
  • Agent initiates call manually
  • One call at a time per agent

2. Progressive Dialer

  • Runs automatically every 5 seconds
  • Dials one contact per available agent
  • Waits for customer to answer before connecting to agent
  • No abandoned calls

3. Predictive Dialer (COMPLETE ALGORITHM)

  • Runs automatically every 3 seconds
  • Implements complete algorithm from specifications:
    1. Get campaign metrics
    2. Calculate contact rate
    3. Calculate dial ratio based on aggressiveness
    4. Adjust for abandonment rate
    5. Dial multiple contacts
    6. Connect answered calls to available agents
    7. Abandon calls if no agent available

Algorithm formula:

ratioBase = availableAgents / contactRate
ratio = ratioBase * aggressiveness
if (abandonmentRate > 5%): ratio = ratio * 0.8
ratio = min(ratio, availableAgents * 3)
callsToMake = ratio - callsInProgress

πŸ”§ FreeSWITCH Integration

ESL Commands Supported:

  • originate - Initiate calls
  • uuid_kill - Hangup calls
  • uuid_bridge - Connect calls
  • uuid_transfer - Transfer calls
  • uuid_record - Record calls
  • uuid_hold - Hold/unhold calls

Events Handled:

  • CHANNEL_CREATE - Call created
  • CHANNEL_ANSWER - Call answered
  • CHANNEL_HANGUP - Call ended
  • CHANNEL_BRIDGE - Calls connected
  • HEARTBEAT - Connection keepalive

πŸ›‘οΈ Security

Authentication

  • JWT token-based authentication
  • Token expiration: 24 hours (configurable)
  • BCrypt password encryption

Authorization

  • Role-based access control (RBAC)
  • Roles: ADMIN, SUPERVISOR, AGENT
  • Method-level security with @PreAuthorize

CORS

πŸ“Š Database Schema

Tables auto-created by JPA:

  • users - System users (agents, supervisors, admins)
  • campaigns - Call campaigns
  • contacts - Contact list
  • calls - Call history
  • agent_status - Agent status tracking
  • call_recordings - Recording metadata

πŸ§ͺ Testing

Test Authentication

curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"admin123"}'

Test Protected Endpoint

curl -X GET http://localhost:8080/api/campaigns \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Test WebSocket

See WebSocket example above

πŸ“ Logging

Logs are configured in application.yml:

  • Root level: INFO
  • Application level: DEBUG
  • FreeSWITCH events: DEBUG
  • SQL queries: DEBUG (in development)

πŸ” Monitoring

Health Check

curl http://localhost:8080/actuator/health

Metrics

curl http://localhost:8080/actuator/metrics

πŸ› Troubleshooting

Issue: FreeSWITCH connection fails

Solution: Check FreeSWITCH is running and ESL is enabled on port 8021

Issue: Database connection fails

Solution: Verify MySQL is running and credentials are correct

Issue: JWT authentication fails

Solution: Ensure JWT secret is at least 32 characters

Issue: WebSocket connection fails

Solution: Check CORS configuration and WebSocket endpoint

πŸ“¦ Production Deployment

1. Build production JAR

mvn clean package -DskipTests

2. Run with production profile

java -jar -Dspring.profiles.active=prod target/callcenter-0.0.1-SNAPSHOT.jar

3. Environment Variables

export DB_URL=jdbc:mysql://production-db:3306/callcenter_db
export DB_USER=callcenter_user
export DB_PASSWORD=secure_password
export JWT_SECRET=your-secure-256-bit-secret-key
export FREESWITCH_HOST=freeswitch-server

4. Docker Deployment (Optional)

FROM openjdk:17-jdk-slim
COPY target/callcenter-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

πŸ” Security Best Practices

  1. Change default JWT secret
  2. Change default admin password
  3. Use HTTPS in production
  4. Configure firewall rules
  5. Enable rate limiting
  6. Regular security updates
  7. Monitor logs for suspicious activity

πŸ“ˆ Performance Tuning

JVM Options

java -Xms2G -Xmx4G -XX:+UseG1GC -jar callcenter.jar

Database Connection Pool

Configure in application.yml:

spring:
  datasource:
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5

🀝 Contributing

  1. Follow Spring Boot best practices
  2. Use Lombok annotations
  3. Add proper logging
  4. Handle exceptions properly
  5. Write unit tests
  6. Document new endpoints

πŸ“„ License

[Your License Here]

πŸ‘₯ Support

For issues and questions:

  • Check logs in logs/ directory
  • Review this README
  • Check IMPLEMENTATION_CHECKLIST.md

Status: Production Ready βœ…

All 56 Java files implemented with complete functionality. No TODOs or stubs.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages