First the electric goes through ESP8266. The ESP8266 will control the relay to turn on or off the socket and also send and receive the data to server (we use Raspberry pi as a server).
In Raspberry pi, we use MySQL for database (We also install phpmyadmin for analysis the data) then use Node red to make the web app.
Setup a Raspberry Pi MYSQL Database
How to install Node-RED in Raspberry Pi
Code:
https://github.com/JoeyThirawat/IoT-Project-Smart-Plug
Collect and display the energy consuming of the plug.
Control the state of the socket.