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. Firebase is used to manage user authentication.
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
- Firebase for user authentication
- 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(Lint app: \nnpm run lint)
D --> E(Build app:\nnpm run build --if-present)
E --> F(Run Jest unit tests:\nnpm test)
flowchart LR
A(Checkout repository) --> B(Build Docker server image)
B --> C(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
- Create a Firebase Project with the following:
- A private key under Service Accounts
- A web API key
Save both of these outside this repo and reference them in .env
:
GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_PRIVATE_KEY
WEB_API_KEY=YOUR_WEB_API_KEY
- Generate a SECRET_KEY for encryption and save it in
.env
:
openssl rand -base64 64 # YOUR_SECRET_KEY
SECRET_KEY=YOUR_SECRET_KEY
- 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 https://localhost:5000
. To stop the server, press CTRL-C
.
- Follow the above installation steps.
- 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.