CLA Backend API

by ministryofjustice


CLA Backend

Backend API for the Civil Legal Aid Tool.



Clone the repository:

git clone

Next, create the environment and start it up:

cd cla_backend
virtualenv env --prompt=\(cla_be\)

source env/bin/activate

Update pip to the latest version:

pip install -U pip

Install python dependencies:

pip install -r requirements/local.txt

Create the database inside postgres. Type psql -d template1 to enter postgres, then enter:

\c cla_backend
create extension pgcrypto;

You should see a message saying CREATE EXTENSION. If you get an error instead, if means that you don't have the related lib installed. This is a rare case as postgresql-contrib gets installed automatically by homebrew and postgresapp. In linux, you can install it using sudo apt-get install postgresql-contrib

Now make postgres create the extension automatically when new databases are created, this is useful otherwise the test command will error.

Open a terminal and type:

psql -d template1 -c 'create extension pgcrypto;'

For OSX, update the PATH and DYLD_LIBRARY_PATH environment variables if necessary:

export PATH="/Applications/$PATH"

Create a settings file from the example file:

cp cla_backend/settings/ cla_backend/settings/

Sync and migrate the database:

./ migrate

Create an admin user by running the following command and specifying username == password == 'admin':

./ createsuperuser

Load initial data:

./ loaddata initial_groups.json kb_from_knowledgebase.json initial_category.json test_provider.json test_provider_allocations.json initial_mattertype.json test_auth_clients.json initial_media_codes.json test_rotas.json

Start the server:

./ runserver 8000

See the list of users in /admin/auth/user/. Passwords are the same as the usernames.


Each time you start a new terminal instance you will need to run the following commands to get the server running again:

source env/bin/activate

./ runserver 8000


When making changes to text (e.g. GraphML files) translations should be updated. To update translations run:

./ translations update

Scope Graphs

  • Edit the .graphml files, e.g. using a tool like [yEd](, to change the scope diagnosis trees
  • Run Django management command python translations update to update translations and templated graph files


If you are experiencing errors when creating and syncing the database, make sure the following are added to your PATH var (amend path to postgres as necessary):

export PATH="/Applications/$PATH"

If you get the error django.db.utils.OperationalError: FATAL: role "postgres" does not exist, you will need to create the user postgres on the database.

createuser -s -e postgres