Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nwylynko/burger-shop
A delicious online burger store, splitting up concerns in to separate modules and dependency injection to enable strong testability.
https://github.com/nwylynko/burger-shop
Last synced: about 1 month ago
JSON representation
A delicious online burger store, splitting up concerns in to separate modules and dependency injection to enable strong testability.
- Host: GitHub
- URL: https://github.com/nwylynko/burger-shop
- Owner: NWylynko
- License: mit
- Created: 2022-11-03T06:24:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-14T07:28:37.000Z (about 2 years ago)
- Last Synced: 2024-10-25T23:10:18.383Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 118 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Burger Shop
This is an example project showing off splitting up the interface (api), the core (business logic) and the persistence (database). This has many benefits including cleaner code, testability, and easier to swap out things like the database or http api in the future if desired.
## Parts
- **The Core module:** This stores all the business logic, it defines the types but does not directly touch anything impure. This means it can install its own packages that do pure functions, for example lodash, but can't directly touch the database or know how the http layer works.
- **The Persistence module:** This has the single job of implementing the database calls, for example it takes getUser("id") and turns that in to SQL that will look up the user. This package will use zod to generate and verify the types coming from the database.
- **The Interface module:** This has the job of converting http api calls in to something usable (thou this is done by the http framework mostly). It needs to call the persistence package to setup the database connection and get the impure functions from that package, then can pass the relevant functions through to the core functions to get them setup to be called on request.
- **The Schemas module:** This stores a bunch of zod schemas and extracts the types from them. This is mainly based around strongly typing the functions to and from the database, but core and interface packages can use types from it or derive ones from it if they please.
- **The Fetch module:** This uses is a simple module that contains fetch functions to call the interface, using zod schemas to verify the request response. This crosses the network boundary so things need to be extra safe to ensure things work as expected.
- **The Web Service:** Running nextjs 13 and the new app dir, this uses the fetch module to call our services.
## Diagram
![Diagram of the relationship between the modules](./Burger-shop.svg)## Setup
You'll need some stuff, node, yarn, bun, and a terminal.
1. Install dependencies
- `yarn`
2. Setup the database, its just a local sqlite3 so nothing crazy
- `cd persistence` // the database layer
- `bun run migrate` // run the migrations
- `bun run data` // seed the database with some data (thou not necessary if you don't want the test data for dev)
- `cd ..` // back to the root3. Run it
- `yarn dev`