In this task you're presented with an API backend of chart data, comments and sharing. The task is to build a frontend that displays the chart and allows users to add comments and share the chart.
Install Docker.
Run docker-compose build
- might take a while for frontend to build.
Run docker-compose up
- wait until yo see "frontend | Compiled successfully!" message; loads in around a 2-3 minutes.
Navigate to http://localhost:3000 to view the app.
To launch only the backend - run docker-compose up backend
backend
folder hosts FastAPI backend.
test_main.py
has integration testsservices/test_comments_service.py
has unit tests for thes comments service- locks are used to prevent race conditions, e.g. multiple comment threads attached to the same chart data point or overwriting the comments
frontend
folder hosts React/Typescript frontend.
Bar chart is used for the test task. Countries are on the X axis, Features are on the Y axis.
Chart Domain
ChartDataPoint
represents single point on the plotChartDataFeature
is an enum with all available featuresCountry
is an enum with all available features
Comment Domain
CommentThread
represents a single thread attached to chartComment
represents an entry within a thread
Backend API runs on http://localhost:8000
type ChartDataFeature = 'hotdog' | 'burger' | 'sandwitch' | 'kebab' | 'fries' | 'donut';
type Country = 'FR' | 'GB' | 'BE' | 'DE' | 'ES' | 'IT'
type ChartDataPoint = {
feature: ChartDataFeature;
country: Country;
}
type CommentThread = {
id: string;
comments_count: number;
chart_data_point: ChartDataPoint[];
}
type Comment = {
user_name: string;
text: string;
}
Returns chart data formatted to be ready-for-consumption.
type ChartDataResponse = {
country: Country;
[key: ChartDataFeature]: number;
}[]
Returns a list of comment threads,
type CommentThreadsResponse = CommentThread[]
Returns a list of comments in a thread
type CommentThreadResponse = CommentThread & {
comments: Comment[];
}
Creates a new comment thread, responds with CommentThreadResponse
type CreateThreadRequest = {
comment: Comment;
data_point: ChartDataPoint;
}
``
Posts a new comment to a thread, responds with CommentThreadResponse
type RespondToCommentThreadRequest = {
comment: Comment;
}
``
Returns a shareable link for a chart
type ShareResponse = {
token: string;
}
Returns chart data by token, responds with ChartDataResponse