How omkashyap007/socialmediasite works
Project type and purpose
• This is a full-stack, real-time social media/chat web application built on Django and Django Channels.
• Purpose: allow authenticated users to manage profiles, add/search friends, chat publicly in rooms or privately, share code snippets (Markdown), and receive real-time notifications.
File structure
• Top-level “SocialMediaSite” folder: Django project settings and URL/routing config.
• Django apps (each with models, views, URLs, templates, migrations, tests):
• account – authentication, registration, profile management
• friend – friend requests, friendship logic
• public_chat – global chat rooms
• chat – one-to-one private chats (Django Channels consumers)
• notification – real-time notifications (consumers)
• personal – homepage, user dashboard
• ASGI entrypoint (asgi.py) and routing.py define WebSocket URL routes for chat & notification consumers.
• Static files and templates for server-rendered HTML; media_cdn for user-uploaded images.
• requirements.txt declares dependencies: Django, channels, channels-redis, markdown-it, etc.
README insights
• Confirms use of Django (WSGI for HTTP, ASGI for WebSockets), Django Channels, WebSockets.
• Key features: public rooms, private messaging, Markdown code sharing, notifications, secure XSS protection.
Main components
a. Client Layer
• Browser UI: HTML/CSS (Django templates + Bootstrap), JavaScript (chat controls, Markdown editor, WebSocket client).
• Static assets served via Django static configuration or a CDN (static_cdn folder).
b. Edge & Load Balancing (optional)
• Nginx (or another proxy) serving static files, proxying HTTP to Gunicorn and WebSocket traffic to Daphne.
c. Application Layer
• ASGI server (Daphne or Uvicorn) hosting the Django project (SocialMediaSite/asgi.py).
• WSGI server (Gunicorn) for traditional HTTP endpoints (profile, friend search, page loads).
• Django apps: account, friend, public_chat, chat, notification, personal.
d. Real-Time Layer
• Channel layer (Redis) as a message broker for Django Channels consumers.
• Consumers: chat.consumers.PrivateChatConsumer, public_chat (if using consumers), notification.consumers.NotificationConsumer.
e. Persistence Layer
• Relational database (PostgreSQL/MySQL) accessed via Django ORM for users, messages, friendships, notifications.
• Media storage: local filesystem (media_cdn) or remote object storage for profile images.
f. External Services
• Markdown-it for sanitizing/rendering code snippets (invoked in chat/utils or notification/utils).
• Optional email backend for password reset flows.
Relationships & interactions
• HTTP login/registration/profile updates → Django WSGI → DB → session.
• HTTP GET page loads → Django WSGI → templates → static assets (direct or via CDN).
• WebSocket connection (ws://…/ws/chat/… and ws://…/ws/notify/) → Daphne ASGI → routing.py → appropriate Consumer.
• Consumer publishes/subscribes on Redis channels → messages broadcast back to connected clients.
• Consumer persists chat messages/notification records to DB via ORM.
• Friend service triggers signals (friend/signals.py) → notification app (model signals) → send real-time update.
Architectural patterns & principles
• MVC (Django models-views-templates) for HTTP endpoints.
• Event-driven, publish-subscribe pattern via Channels layer and Redis for real-time features.
• Modular, app-centric design: each feature in its own Django app, easy to extend or replace.
• Separation of concerns: authentication, profile management, friendships, public chat, private chat, notifications.
Final detailed checklist
• Distinguish static versus media file flows.
• Channel routing (e.g., routing.py) mapping WebSocket endpoints to Consumers.
• Essential middleware or backends (e.g., custom auth backend in account/backends.py).
• Asynchronous tasks or background jobs if present (e.g., Celery for email, though not explicit here).