ref: e41ccd0181757f64258e9cad93ade228687cb614 mataroa/README.md -rw-r--r-- 6.9 KiB
e41ccd01Theodore Keloglou add dark mode 10 months ago


Minimal blogging platform with export as first-class feature.


Feel free to open a PR on GitHub or send an email patch to ~sirodoht/public-inbox@lists.sr.ht.

On how to contribute using email patches see git-send-email.io.

Also checkout our docs on:


This is a Django codebase. Check out the Django docs for general technical documentation.


The Django project is mataroa. There is one Django app, main, with all business logic. Application CLI commands are generally divided into two categories, those under python manage.py and those under make.


Using venv:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements_dev.txt

This project also uses pip-tools for dependency management.

#Environment variables

A file named .envrc is used to define the environment variables required for this project to function. One can either export it directly or use direnv. There is an example environment file one can copy as base:

cp .envrc.example .envrc

.envrc should contain the following variables:

export SECRET_KEY=some-secret-key
export DATABASE_URL=postgres://mataroa:db-password@db:5432/mataroa
export EMAIL_HOST_USER=smtp-user
export EMAIL_HOST_PASSWORD=smtp-password

When on production, also include the following variables (see Deployment and Backup):

export NODEBUG=1
export PGPASSWORD=db-password


This project uses PostgreSQL. Assuming one has set the DATABASE_URL (see above), to create the database schema:

python manage.py migrate

Also, initialising the database with some sample development data is possible with:

python manage.py populate_dev_data


To develop locally with subdomains, one needs something like that in /etc/hosts: mataroalocal.blog random.mataroalocal.blog test.mataroalocal.blog mylocalusername.mataroalocal.blog

As /etc/hosts does not support wildcard entries, there needs to be one entry for each mataroa user/blog.


To run the Django development server:

python manage.py runserver


If Docker and docker-compose are preferred, then:

  1. Set DATABASE_URL in .envrc to postgres://postgres:postgres@db:5432/postgres
  2. Run docker-compose up -d.

The database data will be saved in the git-ignored directory / Docker volume db_data, located in the root of the project.


Using the Django test runner:

python manage.py test

For coverage, run:

make cov

#Code linting & formatting

The following tools are used for code linting and formatting:

  • black for code formatting.
  • isort for imports order consistency.
  • flake8 for code linting.

To use:

make format
make lint


Deployment is configured using uWSGI and Caddy.

A server playbook document is also available, based on Ubuntu 20.04.

Remember to set the environment variables before starting uwsgi. Depending on the deployment environment, this could mean directly exporting the variables or just sourcing .envrc (with all production variables — including NODEBUG):

source .envrc
uwsgi uwsgi.ini  # start djago app
caddy start --config /home/roa/mataroa/Caddyfile  # start caddy server

To reload or stop the uWSGI process:

uwsgi --reload mataroa.pid
uwsgi --stop mataroa.pid

# or find the PID and kill that directly
ps aux|grep uwsgi
kill -9 <PID>

To reload or store the Caddy webserver:

caddy reload --config /home/roa/mataroa/Caddyfile
caddy stop

Note that the value of the NODEBUG variable is ignored. What matters is merely its existence in the environment.

Also, two cronjobs (used by the email newsletter feature) are needed to be installed. The schedule is subject to the administrator's preference. Indicatively:

*/5 * * * * bash -c 'cd /home/roa/mataroa && source ./venv/bin/activate && source .envrc && python manage.py enqueue_notifications'
*/10 * * * * bash -c 'cd /home/roa/mataroa && source ./venv/bin/activate && source .envrc && python manage.py process_notifications'
0 0 1 * * bash -c 'cd /home/roa/mataroa && source ./venv/bin/activate && source .envrc && python manage.py mail_exports'

Documentation about the commands can be found in section Management.

Finally, certain setting variables may need to be redefined:



To automate backup, there is a script which dumps the database and uploads it into any S3-compatible object storage cloud using the MinIO client. The script also needs the database password as an environment variable. The key needs to be PGPASSWORD. The backup script assumes the variable lives in .envrc like so:

export PGPASSWORD=db-password

To restore a dump:

pg_restore -v -h localhost -cO --if-exists -d mataroa -U mataroa -W mataroa.dump

To add on cron:

0 */6 * * * /home/roa/mataroa/backup-database.sh


In addition to the standard Django management commands, there are also:

  • enqueue_notifications: create records for notification emails to be sent.
  • process_notifications: sends notification emails for new blog posts of existing records.
  • mail_exports: emails users of their blog exports.
  • populate_dev_data: populate database with sample development data.

They are triggered using the standard manage.py Django way; eg:

python manage.py enqueue_notifications


One can deploy mataroa without setting up the billing functionalities. This is the default case. To handle payments and subscriptions this project uses Stripe. To enable Stripe and payments, one needs to have a Stripe account with a single Product (eg. "Mataroa Premium Plan").

To configure add the following variables to your .envrc from your Stripe account:

export STRIPE_API_KEY="sk_test_XXX"
export STRIPE_PUBLIC_KEY="pk_test_XXX"
export STRIPE_PRICE_ID="price_XXX"


This software is licensed under the MIT license. For more information, read the LICENSE file.