Giter Club home page Giter Club logo

fastify-example-twitter's Introduction

Fastify twitter clone

The aim of this project is to show how fastify can be used.

NB: This project should be considered WIP and it does not reflect the best way we think fastify should be used, but it's rather an experiment to help driving fastify.

Run

For running this project on your machine:

# terminal 1: Start frontend server
cd frontend && npm start
# terminal 2: start backend
npm start -- --log-level trace --port 3001

Open your browser at http://localhost:3000

NB this project need to access a mongodb and a redis instance. If you haven't them, please consider to use docker.

Backend

Architecture

Fastify helps us to keep this segregation: the plugin system provides us a way to declare pieces of our business logic without exposing them to the whole application. If you looking for a guide to understand better how the plugin system works, please read this Plugin Guide

So, the backend is splitted into plugins:

  • user: user authentication / user database
  • tweet: tweet storage
  • follow: follow storage
  • timeline: timeline for homepage

The last three modules have a preHandler hook to find which the user has made the request.

Each plugin has almost the same structure:

  • index.js is the fastify binding
  • service.js is the business logic
  • schemas.js has the schemas used for http validation and serialization (See fastify schemas)

User plugin

This plugin registers some APIs in order to register, login, search and get a profile for an user.

It uses mongodb to save users and exports a userClient to allow other plugins to access to an user profile.

Tweet plugin

This plugin stores tweets and allows you to retrieve the tweets of an user.

It uses mongodb for storing the tweets and exports a client for tweets retrieving.

Follow plugin

This plugin tracks the following and the followers implementing the flow explained here.

It uses redis for tracking which users follow the other ones and vice versa.

Timeline plugin

This plugin aggregates informations from tweet and follow plugin in order to return the tweet timeline.

This plugin doesn't use any database to track that informations and uses tweetService and followService to build the response.

Frontend

The frontend side has been done only to show a simple UI for avoiding the manual CURLs.

It is built using react + redux stack.

No UX or UI study are made (please PR!)

Coming soon

TODO

  • Search users
  • Timeline
  • Follow microservices for following and unfollowing other users
  • Better test
  • Better README.md
  • Use Docker compose
  • Use fastify-react for react serve side rendering
  • Better UI
  • Even better UI

fastify-example-twitter's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastify-example-twitter's Issues

What is your definition of MicroServices ?

Going through your implementation detail I have noticed the following things which I think are against the MicroServices concept/ Culture.

  1. Shared code base (APP) among all micro services. This can cause a problem where you have to update a certain code base; which leads to the whole application being rebuilt and will have a new version which means for the sake of sanity and not to introduce complexity you also have to update the other service deployments.

In your docker files I have noticed you are doing COPY . /usr/src/app , which is copying the same code base across all Micro Services.

e.g. You have tweets Micro Service and the timeline Micro Service; if for some reason you update the timeline Service since it is maintained in the same code base as my whole project it creates the problem of where your whole build version will change (i.e. the latest version for my tweets will also be updated).

  1. MicroServices also suggests different databases per MicroService. How would you share that across Fastify.

To Summarize; i have attached an image from microservices.io and also what do you think of your current implementation according to suggestions made by https://microservices.io/patterns/microservices.html

image

Question: Best way for context aware logs inside service

Hi,
I have a question around logging inside services.
Let say I would want to log some statements inside user service and it should also contain context information like requestId which would help in debugging production applications.

Is it possible to add some example for this use case?

In other words passing the context information or req.log across all operations.

Feedback needed

I need a feedback from @fastify/fastify here.
Any kind of feedbacks are appreciated. Really....

how to run this example ?

C:\code\fastify\fastify-example-twitter\frontend>npm build
npm WARN build npm build called with no arguments. Did you mean to npm run-sc ript build?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

How to run?

Hello everyone! I'm evaluating fastify, but facing some issues to run this project.

`➜ fastify-example-twitter git:(master) npm start -- --log-level trace --port 3001

[email protected] start /Users/lgertel/fastify-example-twitter
fastify index.js "--log-level" "trace" "--port" "3001"

AsyncFunction
assert.js:663
throw newErr;
^

AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Cannot destructure property ObjectId of 'undefined' or 'null'.
at listen (/Users/lgertel/fastify-example-twitter/node_modules/fastify/node_modules/fastify-cli/cli.js:96:12)
at /Users/lgertel/fastify-example-twitter/node_modules/fastify/fastify.js:209:23
at Function._encapsulateThreeParam (/Users/lgertel/fastify-example-twitter/node_modules/avvio/boot.js:297:7)
at Boot.callWithCbOrNextTick (/Users/lgertel/fastify-example-twitter/node_modules/avvio/boot.js:252:5)
at release (/Users/lgertel/fastify-example-twitter/node_modules/fastq/queue.js:127:16)
at Object.resume (/Users/lgertel/fastify-example-twitter/node_modules/fastq/queue.js:61:7)
at Plugin.loadPlugin.call (/Users/lgertel/fastify-example-twitter/node_modules/avvio/boot.js:141:22)
at registerRoutes (/Users/lgertel/fastify-example-twitter/tweet/index.js:51:32)
at Plugin.exec (/Users/lgertel/fastify-example-twitter/node_modules/avvio/plugin.js:33:17)
at Boot.loadPlugin (/Users/lgertel/fastify-example-twitter/node_modules/avvio/plugin.js:114:10)
at Task.release (/Users/lgertel/fastify-example-twitter/node_modules/fastq/queue.js:127:16)
at worked (/Users/lgertel/fastify-example-twitter/node_modules/fastq/queue.js:169:10)
at toLoad.finish (/Users/lgertel/fastify-example-twitter/node_modules/avvio/plugin.js:117:7)
at done (/Users/lgertel/fastify-example-twitter/node_modules/avvio/plugin.js:74:7)
at check (/Users/lgertel/fastify-example-twitter/node_modules/avvio/plugin.js:86:7)
at process._tickCallback (internal/process/next_tick.js:61:11)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: fastify index.js "--log-level" "trace" "--port" "3001"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/lgertel/.npm/_logs/2018-05-30T20_49_55_734Z-debug.log
➜ fastify-example-twitter git:(master)`

I'm following the readme. Cloned the repo and tryed to run both dev and other option too.
Anyone can help me?

Archive repo?

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Has not seen an update in 3+ years.

Improve README

Add how to run this on local machine

docker run --rm -d -p 6379:6379 redis
docker run --rm -d -p 27017:27017 mongo

See #18

How to build backend as a monolithic service?

I am getting the following exception while building the backend. Am I missing something?

I did,

npm install
npm start -- --log-level trace --port 3001

[email protected] start /Users/digvijay/tools/fastify-example-twitter/fastify-example-twitter
env-cmd local.env fastify start index.js "--log-level" "trace" "--port" "3001"

mongodb://localhost:27017/twitter
assert.js:669
assert.ifError = function ifError(err) { if (err) throw err; };
^

MongoError: unknown option to collMod: validator
at /Users/digvijay/tools/fastify-example-twitter/fastify-example-twitter/node_modules/mongodb-core/lib/connection/pool.js:581:63
at authenticateStragglers (/Users/digvijay/tools/fastify-example-twitter/fastify-example-twitter/node_modules/mongodb-core/lib/connection/pool.js:504:16)
at Connection.messageHandler (/Users/digvijay/tools/fastify-example-twitter/fastify-example-twitter/node_modules/mongodb-core/lib/connection/pool.js:540:5)
at emitMessageHandler (/Users/digvijay/tools/fastify-example-twitter/fastify-example-twitter/node_modules/mongodb-core/lib/connection/connection.js:310:10)
at Socket. (/Users/digvijay/tools/fastify-example-twitter/fastify-example-twitter/node_modules/mongodb-core/lib/connection/connection.js:453:17)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: env-cmd local.env fastify start index.js "--log-level" "trace" "--port" "3001"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/digvijay/.npm/_logs/2019-01-31T22_40_15_559Z-debug.log

Password is not encrypted

Hi,
Just a warning : The password in MongoDB is not encrypted.
🚨 May be don't use this example in Production ! 🚨

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.