Giter VIP home page Giter VIP logo

bliq's Introduction

About

Backend: NestJS v10^

Frontend: NextJS v14.1^ w/ App Router

Instructions

Installing dependencies

To install dependencies, go to ./backend and ./frontend folders and run npm i.

# For backend
$ cd backend
$ npm i
# For frontend
$ cd frontend
$ npm i

Running the apps

Run the apps using two separate terminals.

Backend

Create ./backend/.env file using the ./backend/.env.sample content.

# Run following in the exact same order
$ cd backend
$ npm run build
$ npm run start:prod

You can access the backend via http://localhost:8080

Frontend

Create ./frontend/.env or ./frontend/.env.local file using the ./frontend/.env.sample content.

# Run following in the exact same order
$ cd frontend
$ npm run build
$ npm start

You can access the frontend via http://localhost:3000

Testing

There are some tests in the Backend application. To run tests cd into ./backend. Testing can be done via default NestJS scripts.

$ cd backend
# Possible scripts
$ npm test
$ npm run test:e2e
$ npm run test:cov

Backend API

/ping (GET) - Returns pong

/v1/aggregates (GET) - Returns array of RideInformation's sorted by the average price.

See below for API type definitions.

export enum ProviderType {
  Uber = "UBER",
  Bolt = "BOLT",
}

/**
 * ISO 4217 compliant Currency codes
 */
export enum Currency {
  EUR = "EUR",
}

export enum PriceType {
  Fixed = "FIXED",
  Range = "RANGE",
}

type FixedPrice = {
  fixed: number;
  type: PriceType.Fixed;
  low?: never;
  high?: never;
};
type RangePrice = {
  low: number;
  high: number;
  type: PriceType.Range;
  fixed?: never;
};
export type RidePrice = FixedPrice | RangePrice;

export enum CarType {
  Eco = "ECO",
  Luxurious = "LUXURIOUS",
  Large = "LARGE",
}

export type RideInformation = {
  id: string;
  provider: ProviderType;
  price: RidePrice;
  currency: Currency;
  carType: CarType;
  durationMinutes: number;
};

Notes on backend behavior

Backend application behavior can be configured using the ./backend/src/aggregator/constants/constants.provider.ts. For details, see the JsDoc on the file. PS: The reason for placing configuration in a NestJs value provider instead of an env file is to illustrate the usage of a value provider.

Providers can return empty responses! (to simulate errors)

When a simulated failure occurs for a provider request, an empty array is returned. Therefore, knowing that we have two Ride Platform Providers, there's a chance that an /v1/aggregates API response might be a totally empty array.

Notes on frontend behavior

Frontend application can simulate error occurrence ie. when fetching the data from API. This behavior can be controlled in ./frontend/src/app/components/RideOptionList.tsx#22. Current error rate is 10%. To disable, set as -1.

Future notes

  • Improve error handling by leveraging custom base exceptions and exception filters.
  • Integrate with an open telemetry tool to trace overall system performance.
  • Create a separate library or repository for common code, establishing a single source of truth and minimizing code duplication.

Feature ideas

  • An endpoint that returns VersionInfo to either trigger updates or disable usage on mobile apps.
  • Enabling or disabling providers dynamically or on-demand.
  • Ability to restrict usage in some part of the availability zones.

bliq's People

Contributors

mit4dev avatar

Watchers

 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.