fan control with software
So far so good. You seem to be on the right track. I am assuming that you are able to send a data packet from your phone to esp module. For ex - You can send a value from 0 to 255 and use it to set the fan speed. 0 being OFF and 255 being ON at full speed. 

In your second image, the switch should be replaced with a mosfet which in turn will be switched on/off using a GPIO on esp module. Here is a standard mosfet circuit to get you started:



Pin will be connected to a GPIO on esp8266. You drive this pin HIGH, the fan turns ON, you drive the LOW, the fan turns OFF.

+VDD = whatever DC voltage is required for your fan (make sure your mosfet is able to handle the voltage. Also make sure you can drive the mosfet with a 3.3 V signal).

Once you have made the circuit, learn about PWM output on esp pins. To control the fan, the app sends a value to esp and esp sets a PWM duty cycle depending upon the value received.