SpendSense is a web application for budget and expense tracking, built with Django and Django REST Framework (DRF) for a robust API. It is powered by PostgreSQL and Redis, and uses Docker for easy setup and deployment, making it simple to manage your finances.
- Track income and expenses
- Categorize transactions
- View budget summaries and insights
- RESTful API powered by Django REST Framework (DRF) for seamless integration
- Telegram bot for managing transactions and viewing account details (optional, for enhanced interaction)
- PostgreSQL for data storage (previously used MongoDB)
- Redis for caching and performance
- Celery for asynchronous task processing
- Flower for monitoring Celery tasks
- Dockerized setup for consistent environments
Before you begin, ensure you have the following installed:
- Docker
- Docker Compose
- Python 3.10+ (optional, for manual Django setup)
- Git
Follow these steps to set up and run SpendSense on your local machine.
git clone --depth=1 https://github.com/HappyMaxxx/SpendSense.git spendsense
cd spendsenseNote: The
--depth=1flag performs a shallow clone, downloading only the latest commit to save time and space. If you need the full commit history later, run:git fetch --unshallow
Create a .env file in the project root and add the following:
DJANGO_SECRET_KEY=your-secret-key-here
DEBUG=False
ALLOWED_HOSTS=web,localhost,127.0.0.1
POSTGRES_DB=app_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
BOT_TOKEN=your-telegram-bot-token-here
BOT_URL='https://t.me/your-bot-name'Note:
- Generate a secure
DJANGO_SECRET_KEY(e.g., usingpython -c "import secrets; print(secrets.token_hex(32))").- The
TELEGRAM_BOT_TOKENis optional and only required if you want to use the Telegram bot. Obtain it by creating a bot via BotFather on Telegram.- Optionally, add your local network IP (e.g.,
192.168.1.6or192.168.0.120) toALLOWED_HOSTSto access the app from other devices on your network.
Prepare static assets for production:
python3 manage.py collectstatic # for Linux/macOS
# or
python manage.py collectstatic # for WindowsBuild the Docker images and start the Django, PostgreSQL, Redis, Celery, and Flower containers:
docker-compose up --buildNote: On Linux, you may need
sudodepending on your Docker setup. On Windows, use Docker Desktop and run the command in PowerShell or CMD.
The application will be available at: http://localhost:8000.
The Flower dashboard for monitoring Celery tasks will be available at: http://localhost:5555.
The Telegram bot, if enabled, can be interacted with via Telegram after starting the bot with the provided token.
To stop the running containers:
docker-compose downTo stop containers and remove them along with the PostgreSQL data volume:
docker-compose down -vWarning: The
-vflag deletes the PostgreSQL database volume, resulting in data loss. Use with caution.
Important: After removing the PostgreSQL volume, the Django superuser account will be deleted. Create a new superuser by running:
docker-compose run web python manage.py createsuperuserFollow the prompts to set up a new admin account for accessing the Django admin panel.
The docker-compose.yml defines five services:
- web: The Django application, built from the project directory, exposed on port
8000. - db: PostgreSQL, using the
postgres:15image, with data persisted in the postgres_data volume, exposed on port5432. - bot: The Telegram bot (optional), built from the project directory, running
bot/main.py, dependent on PostgreSQL, with access to the project directory via a volume. This service only runs ifTELEGRAM_BOT_TOKENis provided. - redis: Redis, using the
redis:latestimage, exposed on port6379. - celery: Celery worker for asynchronous task processing, built from the project directory, dependent on Redis and PostgreSQL.
- flower: Flower dashboard for monitoring Celery tasks, using the
mher/flowerimage, exposed on port5555.
services:
web:
build: .
ports:
- "8000:8000"
depends_on:
- db
- redis
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/app_db
command: ["./wait-for-it.sh", "db:5432", "--", "python3", "manage.py", "runserver", "0.0.0.0:8000"]
db:
image: postgres:15
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
bot:
build: .
command: python3 bot/main.py
volumes:
- .:/app
depends_on:
- db
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/app_db
redis:
image: redis:latest
ports:
- "6379:6379"
celery:
build: .
command: celery -A spendsense worker --loglevel=info
depends_on:
- redis
- db
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/app_db
flower:
image: mher/flower
environment:
- CELERY_BROKER_URL=redis://redis:6379/0
ports:
- "5555:5555"
depends_on:
- redis
volumes:
postgres_data:Important: celery and flower services are currently temporarily commented out, as they are not yet in use
- Port conflicts: Ensure ports
8000,27017,6379, and5555are free. Check withsudo netstat -tuln | grep <port>. - PostgreSQL connection issues: Verify the
DATABASE_URLin the.envfile matches the PostgreSQL service name (db) and database name (finance_tracker). - Telegram bot issues: If using the optional Telegram bot, ensure the
TELEGRAM_BOT_TOKENis correctly set in the.envfile and that the bot is properly registered with BotFather. If the bot fails to start, it will not affect the core web application. - Celery issues: Ensure the
CELERY_BROKER_URLin the.envfile is set toredis://redis:6379/0. - Docker permissions: On Linux, if you encounter permission errors, add your user to the Docker group:
sudo usermod -aG docker $USER.
To access SpendSense or the Flower dashboard from another device on your local network:
- Add your machineβs local IP (e.g.,
192.168.1.6or192.168.0.120) toALLOWED_HOSTSin the.envfile. - Ensure your firewall allows traffic on ports
8000(Django) and5555(Flower). - Access the app via
http://<your-ip>:8000or Flower viahttp://<your-ip>:5555from another device.
The SpendSense API is built using Django REST Framework (DRF), providing a robust and scalable RESTful interface for managing budgets, transactions, and other financial data. Full API documentation, including endpoints, request/response formats, and authentication details, is available in API.md.
For easier interaction with the SpendSense API, you can use the dedicated SpendSense-API-Client. This helper program simplifies making API requests to manage your budgets, transactions, and other features programmatically.
- Repository: https://github.com/HappyMaxxx/SpendSense-API-Client
- Features:
- Simplified API calls for creating, updating, and retrieving financial data via DRF endpoints.
- Command-line interface for quick access to SpendSense functionality.
- Well-documented examples to get started.
Check the repository for setup instructions and usage details.
If you find this project useful and would like to support its development, consider donating:
- π Ko-fi: https://ko-fi.com/v1mer
- π¬ PayPal: mpatik2006@gmail.com
Your support helps me dedicate more time to improving this project. Thank you! π
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Happy budgeting with SpendSense! πΈ
