This is simple PoC design for Realtime account monitoring using Socket.io in Nodejs.
- User Authentication (email + pass)
- RBAC (user, admin)
- Twofactor Verification via email
- User dashboard
- all devices (logged in/out)
- logs (all previous activities)
- Device details
- Upgrade account to
admin
- Admin dashboard
- All Users
- All Activities (global)
- Access any account
- Realtime System
- realtime logs/activities
- for both local + global(admin level)
- Emails for each event
- IP blocking after 3 wrong attempts
- Admin can logout any user/device
- Easy deployment (Vercel + Dockerfile)
- Frontend
- NextJS (RTE + UI Framework)
- ChakraUI (UI Framework)
- socket.io-client (Socket connection)
- react-icons + iconsax
- Visitor API (device telemetry)
- Backend
- NodeJS (RTE)
- ExpressJS (Web Server)
- bcryptJS (Password hashing)
- jsonwebtoken (signing auth tokens)
- nodemailer (SMTP client for sending Emails)
- socket.io (socket server)
- zod (schema validation)
- redis (redis client)
- pg (postgres client)
- typeorm (Database ORM)
- envoix (Env management) [theanuragshukla/envoix]
- Docker + Docker compose (containerisation + deployment)
- Azure (Cloud VM)
- Database
- Postgres (Persistent User + device data)
- Redis (IP ban, OTPs, logs, events, pub/sub, etc)
REST API Routes (READ MORE ABOUT ROUTES)
- /auth - [
NO AUTH
]POST
/loginPOST
/registerPOST
/verifyGET
/profile
- /account - [
USER
+ADMIN
]GET
/recent-devicesGET
/recent-activitiesGET
/all-activitiesGET
/logout-device/:deviceIdGET
/device/:deviceIdGET
/upgrade
- /users - [
ADMIN
]GET
/allGET
/:uidDELETE
/:uid
- Server:
Socket.io
- Authentication: AuthToken via cookies (http-only)
- After User connects, If Authorised, gets added to their Unique room, where all their activities are broadcasted
- ADMIN can specify
forUID
inhandshake.query
, to join any users room or set it to admin for global events/logs - every activity is broadcasted to two rooms
- User' room (UID)
- Admin channel (global)
- Activities are added broadcasted by
REDIS CONSUMER
- Their are two redis instances running
- PUB: Publishes all activites to redisDB
- SUB: Consumes activities and takes actions accordingly
- Actions:
- OTP
- saves the users OPT for 2FA (Expire time: 10min)
- BAN
- Saves User's IP as banned (Expire time: 2hrs)
- LOG
- sends new logs through admin and user channels
- Service:
nodemailer
- Sends email to users
developed by Anurag Shukla