Skip to content

laxyyza/chitychat

Repository files navigation

Table of Contents

  1. Chity Chat
  2. Chat App Features
  3. Web Server Features
  4. Web Server Limitations
  5. Current Web Server Challenges
  6. Planned Features
  7. Learning Experience
  8. Project Directory Structure
  9. Running ChityChat server (Docker Compose)
  10. Coding Style

Chity Chat

This is a simple Chat App with the purpose of learning.

  • Fullstack Project
    • Frontend: In JavaScript, HTML and CSS. (My first time)
    • Backend: Custom web server written in C.

Though the front-end is my initial venture into web development, the standout feature lies in the C-written backend.

Chat App Features

  • Private/Public Groups: Users have the option to join public groups or enter private ones using specific codes.
  • Real-time Communication: Messages are sent and received instantly.
  • Real-time User Staus Updates: Instantly see if users comes online and offline.

Web Server Features

  • HTTP/1.1 Parsing: Basic parsing with support for GET and POST requests.
  • Web Sockets Implementation: Real-time communication support.
  • SSL/TLS via OpenSSL: Secure connections.
  • Password Security: Salting and hashing using SHA512.
  • I/O Multiplexing: Utilizes epoll(7) for efficient I/O.
  • Database Management: Uses PostgreSQL for SQL database.
  • Session Management: Users receive session IDs for persistent login.
  • Multi-Threaded: Utilizes a thread pool to efficiently manage concurrent events.
  • IP Versions: Supports both IPv4 and IPv6.

Web Server limitations

  • Exclusively designed for this Chat App.
  • Basic HTTP Parsing: Limited to handling only GET and POST requests.
  • Monolithic Architecture: Combines web server and chat server functionalities within a single process.

Current Web Server Challenges

  • Experiences significant slowdowns with only approximately 100 concurrent users. Fixed.
  • Encounters unexpected errors when multiple clients disconnect simultaneously. Fixed.
  • Worker threads are heavly I/O bound to PostgreSQL. Non-blocking postgres connection maybe?
  • Faces potential deadlock issues during high load, resulting in server unresponsiveness.

Planned Features

  • Private Groups: Invitation-only groups.
    • Mark group as private, only group members can get it.
    • Implement Invite Codes
    • Implement Invite Links
  • Group Member Roles: Admins, mods, etc.
  • User Account Management: Change username, display name, bio, and password.
  • Deletion: Ability to delete accounts, messages, and groups.
    • Delete messages.
    • Delete accounts.
    • Detete groups.
  • Direct Messaging (DM): Private messaging between users (Create Private Group with only 2 users).
  • Enhanced Messaging: Send photos, videos, files, reply to messages, and edit messages.
    • Front-end implementation (images)
      • Add images and paste image from clipboard.
    • Back-end implementation (images)
  • Mobile Compatibility: Improve usability on mobile devices.
  • URL Parameters Support: Support HTTP URL parameters.
  • Real-Time User Status Management: Online, Offline, Away, busy, typing, etc.
    • User Online/Offline
    • Typing.
    • User set status
  • Upload File Management: Avoid duplication user files.
    • Default profile pic
  • Real-Time User Profile Updates: Receive instant updates for user profile changes like usernames, display names, bio, and profile pictures.
    • Profile pictures.
    • Username / Displayname
    • Bio

Learning experience

Through building Chity Chat, I learned:

  • Web Server Implementation:
    • HTTP
    • Web Sockets
    • SSL/TLS
    • Multi-Threading
  • SQL Database Management: SQLite3, later migrated to PostgreSQL.
  • Frontend Development: JavaScript, HTML, and CSS.
  • Password Security: SHA512 hashing.
  • CI/CD with GitHub Actions: Docker-based pipeline.

Project Directory Structure

# chitychat's root
/
├── server/        # Server/Backend 
│   ├── src/       # Server C source code
│   ├── include/   # Server Header Files
│   └── sql/       # SQL schema and queries
│
├── client/        # Client/Frontend
│   ├── public/    # Default Public Directory & Website source code
│   └── headless/  # Headless client; bot source code
│
└── tests/         # Currently only have load_balance_bots.sh

Running ChityChat server (Docker Compose)

  1. Clone the repository and navigate to the project directory:
git clone https://github.com/laxyyza/chitychat.git && cd chitychat
  1. Create .env file, set your own DB_USER and DB_PASSWORD environment variables.
echo "DB_USER=your_user
      DB_PASSWORD=your_password" > .env
  1. Generate SSL certificates for secure communication:
openssl req -x509 -newkey rsa:4096 -keyout server/server.key -out server/server.crt -days 365 -nodes
  1. Build the Docker image:
docker build -t laxyy/chitychat .
  1. Start the ChityChat server and PostgreSQL using Docker Compose:
docker-compose up -d
  1. Access the server: Open your browser and go to: https://localhost:8080. Note: You'll get a warning because of the self-signed SSL certificate.

Coding Style