# sanket9162/codershouse architecture

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

- Interactive diagram: https://gitdiagram.com/sanket9162/codershouse
- Repository: https://github.com/sanket9162/codershouse

## Overview

CodersHouse is a browser-based real-time audio-room platform. Users authenticate by phone OTP, receive JWT cookies, activate a profile, browse or create rooms, and join a room as speakers or listeners. The frontend’s room experience uses WebRTC for peer audio and Socket.IO for signalling; the backend exposes HTTP routes, validates protected requests, and persists users and rooms in MongoDB. The sampled sources substantiate the HTTP and WebRTC client flows; Socket.IO server internals and several frontend page implementations were not sampled, so their detailed wiring is shown only where documented.

Main entry points: [`backend/internal/handler/handler.go`](https://github.com/sanket9162/codershouse/blob/main/backend/internal/handler/handler.go) (API handlers), [`frontend/src/http/index.jsx`](https://github.com/sanket9162/codershouse/blob/main/frontend/src/http/index.jsx) (HTTP client), [`frontend/src/hooks/useLoadingWithRefresh.jsx`](https://github.com/sanket9162/codershouse/blob/main/frontend/src/hooks/useLoadingWithRefresh.jsx) (Session refresh), [`frontend/src/hooks/useWebRTC.jsx`](https://github.com/sanket9162/codershouse/blob/main/frontend/src/hooks/useWebRTC.jsx) (WebRTC hook)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web Client"]
  node_app["App routes<br/>[App.jsx]"]
  node_httpclient["HTTP client<br/>[index.jsx]"]
end

subgraph group_identity["Identity"]
  node_authui["Authentication UI<br/>[Authenticate.jsx]"]
  node_activateui["Profile activation<br/>[Activate.jsx]"]
  node_refresh["Session refresh"]
  node_authstate["Auth state<br/>[authSlice.jsx]"]
  node_authconfig["Token services<br/>[config.go]"]
  node_crypto["OTP encryption<br/>[encryption.go]"]
  node_image["Avatar storage<br/>[image.go]"]
end

subgraph group_rooms["Room Platform"]
  node_roomsui["Room browser<br/>[Rooms.jsx]"]
  node_roomui["Room view<br/>[Room.jsx]"]
  node_webrtc["WebRTC hook<br/>[useWebRTC.jsx]"]
  node_socketclient["Socket client<br/>[index.jsx]"]
  node_socketserver["Signalling server<br/>[socket.go]"]
end

subgraph group_server["Backend Services"]
  node_api["HTTP routes<br/>[routes.go]"]
  node_authmw["JWT middleware<br/>[auth.go]"]
  node_handler["API handlers<br/>[handler.go]"]
end

subgraph group_state["Persistence"]
  node_repo["Repository interface<br/>[repository.go]"]
  node_mongorepo["Mongo repository<br/>[mongo.go]"]
  node_mongodb[("MongoDB<br/>[db.go]")]
end

node_user(("User"))
node_peer(("Peer browser"))
node_media["WebRTC media"]
node_sms["SMS provider"]

node_user -->|"uses"| node_app
node_app -->|"checks session"| node_refresh
node_refresh -->|"requests refresh"| node_httpclient
node_refresh -->|"sets auth"| node_authstate
node_authui -->|"submits OTP"| node_httpclient
node_activateui -->|"activates profile"| node_httpclient
node_roomsui -->|"loads rooms"| node_httpclient
node_roomui -->|"starts audio"| node_webrtc
node_webrtc -->|"signals peers"| node_socketclient
node_webrtc -->|"captures audio"| node_media
node_socketclient -->|"exchanges events"| node_socketserver
node_httpclient -->|"sends requests"| node_api
node_api -->|"dispatches"| node_handler
node_api -->|"protects routes"| node_authmw
node_authmw -->|"passes identity"| node_handler
node_handler -->|"hashes OTP"| node_crypto
node_handler -->|"issues tokens"| node_authconfig
node_handler -->|"saves avatar"| node_image
node_handler -->|"reads and writes"| node_repo
node_repo -->|"implemented by"| node_mongorepo
node_mongorepo -->|"persists records"| node_mongodb
node_peer -->|"exchanges audio"| node_media
node_sms -.->|"optional OTP delivery"| node_handler

click node_app "https://github.com/sanket9162/codershouse/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Authenticate/Authenticate.jsx"
click node_activateui "https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Activate/Activate.jsx"
click node_roomsui "https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Rooms/Rooms.jsx"
click node_roomui "https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Room/Room.jsx"
click node_webrtc "https://github.com/sanket9162/codershouse/blob/main/frontend/src/hooks/useWebRTC.jsx"
click node_socketclient "https://github.com/sanket9162/codershouse/blob/main/frontend/src/socket/index.jsx"
click node_httpclient "https://github.com/sanket9162/codershouse/blob/main/frontend/src/http/index.jsx"
click node_refresh "https://github.com/sanket9162/codershouse/blob/main/frontend/src/hooks/useLoadingWithRefresh.jsx"
click node_authstate "https://github.com/sanket9162/codershouse/blob/main/frontend/src/store/authSlice.jsx"
click node_api "https://github.com/sanket9162/codershouse/blob/main/backend/cmd/api/routes.go"
click node_authmw "https://github.com/sanket9162/codershouse/blob/main/backend/internal/middleware/auth.go"
click node_handler "https://github.com/sanket9162/codershouse/blob/main/backend/internal/handler/handler.go"
click node_socketserver "https://github.com/sanket9162/codershouse/blob/main/backend/internal/socket/socket.go"
click node_authconfig "https://github.com/sanket9162/codershouse/blob/main/backend/internal/config/config.go"
click node_crypto "https://github.com/sanket9162/codershouse/blob/main/backend/internal/utils/encryption.go"
click node_image "https://github.com/sanket9162/codershouse/blob/main/backend/internal/utils/image.go"
click node_repo "https://github.com/sanket9162/codershouse/blob/main/backend/internal/repository/repository.go"
click node_mongorepo "https://github.com/sanket9162/codershouse/blob/main/backend/internal/repository/dbrepo/mongo.go"
click node_mongodb "https://github.com/sanket9162/codershouse/blob/main/backend/internal/database/db.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_app,node_httpclient,node_user,node_peer toneBlue
class node_authui,node_activateui,node_refresh,node_authstate,node_authconfig,node_crypto,node_image toneAmber
class node_roomsui,node_roomui,node_webrtc,node_socketclient,node_socketserver toneMint
class node_api,node_authmw,node_handler toneRose
class node_repo,node_mongorepo,node_mongodb,node_media,node_sms toneIndigo
```

## Components

### Web Client

- [App routes](https://github.com/sanket9162/codershouse/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [HTTP client](https://github.com/sanket9162/codershouse/blob/main/frontend/src/http/index.jsx): `frontend/src/http/index.jsx`

### Identity

- [Authentication UI](https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Authenticate/Authenticate.jsx): `frontend/src/pages/Authenticate/Authenticate.jsx`
- [Profile activation](https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Activate/Activate.jsx): `frontend/src/pages/Activate/Activate.jsx`
- [Session refresh](https://github.com/sanket9162/codershouse/blob/main/frontend/src/hooks/useLoadingWithRefresh.jsx): `frontend/src/hooks/useLoadingWithRefresh.jsx`
- [Auth state](https://github.com/sanket9162/codershouse/blob/main/frontend/src/store/authSlice.jsx): `frontend/src/store/authSlice.jsx`
- [Token services](https://github.com/sanket9162/codershouse/blob/main/backend/internal/config/config.go): `backend/internal/config/config.go`
- [OTP encryption](https://github.com/sanket9162/codershouse/blob/main/backend/internal/utils/encryption.go): `backend/internal/utils/encryption.go`
- [Avatar storage](https://github.com/sanket9162/codershouse/blob/main/backend/internal/utils/image.go): `backend/internal/utils/image.go`

### Room Platform

- [Room browser](https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Rooms/Rooms.jsx): `frontend/src/pages/Rooms/Rooms.jsx`
- [Room view](https://github.com/sanket9162/codershouse/blob/main/frontend/src/pages/Room/Room.jsx): `frontend/src/pages/Room/Room.jsx`
- [WebRTC hook](https://github.com/sanket9162/codershouse/blob/main/frontend/src/hooks/useWebRTC.jsx): `frontend/src/hooks/useWebRTC.jsx`
- [Socket client](https://github.com/sanket9162/codershouse/blob/main/frontend/src/socket/index.jsx): `frontend/src/socket/index.jsx`
- [Signalling server](https://github.com/sanket9162/codershouse/blob/main/backend/internal/socket/socket.go): `backend/internal/socket/socket.go`

### Backend Services

- [HTTP routes](https://github.com/sanket9162/codershouse/blob/main/backend/cmd/api/routes.go): `backend/cmd/api/routes.go`
- [JWT middleware](https://github.com/sanket9162/codershouse/blob/main/backend/internal/middleware/auth.go): `backend/internal/middleware/auth.go`
- [API handlers](https://github.com/sanket9162/codershouse/blob/main/backend/internal/handler/handler.go): `backend/internal/handler/handler.go`

### Persistence

- [Repository interface](https://github.com/sanket9162/codershouse/blob/main/backend/internal/repository/repository.go): `backend/internal/repository/repository.go`
- [Mongo repository](https://github.com/sanket9162/codershouse/blob/main/backend/internal/repository/dbrepo/mongo.go): `backend/internal/repository/dbrepo/mongo.go`
- [MongoDB](https://github.com/sanket9162/codershouse/blob/main/backend/internal/database/db.go): `backend/internal/database/db.go`

### Other components

- **User**
- **Peer browser**
- **WebRTC media**
- **SMS provider**

## Connections

- User → App routes: uses
- App routes → Session refresh: checks session
- Session refresh → HTTP client: requests refresh
- Session refresh → Auth state: sets auth
- Authentication UI → HTTP client: submits OTP
- Profile activation → HTTP client: activates profile
- Room browser → HTTP client: loads rooms
- Room view → WebRTC hook: starts audio
- WebRTC hook → Socket client: signals peers
- WebRTC hook → WebRTC media: captures audio
- Socket client → Signalling server: exchanges events
- HTTP client → HTTP routes: sends requests
- HTTP routes → API handlers: dispatches
- HTTP routes → JWT middleware: protects routes
- JWT middleware → API handlers: passes identity
- API handlers → OTP encryption: hashes OTP
- API handlers → Token services: issues tokens
- API handlers → Avatar storage: saves avatar
- API handlers → Repository interface: reads and writes
- Repository interface → Mongo repository: implemented by
- Mongo repository → MongoDB: persists records
- Peer browser → WebRTC media: exchanges audio
- SMS provider → API handlers: optional OTP delivery
