Shopify / Shopify/shopify-app-template-node
[CLI 3.0] Separate backend from frontend
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 434
- PR merge metrics
- No merged PRs in 30d
Description
Issue summary
It should be a good idea to separate backend from frontend. Right now the structure is:
/web
- /frontend
- - package.json (frontend)
- index.js (which is the main file of backend)
- package.json (main)
The issues with that are:
- developers tend to install frontend stuff in the main package.json (including myself, doing it by mistake as others do)
- import backend utils into frontend and vice versa (in one direction eslint doesn't find it to be an issue)
- that will also encourage making different eslint configs for each dir (FE and BE)
I managed to split it into:
/web
- /frontend
- - package.json
- - shopify.web.toml
- /backend
- - package.json
- - shopify.web.toml
- /extensions (haven't tried but should work too)
But the issue is that I have to import htmlFile from frontend, and I consider it to not be the most elegant solution:
...
const htmlFile = join(
isProd ? PROD_INDEX_PATH : DEV_INDEX_PATH,
"../../frontend/index.html",
);
return res
.status(200)
.set("Content-Type", "text/html")
.send(readFileSync(htmlFile));
});
...
I haven't yet figured out how to do it better. It's just a quick test, but I think there are many pros to doing it this way.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the current /web structure, including frontend/package.json, the main package.json, and backend entry point index.js. Compare it with the proposed frontend/backend layout and investigate how the backend currently reads frontend/index.html through the htmlFile path; done means the separation works without an inelegant cross-directory import and preserves the stated linting boundaries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- full-stack
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100