LocalChat is a locally hosted chatroom for everyone connected to the same WiFi network. It provides a simple, clean interface for group conversations and private messaging between users using Flask, Flask-SocketIO, and PostgreSQL.
- Main Chat: Real-time group messaging for all connected users
- Private Chats: Direct messaging between two users by IP address
- Clean UI: Simple white-themed interface optimized for usability
- Local Network Only: Works across any WiFi network without internet
- Message History: All messages stored in PostgreSQL database
- Real-time Updates: WebSocket-based instant messaging
- Python 3.8+
- PostgreSQL 12+
- Windows/Mac/Linux
- Flask 2.3.0
- Flask-SocketIO 5.3.0
- Flask-SQLAlchemy 3.0.5
- psycopg2-binary 2.9.6
- python-dotenv 1.0.0
git clone https://github.com/yourusername/LocalChat.git
cd LocalChatCREATE DATABASE localchat;python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the root directory:
DATABASE_URL=postgresql://postgres:your_password@localhost/localchat
SECRET_KEY=your-super-secret-key-change-this
FLASK_ENV=development
Replace your_password with your PostgreSQL password.
python app.pyThe application will be available at http://localhost:5000 and accessible from other devices on the same network using your machine's local IP (e.g., http://192.168.1.100:5000).
- Windows: Open Command Prompt and run
ipconfig. Look for "IPv4 Address" - Mac/Linux: Open Terminal and run
ifconfigorhostname -I
- On any device on the same WiFi, go to
http://<your-local-ip>:5000 - Select Main Chat to join the group conversation, or
- Select Private Chat and enter the last octet of an IP address (e.g., for
192.168.1.42, enter42)
LocalChat automatically detects the connecting user's IP address. Private chats use the last octet of the IP for identification, making it easy to find specific users on your network (e.g., 172.168.4.x).
LocalChat/
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── .env # Environment configuration
├── .gitignore # Git ignore rules
├── static/
│ └── styles.css # Clean white-themed CSS
├── templates/
│ ├── overview.html # Landing page
│ ├── main_chat.html # Group chat interface
│ └── private_chat.html # Private chat interface
└── README.md # This file
CREATE TABLE messages (
id SERIAL PRIMARY KEY,
sender_ip VARCHAR(15) NOT NULL,
recipient_ip VARCHAR(15),
content TEXT NOT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
room_type VARCHAR(10) DEFAULT 'main'
);CREATE TABLE users (
id SERIAL PRIMARY KEY,
ip_address VARCHAR(15) UNIQUE NOT NULL,
last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);/main: Main chat namespace for group messaging/private: Private chat namespace with room-based filtering
- Change the
SECRET_KEYin.envbefore deployment - Only use on trusted networks
- Consider adding authentication for production use
- Messages are stored in plaintext; encrypt sensitive data if needed
- Ensure PostgreSQL is running
- Check your credentials in
.env - Verify the database exists:
CREATE DATABASE localchat;
- Check firewall settings
- Ensure port 5000 is not blocked
- Try disabling browser extensions that might interfere
- Check Flask console for errors
- Verify database connection
- Reload the page and try again
- User authentication and profiles
- Message encryption
- File sharing
- User status indicators
- Message reactions and typing indicators
- Docker containerization
MIT License - Feel free to use this project for personal or commercial purposes.
For issues, questions, or suggestions, please open an issue on GitHub.