Segment Challenge is an Elixir Phoenix web application built using Commanded for CQRS/ES. The front-end is mostly server generated HTML plus a few React components for responsive forms.
Segment Challenge allows any Strava athlete to host their own Strava-based challenge. Strava is a social network for athletes.
A challenge comprises one or more stages. You can create a challenge based around different Strava segments, or an activity challenge where you decide what type of activity to record (distance, duration, or elevation) and can set an optional goal.
In March 2019 Strava decided to revoke access to the Strava API for Segment Challenge as "... the purpose of this app is competitive with Strava". Without API access the site cannot function. I am making the source code public to demonstrate one approach to building event sourced Elixir applications using Commanded.
Yes, first you need to create a Strava account and create your own Strava API Application and then follow the steps below to clone the Git repo, prepare, and run the application.
No, Strava will not allow Segment Challenge access to their API in public.
Install Elixir v1.8 and a Postgres database.
You will need to create a Strava API Application to access the API. Any Strava account can be used to create an application. Please refer to the Strava Developers documentation for help.
-
Install Elixir dependencies:
mix deps.get
-
Configure your Strava API Application settings:
cp config/dev.secret.example config/dev.secret.exs
Edit the
config/dev.secret.exs
config file and enter the Client ID, Client Secret, and Access Token values from you Strava API Application settings.You will need to do the same for
test.secret.exs
to run tests andprod.secret.exs
to run in production. -
Create the event store and read store databases:
mix setup
This command will create and initialise two databases (
segmentchallenge_eventstore_dev
andsegmentchallenge_readstore_dev
) using the default Postgres connection settings configured inconfig/dev.exs
. -
Install JavaScript dependencies and compile assets:
npm install npm run compile
You can use the
npm run watch
task to watch the assets and recompile on change. -
Run the Phoenix web server:
iex -S mix phx.server
Attempts at active stages are fetched from Strava every four hours. To import them immediately you can run the following from an iex -S mix
console:
iex> SegmentChallenge.Tasks.ImportActiveStageEfforts.execute()