Skip to content

A production-ready Elixir server implementation providing real-time features through WebSocket connections, with Firebase synchronization and MySQL persistence.

License

Notifications You must be signed in to change notification settings

iamgrawal/socket-elixir

Repository files navigation

Realtime Server

A production-ready Elixir server implementation providing real-time features through WebSocket connections, with Firebase synchronization and MySQL persistence.

Features

🔐 Secure Authentication

  • JWT-based authentication
  • Device-based session management
  • Rate limiting
  • Role-based access control
  • Secure password hashing

🚀 Real-time Communication

  • WebSocket-based real-time updates
  • Presence tracking
  • Comment system
  • Channel-based communication
  • Real-time event broadcasting

🔄 Firebase Integration

  • Real-time data synchronization
  • Fallback mechanism
  • Background synchronization
  • Secure Firebase Admin SDK integration
  • Automatic retry mechanisms

📦 Production Ready

  • Docker support
  • Comprehensive documentation
  • Test coverage
  • Monitoring setup
  • SSL/TLS support
  • Database replication support

📊 Comprehensive Monitoring

  • Multi-backend logging system
  • Metrics collection
  • Telemetry integration
  • Pluggable monitoring solutions
  • Performance tracking
  • Error tracking
  • Business metrics

Quick Start

Prerequisites

  • Elixir 1.14+
  • Erlang/OTP 25+
  • MySQL 8.0+
  • Node.js 16+ (for Firebase client)

Installation

  1. Clone the repository:

    git clone https://github.com/your-org/realtime-server.git
    cd realtime-server
  2. Install dependencies:

    mix deps.get
  3. Setup environment:

    cp .env.example .env
    # Edit .env with your configurations
  4. Setup database:

    mix ecto.setup
  5. Start the server:

    mix phx.server

Docker Setup

docker-compose up --build

Documentation

Detailed documentation is available in the docs directory:

Development

Running Tests

# Run all tests
mix test

# Run with coverage
mix coveralls

# Run specific test file
mix test test/realtime_server/comments_test.exs

Code Quality

# Run formatter
mix format

# Run linter
mix credo

API Examples

Authentication

# Register a new user
curl -X POST http://localhost:4000/api/register \
  -H "Content-Type: application/json" \
  -d '{"user": {"email": "[email protected]", "password": "password123", "username": "testuser"}}'

# Login
curl -X POST http://localhost:4000/api/login \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "password": "password123", "device_id": "device123"}'

WebSocket Connection

// Connect to WebSocket
let socket = new Socket("ws://localhost:4000/socket", {
  params: { token: "your-jwt-token" },
});

socket.connect();

// Join a comment channel
let channel = socket.channel(`comments:${videoId}`, {});
channel
  .join()
  .receive("ok", (resp) => console.log("Joined successfully", resp))
  .receive("error", (resp) => console.log("Unable to join", resp));

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

About

A production-ready Elixir server implementation providing real-time features through WebSocket connections, with Firebase synchronization and MySQL persistence.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published