The Budget Tracker API is a RESTful backend application built with Django and Django REST Framework. It allows users to manage their personal finances by tracking income and expenses with categorization and comprehensive reporting features.
Simple-Budget-Tracker-API/
βββ budget_tracker/ # Main Django project
β βββ __init__.py
β βββ settings.py # Project settings
β βββ urls.py # Main URL configuration
β βββ wsgi.py # WSGI configuration
β βββ asgi.py # ASGI configuration
βββ users/ # User management app
β βββ models.py # User model
β βββ views.py # Authentication views
β βββ serializers.py # User serializers
β βββ urls.py # User URL patterns
β βββ admin.py # Admin configuration
βββ categories/ # Category management app
β βββ models.py # Category model
β βββ views.py # Category CRUD views
β βββ serializers.py # Category serializers
β βββ urls.py # Category URL patterns
β βββ admin.py # Admin configuration
β βββ management/ # Custom management commands
β βββ commands/
β βββ create_default_categories.py
βββ transactions/ # Transaction management app
β βββ models.py # Transaction model
β βββ views.py # Transaction CRUD and filtering views
β βββ serializers.py # Transaction serializers
β βββ urls.py # Transaction URL patterns
β βββ admin.py # Admin configuration
βββ summary/ # Financial summary app
β βββ views.py # Summary and reporting views
β βββ serializers.py # Summary serializers
β βββ urls.py # Summary URL patterns
βββ requirements.txt # Python dependencies
βββ manage.py # Django management script
βββ test_api.py # Comprehensive API testing script
βββ db.sqlite3 # SQLite database (generated)
- Python 3.8 or higher
- Git
git clone <repository-url>
cd Simple-Budget-Tracker-APIpython -m venv venv# Windows
.\venv\Scripts\activate
# macOS/Linux
source venv/bin/activatepip install -r requirements.txtpython manage.py migratepython manage.py create_default_categoriespython manage.py createsuperuserpython manage.py runserverThe API will be available at: http://127.0.0.1:8000/
- Fields: id, username, email, first_name, last_name, password, date_joined, created_at, updated_at
- Features: Extends Django's AbstractUser with additional timestamps
- Fields: id, name, description, created_at, updated_at
- Constraints: name must be unique
- Relationships: One-to-many with Transaction
- Fields: id, user, amount, type, category, date, description, created_at, updated_at
- Types: 'income' or 'expense'
- Constraints: amount must be positive
- Relationships:
- Many-to-one with User
- Many-to-one with Category
The API uses Token-based authentication:
- Register: Create an account and receive a token
- Login: Authenticate with username/password to get a token
- Authorization: Include token in headers:
Authorization: Token <your-token> - Logout: Delete the token
- POST
/users/register/ - Body:
{ "username": "john_doe", "email": "john@example.com", "password": "securepass123", "password_confirm": "securepass123", "first_name": "John", "last_name": "Doe" } - Response: User data + authentication token
- POST
/auth/login/ - Body:
{ "username": "john_doe", "password": "securepass123" } - Response: User data + authentication token
- GET
/users/me/(requires authentication) - PUT/PATCH
/users/me/(update profile)
- POST
/auth/logout/(requires authentication)
- GET
/categories/- List all categories - POST
/categories/- Create new category{ "name": "Food & Dining", "description": "Groceries, restaurants, etc." }
- GET
/categories/{id}/- Get category details - PUT/PATCH
/categories/{id}/- Update category - DELETE
/categories/{id}/- Delete category
- GET
/transactions/- List user's transactions - POST
/transactions/- Create new transaction{ "amount": "150.00", "type": "expense", "category": 1, "date": "2025-08-01T10:00:00Z", "description": "Grocery shopping" }
- GET
/transactions/{id}/- Get transaction details - PUT/PATCH
/transactions/{id}/- Update transaction - DELETE
/transactions/{id}/- Delete transaction
- GET
/transactions/filter/- Advanced filtering with parameters:type: income/expensecategory: category IDstart_date: YYYY-MM-DDend_date: YYYY-MM-DDsearch: search in description/category name
- GET
/summary/- Complete financial overview - Optional Parameters:
start_date: Filter by date rangeend_date: Filter by date range
- GET
/summary/categories/- Category-wise breakdown - Optional Parameters:
type: income/expensestart_date: Filter by date rangeend_date: Filter by date range
{
"total_income": "5500.00",
"total_expenses": "1310.50",
"net_balance": "4189.50",
"transaction_count": 5,
"income_count": 2,
"expense_count": 3,
"category_breakdown": {
"income": [
{
"category__name": "Salary",
"total_amount": 5000.0,
"transaction_count": 1
}
],
"expenses": [
{
"category__name": "Rent",
"total_amount": 1200.0,
"transaction_count": 1
}
]
}
}{
"count": 3,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"amount": "5000.00",
"type": "income",
"category": 9,
"category_detail": {
"id": 9,
"name": "Salary",
"description": "Primary income from employment",
"transaction_count": 1
},
"date": "2025-08-01T07:15:14.688160+01:00",
"description": "Monthly salary",
"user_username": "testuser",
"created_at": "2025-08-01T07:15:14.700928+01:00",
"updated_at": "2025-08-01T07:15:14.700928+01:00"
}
]
}python test_api.pyThis script tests all API endpoints and functionality including:
- User registration and authentication
- Category management
- Transaction CRUD operations
- Filtering and search
- Financial summaries
- Error handling
python manage.py test- Database: SQLite (development) - easily changeable to PostgreSQL for production
- Authentication: Token-based authentication
- Pagination: 20 items per page
- Time Zone: UTC
- Debug Mode: True (development)
Create a .env file for sensitive settings:
SECRET_KEY=your-secret-key-here
DEBUG=True
DATABASE_URL=sqlite:///db.sqlite3
The system comes with 15 pre-configured categories:
Income Categories:
- Salary
- Freelance
- Investment
- Gift
Expense Categories:
- Food & Dining
- Transportation
- Utilities
- Entertainment
- Healthcare
- Shopping
- Education
- Rent
- Insurance
- Savings
- Other
- Token Authentication: Secure API access
- User Isolation: Users can only access their own data
- Input Validation: Comprehensive data validation
- SQL Injection Protection: Django ORM provides protection
- CSRF Protection: Built-in Django protection
- Password Validation: Django's built-in password validators
- Set
DEBUG = False - Configure proper database (PostgreSQL recommended)
- Set up environment variables for sensitive settings
- Configure static file serving
- Set up proper domain and HTTPS
- Consider using Redis for caching
- Set up logging and monitoring
django==4.2.7
djangorestframework==3.14.0
python-decouple==3.8
psycopg2-binary==2.9.6 # For PostgreSQL
gunicorn==20.1.0 # For production server
django-filter==23.3- Recurring Transactions: Support for recurring income/expenses
- Budget Planning: Set budget limits per category
- Data Export: Export data to CSV/PDF
- Mobile App: React Native or Flutter app
- Multi-currency Support: Handle different currencies
- Data Visualization: Charts and graphs
- Expense Receipt Upload: Image upload for receipts
- Notifications: Email/SMS notifications for budget limits
- Django-admin not found: Use
python -m djangoinstead - Package installation errors: Ensure virtual environment is activated
- Migration errors: Delete migrations and recreate if needed
- Permission errors: Ensure proper authentication headers
- Date format errors: Use ISO format (YYYY-MM-DDTHH:MM:SSZ)
- Check Django documentation: https://docs.djangoproject.com/
- Django REST Framework docs: https://www.django-rest-framework.org/
- Check the test script for usage examples
- Review error messages in the terminal
For interactive API documentation, you can add:
- Django REST Framework Browsable API: Built-in (available at each endpoint)
- Swagger/OpenAPI: Add
drf-spectacularfor automatic API documentation - Postman Collection: Import endpoints for easy testing
Your Budget Tracker API is now fully functional with:
β
Complete CRUD operations for transactions and categories
β
User authentication and authorization
β
Advanced filtering and search capabilities
β
Comprehensive financial summaries
β
Well-structured codebase following Django best practices
β
Comprehensive test suite
β
Admin interface for easy data management
β
Production-ready architecture
The API successfully demonstrates your Django and Python skills and provides a solid foundation for a personal finance management system!