Skip to content

mtecnic/cblchat

Repository files navigation

CBL Chat - Enterprise Chat Application

A real-time chat application with LDAP/Active Directory authentication for enterprise use.

Features

  • LDAP/Active Directory Authentication - Seamless integration with domain controllers
  • Real-time Messaging - Powered by WebSocket for instant message delivery
  • Public & Private Channels - Create channels for teams and departments
  • Direct Messages - One-on-one conversations with colleagues
  • Typing Indicators - See when others are typing
  • User Presence - Online/offline/away status
  • Message History - Persistent message storage with PostgreSQL
  • Responsive UI - Modern React-based interface
  • Secure - JWT authentication, HTTPS support, input validation

Technology Stack

Backend

  • Python 3.11+
  • FastAPI
  • WebSocket
  • PostgreSQL
  • SQLAlchemy ORM
  • LDAP3 Authentication

Frontend

  • React 18
  • Native WebSocket Client
  • Axios
  • CSS3

Installation

Option 1: Docker (Recommended)

  1. Clone the repository:
git clone <repository-url>
cd cblchat
  1. Create environment file:
cp backend/.env.example .env
  1. Edit .env with your configuration:
nano .env
  1. Deploy with Docker:
chmod +x deploy.sh
./deploy.sh

The application will be available at http://localhost

Option 2: Manual Installation (Ubuntu)

  1. Run the installation script:
chmod +x install.sh
sudo ./install.sh
  1. Configure environment variables:
nano backend/.env
  1. Run database migrations:
cd backend
npm run migrate
npm run seed
cd ..
  1. Start the application:
pm2 start ecosystem.config.js
pm2 save

Configuration

Environment Variables

Backend (.env)

# Server
NODE_ENV=production
PORT=3000
HOST=0.0.0.0

# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=cblchat
DB_USER=postgres
DB_PASSWORD=your_password

# JWT
JWT_SECRET=your_secret_key_change_this
JWT_EXPIRES_IN=24h

# LDAP/Active Directory
LDAP_URL=ldap://your-dc.local:389
LDAP_BIND_DN=cn=admin,dc=example,dc=com
LDAP_BIND_PASSWORD=your_ldap_password
LDAP_SEARCH_BASE=dc=example,dc=com
LDAP_SEARCH_FILTER=(uid={{username}})
# For Active Directory use: (sAMAccountName={{username}})

# CORS
CORS_ORIGIN=http://localhost

LDAP Configuration

For Active Directory:

LDAP_URL=ldap://dc.company.local:389
LDAP_BIND_DN=cn=ServiceAccount,ou=Users,dc=company,dc=local
LDAP_SEARCH_BASE=dc=company,dc=local
LDAP_SEARCH_FILTER=(sAMAccountName={{username}})

For OpenLDAP:

LDAP_URL=ldap://ldap.company.local:389
LDAP_BIND_DN=cn=admin,dc=company,dc=local
LDAP_SEARCH_BASE=ou=users,dc=company,dc=local
LDAP_SEARCH_FILTER=(uid={{username}})

Nginx Configuration

For production, configure SSL in nginx.conf:

server {
    listen 443 ssl http2;
    server_name chat.company.local;

    ssl_certificate /etc/nginx/ssl/cert.pem;
    ssl_certificate_key /etc/nginx/ssl/key.pem;

    # ... rest of configuration
}

Usage

Starting the Application

With Docker:

docker-compose up -d

With PM2:

pm2 start ecosystem.config.js

Development mode:

# Backend
cd backend
npm run dev

# Frontend (in another terminal)
cd frontend
npm start

Managing the Application

View logs:

docker-compose logs -f              # Docker
pm2 logs                            # PM2

Restart:

docker-compose restart              # Docker
pm2 restart all                     # PM2

Stop:

docker-compose down                 # Docker
pm2 stop all                        # PM2

API Endpoints

Authentication

  • POST /api/auth/login - User login
  • POST /api/auth/logout - User logout
  • GET /api/auth/me - Get current user
  • PUT /api/auth/profile - Update profile

Rooms

  • GET /api/rooms - Get user's rooms
  • POST /api/rooms - Create room
  • POST /api/rooms/direct - Create direct message
  • GET /api/rooms/:id - Get room details
  • PUT /api/rooms/:id - Update room
  • DELETE /api/rooms/:id - Delete room

Messages

  • GET /api/messages/room/:roomId - Get room messages
  • POST /api/messages/room/:roomId - Send message
  • PUT /api/messages/:id - Edit message
  • DELETE /api/messages/:id - Delete message
  • GET /api/messages/search - Search messages

Users

  • GET /api/users - Get all users
  • GET /api/users/:id - Get user by ID

WebSocket Events

Client → Server

  • join_rooms - Join multiple rooms
  • send_message - Send a message
  • typing - User is typing
  • stop_typing - User stopped typing
  • status_change - Change user status

Server → Client

  • new_message - New message received
  • user_typing - User is typing
  • user_stop_typing - User stopped typing
  • message_edited - Message was edited
  • message_deleted - Message was deleted
  • user_status_change - User status changed

Database Schema

Users

  • id, username, displayName, email, department, status, lastSeen, avatarUrl

Rooms

  • id, name, description, roomType (public/private/direct), createdBy

Messages

  • id, senderId, roomId, recipientId, content, messageType, fileUrl, fileName

RoomMembers

  • id, roomId, userId, role (admin/member), lastReadMessageId, joinedAt

Security Considerations

  1. SSL/TLS - Always use HTTPS in production
  2. JWT Secret - Use a strong, random JWT secret
  3. LDAP over SSL - Enable LDAPS for production
  4. Rate Limiting - Configured to prevent abuse
  5. Input Validation - All inputs are validated
  6. CSRF Protection - Enabled for all endpoints
  7. Helmet.js - Security headers configured

Troubleshooting

LDAP Connection Issues

# Test LDAP connection
ldapsearch -x -H ldap://your-dc.local:389 -D "cn=admin,dc=example,dc=com" -W -b "dc=example,dc=com"

Database Connection Issues

# Test PostgreSQL connection
psql -h localhost -U cblchat -d cblchat

Port Already in Use

# Find process using port 3000
sudo lsof -i :3000
# Kill the process
sudo kill -9 <PID>

License

MIT

Support

For issues and questions, please open an issue in the repository.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors