Skip to content

chafan-dev/chafan-core

Repository files navigation

Chafan Core Backend Framework

Main test

Under active construction!! 🚧

Getting Started

Requirements

Set up editor

  • Install Poetry package manager https://python-poetry.org
  • poetry install to create virtual env and install all Python dependencies
  • poetry shell to enter the virtual env. You need to run this everytime in this repo before running other commands that depends on Python code.
  • make link-venv to create a symbolic to virtual env such that VSCode is happy (if necessary, Run "Reload window" and make sure that the Python environment is .venv).
  • Use VSCode with Python extension (Pylance is recommended).

Develop server locally

Example .env for basic development (update DATABASE_URL, REDIS_URL, RABBITMQ_URL if necessary):

SERVER_NAME=dev.cha.fan
SERVER_HOST=http://dev.cha.fan:4582
BACKEND_CORS_ORIGINS=["http://dev.cha.fan:8080"]
PROJECT_NAME=Chafan Dev
SECRET_KEY=chafandev
FIRST_SUPERUSER=admin@cha.fan
FIRST_SUPERUSER_PASSWORD=superuser
USERS_OPEN_REGISTRATION=False
DATABASE_URL=postgresql://chafan@localhost:5432/chafan_dev
ENV=dev
REDIS_URL=redis://127.0.0.1:6379
RABBITMQ_URL=amqp://guest:guest@localhost:5672/%2f

Run following commands to create database and initialize chafan_dev table.

# Run migrations
alembic upgrade head

# Create initial data in DB
python scripts/initial_data.py

After initialization, run dev server:

make dev-run

Open http://dev.cha.fan:4582/docs for API docs.

DB Schema Migrations

$ alembic revision --autogenerate -m "Add column last_name to User model"
$ alembic upgrade head

Test

Reset persistent state before testing:

bash scripts/reset_app_state.sh

Test a single file:

scripts/run-unit-tests.sh

Test all:

pytest

RabbitMQ dev setup in macOS

Management Plugin enabled by default at http://localhost:15672. Default username/password is guest/guest.

To have launchd start rabbitmq now and restart at login:

brew services start rabbitmq

Or, if you don't want/need a background service you can just run:

rabbitmq-server

Staging

stag branch is automatically pushed to the following endpoint for testing:

https://chafan-test.dokku.cha.fan/

How to add a new event type

  • Core backend code changes
    • Add event definition: chafan_core/app/schemas/event.py
    • If the event goes to activity feed
      • Feed distribution: chafan_core/app/feed.py:get_activity_receivers
    • If the event goes to notifications
      • chafan_core/app/materialize.py: materialize_event and _KEYS (if there is a new type of field)
      • chafan_core/app/common.py: EVENT_TEMPLATES
  • PWA code changes
    • Add event definition: src/interfaces/index.ts
    • If the event goes to activity feed
      • Update event card: src/views/main/Home.vue
    • Update event field rendering: src/components/Event.vue (if there is a new type of field)
    • Update event translation rendering: src/main.ts

Dependency

Run poetry update to update all dependencies.

Copyright

For all files within this repo, see LICENSE for default copyright unless otherwise declared in file:

Releases

No releases published

Packages

No packages published

Languages