Coder Social home page Coder Social logo

naderbhrr / fastify-example-twitter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fastify/fastify-example-twitter

0.0 0.0 0.0 117 KB

Fastify example - clone twitter

License: MIT License

HTML 2.57% JavaScript 94.61% CSS 0.61% Dockerfile 2.20%

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

Contributors

allevo avatar cagataycali avatar nicknaso 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.