Multiple architectures in project?
Unanswered
Pip gall wasp posted this in #help-forum
Pip gall waspOP
So I have a very hard time figuring out what my architecture is for a project.
I have two nextjs applications that are mainly based on server actions only, to perform actions and mutate data, like updating something in the database. From my understanding, this is the structure for a monolithic application.
However, the first application has some REST API endpoints defined that the second app will consume to retrieve some data. This makes me go for a REST architecture.
But these applications are deployed on vercel, and how vercel said, the functions from the /api folder will be deployed as serverless functions, so should I include this in my documentation?
I just can't work my head around it and come to a better understanding
I have two nextjs applications that are mainly based on server actions only, to perform actions and mutate data, like updating something in the database. From my understanding, this is the structure for a monolithic application.
However, the first application has some REST API endpoints defined that the second app will consume to retrieve some data. This makes me go for a REST architecture.
But these applications are deployed on vercel, and how vercel said, the functions from the /api folder will be deployed as serverless functions, so should I include this in my documentation?
I just can't work my head around it and come to a better understanding
6 Replies
@Pip gall wasp So I have a very hard time figuring out what my architecture is for a project.
I have two nextjs applications that are mainly based on server actions only, to perform actions and mutate data, like updating something in the database. From my understanding, this is the structure for a monolithic application.
However, the first application has some REST API endpoints defined that the second app will consume to retrieve some data. This makes me go for a REST architecture.
But these applications are deployed on vercel, and how vercel said, the functions from the /api folder will be deployed as serverless functions, so should I include this in my documentation?
I just can't work my head around it and come to a better understanding
how vercel deploys your REST endpoints doesn't really matter much. serverless functions or edge functions or whatever that they come up with, it's still your REST endpoints and still works the same way.
if you use server components to fetch your data like
then you should use server actions to mutate the data
if instead of that, you use, say, tanstack query to fetch your data, then you should also use tanstack query's mutation hooks to mutate the data.
if you use server components to fetch your data like
async function Page() {
const res = await fetch("your-rest-api")
return ...
}then you should use server actions to mutate the data
"use server";
async function updateUser() {
await fetch("your-rest-api", ...);
}if instead of that, you use, say, tanstack query to fetch your data, then you should also use tanstack query's mutation hooks to mutate the data.
@joulev how vercel deploys your REST endpoints doesn't really matter much. serverless functions or edge functions or whatever that they come up with, it's still your REST endpoints and still works the same way.
if you use server components to fetch your data like
tsx
async function Page() {
const res = await fetch("your-rest-api")
return ...
}
then you should use server actions to mutate the data
tsx
"use server";
async function updateUser() {
await fetch("your-rest-api", ...);
}
if instead of that, you use, say, tanstack query to fetch your data, then you should also use tanstack query's mutation hooks to mutate the data.
Pip gall waspOP
I use server components to fetch the data as you said, but for mutating data I use actions that run directly on the database:
As these actions are independent from the first server APIs
"use server";
async function updateUser() {
Db.update()
}As these actions are independent from the first server APIs
@Pip gall wasp I use server components to fetch the data as you said, but for mutating data I use actions that run directly on the database:
tsx
"use server";
async function updateUser() {
Db.update()
}
As these actions are independent from the first server APIs
hmm i dont get your question here then, what exactly are you asking?
American Crow
I am gonna suggest to switch from words to a drawing for this to communicate better.
This is how i understand OP's question:
Blue or orange way? (see image)
@Pip gall wasp feel free to adjust
https://excalidraw.com/#json=doj3YGXjWilvxBxqrDnls,JA151gg6sc1b086b9RQHxg
This is how i understand OP's question:
Blue or orange way? (see image)
@Pip gall wasp feel free to adjust
https://excalidraw.com/#json=doj3YGXjWilvxBxqrDnls,JA151gg6sc1b086b9RQHxg
@American Crow I am gonna suggest to switch from words to a drawing for this to communicate better.
This is how i understand OP's question:
Blue or orange way? (see image)
<@367379852254248960> feel free to adjust
https://excalidraw.com/#json=doj3YGXjWilvxBxqrDnls,JA151gg6sc1b086b9RQHxg
Pip gall waspOP
Sorry for my long time response, yes, that's what I mean.
As this drawing suggests, for the first application the architecture is pretty straight forward as there are REST endpoints.
However on the second, even though it seems pretty straight forward too, I'm a little bit confused because of the way data is manipulated. The data is received from the endpoint made in the first application but beyond that, everything else(mutations/updates) is directly run on the server via server actions and thus does not interfere with the first application.
I'm sorry again for the late response and let me know if I can do anything else to clarify this question
As this drawing suggests, for the first application the architecture is pretty straight forward as there are REST endpoints.
However on the second, even though it seems pretty straight forward too, I'm a little bit confused because of the way data is manipulated. The data is received from the endpoint made in the first application but beyond that, everything else(mutations/updates) is directly run on the server via server actions and thus does not interfere with the first application.
I'm sorry again for the late response and let me know if I can do anything else to clarify this question
blue way is better. if you want to send data between the db and the second app, there is no reason to take a detour through the first app, you can just go straight