# omkashyap007/socialmediasite architecture

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

- Interactive diagram: https://gitdiagram.com/omkashyap007/socialmediasite
- Repository: https://github.com/omkashyap007/socialmediasite

## Overview

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

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser UI\n(Templates + JS)"]:::client
        StaticCDN["Static Assets\n(static/ or static_cdn/)"]:::client
    end

    %% Edge Layer
    subgraph "Edge & Load Balancer"
        Nginx["Nginx Proxy\n(HTTP & WS)"]:::edge
    end

    %% Application Layer
    subgraph "Application Layer"
        Settings["Django Settings"]:::app
        URLRouter["HTTP URL Dispatcher"]:::app
        WSGI["Gunicorn WSGI\nEntry: wsgi.py"]:::app
        ASGI["Daphne ASGI\nEntry: asgi.py"]:::app
        RoutingWS["WebSocket Routing"]:::app
    end

    %% Django Apps
    subgraph "Django Apps"
        subgraph "Account App"
            AccountMVFB["Models / Views / Forms / Backends"]:::appfiles
            AccountURLs["account/urls.py"]:::appfiles
        end
        subgraph "Friend App"
            FriendModels["friend/models.py"]:::appfiles
            FriendSignals["friend/signals.py"]:::appfiles
            FriendURLs["friend/urls.py"]:::appfiles
        end
        subgraph "Public Chat App"
            PublicConsumers["public_chat/consumers.py"]:::realtime
        end
        subgraph "Private Chat App"
            ChatConsumers["chat/consumers.py"]:::realtime
        end
        subgraph "Notification App"
            NotifyConsumers["notification/consumers.py"]:::realtime
        end
        subgraph "Personal App"
            PersonalHome["personal/views.py"]:::appfiles
        end
    end

    %% Real-Time Layer
    subgraph "Real-Time Layer"
        Redis["Redis (Channel Layer)"]:::realtime
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        Database["Relational DB\n(PostgreSQL/MySQL)"]:::db
        MediaStore["Media Storage\n(media_cdn/)"]:::db
    end

    %% External Services
    subgraph "External Services"
        Markdown["Markdown-it Sanitizer"]:::external
        EmailBackend["Email Backend"]:::external
    end

    %% Connections
    Browser -->|"HTTP"| Nginx
    Browser -->|"Fetch Assets"| StaticCDN
    Nginx -->|"HTTP"| WSGI
    Nginx -->|"WS"| ASGI
    WSGI -->|"Load Settings"| Settings
    ASGI -->|"Load Settings"| Settings
    WSGI -->|"HTTP Request"| URLRouter
    URLRouter -->|"Dispatch to Apps"| AccountMVFB
    URLRouter -->|"Dispatch to Apps"| FriendModels
    URLRouter -->|"Dispatch to Apps"| PersonalHome
    ASGI -->|"WS Connect"| RoutingWS
    RoutingWS -->|"route to"| PublicConsumers
    RoutingWS -->|"route to"| ChatConsumers
    RoutingWS -->|"route to"| NotifyConsumers
    PublicConsumers -->|"Pub/Sub"| Redis
    ChatConsumers -->|"Pub/Sub"| Redis
    NotifyConsumers -->|"Pub/Sub"| Redis
    AccountMVFB -->|"ORM"| Database
    FriendModels -->|"ORM"| Database
    ChatConsumers -->|"ORM"| Database
    PublicConsumers -->|"ORM"| Database
    NotifyConsumers -->|"ORM"| Database
    AccountMVFB -->|"Upload"| MediaStore
    ChatConsumers -->|"Invoke"| Markdown
    NotifyConsumers -->|"Invoke"| Markdown
    AccountMVFB -->|"Send Email"| EmailBackend
    FriendSignals -->|"Trigger"| NotifyConsumers

    %% Click Events
    click ASGI "https://github.com/omkashyap007/socialmediasite/blob/master/SocialMediaSite/asgi.py"
    click RoutingWS "https://github.com/omkashyap007/socialmediasite/blob/master/SocialMediaSite/routing.py"
    click WSGI "https://github.com/omkashyap007/socialmediasite/blob/master/SocialMediaSite/wsgi.py"
    click URLRouter "https://github.com/omkashyap007/socialmediasite/blob/master/SocialMediaSite/urls.py"
    click Settings "https://github.com/omkashyap007/socialmediasite/blob/master/SocialMediaSite/settings.py"
    click AccountMVFB "https://github.com/omkashyap007/socialmediasite/blob/master/account/models.py"
    click AccountMVFB "https://github.com/omkashyap007/socialmediasite/blob/master/account/views.py"
    click AccountMVFB "https://github.com/omkashyap007/socialmediasite/blob/master/account/forms.py"
    click AccountMVFB "https://github.com/omkashyap007/socialmediasite/blob/master/account/backends.py"
    click AccountURLs "https://github.com/omkashyap007/socialmediasite/blob/master/account/urls.py"
    click FriendModels "https://github.com/omkashyap007/socialmediasite/blob/master/friend/models.py"
    click FriendSignals "https://github.com/omkashyap007/socialmediasite/blob/master/friend/signals.py"
    click FriendURLs "https://github.com/omkashyap007/socialmediasite/blob/master/friend/urls.py"
    click PublicConsumers "https://github.com/omkashyap007/socialmediasite/blob/master/public_chat/consumers.py"
    click ChatConsumers "https://github.com/omkashyap007/socialmediasite/blob/master/chat/consumers.py"
    click NotifyConsumers "https://github.com/omkashyap007/socialmediasite/blob/master/notification/consumers.py"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#003366,color:#003366
    classDef edge fill:#CCEACC,stroke:#006600,color:#006600
    classDef app fill:#E6F5D0,stroke:#336600,color:#336600
    classDef appfiles fill:#F2E6FF,stroke:#662266,color:#662266
    classDef realtime fill:#FFE5CC,stroke:#CC6600,color:#CC6600
    classDef db fill:#F0F0F0,stroke:#666666,color:#333333
    classDef external fill:#FFE6F2,stroke:#CC0066,color:#990033
```
