GithubHelp home page GithubHelp logo

laxyy69 / chitychat Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 567 KB

A simple Chat App with the purpose of learning.

License: MIT License

C 67.93% HTML 3.21% CSS 5.40% JavaScript 14.45% PLpgSQL 0.91% Meson 0.51% Python 7.47% Shell 0.11%
c chatapp html-css-javascript linux postgresql webserver websokcet

chitychat's Introduction

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. Build Web Server
  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 Usage with SQLite3, later PostgreSQL.
  • Frontend Development with JavaScript, HTML, and CSS.
  • Password Security with SHA512 hashing.

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

Build Web Server

Note

Exclusively for Linux.

Dependencies

  • clang
  • json-c
  • libmagic
  • postgresql
  • openssl
  • meson

Dependencies Package Names

  • Arch: json-c file postgresql openssl meson clang
  • Debian: libjson-c-dev libmagic-dev postgresql postgresql-client libpq-dev libssl-dev meson clang

Clone repo and cd into:

git clone https://github.com/laxyyza/chitychat.git && cd chitychat

Setup build directory:

CC=clang meson setup build/

Compile:

ninja -C build/

Executable name: chitychat inside build/

After compilation: PostgreSQL and SSL certificates.

PostgreSQL:

Read the Arch Wiki (or your distro wiki) for setting up PostgreSQL.

After you setup PostgreSQL, create a PostgreSQL database called: chitychat

sudo -u postgres createdb chitychat

SSL certificates:

Generate self-signed SSL keys: (in project's root directory)

Note

Your browser will display a warning when using self-signed SSL keys.

openssl req -x509 -newkey rsa:4096 -keyout server/server.key -out server/server.crt -days 365 -nodes

Now you should be done, and execute build/chitychat server.

Config file: server/config.json

In your browser: https://localhost:8080 or https:// + ip address + :8080

Change port in config file or use --port arguments. See build/chitychat --help

Coding Style

chitychat's People

Contributors

laxyyza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.