This is my solution to the Frontend Challenge for Q3 2024.
I've used Node 20.9.0 to develop this project, so I recommend using the same version to avoid any issues (if there are any).
First, install the dependencies:
pnpm install --frozen-lockfile
Then build and run:
pnpm build
pnpm start
Open http://localhost:3000 with your browser to see the result.
The app has two main pages:
Everything should be responsive (Check out the container queries on the stack summaries in the root page), accessible and resilient. I noticed that the API sometimes fails, but I've handled it gracefully by allowing the user to reload the page (I've disabled the react-query retries to show this, otherwise the users would almost never see any errors and just wait until the backend does not fail, but normally I would leave it on).
To improve the navigation when there are a lot of stacks, I would add a search box and a order/sort by dropdown. A pagination would also make sense to improve performance in this situation.
I would also like to turn things like the is_shared
icon in the stack details page into a switch (maybe with an confirmation alert) and add the user's avatar and name, because at the moment there are too few informations.
I would like to add some more colors and animations to make the app more visually appealing, but I did not want to over-do it, so I've kept it simple.
I've made some decisions that I would not never make in a real-world project, but I did it to save time and because I think it's not the focus of the challenge. Here are some of them:
main
branch: I've worked alone, no need to waste time branchingmock.ts
: This file exist because I could not change the API I was consuming (I needed the name alongside the ids of the stack components), so instead of making another request to get the name, confuse my code in the process and waste time, I've decided to just add the names directly in the mock file.There are also some other minor compromises in the code, but there are dedicated comments in the code explaining them.
fetch
in my React code, it's just bad, react query solves that problem and more.
- How would you add the remaining CRUD operations (create, update, and delete) for a stack and stack component to your application?
I would add:
It would make sense to add a state management library like Zustand, so that we can easily handle optimistic CRUD operations without the need refreshing the page.
I would also like to turn things like the is_shared
icon into a switch in the stack details page (maybe with an confirmation alert) and add a sort of "selected" switch in the stack component dialog's table.
- How would you handle a token or a cookie, in case the API would need authentication?
I would handle it with a JWT in the cookies. The main reason to not put it in localStorage
is because Next.js server components would not work with it, but it can with cookies. To implement it, I would add the Authorization: Bearer <token>
header to the fetch requests on the queryFn
of react-query, and try to make it so I don't have to add it manually every time for every request (if it makes sense).
- Given that some features are open-source and some are not, how would you approach separating and integrating open and closed-source features?
Generally I would just separate the open-source features (or the closed source features) in a different repository and install them though a private npm package. Of course you need to give a proper license to the open-source repository, to make sure you can use it in your closed source project. I also saw that there are some tools that can help with this, without the need for a refactor (see link), but I have never used them.