Simple Social Network
Django-based social network with real-time messaging
Provides real-time messaging, friendship management, user profiles, and two-factor authentication. Designed for secure communication with a modern dark-themed interface.
Simple Social Network is a Django-based web application that provides real-time messaging, friendship management, user profiles, and two-factor authentication. The platform is designed for secure communication and social interaction with a modern, dark-themed interface.
- User Authentication — Registration, login, email verification, password reset
- Two-Factor Authentication — TOTP-based 2FA with backup codes
- Real-time Chat — WebSocket-powered messaging with edit/delete capabilities
- Friend System — Send, accept, reject, and cancel friend requests
- User Profiles — Customizable profiles with avatars, biography, and personal information
- Chat Management — Archive, mute, delete, and restore chats
- Message Status — Read receipts and message timestamps
- User Search — Find users by username or first name
- Responsive Design — Works on desktop and mobile devices
Backend:
- Django 6.0.5 — Web framework
- PostgreSQL — Database
- Redis — Caching and session storage
- Django Channels — WebSocket support for real-time features
Frontend:
- Django Templates — Server-side rendering
- Semantic UI — Frontend framework
- JavaScript — Native WebSocket client
Security:
- pyotp — TOTP generation/verification
- bcrypt — Backup code hashing
Prerequisites: Python 3.11+, PostgreSQL 15+, Redis 7+, Git
# Clone repository git clone https://github.com/aixandrolab/simple-social-network.git cd simple-social-network # Create virtual environment python -m venv venv source venv/bin/activate # Install dependencies pip install -r requirements.txt
Configure PostgreSQL:
# Arch Linux
sudo pacman -S postgresql
sudo su - postgres -c "initdb --locale en_US.UTF-8 -D '/var/lib/postgres/data'"
sudo systemctl start postgresql
sudo systemctl enable postgresql
# Create database
sudo -u postgres psql
CREATE DATABASE simple_social_network_db
OWNER postgres
ENCODING 'UTF-8'
LC_COLLATE 'en_US.UTF-8'
LC_CTYPE 'en_US.UTF-8'
TEMPLATE template0;
Configure Redis:
# Arch Linux sudo pacman -S redis sudo systemctl start redis sudo systemctl enable redis
Environment Variables (.env):
DJANGO_ENV=development SECRET_KEY=your-secret-key-here DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1 DB_NAME=simple_social_network_db DB_USER=postgres DB_PASSWORD=your-db-password DB_HOST=localhost DB_PORT=5432 REDIS_URL=redis://localhost:6379/1
Apply Migrations & Run:
python manage.py migrate python manage.py createsuperuser python manage.py collectstatic python manage.py runserver
Access at: http://localhost:8000
simple-social-network/ ├── chats/ │ ├── signals.py # Post-save signals │ ├── forms/ # Chat settings form │ ├── templatetags/ # Custom template tags │ ├── models/ # Chat, ChatStatus, ChatMessage │ └── views/ # Chat views ├── core/ │ ├── consumers.py # WebSocket consumers │ ├── context_processors.py # Site config context │ ├── models.py # SiteConfig singleton │ ├── services.py # Email services │ ├── routing.py # WebSocket routing │ ├── signals.py # SiteConfig signals │ ├── utils/ # Pagination utilities │ └── views/ # Home, auth, password views ├── friends/ │ ├── services.py # Friendship business logic │ ├── signals.py # Status change logging │ ├── models/ # Friendship, FriendshipHistory │ └── views/ # Friend request views ├── profiles/ │ ├── middleware.py # Last activity tracking │ ├── signals.py # User profile creation │ ├── forms/ # Profile, 2FA, password forms │ ├── utils/ # Image validation │ ├── models/ # Profile, token models │ └── views/ # Profile, 2FA, settings views ├── static/ # Static files ├── templates/ # Base templates and components ├── media/ # User-uploaded files ├── .env # Environment variables ├── manage.py ├── requirements.txt └── README.md
- Profile — User profile with avatar, biography, 2FA settings. Tracks online status via Redis. Supports TOTP and backup codes.
- Friendship — Manages friend relationships with status (pending/accepted/rejected). Maintains history of status changes.
- Chat — Two-user private chat. Supports naming, archiving, muting, and deletion.
- ChatMessage — Messages with content, read status, edit/delete support. Timestamp tracking.
- ChatStatus — Per-user chat preferences (archived, muted, deleted, visible). Unique constraint per chat and profile.
WebSocket:
ws://localhost:8000/ws/chat/{chat_id}/
Message Types:
chat_message_event— Send/receive new messagesedit_message_event— Edit existing messagesdelete_message_event— Delete messages
URL Patterns:
| URL | Description |
|---|---|
/ | Home page |
/login/ | User login |
/register/ | User registration |
/profile/detail/{slug}/ | User profile |
/profile/search/ | Search users |
/friends/@username/ | Friends list |
/friends/incoming/ | Incoming friend requests |
/friends/outgoing/ | Outgoing friend requests |
/chats/active/ | Active chats list |
/chats/archived/ | Archived chats |
/chats/deleted/ | Deleted chats |
/chats/create/{profile_id}/ | Create new chat |
/chat/details/{chat_id}/ | Chat detail/messages |
/chat/settings/{chat_id}/ | Chat settings |
/two-factor/ | 2FA management |
| Variable | Description | Default |
|---|---|---|
DJANGO_ENV | Environment (development/production) | development |
SECRET_KEY | Django secret key | Required |
DEBUG | Debug mode | True |
ALLOWED_HOSTS | Comma-separated hosts | localhost |
DB_NAME | Database name | simple_social_network_db |
DB_USER | Database user | postgres |
DB_PASSWORD | Database password | Required |
DB_HOST | Database host | localhost |
DB_PORT | Database port | 5432 |
REDIS_URL | Redis connection URL | redis://localhost:6379/1 |
EMAIL_ON | Enable email sending | False |
- Database Connection Issues:
- Check PostgreSQL is running:
sudo systemctl status postgresql - Verify database exists:
sudo -u postgres psql -l - Redis Connection Issues:
- Check Redis is running:
sudo systemctl status redis - Test Redis connection:
redis-cli ping - WebSocket Connection Issues:
- Ensure Daphne is running:
ps aux | grep daphne - 2FA Issues:
- Clear session data:
python manage.py shell→from django.contrib.sessions.models import Session; Session.objects.all().delete()
- All passwords are hashed using Django's PBKDF2
- 2FA uses TOTP with 30-second windows
- Backup codes are hashed with bcrypt
- CSRF protection is enabled
- Session data is stored in Redis
- SQL injection prevention via ORM
- XSS protection via Django templates
By using this software, you agree to the full disclaimer terms.
Software provided "AS IS" without warranty. You assume all risks.
Full legal disclaimer: See DISCLAIMER.md
License: BSD 3-Clause License