Skip to main content

Technical Documentation of Services - EML Backend

1. Introduction

The EML Backend system consists of multiple microservices designed to efficiently manage calls, messages, and notifications in a call center environment. This documentation details each service, its functionalities, endpoints, and the communication between them.


2. Main Services

2.1 API Gateway

  • Description: Central service that receives all external requests and distributes them to the appropriate microservices.
  • Technology: NestJS + Express
  • Responsibilities:
    • Manages authentication and authorization.
    • Routes requests to the corresponding microservices.
    • Logs and monitors requests.
  • Main Endpoints:
    • POST /auth/login → User authentication.
    • GET /users/profile → Retrieve authenticated user profile.
    • GET /health → Service health check.
  • Security Management: Implements JWT and OAuth2.
  • Communication:
    • Connects with all other microservices.
    • Uses Redis for caching user sessions.
    • Logs centralized in the ELK Stack.

2.2 Communication Service

  • Description: Handles receiving and sending calls and messages.
  • Technology: NestJS + WebSockets
  • Responsibilities:
    • Manages the flow of calls and messages.
    • Connects with the telecommunications API.
    • Processes real-time events.
  • Main Endpoints:
    • POST /calls/start → Start a call.
    • POST /messages/send → Send a message.
    • GET /calls/history → Retrieve call history.
  • Asynchronous Messaging:
    • Uses RabbitMQ to process communication events.
    • Implements WebSockets for persistent connections.
  • Monitoring and Logs:
    • Prometheus and Grafana for usage metrics.
    • Detailed logs in Kibana.

2.3 Notification Service

  • Description: Automates the sending of reminders and alerts.
  • Technology: NestJS + RabbitMQ
  • Responsibilities:
    • Processes notification events.
    • Integrates with SMS and email providers.
    • Configures custom notification rules.
  • Main Endpoints:
    • POST /notifications/create → Schedule a notification.
    • GET /notifications/pending → Retrieve pending notifications.
  • Queue Management:
    • Uses RabbitMQ to handle message distribution.
    • Implements retries in case of failures.

2.4 User Service

  • Description: Manages authentication and user administration.
  • Technology: NestJS + TypeORM + PostgreSQL
  • Responsibilities:
    • User creation and management.
    • Credential validation and session control.
    • Role and permission administration.
  • Main Endpoints:
    • POST /users/register → Create a user.
    • POST /users/login → Log in.
    • GET /users/list → List users.
  • Security:
    • Implements JWT and OAuth2 for secure authentication.
    • Supports 2FA for critical authentications.
    • Password hashing with bcrypt.

2.5 Reports Service

  • Description: Generates reports on system usage and statistics.
  • Technology: NestJS + MongoDB
  • Responsibilities:
    • Collects usage data from other microservices.
    • Generates real-time and scheduled reports.
    • Exports data in JSON and CSV formats.
  • Main Endpoints:
    • GET /reports/summary → Retrieve activity summary.
    • GET /reports/calls → Report on processed calls.
  • Storage:
    • Uses MongoDB for historical data storage.
    • Implements data partitioning for performance optimization.
  • Monitoring:
    • Alerts for failed reports via Prometheus.
    • Detailed logs in ElasticSearch.

3. Microservices Communication

  • Data Format: JSON is used for communication between services.
  • Messaging: RabbitMQ is used for asynchronous communication.
  • Security: All requests between services require authentication via JWT.
  • Failover Rules:
    • If a service does not respond, an automatic retry mechanism is used.
    • In case of a critical failure, backup instances are activated.

4. Monitoring and Logs

  • Prometheus + Grafana:

    • Metric exporters are configured for each service.
    • Example of a Prometheus metric for the API Gateway:
      - job_name: 'api_gateway'
      static_configs:
      - targets: ['api-gateway:9090']
    • Dashboard visualization in Grafana for traffic and latency analysis.
  • ELK Stack (ElasticSearch, Logstash, Kibana):

    • All microservices send logs to Logstash.
    • Logs are indexed in ElasticSearch for fast queries.
    • Example of a structured log in JSON format:
      {
      "timestamp": "2025-03-03T12:34:56Z",
      "service": "api_gateway",
      "level": "error",
      "message": "User authentication error",
      "user": "user123",
      "ip": "192.168.1.10"
      }
    • Kibana allows viewing logs with advanced filters and generating automated alerts.
  • Alerts and Metrics:

    • Latency thresholds are set for each microservice.
    • Alert notifications via Slack and email when a service exceeds response time limits.
    • Prometheus AlertManager configuration:
      groups:
      - name: instance_down
      rules:
      - alert: ServiceDown
      expr: up == 0
      for: 5m
      labels:
      severity: critical
      annotations:
      summary: "Instance down"
      description: "{{ $labels.instance }} has been down for more than 5 minutes"

5. Scalability and Optimization

  • Load balancing with Nginx and HAProxy.
  • Use of Redis for caching frequently accessed data.
  • Database indexing and query optimization strategies.
  • Deployment in Kubernetes clusters with auto-scaling.

6. Conclusion

This technical documentation provides a detailed overview of the microservices that make up EML Backend. For specific details, refer to the documentation for each service in its respective module. 🚀