Coder Social home page Coder Social logo

muzz's Introduction

muzz

Setup and running

make up - Run the api available on 0.0.0.0:3000

make down to shut down the api

The whole project is composed of an api service, a postgres database and a redis cache (currently unused). The api container is built using air which is a hot-reload go docker image used solely for development

Design choices

The project is split between 3 layers (packages) each with its own purpose. Each layer is independent of the layers below and its dependencies could be abstracted with mocks:

  • rest/

    • Here lies all logic regarding request/response processing, payload validation and middlewares such as authentication
  • service/

    • Here lies all the business logic of the application where for instance, upon performing a login (/login) the user email is validated, the password is compared against the hashed password which is stored and the token is generated
  • respository/

    • Here lies all data retrieval functionality where the data access is abstracted using interfaces to obscure the type of datasource. For instance UserRepository currenlty uses a postgres database but it could be changed to MySQL / MariaDB / MongoDB without compromising the layers above it with changes

For the /discover endpoint logic the following assumptions were made:

attractiveness_score is calculated based on positive swipes from a user representing the likelyhood of a future match. For ex. if a user has the tendency to positively swipe across other profiles then it is more likely that it has partial match to the current user

distance is calculated using the postgres earthdistance extension (https://www.postgresql.org/docs/current/earthdistance.html)

The returing profiles are sorted by attractiveness_score and closer distance to the current user.

Available routes

  • /swagger: auto generated api docs

  • /healthz: for checking service is healthy

  • /user/create: for creating a profile

  • /login: for authenticating a user

  • /swipe: for simulating a user swipe over a profile

  • /discover: for returing interesting profiles for a user with the following optional parameters:

    • min_age: number detailing minimum age for a prospective profile
    • max_age: number detailing minimum age for a prospective profile
    • gender: the profile gender (M | F)

All requests go through a layer of validation using the https://github.com/go-playground/validator package

Points of improvement

  • Add unit tests: due to lack of time I mostly focused on developing the features and setting only partial e2e tests using hurl (https://hurl.dev) available on /hurl folder of the repo. Unit test would provide an additional layer of safety to the source code.

  • Add /user/delete endpoint to make each e2e test self sufficient. Currently we need to clear the db after each hurl test run as the user would fail the email validation upon creation

  • Optimize discover query: The discover query would perform badly in large datasets, specially the portion where the attractiveness_score is calculated. This calculation could be abstracted in a db view.

  • Add ci/cd pipeline to run unit tests and hurl e2e tests

  • Improve /healthz by pinging db and cache for ensuring connections/repositories are up

muzz's People

Contributors

andrelince 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.