Skip to content

Aakarsh-Kumar/chatoos

Repository files navigation

Chatoos — Realtime Chat Rooms

A modern, realtime group chat application built with Flask that supports Google Sign‑In, room management, web push notifications, and live messaging via Socket.IO.

Python Flask Socket.IO MongoDB Render

🌟 Features

  • Google Sign‑In (OAuth 2.0): One‑click login using Google accounts
  • Realtime Messaging: Live chat using Flask‑SocketIO with Eventlet
  • Room Management: Create rooms, add/remove members, and manage admins
  • Message History: Persist messages and members in MongoDB
  • Web Push Notifications: VAPID‑backed push for new messages
  • Responsive UI: Clean templates with static assets for an app‑like feel
  • Production‑Ready: Procfile, runtime pinning, and Gunicorn configuration

🚀 Tech Stack

  • Framework: Flask 2.0.1 (Jinja2, Werkzeug)
  • Realtime: Flask‑SocketIO 5.1.1 + Eventlet 0.33.3
  • Auth: Google OAuth (google‑auth‑oauthlib, google‑auth)
  • Database: MongoDB (pymongo)
  • Notifications: Web Push (pywebpush, py‑vapid, cryptography)
  • Server: Gunicorn (eventlet worker)
  • Deploy: Render Web Services

📋 Prerequisites

  • Python 3.8.6
  • A MongoDB connection string (Atlas or self‑hosted)
  • Google OAuth 2.0 credentials (OAuth Client ID + client_secrets.json)
  • VAPID key pair for web push (public and private)

🛠️ Installation

  1. Clone the repository
git clone https://github.com/Aakarsh-Kumar/chatoos.git
cd chatoos
  1. Create and activate a virtual environment
python -m venv .venv
. .venv/Scripts/activate   # Windows PowerShell: .venv\Scripts\Activate.ps1
  1. Install dependencies
pip install -r requirements.txt
  1. Provide Google OAuth secrets
  • Place your OAuth client file at etc/secrets/client_secrets.json (local)
  • On Render, mount or upload it to /etc/secrets/client_secrets.json

🔐 Environment Variables

Set the following environment variables (locally in a .env file or via Render dashboard):

  • APP_SECRET_KEY: Flask secret key
  • app_url: Public app URL (e.g., https://chatoos.onrender.com)
  • GOOGLE_CLIENT_ID: Google OAuth Client ID (must match client secrets)
  • MONGODB_URI: MongoDB connection string
  • VAPID_PRIVATE_KEY: VAPID private key (PEM)
  • VAPID_PUBLIC_KEY: VAPID public key (base64url)
  • VAPID_CLAIMS_EMAIL: Contact email for VAPID claims
  • CHATOOS_ROOM_ID (optional): Seed room id
  • CHATOOS_ROOM_NAME (optional): Seed room name
  • CHATOOS_ADDED_BY (optional): Seed room creator email

OAuth Redirect URI (Google Console):

  • https://chatoos.onrender.com/callback

▶️ Running Locally

Development (Socket.IO will pick the best async driver available):

python app.py

Production‑like run with Gunicorn + Eventlet:

gunicorn -k eventlet -w 1 wsgi:app

📦 Build & Deploy (Render)

This repo includes:

  • runtime.txtpython-3.8.6
  • Procfileweb: gunicorn -k eventlet -w 1 wsgi:app
  • wsgi.py → exposes app for Gunicorn

Steps:

  1. Push to GitHub
  2. Create a Render Web Service from the repo
  3. Set environment variables (see above)
  4. Upload/mount client_secrets.json at /etc/secrets/client_secrets.json
  5. Add the authorized redirect URI in Google Cloud Console
  6. Deploy — your app will be available at your Render URL

🗂️ Project Structure

app.py
wsgi.py
Procfile
requirements.txt
runtime.txt
db.py
user.py
etc/
  secrets/
    client_secrets.json
static/
  sw.js
  css/
  fonts/
  img/
  vendor/
templates/
  create_room.html
  edit_room.html
  index.html
  login.html
  members.html
  signup.html
  view_room.html

🎨 Available Routes

  • / — Home, room list and join actions
  • /login — Google Sign‑In start (OAuth authorization URL)
  • /callback — OAuth2 callback handler
  • /logout — End session
  • /create-room — Create a new room (auth required)
  • /rooms/<room_id> — View room and live messages (auth required)
  • /rooms/<room_id>/members — List members (auth required)
  • /rooms/<room_id>/messages — Paginated older messages (auth required)

🔌 Integrations

  • Google OAuth: Uses google_auth_oauthlib.flow.Flow to initiate login and fetch tokens, with ID token verification via google.oauth2.id_token.
  • MongoDB: Stores users, rooms, membership, and messages via helper functions in db.py.
  • Web Push (VAPID): Sends push notifications with pywebpush when room messages are posted.
  • Socket.IO: Real‑time events for join/leave/message flows (@socketio.on(...)).

🧪 Tips & Troubleshooting

  • Ensure app_url matches your deployed URL to avoid OAuth redirect mismatches.
  • The Google Console redirect must exactly be https://<your-domain>/callback.
  • On Render, ensure the secret file is available at /etc/secrets/client_secrets.json.
  • If switching async workers, keep eventlet.monkey_patch() at the very top of app.py.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Please open an issue or PR.

Suggested Workflow

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

👥 Author

Aakarsh Kumar


Made with ❤️ by Aakarsh

About

Realtime chat rooms with self chat rooms creation and push notifications

Topics

Resources

Stars

Watchers

Forks