How bukeme/social-network works
Project Type and Purpose
• This is a full-stack social media web application built on Django (Python) with real-time capabilities via Django Channels. Users can authenticate, create/edit posts, follow/unfollow, chat privately, and create/join groups. The project uses Django’s MVC-style (MTV) pattern, serves static and media assets, persists state in a relational database, and handles WebSocket connections for chat.
File Structure Highlights & Architectural Implications
• Top-level directories:
• socialnetwork/ – Django project settings, ASGI/WGSI entry points, URL routing
• accounts/, posts/, groups/, chats/ – Four Django “apps,” each encapsulating models, views, templates, URLs, and tests
• static/ & staticfiles/ – CSS, JS, images served via Django’s staticfiles pipeline
• media/ – User-uploaded assets (profile, group, post images)
• Channels integration:
• socialnetwork/asgi.py + chats/routing.py + chats/consumers.py indicate WebSocket handling for real-time chat
• Deployment orchestration:
• Procfile & runtime.txt suggest a Heroku-style or similar PaaS deployment
• vercel.json indicates Vercel configuration (for front or serverless endpoints)
Key Components
a. Clients (Web Browser / Mobile Browser)
b. HTTP Layer (NGINX or Cloudflare CDN for static files)
c. ASGI Server (Daphne or Uvicorn) managing HTTP requests and WebSockets
d. Django Application Layer:
• accounts app (authentication, profiles)
• posts app (posting, feed)
• groups app (group management)
• chats app (real-time messaging via Consumers)
e. Channel Layer (Redis or In-Memory – used by Django Channels for pub/sub)
f. Database (SQLite in development; typically PostgreSQL in production)
g. Media Storage (local media/ folder or Cloudinary external service)
h. Static Asset Server (Django staticfiles or CDN)
Relationships & Data Flows
• HTTP Request Flow:
Browser → NGINX/CDN → Daphne → Django URL Router → Appropriate App’s View → ORM → Database → Template Renderer → Response → Browser
• WebSocket Flow (Chat):
Browser WebSocket → Daphne ASGI → chats.routing → ChatConsumer → Channel Layer → ChatConsumer (other user connection) → Browser
• Static/Media Flow:
Browser GET static/css, js → Staticfiles/CDN
Browser GET media/uploads → Media Server or Cloudinary
Architectural Patterns & Principles
• Separation of Concerns: Each Django app handles a distinct domain (accounts, posts, groups, chats).
• MVC/MTV Pattern: Models ↔ ORM, Templates ↔ Views, Controllers ↔ URL dispatchers.
• Pub/Sub for Real-Time: Channel Layer decouples Producer (one ChatConsumer) from Consumer (another ChatConsumer).
• 12-Factor App for Deployment: Procfile, environment configuration, static file handling.
Step-by-Step Construction
• HTTP → URL Routing → Views in Django
• WS → chats.routing → ChatConsumer