This project is a API built to manage a collection of heroes. It allows authenticated users to perform CRUD operations (Create, Read, Update, and Delete) on a MongoDB database. User authentication and authorization are handled via a PostgreSQL database.
The API is designed with a focus on scalability, security, and maintainability, ensuring that only authenticated users can manage the data. It is fully tested with high code coverage, guaranteeing the quality and reliability of the application.
- CRUD Operations: Create, Read, Update, and Delete heroes.
- Authentication: Secure user authentication using PostgreSQL.
- MongoDB Integration: Heroes are stored and managed in a MongoDB database.
- Test Coverage: Comprehensive test suite ensuring high-quality code.
- Scalable: Built to handle large datasets and numerous users.
- Node.js: JavaScript runtime.
- MongoDB: For storing hero data.
- PostgreSQL: For user authentication.
- Mocha: For unit and integration tests.
- JWT: For securing API endpoints.
- Hapi: Web framework for routing and middleware.
- Swagger: Documentation.
-
Clone the repository:
git clone git@github.com:victorsfranco/heroes-api.git
-
Install dependencies:
npm install
-
Configure environment variables for MongoDB, PostgreSQL, and JWT.
-
Run docker containers:
-
Client for PostgreSQL
docker run \ --name postgres \ -e POSTGRES_USER=myUser \ -e POSTGRES_PASSWORD=mySecretPassword \ -e POSTGRES_DB=heroes \ -p 5432:5432 \ -d \ postgres docker exec -it postgres /bin/bash
-
Client for PostgreSQL
docker run \
--name adminer \
-p 9090:8080 \
--link postgres \
-d \
adminer
- MongoDB
docker run \
--name mongodb \
-p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=mySecretPassword \
-d \
mongo:4
- Client for MongoDB
docker run \
--name mongoclient \
-p 3000:3000 \
--link mongodb:mongodb \
-d \
mongoclient/mongoclient
- Run the application:
npm run prod
- Run tests:
npm test
The API endpoints can be view on swagger, starting the API and navigating to /documentation
endpoint.
The API is covered by automated tests that verify the correctness of each feature. Tests ensure that user authentication, data validation, and all CRUD operations are working as expected.
Run the tests using:
npm test
Contributions are welcome! Feel free to fork the repository, create a new branch, and submit a pull request for review.