Skip to content

API for Nevroth – an app to help users track and improve their progress in overcoming harmful habits.

Notifications You must be signed in to change notification settings

bzadorozhnyi/nevroth

Repository files navigation

😊 Nervoth Backend API

Python Django DRF Docker PostgreSQL Celery Flower

API for Nevroth – an app to help users track and improve their progress in overcoming harmful habits.

🌟 Features

Core API

  • Modern REST Architecture: JWT authentication, OpenAPI 3.0 docs, and DRF-powered endpoints.
  • Django ORM: PostgreSQL-optimized queries with atomic transactions.
  • Admin Dashboard: Pre-configured Django Admin.

Developer Experience

  • Dockerized: Docker
    • Local development with docker-compose (API + PostgreSQL).
  • Ruff for code quality: Ruff

💻 Local Development

Use Docker Compose for easy local setup. It starts the API and PostgreSQL database automatically.

✅ Prerequisites

🏁 Getting Started

  1. Clone the repository.

  2. Start the services:

    docker compose up -d
  3. The API will be available at http://127.0.0.1:8000/

  4. Database connection details:

    • Host: localhost
    • Port: 5432
    • User: postgres
    • Password: password
    • Database: nevroth_db

Access the admin panel at http://127.0.0.1:8000/admin

🚀 CI/CD with GitHub Actions

This project includes a GitHub Actions workflow:

  • Automatically runs on push and pull_request events to the main branch.
  • Spins up PostgreSQL and Redis services for integration testing.
  • Runs code quality checks with Ruff.
  • Builds a Docker image tagged with the commit SHA.
  • Executes Django database migrations and tests inside the Docker container.

⏳ Background Tasks with Celery

To ensure fast API response times and a smooth user experience, Nevroth offloads time-consuming tasks to Celery workers.

Implemented asynchronous tasks:

  • 📧 send_mail_task — used to send password recovery emails.

  • 🧠 follow_up_no_habits_selected_task — reminds users to select habits if they forgot to.

  • 🧹 cleanup_old_messages_task — regularly purges outdated chat messages to keep the database clean.

All tasks are run asynchronously via Celery and can be monitored using tools like Flower or logs inside Docker.

🔌 Real-Time Communication

Nevroth supports real-time features via Django Channels and WebSockets:

  • 🔁 ws/chats/<chat_id>/ — new messages inside a selected chat.

  • 📥 ws/chat-list/ — receive real-time updates from other chats.

This allows seamless user experience for chat interactions and live updates without page reloads.

🔧 Useful Commands

  • Check management commands:

    docker compose exec api python manage.py help
  • View logs:

    docker compose logs -f api
  • Run tests inside container:

    docker compose exec api python manage.py test

🎨 For Frontend Developers

About

API for Nevroth – an app to help users track and improve their progress in overcoming harmful habits.

Topics

Resources

Stars

Watchers

Forks

Languages