I think the first thing you need to understand is the architecture of a module. You could watch the video that Seb and Darren put together a while back on building modules but I'll give a quick description here.
index.html - The homepage of your module. It contains all of the code to display the features of your module to the user. It also contains elements of AngularJS to bind controls to functions in your module.js file.
js/module.js - Includes an AngularJS controller with all necessary code to interface between index.html and module.php asynchronously.
api/module.php - Contains the server-side code that performs tasks when called by module.js.
In the case of building a web terminal it would be as simple as having a textarea in index.html with a javascript event that fires every time return is pressed. When the event fires it would call a function within module.js that extracts the last line of text from the data within the textarea (this can be a variable within your scope that is simply bound to the textarea). It then sends an AJAX request to module.php which takes the line, runs it through a function like shell_exec and returns the output to module.js. When it's received, your function in module.js appends the returned data to the scoped variable that's bound to your textarea and it automatically gets updated in the user interface.
Of course it would take a bit more work than this to make everything look exactly like a shell, and for it to be secure, but the basic functionality really is simple.