# bukeme/social-network architecture

> Architecture diagram of the GitHub repository bukeme/social-network, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bukeme/social-network
- Repository: https://github.com/bukeme/social-network

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Web Layer
    subgraph "Web Layer"
        direction TB
        Browser["Web/Mobile Browser"]:::browser
        CDN["NGINX / CDN"]:::proxy
    end

    Browser -->|"HTTP"| CDN
    Browser -->|"WebSocket"| ASGI

    %% PaaS Boundary
    subgraph "PaaS (Heroku/Vercel)"
        direction TB
        ASGI["Daphne/Uvicorn (ASGI Server)"]:::asgi
        WSGI["Gunicorn/UWSGI (WSGI Server)"]:::asgi
    end

    CDN -->|"HTTP"| ASGI
    ASGI -->|"WSGI Pass"| WSGI

    %% Application Layer
    subgraph "Django Application Layer"
        direction TB
        subgraph "Project Core"
            direction TB
            Settings["settings.py"]:::app
            URLs["urls.py"]:::app
        end
        subgraph "Accounts App"
            direction TB
            Accounts["accounts/"]:::app
        end
        subgraph "Posts App"
            direction TB
            Posts["posts/"]:::app
        end
        subgraph "Groups App"
            direction TB
            Groups["groups/"]:::app
        end
        subgraph "Chats App"
            direction TB
            Chats["chats/"]:::app
            Routing["routing.py"]:::app
            Consumers["consumers.py"]:::app
        end
    end

    ASGI -->|"Route HTTP"| URLs
    URLs --> Accounts
    URLs --> Posts
    URLs --> Groups
    URLs --> Chats

    ASGI -->|"Route WS"| Routing
    Routing --> Consumers
    Consumers --> ChannelLayer

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        Database["db.sqlite3 (SQLite/Postgres)"]:::db
        ChannelLayer["Redis (Channel Layer)"]:::db
        subgraph "Static & Media"
            direction TB
            StaticFS["static/ & staticfiles/"]:::infra
            MediaStorage["media/ or Cloudinary"]:::infra
        end
    end

    Accounts --> Database
    Posts --> Database
    Groups --> Database
    Chats --> Database

    Consumers --> ChannelLayer

    Accounts --> StaticFS
    Posts --> StaticFS
    Groups --> StaticFS
    Chats --> StaticFS

    Accounts --> MediaStorage
    Posts --> MediaStorage
    Groups --> MediaStorage
    Chats --> MediaStorage

    %% Deployment Config
    Procfile["Procfile"]:::ext
    Runtime["runtime.txt"]:::ext
    Vercel["vercel.json"]:::ext

    Procfile --> ASGI
    Runtime --> ASGI
    Vercel --> ASGI

    %% Click Events
    click ASGI "https://github.com/bukeme/social-network/blob/render/socialnetwork/asgi.py"
    click WSGI "https://github.com/bukeme/social-network/blob/render/socialnetwork/wsgi.py"
    click Settings "https://github.com/bukeme/social-network/blob/render/socialnetwork/settings.py"
    click URLs "https://github.com/bukeme/social-network/blob/render/socialnetwork/urls.py"
    click Accounts "https://github.com/bukeme/social-network/tree/render/accounts/"
    click Posts "https://github.com/bukeme/social-network/tree/render/posts/"
    click Groups "https://github.com/bukeme/social-network/tree/render/groups/"
    click Chats "https://github.com/bukeme/social-network/tree/render/chats/"
    click Routing "https://github.com/bukeme/social-network/blob/render/chats/routing.py"
    click Consumers "https://github.com/bukeme/social-network/blob/render/chats/consumers.py"
    click Database "https://github.com/bukeme/social-network/blob/render/db.sqlite3"
    click StaticFS "https://github.com/bukeme/social-network/tree/render/static/"
    click MediaStorage "https://github.com/bukeme/social-network/tree/render/media/"
    click Procfile "https://github.com/bukeme/social-network/tree/render/Procfile"
    click Runtime "https://github.com/bukeme/social-network/blob/render/runtime.txt"
    click Vercel "https://github.com/bukeme/social-network/blob/render/vercel.json"

    %% Styles
    classDef browser fill:#D5E8D4,stroke:#82B366
    classDef proxy fill:#FFF2CC,stroke:#D6B656
    classDef asgi fill:#DAE8FC,stroke:#6C8EBF
    classDef app fill:#F8CECC,stroke:#B85450
    classDef db fill:#E1D5E7,stroke:#9673A6
    classDef infra fill:#F5F5F5,stroke:#CCCCCC
    classDef ext fill:#FFF2F2,stroke:#E60000
```
