# mrshd3im05/social-network architecture

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

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

## Overview

This is a Facebook-like social network: users manage profiles and follows, publish privacy-controlled posts, interact through comments and reactions, join groups and events, and chat in real time. The principal workflow runs from the browser through the frontend API client to Go handlers, business services, SQL repositories, and SQLite; WebSocket messaging provides a separate live path. The README documents the backend layer sequence and product capabilities; sampled frontend code shows chat history and live-message behavior. Other feature-level wiring is summarized from documentation, not inspected source.

Main entry points: [`backend/internal/server/server.go`](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/server/server.go) (HTTP server and routes), [`backend/internal/service`](https://github.com/mrshd3im05/social-network/tree/main/backend/internal/service) (Business services), [`frontend/lib/api.js`](https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/api.js) (API client), [`frontend/lib/useChat.js`](https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/useChat.js) (Chat state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web app"]
  node_pages["Social pages"]
  node_authpages["Login and registration"]
  node_components["Shared UI"]
  node_client["API client<br/>[api.js]"]
  node_webchat["Chat state<br/>[useChat.js]"]
  node_history["Message history"]
  node_websocketclient["Socket client<br/>[socket.js]"]
  node_webutils["Frontend utilities"]
end

subgraph group_api["Social API"]
  node_server["HTTP server and routes<br/>[server.go]"]
  node_middleware["Request middleware"]
  node_auth["Sessions and identity<br/>[service.go]"]
  node_social["Profiles and follows"]
  node_posts["Posts and interactions<br/>[handler.go]"]
  node_groups["Groups and events<br/>[service.go]"]
  node_files["Image files<br/>[service.go]"]
  node_chat["Message handling<br/>[handler.go]"]
  node_notifications["Notifications<br/>[handler.go]"]
  node_services["Business services"]
end

subgraph group_live["Real-time"]
  node_hub["WebSocket hub<br/>[hub.go]"]
  node_publisher["Live event publishing<br/>[publish.go]"]
  node_socket["WebSocket endpoint<br/>[session.go]"]
end

subgraph group_data["Persistence"]
  node_repositories["SQL repositories"]
  node_sqlite[("SQLite database<br/>[sqlite.go]")]
end

node_browser(("Browser user"))

node_browser -->|"uses"| node_pages
node_browser -->|"signs in"| node_authpages
node_pages -->|"requests data"| node_client
node_pages -.->|"presents features"| node_components
node_webchat -->|"loads history"| node_history
node_history -->|"fetches pages"| node_client
node_webchat -->|"uploads messages"| node_client
node_webchat -->|"sends and receives"| node_websocketclient
node_websocketclient -->|"gets socket URL"| node_client
node_webutils -.->|"supports requests"| node_client
node_client -->|"calls API"| node_server
node_server -.->|"applies"| node_middleware
node_server -.->|"routes auth"| node_auth
node_server -.->|"routes requests"| node_social
node_server -.->|"routes requests"| node_posts
node_server -.->|"routes requests"| node_groups
node_server -.->|"routes requests"| node_files
node_server -.->|"routes requests"| node_chat
node_server -.->|"routes requests"| node_notifications
node_auth -.->|"implements rules"| node_services
node_social -.->|"applies rules"| node_services
node_posts -.->|"applies rules"| node_services
node_groups -.->|"applies rules"| node_services
node_files -.->|"applies rules"| node_services
node_chat -.->|"applies rules"| node_services
node_notifications -.->|"applies rules"| node_services
node_services -->|"queries SQL"| node_repositories
node_repositories -.->|"reads and writes"| node_sqlite
node_browser -->|"opens connection"| node_socket
node_socket -.->|"dispatches live events"| node_hub
node_hub -.->|"publishes events"| node_publisher
node_publisher -->|"pushes updates"| node_websocketclient

click node_pages "https://github.com/mrshd3im05/social-network/tree/main/frontend/app/(main)"
click node_authpages "https://github.com/mrshd3im05/social-network/tree/main/frontend/app/(auth)"
click node_components "https://github.com/mrshd3im05/social-network/tree/main/frontend/components"
click node_client "https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/api.js"
click node_webchat "https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/useChat.js"
click node_history "https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/useMessageHistory.js"
click node_websocketclient "https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/socket.js"
click node_webutils "https://github.com/mrshd3im05/social-network/tree/main/frontend/lib"
click node_server "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/server/server.go"
click node_middleware "https://github.com/mrshd3im05/social-network/tree/main/backend/internal/middleware"
click node_auth "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/service/authsvc/service.go"
click node_social "https://github.com/mrshd3im05/social-network/tree/main/backend/internal/handler/userhandler"
click node_posts "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/handler/posthandler/handler.go"
click node_groups "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/service/groupsvc/service.go"
click node_files "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/service/filesvc/service.go"
click node_chat "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/handler/messagehandler/handler.go"
click node_notifications "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/handler/notificationhandler/handler.go"
click node_services "https://github.com/mrshd3im05/social-network/tree/main/backend/internal/service"
click node_repositories "https://github.com/mrshd3im05/social-network/tree/main/backend/internal/repository"
click node_sqlite "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/db/sqlite/sqlite.go"
click node_hub "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/websocket/hub.go"
click node_publisher "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/websocket/publish.go"
click node_socket "https://github.com/mrshd3im05/social-network/blob/main/backend/internal/websocket/session.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pages,node_authpages,node_components,node_client,node_webchat,node_history,node_websocketclient,node_webutils,node_browser toneBlue
class node_server,node_middleware,node_auth,node_social,node_posts,node_groups,node_files,node_chat,node_notifications,node_services toneAmber
class node_hub,node_publisher,node_socket toneMint
class node_repositories,node_sqlite toneRose
```

## Components

### Web app

- [Social pages](https://github.com/mrshd3im05/social-network/tree/main/frontend/app/(main)): `frontend/app/(main)`
- [Login and registration](https://github.com/mrshd3im05/social-network/tree/main/frontend/app/(auth)): `frontend/app/(auth)`
- [Shared UI](https://github.com/mrshd3im05/social-network/tree/main/frontend/components): `frontend/components`
- [API client](https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/api.js): `frontend/lib/api.js`
- [Chat state](https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/useChat.js): `frontend/lib/useChat.js`
- [Message history](https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/useMessageHistory.js): `frontend/lib/useMessageHistory.js`
- [Socket client](https://github.com/mrshd3im05/social-network/blob/main/frontend/lib/socket.js): `frontend/lib/socket.js`
- [Frontend utilities](https://github.com/mrshd3im05/social-network/tree/main/frontend/lib): `frontend/lib`

### Social API

- [HTTP server and routes](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/server/server.go): `backend/internal/server/server.go`
- [Request middleware](https://github.com/mrshd3im05/social-network/tree/main/backend/internal/middleware): `backend/internal/middleware`
- [Sessions and identity](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/service/authsvc/service.go): `backend/internal/service/authsvc/service.go`
- [Profiles and follows](https://github.com/mrshd3im05/social-network/tree/main/backend/internal/handler/userhandler): `backend/internal/handler/userhandler`
- [Posts and interactions](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/handler/posthandler/handler.go): `backend/internal/handler/posthandler/handler.go`
- [Groups and events](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/service/groupsvc/service.go): `backend/internal/service/groupsvc/service.go`
- [Image files](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/service/filesvc/service.go): `backend/internal/service/filesvc/service.go`
- [Message handling](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/handler/messagehandler/handler.go): `backend/internal/handler/messagehandler/handler.go`
- [Notifications](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/handler/notificationhandler/handler.go): `backend/internal/handler/notificationhandler/handler.go`
- [Business services](https://github.com/mrshd3im05/social-network/tree/main/backend/internal/service): `backend/internal/service`

### Real-time

- [WebSocket hub](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/websocket/hub.go): `backend/internal/websocket/hub.go`
- [Live event publishing](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/websocket/publish.go): `backend/internal/websocket/publish.go`
- [WebSocket endpoint](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/websocket/session.go): `backend/internal/websocket/session.go`

### Persistence

- [SQL repositories](https://github.com/mrshd3im05/social-network/tree/main/backend/internal/repository): `backend/internal/repository`
- [SQLite database](https://github.com/mrshd3im05/social-network/blob/main/backend/internal/db/sqlite/sqlite.go): `backend/internal/db/sqlite/sqlite.go`

### Other components

- **Browser user**

## Connections

- Browser user → Social pages: uses
- Browser user → Login and registration: signs in
- Social pages → API client: requests data
- Social pages → Shared UI: presents features
- Chat state → Message history: loads history (evidence: `frontend/lib/useChat.js`)
- Message history → API client: fetches pages (evidence: `frontend/lib/useMessageHistory.js`)
- Chat state → API client: uploads messages (evidence: `frontend/lib/useChat.js`)
- Chat state → Socket client: sends and receives (evidence: `frontend/lib/useChat.js`)
- Socket client → API client: gets socket URL (evidence: `frontend/lib/socket.js`)
- Frontend utilities → API client: supports requests (evidence: `frontend/lib/useChat.js`)
- API client → HTTP server and routes: calls API
- HTTP server and routes → Request middleware: applies
- HTTP server and routes → Sessions and identity: routes auth
- HTTP server and routes → Profiles and follows: routes requests
- HTTP server and routes → Posts and interactions: routes requests
- HTTP server and routes → Groups and events: routes requests
- HTTP server and routes → Image files: routes requests
- HTTP server and routes → Message handling: routes requests
- HTTP server and routes → Notifications: routes requests
- Sessions and identity → Business services: implements rules
- Profiles and follows → Business services: applies rules
- Posts and interactions → Business services: applies rules
- Groups and events → Business services: applies rules
- Image files → Business services: applies rules
- Message handling → Business services: applies rules
- Notifications → Business services: applies rules
- Business services → SQL repositories: queries SQL
- SQL repositories → SQLite database: reads and writes
- Browser user → WebSocket endpoint: opens connection
- WebSocket endpoint → WebSocket hub: dispatches live events
- WebSocket hub → Live event publishing: publishes events
- Live event publishing → Socket client: pushes updates
