Fastify example - clone twitter
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
The aim of this project is to show how
fastifycan 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.
For running this project on your machine: ```bash
cd frontend && npm start
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.
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
preHandlerhook to find which the user has made the request.
Each plugin has almost the same structure: -
index.jsis the fastify binding -
service.jsis the business logic -
schemas.jshas the schemas used for http validation and serialization (See
This plugin registers some APIs in order to register, login, search and get a profile for an user.
mongodbto save users and exports a
userClientto allow other plugins to access to an user profile.
This plugin stores tweets and allows you to retrieve the tweets of an user.
mongodbfor storing the tweets and exports a client for tweets retrieving.
This plugin tracks the following and the followers implementing the flow explained here.
redisfor tracking which users follow the other ones and vice versa.
This plugin aggregates informations from
followplugin 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.
The frontend side has been done only to show a simple UI for avoiding the manual CURLs.
It is built using
No UX or UI study are made (please PR!)
fastify-reactfor react serve side rendering