Full-stack development is about developing all parts of the application by using a single framework. It includes back-end which belongs to the database, middleware where the application logic and control reside and the last but not the least part is the user interface.
The big advantage of the full-stack framework is that it has a holistic approach that looks at the system as a whole with all its components that exist on their own. In order to function together as the whole the system components have some interdependencies that need to be considered as well. These interdependences should be minimized in order to properly support decoupling between the system components which is one of the most important aspects of the overall architecture of the system.
The framework is modular what means if tomorrow some of the components become obsolete it can be replaced with the new component. It would require some changes with some of the dependable components but they should be minimal.
The full-stack approach gives you better overall control since it helps the different parts work seamlessly together since they are built by a single developer or a small team of developers. This also supports microservices way of service design and implementation especially for systems that change frequently and/or have to be web scalable. The disposable services are the way to go in these kind of environments.
If you are interested in additional details about the MEAN architectural patterns, Getting MEAN with Mongo, Express, Angular and Node book authored by Simon Holmes is a good source of information.
There are two types of MEAN applications:
- Server Applications
- Single Page Applications (SPA)
MEAN includes five main technologies:
- MongoDB database and Mongoose object data modeling (ODM) tool
- Express middleware
- AngularJS front-end
- Node.js server platform
MongoDB is a NoSQL document-based database management system which data model includes:
A Collection is a top model element. Each model can have one or more collections. Collections are analogous to tables in a relational database. Each collection contains documents that are analogous to records in the relational database. Collections model one or more concepts (e.g., account, user, order, publisher, book, etc.) the data is based on.
Documents are JSON-like data structures containing fields that have values of different types (e.g., String, Date, Number, Boolean, etc.). A value can also belong to another document or an array of documents embedded in a document. Documents can have different structures in a collection. However, in most cases in practice, collections are highly homogeneous.
Fields are analogous to columns in the relational database. The field/value pairs (better known as key/value pairs) construct document’s structure.
MongoDB resolves relationships between documents by either embedding related documents or referencing related documents.
Mongoose is a MongoDB object data modeling (ODM) tool designed to work in an asynchronous environment. Besides the data modeling in Node.js, Mongoose also provides a layer of CRUD features on top of MongoDB. It also makes it easier to manage connections to MongoDB databases and perform data validations.
Express is a middleware framework for Node.js that abstracts away some common web server functionalities. Some of these functionalities include session management, routing, templating, and others.
The web server running on Node.js is different from traditional multi-threaded web servers (e.g., Apache, IIS, etc.). The multi-threaded servers create new thread for each new user session and allocates memory and other computing resources for it. During the peak periods when many users access the server concurrently its resources can get exhausted in which case the system could halt its operations until the load decreases and/or more machines and resources are added. The precocious approach that many systems take is to often overpower the servers even if they do not need so much resources most of the time. This definitely increases the cost of system operations. When Node.js is used, rather than giving each user a separate thread and pool of resources, each user joins the same thread and the interaction between the user and thread exist only when it is needed. In order to ensure that this approach works Node.js supports non-blocking by making blocking operations run asynchronously.
While you can use Node.js, Express and MongoDB to build data-driven applications, the use of AngularJS will bring more sophisticated features to the interactivity element of the MVC architectural pattern supported by MEAN. AngularJS puts HTML together based on provided data. It also supports two-way data binding by immediately updating the HTML based on changed data and also by updating the data if HTML changes.
MEAN Architectural Patterns
When you create MEAN-based applications, you can choose any of the architectural patterns or a combination of the architectural patterns (hybrid architectural patterns) listed here.
MEAN architectural patterns are based on the Model-View-Controller (MVC) pattern.
The MVC pattern is data oriented. Model holds data, Controller processes data and view renders data. There is also a route component between the controller and users’ browsers (Web). The route component coordinates interactions with the controller.
A common way to architect MEAN stack is to have a REST interface feeding a single page application (SPA). REST interface is implemented via REST API that is built with MongoDB, Node.js and Express and SPA is built with AngularJS that runs in browser.
REST API creates a stateless interface to your database. It enables other applications to work with your data. There is also one more important technology component, Mongoose, that is a liaison between the controller and MongoDB.
MongoDB communicates with Mongoose only. Mongoose communicates with Node.js and Express and AngularJS communicates with Express only.
The REST API is a common architectural element used in all MEAN architectural patterns.
- Node.js and Express application with AngularJS addition for better interactivity (NEA2)
- AngularJS Single Page Application (SPA)
- Hybrid Patterns:
- NEA and SPA
- NEA2 and SPA
Node.js and Express application (NEA)
HTML and content are directly delivered from the server. The HTML content requires data that is delivered via REST API. REST API is developed with Node.js, Express, Mongoose and MongoDB.
Node.js and Express Application with AngularJS Addition for Better Interactivity (NEA2)
If you need a richer interactive experience for your users, you can add AngularJS to your pages.
AngularJS Single Page Application (SPA)
In order to implement Single Page Applications, AngularJS is needed.
The three above listed architectural patterns can also be combined into hybrid architectural patterns. The two most common combinations are:
- NEA and SPA
- NEA2 and SPA
NEA and SPA
This pattern is for the applications that require combination of application constraints that are best supported by both NEA and SPA. For example, NEA best supported application constraints include: short duration of user interactions, low interactions, content rich, etc. SPA best supported application constraints include: feature-rich, highly interactive, long duration of user interactions, private, fast response, etc..
NEA2 and SPA
Finally, NEA2 and SPA is like NEA and SPA with a bit richer interactivity on the server side (NEA2) via AngularJS addition.