# sachin1880/homesmartcctv architecture

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

- Interactive diagram: https://gitdiagram.com/sachin1880/homesmartcctv
- Repository: https://github.com/sachin1880/homesmartcctv

## Overview

Smart Home Camera pairs an old phone in Camera Device mode with a current phone in Viewer mode; the FastAPI backend manages accounts, device state, events, and WebRTC signaling, while live media travels peer-to-peer. The main flow is role selection and authentication, camera registration and heartbeats, viewer monitoring, then signaling negotiation and direct streaming. The README also documents event history and retained capture/video features. Edges rely on the supplied README and source index; unsampled implementation details are represented only where the documented capability supports them.

Main entry points: [`backend/app/api/routes/devices.py`](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/api/routes/devices.py) (API routes), [`mobile/App.tsx`](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/App.tsx) (App navigation), [`backend/app/main.py`](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/models/camera_device.py`](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/models/camera_device.py) (Device and event records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile app"]
  node_app["App navigation<br/>[App.tsx]"]
  node_auth_screens["Sign-in and roles<br/>[LoginScreen.tsx]"]
  node_camera_ui["Camera controls"]
  node_viewer_ui["Viewer dashboard"]
  node_history_ui["Event history"]
  node_recording_ui["Video browsing"]
  node_mobile_api["REST client<br/>[client.ts]"]
  node_device_api["Device API<br/>[devices.ts]"]
  node_auth_store[("Auth storage<br/>[authStorage.ts]")]
end

subgraph group_backend["Backend API"]
  node_api_app["FastAPI application<br/>[main.py]"]
  node_routes["API routes<br/>[devices.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
  node_status_service["Heartbeat status<br/>[device_status.py]"]
  node_signaling_service["Signaling relay<br/>[signaling.py]"]
  node_capture_service["Capture retention<br/>[captures.py]"]
  node_video_service["Video retention<br/>[videos.py]"]
end

subgraph group_state["Persistence and media"]
  node_db_session["Database session<br/>[session.py]"]
  node_device_models[("Device and event records<br/>[camera_device.py]")]
  node_user_model[("User records<br/>[user.py]")]
end

subgraph group_realtime["Realtime streaming"]
  node_camera_peer["Camera peer hook"]
  node_viewer_peer["Viewer peer hook"]
  node_signaling_client["Signaling client<br/>[signalingClient.ts]"]
  node_direct_media(("Peer media stream"))
end

node_user(("Camera owner"))
node_postgres[("PostgreSQL")]

node_user -->|"uses"| node_app
node_app -->|"navigates"| node_auth_screens
node_app -->|"navigates"| node_camera_ui
node_app -->|"navigates"| node_viewer_ui
node_app -->|"navigates"| node_history_ui
node_app -->|"navigates"| node_recording_ui
node_auth_screens -.->|"requests"| node_mobile_api
node_mobile_api -->|"reads token"| node_auth_store
node_camera_ui -->|"controls device"| node_device_api
node_viewer_ui -.->|"loads devices"| node_device_api
node_history_ui -.->|"loads events"| node_device_api
node_mobile_api -->|"REST requests"| node_api_app
node_api_app -->|"routes requests"| node_routes
node_api_app -->|"cleans expired media"| node_db_session
node_auth_routes -->|"reads and writes"| node_user_model
node_auth_routes -->|"uses session"| node_db_session
node_routes -->|"uses session"| node_db_session
node_routes -->|"manages devices"| node_device_models
node_routes -->|"updates status"| node_status_service
node_routes -->|"delegates signaling"| node_signaling_service
node_routes -->|"uses captures"| node_capture_service
node_routes -->|"uses videos"| node_video_service
node_status_service -->|"updates records"| node_device_models
node_db_session -->|"connects"| node_postgres
node_device_models -.->|"persists state"| node_postgres
node_user_model -.->|"persists accounts"| node_postgres
node_camera_ui -->|"starts camera"| node_camera_peer
node_viewer_ui -.->|"opens live view"| node_viewer_peer
node_camera_peer -->|"exchanges messages"| node_signaling_client
node_viewer_peer -->|"exchanges messages"| node_signaling_client
node_signaling_client -->|"opens WebSocket"| node_api_app
node_api_app -->|"handles signaling"| node_signaling_service
node_signaling_service -.->|"relays signaling"| node_camera_peer
node_signaling_service -.->|"relays signaling"| node_viewer_peer
node_camera_peer -->|"streams media"| node_direct_media
node_viewer_peer -->|"receives media"| node_direct_media
node_capture_service -.->|"retains capture records"| node_device_models
node_video_service -.->|"retains video records"| node_device_models

click node_app "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/App.tsx"
click node_auth_screens "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/LoginScreen.tsx"
click node_camera_ui "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/CameraDeviceScreen.tsx"
click node_viewer_ui "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/ViewerDashboardScreen.tsx"
click node_history_ui "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/EventHistoryScreen.tsx"
click node_recording_ui "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/VideoPlaylistScreen.tsx"
click node_mobile_api "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/api/client.ts"
click node_device_api "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/api/devices.ts"
click node_auth_store "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/storage/authStorage.ts"
click node_camera_peer "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/webrtc/useCameraPeerConnection.ts"
click node_viewer_peer "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/webrtc/useViewerPeerConnection.ts"
click node_signaling_client "https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/webrtc/signalingClient.ts"
click node_api_app "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/main.py"
click node_routes "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/api/routes/devices.py"
click node_auth_routes "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/api/routes/auth.py"
click node_status_service "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/device_status.py"
click node_signaling_service "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/signaling.py"
click node_capture_service "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/captures.py"
click node_video_service "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/videos.py"
click node_db_session "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/db/session.py"
click node_device_models "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/models/camera_device.py"
click node_user_model "https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/models/user.py"

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_auth_screens,node_camera_ui,node_viewer_ui,node_history_ui,node_recording_ui,node_mobile_api,node_device_api,node_auth_store toneBlue
class node_api_app,node_routes,node_auth_routes,node_status_service,node_signaling_service,node_capture_service,node_video_service,node_postgres toneAmber
class node_db_session,node_device_models,node_user_model toneMint
class node_camera_peer,node_viewer_peer,node_signaling_client,node_direct_media toneRose
class node_user toneIndigo
```

## Components

### Mobile app

- [App navigation](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/App.tsx): `mobile/App.tsx`
- [Sign-in and roles](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/LoginScreen.tsx): `mobile/src/screens/LoginScreen.tsx`
- [Camera controls](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/CameraDeviceScreen.tsx): `mobile/src/screens/CameraDeviceScreen.tsx`
- [Viewer dashboard](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/ViewerDashboardScreen.tsx): `mobile/src/screens/ViewerDashboardScreen.tsx`
- [Event history](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/EventHistoryScreen.tsx): `mobile/src/screens/EventHistoryScreen.tsx`
- [Video browsing](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/screens/VideoPlaylistScreen.tsx): `mobile/src/screens/VideoPlaylistScreen.tsx`
- [REST client](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/api/client.ts): `mobile/src/api/client.ts`
- [Device API](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/api/devices.ts): `mobile/src/api/devices.ts`
- [Auth storage](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/storage/authStorage.ts): `mobile/src/storage/authStorage.ts`

### Backend API

- [FastAPI application](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/main.py): `backend/app/main.py`
- [API routes](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/api/routes/devices.py): `backend/app/api/routes/devices.py`
- [Authentication routes](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/api/routes/auth.py): `backend/app/api/routes/auth.py`
- [Heartbeat status](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/device_status.py): `backend/app/services/device_status.py`
- [Signaling relay](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/signaling.py): `backend/app/services/signaling.py`
- [Capture retention](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/captures.py): `backend/app/services/captures.py`
- [Video retention](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/services/videos.py): `backend/app/services/videos.py`

### Persistence and media

- [Database session](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/db/session.py): `backend/app/db/session.py`
- [Device and event records](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/models/camera_device.py): `backend/app/models/camera_device.py`
- [User records](https://github.com/sachin1880/homesmartcctv/blob/main/backend/app/models/user.py): `backend/app/models/user.py`

### Realtime streaming

- [Camera peer hook](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/webrtc/useCameraPeerConnection.ts): `mobile/src/webrtc/useCameraPeerConnection.ts`
- [Viewer peer hook](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/webrtc/useViewerPeerConnection.ts): `mobile/src/webrtc/useViewerPeerConnection.ts`
- [Signaling client](https://github.com/sachin1880/homesmartcctv/blob/main/mobile/src/webrtc/signalingClient.ts): `mobile/src/webrtc/signalingClient.ts`
- **Peer media stream**

### Other components

- **Camera owner**
- **PostgreSQL**

## Connections

- Camera owner → App navigation: uses (evidence: `mobile/App.tsx`)
- App navigation → Sign-in and roles: navigates (evidence: `mobile/App.tsx`)
- App navigation → Camera controls: navigates (evidence: `mobile/App.tsx`)
- App navigation → Viewer dashboard: navigates (evidence: `mobile/App.tsx`)
- App navigation → Event history: navigates (evidence: `mobile/App.tsx`)
- App navigation → Video browsing: navigates (evidence: `mobile/App.tsx`)
- Sign-in and roles → REST client: requests
- REST client → Auth storage: reads token (evidence: `mobile/src/api/client.ts`)
- Camera controls → Device API: controls device (evidence: `mobile/src/screens/CameraDeviceScreen.tsx`)
- Viewer dashboard → Device API: loads devices
- Event history → Device API: loads events
- REST client → FastAPI application: REST requests (evidence: `README.md`)
- FastAPI application → API routes: routes requests
- FastAPI application → Database session: cleans expired media (evidence: `backend/app/main.py`)
- Authentication routes → User records: reads and writes (evidence: `backend/app/api/routes/auth.py`)
- Authentication routes → Database session: uses session (evidence: `backend/app/api/routes/auth.py`)
- API routes → Database session: uses session (evidence: `backend/app/api/routes/devices.py`)
- API routes → Device and event records: manages devices (evidence: `backend/app/api/routes/devices.py`)
- API routes → Heartbeat status: updates status (evidence: `backend/app/api/routes/devices.py`)
- API routes → Signaling relay: delegates signaling (evidence: `backend/app/api/routes/devices.py`)
- API routes → Capture retention: uses captures (evidence: `backend/app/api/routes/devices.py`)
- API routes → Video retention: uses videos (evidence: `backend/app/api/routes/devices.py`)
- Heartbeat status → Device and event records: updates records (evidence: `backend/app/services/device_status.py`)
- Database session → PostgreSQL: connects (evidence: `backend/app/db/session.py`)
- Device and event records → PostgreSQL: persists state
- User records → PostgreSQL: persists accounts
- Camera controls → Camera peer hook: starts camera (evidence: `mobile/src/screens/CameraDeviceScreen.tsx`)
- Viewer dashboard → Viewer peer hook: opens live view
- Camera peer hook → Signaling client: exchanges messages (evidence: `mobile/src/webrtc/useCameraPeerConnection.ts`)
- Viewer peer hook → Signaling client: exchanges messages (evidence: `mobile/src/webrtc/useViewerPeerConnection.ts`)
- Signaling client → FastAPI application: opens WebSocket (evidence: `mobile/src/webrtc/signalingClient.ts`)
- FastAPI application → Signaling relay: handles signaling
- Signaling relay → Camera peer hook: relays signaling (evidence: `README.md`)
- Signaling relay → Viewer peer hook: relays signaling (evidence: `README.md`)
- Camera peer hook → Peer media stream: streams media (evidence: `README.md`)
- Viewer peer hook → Peer media stream: receives media (evidence: `README.md`)
- Capture retention → Device and event records: retains capture records
- Video retention → Device and event records: retains video records
