This is a complex implementation of the social networking kata proposed by Xpeppers team.
A simple implementation can be found here.
This kata is implemented using:
This kata runs in two modes:
- mono is the quick as a snake, quiet as a shadow way:
- a single script does everything
- data is managed directly on the file system
- full is the calm like a giant tree in a storm way:
- some services work together to get the things done
- data is managed in distinct locations:
- timelines in a time series database
- followers in an object database
When the CLI is ready you can type help
to display available commands.
Enjoy!
To execute the script in mono mode:
- clone the repo — follow this guide
- on Windows you'll have to change the end of line sequence
from
CRLF
toLF
in following files:
- on Windows you'll have to change the end of line sequence
from
- run the
kataq
command (addingdemo
to run a non-interactive session):- on Windows:
%SYSTEMDRIVE%:\path\to\the\repo\kataq.cmd [demo]
- on Linux:
/path/to/the/repo/kataq.sh [demo]
- on Windows:
To spin up the services in full mode:
- make sure you have Docker 1.12.0 or higher
- clone the repo — follow this guide
- on Windows you'll have to change the end of line sequence
from
CRLF
toLF
in following files:
- on Windows you'll have to change the end of line sequence
from
- run the
kata
command (addingdemo
to run a non-interactive session):- on Windows:
%SYSTEMDRIVE%:\path\to\the\repo\kata.cmd [demo]
- on Linux:
/path/to/the/repo/kata.sh [demo]
- on Windows:
The first run may take a few minutes... meanwhile you can have a look at:
Timelines API ---- Timelines DB ---- Timelines DB admin / \ / / \ / CLI ---- API gateway < >---- Web UI ----< \ / \ \ / \ Followers API ---- Followers DB ---- Timelines DB admin
Frontend user interfaces include:
The command line interface is implemented in Bash using curl and jq to interact with the API gateway when running in full mode.
If you type help
in the CLI you'll see this:
kata commands:
<user name> -> <message> -> post message to user timeline
<user name> -> read messages from user timeline
<user name> follows <another user> -> subscribe user to another user timeline
<user name> wall -> read messages from user timeline and subscriptions
utility commands:
exit -> exit the cli
help -> read this help
kata -> read full readme of kata requirements
mode -> tell if running in:
- 'full' mode: attached to an API server which handles user data
- 'mono' mode: handling user data using the file system
kata readme: https://github.com/xpeppers/social_networking_kata
This is the output of a demo run:
> Alice -> I love the weather today
> Bob -> Damn! We lost!
> Bob -> Good game though.
> Alice
> Alice - I love the weather today (5 seconds ago)
> Bob
> Bob - Good game though. (4 seconds ago)
> Bob - Damn! We lost! (6 seconds ago)
> Charlie -> I'm in New York today! Anyone wants to have a coffee?
> Charlie follows Alice
> Charlie wall
> Charlie - I'm in New York today! Anyone wants to have a coffee? (4 seconds ago)
> Alice - I love the weather today (14 seconds ago)
> Charlie follows Bob
> Charlie wall
> Charlie - I'm in New York today! Anyone wants to have a coffee? (7 seconds ago)
> Bob - Good game though. (14 seconds ago)
> Bob - Damn! We lost! (16 seconds ago)
> Alice - I love the weather today (17 seconds ago)
The web user interface is implemented in HTML, CSS and JavaScript using React.
When the CLI is ready you can open the web UI here to inspect services.
Once the backend services are up and running, you can [inspect] them.
You can find the credentials in the /backend/.env file.
The API gateway exposes the 4 kata requirements using Node-RED with JSONata:
- posting
POST http://localhost:11881/posting?user=Alice
Hi!
routes to timelines posting - reading GET http://localhost:11881/reading?user=Alice routes to timelines reading
- following
PUT http://localhost:11881/following?user=Charlie
Alice
routes to followers following - wall GET http://localhost:11881/wall?user=Charlie composes followers following + timelines reading
Users timelines are written (posting kata) and read (reading and wall kata) using Node-RED with JSONata.
Exposed endpoints are:
- reading/wall
GET http://localhost:11888/api/v1/reading?users=Alice,Bob,Charlie
Only last 50 posts within last week are returned for each user.
- posting
POST http://localhost:11888/api/v1/posting
{"user":"Alice","text":"Hi!"}
- testing
GET http://localhost:11888/api/v1/test
returns
200
if passed or418
if failed
Users posts are stored into a time serie using InfluxDB, with infinite
retention policy and 1s
precision.
The time series database server is managed using Chronograf. You can query the timelines here.
All different timelines are stored into the same timeline
measurement, indexed by the user
tag.
The information about "who-follows-who" is written (following kata) and read (wall kata) using a Spring Boot application with Lombok and JPA.
Exposed endpoints are (more than necessary, for test purposes):
- posting
PUT http://localhost:18080/api/v1/users
Alice
No validation is performed against data, as we focus on the sunny day scenarios.
- following
PUT http://localhost:18080/api/v1/users/Charlie
Alice
Everyone can follow anyone: users are addedd if missing.
- wall GET http://localhost:18080/api/v1/users/Charlie
- listing GET http://localhost:18080/api/v1/users
The information about "who-follows-who" is stored into a PostgreSQL database.
The user entity "follows" other user entities in an unidirectional many-to-many relationship.
The database is managed using pgAdmin.
To view DB tables open Servers > pgkata > Databases > kata > Schemas > public > Tables
- Take a look at these examples of simple unit tests.
- Import this collection in Postman to run functional and integration tests.
- Run
npm test
command infrontend/react
directory to run a minimal ui test.
Made with ❤️ by Fabio Michelini