This is an API built using Express to fetch low-effort recipes from spoonacular. These are recipes that can be made within an hour, use common kitchen ingredients, and can produce multiple servings. It's ideal for new chefs learning how to cook, or people with little free time who want to cook something tasty. This API is connected to the web, iOS, and Android apps so anyone can view the recipes on any device.
In addition to spoonacular, MongoDB is used to cache the recipes for improved query performance. It is also used to perform full-text search on recipes based on various criteria like recipe name, description, or ingredients.
Below is a sequence diagram when the client asks the server to fetch a random recipe:
sequenceDiagram
Client->>Server: Get random recipe
Server->>spoonacular: Recipe search
spoonacular-->>Server: Server recipe
Server->>spoonacular: Spice level lookup
spoonacular-->>Server: Spice level
Server->>Server: Transform recipe
Server->>MongoDB: Upsert recipe
Server-->>Client: Client recipe
- TypeScript for added type safety
- RESTful APIs
- MongoDB to store data, query data, and do full-text search
- Pagination to reduce bandwidth and optimize query performance
- Docker to containerize the server on any machine
- OpenAPI to publish standardized API documentation
- GitHub Actions for automated testing and deployment in a CI/CD pipeline
- Mermaid to write diagrams as code
flowchart LR
A(Checkout repository) -->|18.x, 20.x| B(Install Node.js)
B --> C(Install dependencies:\nnpm ci)
C --> D(Build app:\nnpm run build --if-present)
D --> E(Run Jest unit tests:\nnpm test)
flowchart LR
A(Checkout repository) --> B(Add environment variables)
B --> C(Build Docker server image)
C --> D(Run tests inside the container)
flowchart LR
A(Checkout repository) -->|JavaScript| B(Initialize CodeQL)
B --> C(Build code)
C --> D(Perform CodeQL analysis)
flowchart LR
A(Merge PR to main) -->|Dockerfile.prod| B(Auto-Deploy to Render)
subgraph B [Auto-Deploy to Render]
direction TB
C(Use Node 18 Alpine image) --> D(Install dependencies)
D --> E(Compile TypeScript)
E --> F(Start PM2 server)
end
Visit Swagger UI to view the OpenAPI docs for this API.
- Clone this repo.
- Create an account at https://spoonacular.com/food-api to obtain an API key. Then create a file called
.env
with the following content:
API_KEY=YOUR_API_KEY
- Create a database in MongoDB Atlas and copy the URI in
.env
:
MONGO_URI=YOUR_MONGODB_URI
- Run
npm install
to install all the dependencies.
Dev: Run npm start
.
Prod: Run npm run build
to generate a build in the dist
directory. Then run npm run server
to start the server using pm2.
The server will be listening on http://localhost:5000
. To stop the server, press CTRL-C
.
- Follow steps 1-3 above.
- Run
docker compose -f docker-compose.yml -f docker-compose-[dev|prod].yml up -d
to start up both the web and server containers in dev or prod.
To stop the containers, run docker compose down
.
Run npm test
to run the unit tests using Jest.