|
2 | 2 |
|
3 | 3 | An open-source API for managing recipes, built with Express and TypeScript using Prisma.
|
4 | 4 |
|
| 5 | +# API Documentation |
| 6 | + |
| 7 | +> Currently supporting Minecraft PC (Java) **V.1.19** |
| 8 | +
|
| 9 | +#### Table of Contents |
| 10 | +- [Items](./docs/api/items.md) |
| 11 | +- [Blocks](./docs/api/blocks.md) |
| 12 | +- [Recipes](./docs/api/recipes.md) |
| 13 | +- [Foodstuffs](./docs/api/foods.md) |
| 14 | +- [Entities](./docs/api/entities.md) |
| 15 | +- [Biomes](./docs/api/biomes.md) |
| 16 | + |
| 17 | + |
| 18 | +#### Quick Nav |
| 19 | +- [Installation](#installation) |
| 20 | +- [Architecture](#project-structure) |
| 21 | +- [Running the Api](#development) |
| 22 | +- [API documentation](#api-documentation) |
| 23 | + |
5 | 24 | ## Installation
|
6 | 25 |
|
7 |
| -1. **Clone the repository:** |
| 26 | +1. **Clone the repository** |
| 27 | + |
| 28 | +### SSH |
| 29 | + |
| 30 | +```bash |
| 31 | +$ git clone [email protected]:ejkorol/recipe-book.git |
| 32 | +``` |
| 33 | + |
| 34 | +### HTTPS |
| 35 | + |
| 36 | +```bash |
| 37 | +$ git clone https://github.com/ejkorol/recipe-book.git |
| 38 | +``` |
8 | 39 |
|
| 40 | +2. **Install dependencies** |
| 41 | + |
| 42 | +```bash |
| 43 | +$ cd recipe-book |
| 44 | +$ npm install |
| 45 | +``` |
| 46 | + |
| 47 | +3. **Set up ENV variables** |
| 48 | + |
| 49 | + 1. Create a .env file in the root directory and add `.env.sample` variables with your own sercrets: |
| 50 | + |
| 51 | + ```bash |
| 52 | + $ touch .env |
| 53 | + $ cat .env.sample > .env |
9 | 54 | ```
|
10 |
| - git clone <repository-url> |
11 |
| - cd recipe-book |
| 55 | + |
| 56 | + > For development purposes, set `NODE_ENV=development` |
| 57 | + |
| 58 | + 2. Add the `DATABASE_URL` variable with your own config: |
| 59 | + |
| 60 | + ```.env |
| 61 | + PORT=8080 // localhost port |
| 62 | + DATABASE_URL=mysql://username:password@localhost:port/db // This prisma config uses mySQL |
| 63 | + NODE_ENV=development |
12 | 64 | ```
|
13 | 65 |
|
14 |
| -2. **Install dependencies:** |
| 66 | +3. **Set up Prisma client** |
| 67 | + |
| 68 | + 1. Reset db |
15 | 69 |
|
| 70 | + ```bash |
| 71 | + $ npx prisma migrate reset |
16 | 72 | ```
|
17 |
| - npm install |
| 73 | + |
| 74 | + 2. Run the migration |
| 75 | + |
| 76 | + ```bash |
| 77 | + $ npx prisma migrate dev |
18 | 78 | ```
|
19 | 79 |
|
20 |
| -3. **Set up Prisma:** |
| 80 | + 3. Generate prisma client |
21 | 81 |
|
22 |
| - 1. **Create a `.env` file in the root directory and add the `DATABASE_URL` variable:** |
| 82 | + ```bash |
| 83 | + $ npx prisma generate |
| 84 | + ``` |
23 | 85 |
|
| 86 | + > Ensure database exists prior to migrating. |
| 87 | + |
| 88 | +4. **Seeding the database** |
| 89 | + |
| 90 | + Quick Note: |
| 91 | + Located in `./data/index.ts` exists versions of Minecraft (pc/java edition) that have the data supported for this API. |
| 92 | + |
| 93 | + Formatted as: |
| 94 | + |
| 95 | + ```ts |
| 96 | + const data = { |
| 97 | + "VERSION": { |
| 98 | + files: { |
| 99 | + blocks: "./path/from/root/to/data/file", |
| 100 | + biomes: "./path/from/root/to/data/file", |
| 101 | + foods: "./path/from/root/to/data/file", |
| 102 | + entities: "./path/from/root/to/data/file", |
| 103 | + items: "./path/from/root/to/data/file", |
| 104 | + materials: "./path/from/root/to/data/file", |
| 105 | + recipes: "./path/from/root/to/data/file" |
| 106 | + } |
| 107 | + } |
| 108 | + }; |
24 | 109 | ```
|
25 |
| - DATABASE_URL="mysql://username:password@localhost:3306/mydatabase" |
| 110 | + |
| 111 | + 1. **Setup seeding script:** |
| 112 | + |
| 113 | + Located in `./src/seed/seed.ts` exists the script to handle the seeding process of the above data: |
| 114 | + |
| 115 | + ```ts |
| 116 | + import { data } from "../../data"; |
| 117 | + import { |
| 118 | + blocks, |
| 119 | + foods, |
| 120 | + biomes, |
| 121 | + entities, |
| 122 | + items, |
| 123 | + materials, |
| 124 | + recipes |
| 125 | + } from "./scripts/1.20.2/index" // this is the version of the scripts |
| 126 | +
|
| 127 | + const version = "1.20.2"; // this is the version of data |
| 128 | + const paths = data[version].files |
| 129 | +
|
| 130 | + const main = async () => { |
| 131 | + await blocks(paths.blocks); |
| 132 | + await foods(paths.foods); |
| 133 | + await biomes(paths.biomes); |
| 134 | + await entities(paths.entities); |
| 135 | + await items(paths.items); |
| 136 | + await materials(paths.materials); |
| 137 | + await recipes(paths.recipes); |
| 138 | + }; |
| 139 | +
|
| 140 | + main(); |
26 | 141 | ```
|
27 | 142 |
|
28 |
| - 2. **Generate the Prisma client:** |
| 143 | + Ensure that `version` is the version of data you intend to seed, and such that it exists in `./data/index.ts`. |
| 144 | +
|
| 145 | + Ensure that the scripts for that version exists in `./src/seed/scripts`. |
| 146 | +
|
| 147 | + > In the event that the seed script for the latest version does not exist, please use the most recent script. |
| 148 | +
|
| 149 | + 2. **Seed the database:** |
29 | 150 |
|
| 151 | + Prior to running the seed script, do a reset of the last seeded data in prisma, and migrate the latest version of schemas: |
| 152 | +
|
| 153 | + ```bash |
| 154 | + $ npx prisma migrate reset |
30 | 155 | ```
|
31 |
| - npx prisma generate |
| 156 | +
|
| 157 | + ```bash |
| 158 | + $ npx prisma migrate dev |
32 | 159 | ```
|
33 | 160 |
|
34 |
| - 3. **Run migrations to set up the database schema:** |
| 161 | + Run the seeding script: |
35 | 162 |
|
| 163 | + ```bash |
| 164 | + $ npm run seed |
36 | 165 | ```
|
37 |
| - npx prisma migrate dev |
38 |
| - ``` |
39 | 166 |
|
40 |
| -## Config |
| 167 | + 3. To ensure the data has been successfully seeded: |
| 168 | +
|
| 169 | + ```bash |
| 170 | + $ npx prisma studio |
| 171 | + ``` |
41 | 172 |
|
42 |
| -- **`.env` file**: Store environment variables |
43 |
| - |
44 |
| -- **`src/api.ts`**: Entry point |
| 173 | + Will open a front-end to preview the seeded data in prisma. |
45 | 174 |
|
46 | 175 | ## Project Structure
|
47 | 176 |
|
| 177 | +``` |
48 | 178 | recipe-book/
|
| 179 | +├── data/ |
| 180 | +│ ├── DATA_VERSION/ |
| 181 | +│ └── index.ts |
49 | 182 | ├── src/
|
50 | 183 | │ ├── controllers/
|
51 |
| -│ │ └── fooController.ts |
52 |
| -│ ├── services/ |
53 |
| -│ │ └── fooService.ts |
| 184 | +│ ├── middleware/ |
54 | 185 | │ ├── routes/
|
55 |
| -│ │ └── fooRoutes.ts |
| 186 | +│ │ └── index.ts |
| 187 | +│ ├── schemas/ |
| 188 | +│ ├── seed/ |
| 189 | +│ │ ├── scripts/ |
| 190 | +│ │ │ └── DATA_VERSION/ |
| 191 | +│ │ └── seed.ts |
| 192 | +│ ├── services/ |
56 | 193 | │ ├── utils/
|
57 |
| -│ │ └── prismaClient.ts |
58 | 194 | │ └── api.ts
|
59 | 195 | ├── dist/
|
60 |
| -│ └── ... |
61 |
| -├── .gitignore |
| 196 | +├── types/ |
62 | 197 | ├── .env
|
63 |
| -├── .env.sample |
64 |
| -├── package-lock.json |
65 |
| -├── package.json |
66 |
| -├── tsconfig.json |
67 | 198 | └── README.md
|
| 199 | +``` |
68 | 200 |
|
| 201 | +- **`data/`**: Contains versionized data of (pc/java) data used in the API |
69 | 202 | - **`src/controllers/`**: Manages request processing and response generation
|
70 |
| -- **`src/services/`**: Contains business logic and operations |
| 203 | +- **`src/middleware/`**: Manages useful middlware used by the api (i.e. error handling, typeguards, rate limits) |
71 | 204 | - **`src/routes/`**: Maps HTTP requests to controller functions
|
| 205 | +- **`src/schemas/`**: Manages schemas for zod typechecks |
| 206 | +- **`src/seed/`**: Manages seed scripts and versionized seed history |
| 207 | +- **`src/services/`**: Contains business logic and operations |
72 | 208 | - **`src/utils/`**: Provides utility functions and configurations
|
73 |
| -- **`dist/`**: Compiled JavaScript files. |
| 209 | +- **`types/`**: For organizing types (always prefaced with I<type> and exported from singular `index`) |
| 210 | +- **`dist/`**: Compiled JavaScript files |
74 | 211 |
|
75 | 212 | ## Development
|
76 | 213 |
|
77 | 214 | To start the development server with automatic reloading, run:
|
78 | 215 |
|
79 |
| - ``` |
80 |
| - npm run dev |
81 |
| - ``` |
82 |
| -
|
83 |
| -# Minecraft Item Categories |
84 |
| -
|
85 |
| -## 1. Raw Ingredients |
86 |
| -
|
87 |
| -- **Ores**: |
88 |
| - - Iron Ore |
89 |
| - - Gold Ore |
90 |
| - - Coal Ore |
| 216 | +```bash |
| 217 | +$ npm run dev |
| 218 | +``` |
91 | 219 |
|
92 |
| -- **Raw Materials:** |
93 |
| - - Raw Iron |
94 |
| - - Raw Gold |
95 |
| -
|
96 |
| -- **Plant-Based**: |
97 |
| - - Wheat |
98 |
| - - Sugar Cane |
99 |
| - - Cocoa Beans |
100 |
| - - Seeds |
101 |
| -
|
102 |
| -- **Animal Products**: |
103 |
| - - Raw Beef |
104 |
| - - Raw Porkchop |
105 |
| - - Raw Chicken |
106 |
| - - Eggs |
107 |
| -
|
108 |
| -## 2. Processed Ingredients |
109 |
| -
|
110 |
| -- **Crafted Items**: |
111 |
| - - Iron Ingot |
112 |
| - - Gold Ingot |
113 |
| - - Coal |
114 |
| - - Bread |
115 |
| - - Cooked Beef |
116 |
| -
|
117 |
| -- **Crafting Materials**: |
118 |
| -
|
119 |
| - - Wood Planks |
120 |
| - - Stone Bricks |
121 |
| - - Iron Bars |
122 |
| - - Glass |
123 |
| -
|
124 |
| -- **Food**: |
125 |
| - - Cooked Porkchop |
126 |
| - - Cooked Chicken |
127 |
| - - Cake |
128 |
| -
|
129 |
| -## 3. Building & Decoration |
130 |
| -
|
131 |
| -- **Blocks**: |
132 |
| - - Stone |
133 |
| - - Wood Planks |
134 |
| - - Bricks |
135 |
| - - Sandstone |
136 |
| -
|
137 |
| -- **Decoration**: |
138 |
| - - Flower Pots |
139 |
| - - Paintings |
140 |
| - - Carpets |
141 |
| - - Lanterns |
142 |
| -
|
143 |
| -## 4. Tools & Weapons |
144 |
| -
|
145 |
| -- **Tools**: |
146 |
| - - Pickaxes |
147 |
| - - Shovels |
148 |
| - - Axes |
149 |
| - - Bows |
150 |
| -
|
151 |
| -- **Weapons**: |
152 |
| - - Swords |
153 |
| - - Crossbows |
154 |
| - - Tridents |
155 |
| -
|
156 |
| -## 5. Armor |
157 |
| -
|
158 |
| -- **Protective Gear**: |
159 |
| - - Helmets |
160 |
| - - Chestplates |
161 |
| - - Leggings |
162 |
| - - Boots |
163 |
| -
|
164 |
| -## 7. Brewing & Potions |
165 |
| -
|
166 |
| -- **Brewing Ingredients**: |
167 |
| - - Blaze Powder |
168 |
| - - Nether Wart |
169 |
| - - Glass Bottles |
170 |
| -
|
171 |
| -- **Potions**: |
172 |
| - - Healing Potions |
173 |
| - - Speed Potions |
174 |
| - - Strength Potions |
175 |
| -
|
176 |
| -## 8. Miscellaneous |
177 |
| -
|
178 |
| -- **Other Items**: |
179 |
| - - Maps |
180 |
| - - Compasses |
181 |
| - - Name Tags |
182 |
| - - Spawn Eggs |
183 |
| -
|
184 |
| -- **Music Discs**: |
185 |
| - - Cat |
186 |
| - - Blocks |
187 |
| - - 13 |
188 |
| - - Chirp |
189 |
| -
|
190 |
| -## 9. Transportation |
191 |
| -
|
192 |
| -- **Transport Items**: |
193 |
| - - Boats |
194 |
| - - Minecarts |
195 |
| - - Rails |
196 |
| - - Elytra |
| 220 | +> Ensure that you have correctly performed the [Installation](#installation). |
0 commit comments