Skip to content

Backend API for habit tracking with JWT auth, Celery background jobs and Telegram notifications.

Notifications You must be signed in to change notification settings

ScherbAlex/AtomicHabits

Repository files navigation

AtomicHabits API 🌱

Python Django Celery Redis JWT CI

Backend service for habit tracking based on the Atomic Habits methodology,
with authentication, background processing and Telegram notifications.


🔎 Overview

AtomicHabits API is a production-ready backend service that allows users to:

  • manage personal habits,
  • schedule reminders,
  • receive notifications via Telegram,
  • track progress asynchronously.

The project focuses on clean architecture, business rules enforcement and testability.


✨ Key features

  • JWT token authentication
  • CRUD habits with business validation
  • Public habits (read-only)
  • Scheduled reminders (Celery + Beat)
  • Telegram integration via deep-link (/start <token>)
  • Full OpenAPI / Swagger documentation
  • High test coverage (unit, API, E2E)

🛠 Tech stack

  • Backend: Python 3.12, Django, Django REST Framework
  • Async: Celery, Redis
  • Auth: JWT
  • Database: PostgreSQL
  • Docs: drf-spectacular (OpenAPI 3)
  • Testing: pytest, DRF APIClient, mocks
  • CI/CD: GitHub Actions, Docker

🏗 Architecture

flowchart TD
  Client -->|REST API| DjangoAPI
  DjangoAPI -->|JWT auth| Auth
  DjangoAPI -->|CRUD habits| DB[(PostgreSQL)]
  DjangoAPI -->|enqueue tasks| Celery
  Celery --> Redis[(Redis)]
  Celery -->|send notifications| Telegram[Telegram Bot API]
Loading

📂 Project structure (simplified)

AtomicHabits/
├── accounts/ # registration & auth
├── habits/ # core business logic
│ ├── validators.py
│ ├── tasks.py # Celery tasks
│ └── tests/
├── notifications/ # Telegram integration
│ └── tests/
├── config/ # settings, URLs, Celery config
├── tests/ # E2E tests
└── manage.py

🔐 Authentication Token-based authentication (JWT).

POST /api/auth/register/
POST /api/auth/login/
Usage:

Authorization: Bearer
Swagger UI supports Authorize button.

📘 OpenAPI / Swagger

Swagger UI preview

Swagger UI: /api/docs/

OpenAPI schema: /api/schema/

🎬 Demo

AtomicHabits API demo (admin / API flow)

Demo shows: authentication → create habit → scheduled reminder → Telegram notification.

🧪 Testing & code quality
The project is heavily tested to ensure reliability and safe refactoring.

Covered by tests:

unit tests for models and validators

API tests (permissions, pagination, business rules)

Celery tasks (mocked execution)

Telegram API (mocked HTTP calls)

E2E flow: habit → reminder → notification

Run tests:
pytest -q
CI runs tests with:

CELERY_TASK_ALWAYS_EAGER=True
CELERY_TASK_EAGER_PROPAGATES=True
This allows testing async logic without Redis in pipeline.

🚀 Quickstart (local)

python -m venv .venv
source .venv/bin/activate # or .venv\Scripts\activate
pip install -r requirements.txt

python manage.py migrate
python manage.py runserver
Run Redis and Celery:

redis-server
celery -A config worker -B -l info
🐳 Deployment (production-ready)
The project includes automated CI/CD with GitHub Actions + Docker Compose:

build & test pipeline

Docker image build
zero-touch deployment on server

Full deployment details are documented in .github/workflows.

📌 What this project demonstrates
real-world REST API design

background task processing

strict business rule validation

external service integration

production-oriented CI/CD

emphasis on maintainability and clarity

👨‍💻 Author
Built as a showcase of production-ready backend development with a focus on
architecture, testability and scalability.

About

Backend API for habit tracking with JWT auth, Celery background jobs and Telegram notifications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages