Skip to content

rpairo/exoplanets-api

Repository files navigation

Exoplanets API

The Exoplanets API is a Swift-based web service that fetches data from the ExoplanetAnalyzer, processes it, and exposes endpoints to retrieve exoplanet-related information. It is imported as a library via Swift Package Manager.

This project also provides a website for a user-friendly navigation experience. Additionally, it integrates the Google Custom Search API to dynamically fetch exoplanet images, addressing the lack of images from sources like NASA and Wikimedia.

The API’s JSON models mirror the exoplanet data while including a URL for the exoplanet’s image.

Endpoints

The server simultaneously provides a website and an API:

API (JSON Responses)

. /api/orphans: Retrieve orphan exoplanets.

. /api/hottest: Fetch the exoplanet orbiting the hottest star.

. /api/timeline: Get a discovery timeline categorized by exoplanet size.

Website (HTML Pages)

. /website/: Homepage of the exoplanet service.

. /website/orphans: View orphan exoplanets.

. /website/hottest: See the hottest star’s exoplanet.

. /website/timeline: Explore the discovery timeline.

Visual Examples

Website

/website/

website-index

/website/orphans

website-orphans

/website/hottest

website-hottest

/website/timeline

website-timeline

API (JSON)

/api/orphans

api-orphans

/api/hottest

api-hottest

/api/timeline

api-timeline

Testing

Running the tests

The tests files are located in the Tests/ directory in the project root. They are mirroning the Sources/ structure to make easier the management. In order to make easier to run the testing, I have created the file setup-tests-manual.sh, wich will set up the env variables and run the tests by terminal. Another option is to open the project by Xcode, and run the test by pressing "CMD + U"

Manual testing

Requeriments

To properly run the project, it will be expecting 5 env vars. They will be fetched by AWS Secrets Manager if you use the AWS CLI with the "-aws-".sh to run Docker and Kubernetes.

  • BASE_URL
  • PATH_SEGMENT
  • ENDPOINT_EXOPLANETS
  • GOOGLE_API_KEY
  • GOOGLE_SEARCH_ENGINE_ID

Docker

you can run it in docker by the scripts that I have prepared for it.

  • /docker/setup-docker.sh: easiest way, just inject the env vars and run run docker.
  • /docker/setup-docker-aws-secrets-sh: if you want to use the AWS secrets Manager, it requires AWS CLI installed.

ExoplanetAPI in Dcoker

Download

You can find the image in Docker Hub by: https://hub.docker.com/repository/docker/rpairo/exoplanets-api/general

ExoplanetAPI DockerHub

Kubernetes

I recommend to deploy by deploy-k8s-resources-easy.sh. Since will set up everything straigh forward. You can choose the other ways if you prefer checking the other scripts I made.

Kubernetes has required beyond investigation, cause as well as in the ExoplanetsAnalyzer project, I am running Kubernetes by Docker Desktop, and this makes not easily to work with.

After further investigations, I have found out the way to solve the missing calls to my running services: port-forwarding. In /k8s/ directory will find the deploy-k8s-resources.sh file, who has all the logic to set up the ENV VARs, clean up the secrets, deploy the image and if you are using docker, will wait until the service is running to perform the port-forward. It is the only way I have found to be able to reach out the service in kubernetes by docker desktop.

Running by deploy-k8s-resources-easy.sh Kubernetes all

Xcode

To run it by xcode, will be important to set up few configurations:

  • ENV VAR: Xcode will not share the ENV VARs with the OS, they must to be injected by Xcode Scheme.

The path to get this menu is: Product -> Scheme -> Edit Scheme -> (your-target) -> Arguments

  • Working Directory: To be able to run properly the server, Vapor recommends to enable the working directory option and set it up pointing to the project root. This option will not shared by xcodes, so it must to be set up manually.

Frontend with Leaf and Bootstrap

The website is built using Vapor’s Leaf as the templating engine and Bootstrap for responsive and pre-designed components.

Project Structure

The project follows a modular architecture with the following components:

  • Domain: Contains core business logic and models.
  • Data: Handles data fetching and processing.
  • Infrastructure: Manages configurations and external services integration.
  • Presentation: Prepares and formats data for API responses.
  • Composition: Assembles dependencies and builds the application.
  • API: Exposes the endpoints for client interactions.

CI/CD

This project also has the same configuration as ExoplanetsAnalyzer](https://github.com/rpairo/exoplanets) in GitHub by Actions to perform the CI/CD flows: Run test, Scan vulnerabilities, Post to Docker Hub.

About

Analyze exoplanet data: orphan planets, hottest star, and discovery timeline by size.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published