Code Monkey home page Code Monkey logo

sample-api's Introduction

Sample API

Sample API

Technologies   |    About the Project   |    Architecture Decisions   |    How to Run   |    How to Run the Tests


Coverage Report

Statements Branches Functions Lines

Statements

Branches

Functions

Lines


🚀 Technologies


📜 About the Project

This is a sample API that was created to demonstrate the use of Clean Architecture and TDD. For that we have a single route that receives a payment confirmation from an external provider (*). This route is responsible for validating the request, marking the payment as confirmed (**) and logging analytics events to multiple external services (***).

The main goal here is to demonstrate how to solve a real world problem of needing to log a purchase event to multiple external services in a scalable and maintainable way. For that, this project used a well-known design pattern called Composite[https://refactoring.guru/design-patterns/composite].

In other to persist data in Intercom, of course you would need an Intercom API Key, defined in a .env file (example in .env.example), but this API will not throw any error if you don't.

(*) For simplicity purposes, we are not implementing authentication for this.

(**) For simplicity purposes, this is not implemented in this project.

(***) For simplicity purposes, only one external service (Intercom) is implemented in this project.


💻 Architecture Decisions

Clean Architecture was chosen due to the folowing reasons:

  • Modular application with well defined layers, responsabilities and data flow
  • Easier to test (unit and integration) every portion of the application due to modularity
  • Easier to maintain as the business logic is not coupled to a specific framework or library

🏁 How to Run

If you are going to use Docker it is as simple as running the following command:

docker-compose-up

If you are going to run the project without Docker, follow the steps bellow:

1 - Install the project dependencies

yarn install

2 - Duplicate the .env.example file and rename it to .env

3 - Get the secret values with the Lead Developer and replace it in your .env

4 - Build the project

yarn build

5 - Run the project

Watch mode (auto restart on every file change)

yarn dev

Regular mode (need to restart manually if a file changes)

yarn build && yarn start

🧪 How to Run the Tests

The are mainly two types of automated tests in the application: unit and integration. We have 5 different commands to run the tests depending on the developer needs:

1 - Runs the unit tests of the application.

yarn test:unit

2 - Runs the integration tests of the application.

yarn test:integration

3 - Run both the unit and the integration tests.

yarn test

4- Run both the unit and the integration tests, also generating a coverage report.

yarn test:ci

5 - Run both the unit and the integration tests but with greater logging information for debug purposes.

yarn test:verbose

sample-api's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.