Professional Documents
Culture Documents
Implementing AppAsap TRPC REST Integration-14 2
Implementing AppAsap TRPC REST Integration-14 2
1 Abstract 3 Rules
This section sets a guideline to follow so that we know
This document describes a stage one implementation what is the scope of the side effects that this imple-
of integrating generic RESTful API generation func- mentation will have on the existing code base. Rules
tionality into the already existing tRPC API genera- include the following:
tion, this is part of sprint 6 with an estimated time
span of (7/23 - 8/5), this should describe the approach
taken to achieve that. I will talk about the rules that 3.1 Isolation
I’ve set for the implementation design, then describe
the steps needed to finish that implementation. I will The REST generation implementation should and will
also try to constructively criticize the implementation be isolated from the tRPC implementation, so if there
by mainly talking about the disadvantages and the exist any breaking changes after the merge, we most
things that can possibly go bad using this implemen- likely know that this happens on the REST generation
tation and finally talk in general about operations we and not on generating a tRPC API, because integrat-
can perform on the output API like automatic CI/CD, ing REST didn’t introduce any breaking changes to
deployment options, scalability, etc... the stable tRPC generation process.
1
4.2.1 Controller Template
I will provide an example output of the controller tem-
plate for a single resource and you should understand
the pattern, on the left is an example output for the
user resource, it uses the createCRUDRouter()
helper function, helpers are a topic on themselves and
I will talk about them later in the document, but the
main idea is. any output backend (the API part) will
be divided into two folders entities and helpers, en-
tities contain generated code and each entity should
be divided into three components controller, service,
and validator, but helpers doesn’t contain generated
code, these are (at least in development environment)
injected at generation-time, also as a note, a REST
Figure 1: Controller Template Example Output API helpers won’t be the same as the helpers from a
tRPC API but might reuse some of it.
Referencing the pickle repository, we should try to The service template is simple, this is an example of
adapt the templates implemented there and move it the output code related to a user resources:
to the appasap-beta codebase, the template we are
interested in the most is the template containing the
swagger jsdocs, we might also transfer the template
containing the code for the entry point to the server
(the code initializing the express server) if it doesn’t
need many changes, otherwise, we can rewrite it to fit
our needs. We are not interested in the Prisma schema
template because it’s not relevant to us anymore, it
was just adding a datasource and a generator defini-
tions to the Prisma schema, but we already have these
definitions in the input Prisma schema when dealing
with the appasap-beta code base.
Figure 2: Service Template Example Output
4.2 Adapting Templates In contrast, the service template uses another helper
called crudService(), which automatically provides
After transferring the relevant templates we will most business logic for Create-Read-Update-Delete to all
likely need to change things including but not limited entities generated, it can also be extended by adding
to the following: custom business logic
• Naming.
4.2.3 Validation
• Import paths inside the templates. This document won’t go over templates or code related
to validation, or how to adapt the current validation
• Optionally add meaningful JSDocs comments. layer implementation to fit the RESTful API, this is
done for simplicity and because I need more research
This will make these templates usable inside the on this and need to study more possible scenarios be-
appasap-beta code base. fore I am able to settle on the details.
2
4.3 Helpers 5 Standard
At this point, we have templates capable of generat- This section talks about assumptions in the implemen-
ing an extendable CRUD controller and an extend- tation, the front-end client should take these assump-
able CRUD service/business logic that the controller tions into consideration for a working predictable re-
will use, each entity will get its own (controller, ser- quest life-cycle.
vice) pair. But looking at the templates’ code above,
we see that the implementation is abstracted and pro-
vided via the helper functions, namely, the create- 5.1
CRUDRouter() for the controller implementation
and crudService() for the service implementation. It 6 Improvements
is not important to show the code of these functions,
In this section, I will talk about the things that I don’t
it is important to understand the idea that the entities
necessarily like about this implementation and that
will use helpers to implement most of their function-
have gaps for improvement.
ality and that entities are generated but helpers will
most likely be pre-written and injected. These are the
current helpers for tRPC APIs: 6.1 Extension
We should be improving the way we extend the output
• auth
controller and service, I would prefer a more structured
• cache way of handling that and not to leave things very flex-
ible, at this point, we write customRoutes in the same
• configs file as the controller entity which isn’t very scalable,
• cryptography so this probably needs to change.
• mail
6.3 More
• monitoring
This is currently the end of the document, I will add
• payments more as I go deeper through the integration process.
• server
• types