Professional Documents
Culture Documents
Client-Server Architecture
“Client-Server” is a distributed application structure in which tasks and jobs
are divided between resource or service providers called “Server” and resource or
service consumers call “Client”. Client and server communicate with each other
through computer networks on separate hardware or on the same system. The
clients normally share nothing with the server, they request resources from the
server. So that, they will set up the session to communicate with the server,
meanwhile, the server will be kept alive to wait for requests, handle them and
respond to the clients.
Clients and Servers “talk” to each other via messages, the messages coming
from the Client to Server are requests, the ones coming from Server for answering
those requests to the Client are responses through an Inter-process Communication
(IPC) and the messages must be in a standard called “Protocol”. Nowadays, in the
Application Layer in TCP/IP Model, there are many choices to choose protocols
for the app such as HTTP, MQTT, AMQP, FTP, SMTP and so on, however, HTTP
is the most popular one for developing a web application, the others still have their
own strengths but they will be used in some special cases (FTP is used for file
transfer, SMTP is used for sending emails,…).
The client will be responsible for providing the user interface (UI) and user
experience (UX) to the end-user, sending and receiving the message from the
server and presenting the data contained in the messages in an appropriate method.
The server will be responsible for receiving the message from clients,
handling them and sending the result back to the clients.
I.2. Model – View – Service – Controller (MVSC) Design Pattern
Mechanism
- The model is responsible for managing the data of the application. It
receives user input from the controller, queries into the database to get
suitable records or performs data transformations (create, update or delete
records) and returns to the controllers.
- The view renders the presentation of the data received from the service in a
particular format.
- The controller responds to the user input from services, performs
interactions on the data model objects, collects the records returned by
models and handles the logic interaction with those data before passing them
to services. The controller receives the input, optionally validates it and then
passes the input to the model.
- The service is responsible to transfer the user inputs from views, direct them
to the right function in the controller and return the result from them.
As with other software patterns, MVC expresses the "core of the solution" to a
problem while allowing it to be adapted for each system.[17] Particular MVC
designs can vary significantly from the traditional description here.
I.3. PostgreSQL
PostgreSQL is one of the most advanced, free and open source object-relational
database management system (RDBMS) available. It is high scalability and
compliance with technical standards, designed to handle a wide range of
workloads, from personal computers to data warehouses or Web services with
many concurrent users.
- Developed by PostgreSQL Global Development Group, First Released:
08/07/1996.
- Flexible and can be run on a variety of platforms such as Mac OS X, Solaris,
and Windows.
- Free and open source software so PostgreSQL can be used, modified, and
disseminated by anyone for any purpose.
- Highly stable.
Features
PostgreSQL integrates many great features to help developers build apps that
respond to complex functions, query quickly, and securely maintain integrity and
reliability. To be more reliable, It also provides various security, authentication,
and disaster recovery options. PostgreSQL has proven to be highly scalable both in
terms of the amount of data and the number of concurrent users.
- Complex query (complex query)
- Event procedures (triggers)
- Views
- Integrity transactions
- Multi-version concurrency control
- Parallel query (parallel query)
- Streaming replication
Datatypes
- Primitives: Integer, Number, String, Boolean
- Structure: Date/Time, Array, Range, UUID.
- Document: JSON/JSONB, XML, Key-value
Data integrity
- UNIQUE, NOT NULL
- Primary Keys
- Foreign Keys
- Exclusion constraints
- Function Lock, Recommended Lock
- Concurrent, efficiency
- Cataloging: B-tree, Multicolumn, Expressions, Partial
- …
Security
- Authentication: GSSAPI, SSPI, LDAP, SCRAM-SHA-256, Certificate and
others
- Powerful access control system
- Column and row level security
Ability of extension
- Storage method
- Procedural Languages: PL/PGSQL, Perl, Python (and many more)
- External data wrapper: connect to other databases or streams with standard
SQL interface
- And many extensions provide additional functionality, including PostGIS
- Text search:
- Support for international character sets, e.g. through ICU collations
- Full-text search
I.4. Typescript and NodeJS
I.4.1. Typescript
TypeScript is a programming language developed and maintained by Microsoft.
It is built on JavaScript
TypeScript may be used to develop JavaScript applications for both
client or server execution (as with Node.js). The default TypeScript Compiler can
be used or the Babel compiler can be invoked to convert TypeScript to JavaScript.
TypeScript offers all of JavaScript’s features and an additional layer on top
of these: TypeScript’s type system. This means that your existing working
JavaScript code is also TypeScript code. The main benefit of TypeScript is that it
can highlight unexpected behavior in your code, lowering the chance of bugs.
I.4.2. NodeJS
Node.js is a free, open-source server environment and runs on various
platforms (Windows, Linux, Unix, Mac OS X,…). It uses asynchronous
programming, eliminates the waiting, and simply continues with the next request.
It also runs single-threaded, non-blocking, which is very memory efficient.
- Nodejs generate many dynamic page content
- Node.js can create, open, read, write, delete, and close files on the server
- Node.js can collect form data
- Node.js can add, delete, and modify data in your database
- Node.js can do anything that a server app needs to do.
I.4.3. Knex JS and Objection JS
Knex.js is a. SQL query builder for PostgreSQL, MSSQL, MySQL,
MariaDB, SQLite3, Better-SQLite3, Oracle and Amazon Redshift designed to be
flexible, and portable to use.
It features both traditional node style callbacks as well as a “Promise” interface for
cleaner async flow control, a stream interface, full–featured query and schema
builders, transaction support (with save points), connection pooling and
standardized responses between different query clients.
Objection.js is Object-relational programming (ORM) for Node.js that aims
to stay out of your way and make it as easy as possible to use the full power of
SQL and the underlying database engine while still making the common stuff easy
and enjoyable. Objection.js is built on an SQL query builder called Knex.js. All
databases supported by Knex are supported by Objection.js. SQLite3, Postgres and
MySQL are thoroughly tested.
I.4.4. Express JS
Express.js is a framework built on top of Nodejs. It provides powerful
features for web or mobile development. Express.js supports HTTP and
middleware methods creating an ie API.
Features:
- Set up intermediate classes to return HTTP requests.
- Define router allows use with different actions based on HTTP method and
URL.
- Allows returning HTML pages based on parameters.
Routings:
Routing refers to determining how an application responds to a client request
to a particular endpoint, which is a URI (or path) and a specific HTTP request
method (GET, POST, and so on).
Each route can have one or more handler functions, which are executed
when the route is matched.
Defining routing using methods of the Express app object that correspond to
HTTP methods; for example, app.get() to handle GET requests and app.post to
handle POST requests. For a full list, see app.METHOD.
These routing methods specify a callback function (sometimes called
“handler functions”) called when the application receives a request to the specified
route (endpoint) and HTTP method. In other words, the application “listens” for
requests that match the specified route(s) and method(s), and when it detects a
match, it calls the specified callback function.
Middlewares
Middleware functions are functions that have access to the request object
(req), the response object (res), and the next function in the application’s request-
response cycle. The next function is a function in the Express router which, when
invoked, executes the middleware succeeding the current middleware.
Docker Compose is a tool used to define and run Docker programs that use
multi-containers. With Docker Compose, we use a YAML file to set up the
necessary services for the program. Finally, with one command, we will create and
start all services from those settings.
Using Compose typically involves the following three steps:
- Declare the program's environments in the Dockerfile.
- Declare the necessary services for the program in the docker-compose.yml
file so that the services can run together in an environment.
- Run the docker-compose up command to start Compose and run the
program.
Docker Compose has commands that allow to manage your program's lifecycle:
- Start, Stop and Rebuild the service.
- View the status of running services.
- View the log output of the running service.
I.6. Nginx
NGINX is open source software for web serving, reverse proxying, caching, load
balancing, media streaming, and more. It started out as a web server designed for
maximum performance and stability. In addition to its HTTP server capabilities,
NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP)
and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.