N-Tier Architecture
Elements uses the N-Tier Architecture style with three layers, including the Presentation Layer, Service Layer, and DAO Layer.
Internally, Elements uses an N-tier architecture style consisting of three layers.
The Presentation Layer is a thinly defined layer of abstraction over the underlying Service Layer. RESTful APIs provide a translation between the Service layer and the Presentation layer. JSON-RPC APIs (experimental) are essentially calling service layer methods directly. The endpoint code simply unpacks the requests and translates that to the Service layer. The Presentation layer does nothing to enforce security.
The Service Layer (also sometimes called the Logic Layer) houses all the business logic of the system. This layer exists with multiple implementations of each service. All APIs labeled "service" (e.g. -
namazu.elements.service.smartcontract.evm
) will always consider the context of the user making the request. In some cases, the Service layer implementation is configured to do nothing but throw exceptions.The DAO Layer (also sometimes called the Data Layer) is the layer that provides access to the database through layers of abstraction. All APIs labeled "dao" (e.g. -
namazu.elements.dao.user
) are part of the DAO layer.
Presentation Layer
The presentation layer is the layer closet to the client code. In the context of Elements, this is the Resource handling the cloud function invocation. Internally, Elements uses JAX-RS annotated methods at the presentation layer.
Service Layer
The Service Layer houses the logic of the application. Each Service is a common interface through which client code makes calls. Depending on User Acccess Level, Elements will use a different implementation of the Service. Most services honor user access level. However, as the developer of the application, you should not worry about these details. When using the Scripting engine, invoking service layer code will typically enforce the appropriate permissions.
If a Service is not available for a particular access level, the Service will throw the appropriate exception indicating that the permission check failed.
Scoped Services
A service that specifically honors User Access Levels is said to be scoped, which means it may have a reference to the currently logged-in user when processing the request. Useful information may be inferred from this scoping.
Unscoped Services
A service that does not honor User Access Levels is said to be unscoped, meaning it will not have any reference to the currently logged-in user. Typically, unscoped services provide super-user access to the system. Alternatively, they may provide information that is available to all users without restriction.
When writing cloud functions, you should handle the service layer with care because it is unscoped and super-user access is provided.
DAO Layer
The data layer has no user scope, and therefore provides unrestricted access to the database. The Data Layer abstracts the database details. The Data Layer performs operations such as querying, inserting, updating, and deleting.
As with unscoped services, Data Layer code provides raw access to the database without regard for any scoping rules. Therefore, special care must be taken to make use of this.
Last updated