This project is a robust and secure backend API for a personal digital wallet, built with Django and Django REST Framework. It allows users to manage their financial accounts, track income and expenses, and transfer funds between users.
This project demonstrates core skills in backend development, including API design, database management, and a focus on data integrity and security.
- User Management: Secure user registration, authentication, and profile management.
- Multi-Account Support: Users can create and manage multiple financial accounts.
- Transaction Tracking: Record income and expenses for each account.
- Inter-User Transfers: Securely transfer funds between different user accounts.
- Categorization: Categorize transactions for better financial tracking.
- Data Integrity: All transfers are handled within a database transaction to ensure atomicity and prevent inconsistencies.
The project is built on the Model-View-Controller (MVC) pattern, implemented through Django and Django REST Framework.
- Models: Define the database schema for users, accounts, transactions, and categories.
- Serializers: Handle the conversion of complex data types (model instances) into native Python data types that can be easily rendered into JSON.
- ViewSets: Provide the API logic, combining the functionality of a view with the convenience of a router.
- Permissions: Control access to API endpoints to ensure data security and user privacy.
- Backend Framework: Django, Django REST Framework
- Language: Python 3.x
- Database: SQLite
- Package Management: pip
These instructions will get a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.8+
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/meez-111/pywalletapi.git cd pywalletapi
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install dependencies: You will need to install
drf-yasg
andgunicorn
.pip install -r requirements.txt
-
Set up the database: Create a
.env
file or set environment variables for your database configuration. Then, apply database migrations:python manage.py makemigrations python manage.py migrate
-
Run the development server:
python manage.py runserver
The API will be available at
http://127.0.0.1:8000/
.
This project includes live, interactive API documentation using Swagger/OpenAPI, which can be viewed at the following endpoints after starting the server:
- Swagger UI:
http://127.0.0.1:8000/api/swagger/
- Redoc UI:
http://127.0.0.1:8000/api/redoc/
You can easily deploy this project to a production environment using a platform like Render.com.
-
Create a New Web Service: Log in to Render and create a new Web Service. Connect your GitHub repository where this project is hosted.
-
Configure Build and Start Commands:
- Build Command:
pip install -r requirements.txt
- Start Command:
gunicorn my_project.wsgi
(Replacemy_project
with your project's root folder name).
- Build Command:
-
Set Environment Variables: Add your environment variables (e.g.,
SECRET_KEY
). Render will provide aDATABASE_URL
for PostgreSQL, which you'll need to configure in yoursettings.py
file. -
Run Database Migrations: After your first successful deployment, you'll need to run your migrations on the server. Go to your web service on Render, click the Shell tab, and run:
python manage.py makemigrations python manage.py migrate
-
Test Your Live API: After the deployment is complete, Render will provide you with a live URL for your API. You can use this URL to test your endpoints.
You can interact with a live version of this API at the following URL:
The following are the main API endpoints for the project.
Method | Endpoint | Description |
---|---|---|
POST | /users/ |
Create a new user account. |
GET | /users/{id}/ |
Retrieve a user's details. |
PATCH | /users/{id}/ |
Update user details. |
DELETE | /users/{id}/ |
Delete a user account. |
Example: Create a User
POST /users/
{
"username": "jane_doe",
"password": "strong_password123",
"email": "jane@example.com"
}
Requires authentication.
Method | Endpoint | Description |
---|---|---|
GET | /accounts/ |
List all accounts for the authenticated user. |
POST | /accounts/ |
Create a new account. |
GET | /accounts/{id}/ |
Retrieve a specific account. |
Example: Create an Account
POST /accounts/
{
"account_name": "Savings Account",
}
Requires authentication.
Method | Endpoint | Description |
---|---|---|
GET | /transactions/ |
List all transactions for the authenticated user. |
POST | /transactions/ |
Create a new income or expense transaction. |
Example: Create a Transaction
POST /transactions/
{
"account": 1,
"transaction_type": "expense",
"transaction_amount": 50.25,
"transaction_description": "Lunch with a friend",
"transaction_category": 3
}
Requires authentication. This is a custom action on the TransactionViewSet
.
Method | Endpoint | Description |
---|---|---|
POST | /transactions/transfer/ |
Transfer funds between two user accounts. |
Example: Transfer Funds
POST /transactions/transfer/
{
"sender_account": 1,
"recipient_username": "john_doe",
"recipient_account": 2,
"transaction_amount": 75.00
}
We welcome contributions! If you have suggestions or want to fix a bug, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name
). - Make your changes and write tests.
- Commit your changes (
git commit -m 'Add a new feature'
). - Push to the branch (
git push origin feature/your-feature-name
). - Create a new Pull Request.
- Budgeting: Implement a budgeting feature to help users monitor their spending against a set limit.
- API Enhancements: Add filtering and sorting to the transactions endpoint.
- Two-Factor Authentication (2FA): Integrate a secure 2FA system to enhance user security.
Email: Email
LinkedIn: LinkedIn