Skip to content

Commit

Permalink
Fix README
Browse files Browse the repository at this point in the history
  • Loading branch information
allevo committed Dec 27, 2018
1 parent b86c111 commit 3c237e3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
48 changes: 3 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,6 @@ Open your browser at [http://localhost:3000](http://localhost:3000)

### Architecture


Currently the backend is built considering the following modules:
```
+------+ +-------+ +--------+ +----------+
| | | | | | | |
| | | tweet | | follow | | timeline |
| | | | | | | |
| user | +-------+ +--------+ +----------+
| | | | |
| | | | |
| | +----------------------------------+
| | | auth pre handler |
+------+ +----------------------------------+
| |
+---------------------------------------------+
| |
| fastify |
| |
+---------------------------------------------+
```

With this configuration, the backend can be developed keeping each business logic segregated in own plugin.
For instance, the `TimelineService` is instanced only one time inside its module and the timeline module doesn't know the existance of the user module at all!

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](https://www.fastify.io/docs/latest/Plugins-Guide/)

So, the backend is splitted into plugins:
Expand All @@ -62,17 +36,6 @@ 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](https://www.fastify.io/docs/latest/Validation-and-Serialization/))
- `client.js` has a class that exports a connector for the business logic (See below)

In some circumstance a module has to have access to another module. For instance, when an user want to add a new tweet, the backend has to check which user is querying. In that situations the tweet module depends on the user module. In order to avoid sharing business logics, each module exposes its own client: in that way the developer chooses to which parts the other plugin can have an access.

Each module has some dependency checked by [`fastify-plugin`](https://github.com/fastify/fastify-plugin) like mongodb or redis client or other kind of dependency.


All plugins are registered in the `index.js` file in the right order.

The user authentication is made through JSON Web Token using `fastify-jwt`.


### User plugin

Expand All @@ -90,13 +53,13 @@ It uses `mongodb` for storing the tweets and exports a client for tweets retriev

This plugin tracks the following and the followers implementing the flow explained [here](https://redis.io/topics/twitter-clone).

It uses `redis` for tracking which users follow the other ones and vice versa. This plugin exports a client in order to find the tweet given a list of users.
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 tweetClient and followClient to build the response.
This plugin doesn't use any database to track that informations and uses tweetService and followService to build the response.

## Frontend

Expand All @@ -106,19 +69,14 @@ It is built using `react` + `redux` stack.

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

## Split for building microservices

Now our code is a monolith. But is a nice monolith!
Our code is split keeping the logic separated: this is the good thing.

***Coming soon***

## TODO

- [x] Search users
- [x] Timeline
- [x] Follow microservices for following and unfollowing other users
- [ ] Better test
- [x] Better test
- [ ] Better README.md
- [x] Use Docker compose
- [ ] Use `fastify-react` for react serve side rendering
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"unit": "tap test/*.test.js",
"test": "npm run lint && npm run build-frontend && npm run unit",
"build-frontend": "cd frontend && npm install && npm run build",
"microservice": "fastify",
"start": "env-cmd local.env fastify index.js"
"start": "env-cmd local.env fastify start index.js"
},
"author": "Tommaso Allevi <tomallevi@gmail.com>",
"license": "MIT",
Expand Down

0 comments on commit 3c237e3

Please sign in to comment.