1

I have a Symfony project.

I want to make this project API based, but also with a Web UI.

So, I have 2 Bundles, ApplicationBundle and WebUiBundle.

In Application Bundle, I have application, domain and infrastructure (tiers?), where application has the public API (presentation layer).

Now, I need to access an API from the WebUiBundle, but not the public API for first-rendering, I want to make it internal.

What is the best approach for this?

Since I will have application, domain and infrastructure services, I thought about making an application service for each domain service I need. For example, Users service needs an interface and validations (domain), an implementation (infrastructure) and I then the Users Application Service, which would be nothing more than an API that is exposed internally. So the WebUiBundle only interacts with Application API.

What do you think?

4
  • 1
    What do you mean by "internal"? A private API? – Laiv May 30 '17 at 8:42
  • @Laiv I mean to have a WebUI that needs to reference the Application Services internally. (Not making REST calls for example). The WebUI bundle would have to be deployed with the backend Application. I guess that way there isn't any way to really decouple the WebUI but to make http request to localhost... – JorgeeFG May 30 '17 at 18:20
  • If I understood well. You want a public API (Rest) and a frontend. The frontend is going to be rendered at server side and it doesn't consume the public API (REST). Am I right? – Laiv May 30 '17 at 18:27
  • @Laiv yes that is. I don't want to use the public API for first render (because it is faster in server side) and then use the API with AJAX. But I still want to somehow make an internal API so that the REST uses the same API as the WebUI, so I don't have to duplicate code for example for getting all the users, or getting users that meet certain criteria. That is why I thought about an Application Service that is consumed by both the App Presentation Layer REST and the Presentation Layer Web UI. – JorgeeFG May 30 '17 at 19:15
1

Whatever you do keep the Domain layer pure, without any dependencies to other layers.

In Application Bundle, I have application, domain and infrastructure (tiers?), where application has the public API (presentation layer).

The Application layer is not the Presentation layer.

The Application layer exposes the use cases of your domain. It's a thin layer, with no business rules. In general there is only one layer of this type. In this layer you most probable have Application services (classes) that basically do this: load an Aggregate root from the Repository, calls a method on it and then it persists the changes to the Repository. Of course, it may have other responsibilities like authorization: for example here you check that if the user is an admin it can delete any Product.

The Presentation layer is the client of the Application layer. There could be more than one Presentation layer that uses the Application layer. The main responsibility of this layer is to gather the input from the user and call Application services - services that live in the Application layer. One other responsibility is to display the data to the user. Examples of Presentation layers: A MVC presentation layer, a REST endpoint.

Since I will have application, domain and infrastructure services, I thought about making an application service for each domain service I need

You should create an application service for each use case, not for every domain service. One note about domain services: be aware of the anemic domain model.

About the types of use of the Application layer: if you host the Presentation layer and the Application layer on the same server, for example if you have a MCV on top of the Application layer, then you can call the Application services directly from your Controller, like normal method calls. If you separate the frontend from the backend then you cannot call the application services directly but you can use a REST endpoint on top of the Application layer.

Now, I need to access an API from the WebUiBundle, but not the public API for first-rendering, I want to make it internal.

Application layer is always internal. It needs a Presentation layer to make it accessible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.