An open-source API for managing recipes, built with Express and TypeScript using Prisma.
Currently supporting Minecraft PC (Java) V.1.19
- Clone the repository
$ git clone git@github.com:ejkorol/recipe-book.git
$ git clone https://github.com/ejkorol/recipe-book.git
- Install dependencies
$ cd recipe-book
$ npm install
-
Set up ENV variables
- Create a .env file in the root directory and add
.env.sample
variables with your own sercrets:
$ touch .env $ cat .env.sample > .env
For development purposes, set
NODE_ENV=development
- Add the
DATABASE_URL
variable with your own config:
PORT=8080 // localhost port DATABASE_URL=mysql://username:password@localhost:port/db // This prisma config uses mySQL NODE_ENV=development
- Create a .env file in the root directory and add
-
Set up Prisma client
- Reset db
$ npx prisma migrate reset
- Run the migration
$ npx prisma migrate dev
- Generate prisma client
$ npx prisma generate
Ensure database exists prior to migrating.
-
Seeding the database
Quick Note: Located in
./data/index.ts
exists versions of Minecraft (pc/java edition) that have the data supported for this API.Formatted as:
const data = { "VERSION": { files: { blocks: "./path/from/root/to/data/file", biomes: "./path/from/root/to/data/file", foods: "./path/from/root/to/data/file", entities: "./path/from/root/to/data/file", items: "./path/from/root/to/data/file", materials: "./path/from/root/to/data/file", recipes: "./path/from/root/to/data/file" } } };
- Setup seeding script:
Located in
./src/seed/seed.ts
exists the script to handle the seeding process of the above data:import { data } from "../../data"; import { blocks, foods, biomes, entities, items, materials, recipes } from "./scripts/1.20.2/index" // this is the version of the scripts const version = "1.20.2"; // this is the version of data const paths = data[version].files const main = async () => { await blocks(paths.blocks); await foods(paths.foods); await biomes(paths.biomes); await entities(paths.entities); await items(paths.items); await materials(paths.materials); await recipes(paths.recipes); }; main();
Ensure that
version
is the version of data you intend to seed, and such that it exists in./data/index.ts
.Ensure that the scripts for that version exists in
./src/seed/scripts
.In the event that the seed script for the latest version does not exist, please use the most recent script.
- Seed the database:
Prior to running the seed script, do a reset of the last seeded data in prisma, and migrate the latest version of schemas:
$ npx prisma migrate reset
$ npx prisma migrate dev
Run the seeding script:
$ npm run seed
- To ensure the data has been successfully seeded:
$ npx prisma studio
Will open a front-end to preview the seeded data in prisma.
recipe-book/
├── data/
│ ├── DATA_VERSION/
│ └── index.ts
├── src/
│ ├── controllers/
│ ├── middleware/
│ ├── routes/
│ │ └── index.ts
│ ├── schemas/
│ ├── seed/
│ │ ├── scripts/
│ │ │ └── DATA_VERSION/
│ │ └── seed.ts
│ ├── services/
│ ├── utils/
│ └── api.ts
├── dist/
├── types/
├── .env
└── README.md
data/
: Contains versionized data of (pc/java) data used in the APIsrc/controllers/
: Manages request processing and response generationsrc/middleware/
: Manages useful middlware used by the api (i.e. error handling, typeguards, rate limits)src/routes/
: Maps HTTP requests to controller functionssrc/schemas/
: Manages schemas for zod typecheckssrc/seed/
: Manages seed scripts and versionized seed historysrc/services/
: Contains business logic and operationssrc/utils/
: Provides utility functions and configurationstypes/
: For organizing types (always prefaced with I and exported from singularindex
)dist/
: Compiled JavaScript files
To start the development server with automatic reloading, run:
$ npm run dev
Ensure that you have correctly performed the Installation.