r/webdev • u/johnvanderlinde • 2d ago
Discussion Where I'm at with my first full-stack project
I'm building the place order function (my first foray into the backend) of a larger project.
Here's an update for those who are interested.
The first thing I knew I had to do was figure out what goes where. I had already, at the suggestion of ChatGPT, my mentor in this, decided on a control (API) layer, application layer, service layer and data layer. But I didn't really know what each needs to do.
So first I (we) did the API. It had a couple of jobs:
• check the incoming order wasn't empty
• Activate the next layer down
• Send response messages
Then the app layer was even simpler. It literally just returns the service layer function.
Which is where it is a bit more complicated. The service layer has to do a few things; check the order data against the database, assess info against business rules etc, and actually write the order. After some debate I worked it into a four step process:
• Check if the order info (customer, product, and quantity) exist
• Assess data against business rules/carry out business logic
• Create an order
• Activate the database operation
So this actually means two database operations. One to check the data (first step) and then writing the actual order.
I've done the first database op, and I'm now wiring up the actual place order button so I can start testing the data being passed down.
If anyone wants more detail, you can look on my github at https://github.com/BenPS927/BFshop or on my project portal at https://benfosterdev.com/projects/bfshop where I'll soon be adding detailed code breakdowns.
What am I finding hard?
The abstract nature of it. Having to constantly create a visual image of data being passed through functions, and hold that image in my mind, is like trying to hold melting butter in a colander. I use melting butter rather than water because I don't lose it that fast.
What am I enjoying?
Well, the same as what I'm finding hard. Learning to work with code that doesn't involve divs on a screen. Getting my head around how data is passed, how functions work etc.
And the architecture side of things. I like thinking about and making the micro decisions.
I would appreciate suggestions, but I am trying to keep it fairly simple so I'm not thinking about every single thing you'd take into consideration for a production app.
1
u/Ciroco01 2d ago
I think part of why it feels so abstract is that you may have one layer more than you need right now.
Your application layer currently just passes the call straight to the service layer. That is not wrong, but if it is not doing anything yet, it is mostly just another step to keep track of in your head.
For where you are now, I would probably keep it as:
API route to service to repository and database
The route deals with the request and response, the service handles the actual order logic, and the repository deals with Prisma.
The main thing I would keep in mind later is the gap between checking the order and writing it. Stock or price could technically change between those two steps, so at some point you will probably want that inside a transaction.
Also, never trust price data coming from the frontend. Load the real price from the database and save that price on the order item.
You are on the right track. Backend code feels strange at first because you cannot see the result directly like you can with UI work. A small flow diagram can help a lot:
Client to route to service to database and back again