Splitwise project is an example Flask web application designed to manage expenses among users. This README provides an overview of the project structure and how to run the application.
splitwise/
├── db.sqlite3
├── manage.py
├── splitwise/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── divvy/
│ ├── migrations/
│ │ └── __init__.py
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── serializers.py
│ ├── tests.py
│ └── views.py
├── templates/
│ └── index.html
└── BackendProgrammingAssignment-SplitwiseIndore.pdfThe
splitwise/directory serves as the root directory of the Django project.manage.py: A command-line utility for managing the project.splitwise/: The main Django app for the Splitwise project.__init__.py: Marks the directory as a Python package.settings.py: Contains project settings and configurations.urls.py: Defines URL patterns for routing requests to views.wsgi.py: Entry point for WSGI-compatible web servers.
divvy/: A secondary app within the project, possibly handling expense-related functionalities.migrations/: Contains database migration files.__init__.py,admin.py,apps.py,models.py,serializers.py,tests.py,views.py: Standard Django files for defining models, views, serializers, tests, etc.
templates/: Directory containing HTML templates for rendering views.
This structure organizes the project's files and directories according to Django conventions, facilitating easy management and navigation.
To set up and run the Django project with Django REST Framework:
Install Django and Django REST Framework:
pip install django djangorestframework
Navigate to the project directory:
cd splitwise/Apply database migrations:
python manage.py migrate
Start the development server:
python manage.py runserver
Access the application at http://localhost:8000/.
(Optional) Create a superuser to access the Django admin panel:
python manage.py createsuperuser
Follow the prompts to create a username, email, and password.
Now you're ready to use the Splitwise Django application with Django REST Framework!
+------------------+ +-------------------+ +---------------------+ +---------------------+
| User || Expense || ExpensePaidBy || ExpenseOwedBy |
+------------------+ +-------------------+ +---------------------+ +---------------------+
| - userId (PK) || - expenseId (PK) || - userId (FK) || - userId (FK) || - name || - desc || - expenseId (FK) || - expenseId (FK) || - email || - amount || - amountPaid || - amountOwed || - mobileNumber || - createdById (FK)| +---------------------+ +---------------------+
+------------------+ | - createdAt | +-------------------+- userId
- name
- mobileNumber
- expenseId
- desc
- amount
- createdById
- createdAt
- userId
- expenseId
- amount
- userId
- expenseId
- amount
- userId: Integer (Primary Key)
- name: String (255), Not Null
- email: String (255), Unique, Not Null
- mobileNumber: String (20), Not Null
- expenseId: Integer (Primary Key)
- desc: String (255), Not Null
- amount: Decimal (15, 2), Not Null
- createdById: Integer, Not Null
- createdAt: Timestamp, Default: Current Timestamp
- userId: Integer (Foreign Key to User.userId, Primary Key)
- expenseId: Integer (Foreign Key to Expense.expenseId, Primary Key)
- amount: Decimal (15, 2), Not Null
- userId: Integer (Foreign Key to User.userId, Primary Key)
- expenseId: Integer (Foreign Key to Expense.expenseId, Primary Key)
- amount: Decimal (15, 2), Not Null
- userId: Unique identifier for each user.
- name: Name of the user.
- email: Email address of the user.
- mobileNumber: Mobile number of the user.
- expenseId: Unique identifier for each expense.
- desc: Description of the expense.
- amount: Total amount of the expense.
- createdById: User ID of the creator of the expense. Default: userId = 1
- createdAt: Timestamp indicating when the expense was created.
- user: User who paid for the expense.
- expense: Expense for which the user made a payment.
- amountPaid: Amount paid by the user for the expense.
- user: User who owes money for the expense.
- expense: Expense for which the user owes money.
- amountOwed: Amount owed by the user for the expense.
- The
Userentity is associated with theUserExpensePaidandUserExpenseOwedentities. - The
Expenseentity is associated with theUserExpensePaidandUserExpenseOwedentities.
- Endpoint:
/users - Method: GET
- Description: Retrieves a list of all users.
- Response Format:
{ "users": [ { "userId": 1, "name": "John Doe", "email": "john.doe@example.com", "mobileNumber": "123-456-7890" }, // Additional user objects... ] }
- Endpoint:
/add_user - Method: POST
- Description: Adds a new user to the system.
- Request Format:
{ "name": "John Doe", "email": "john.doe@example.com", "mobileNumber": "123-456-7890" } - Response Format:
{ "message": "User added successfully" }
Equal Split
- Endpoint:
/add_expense - Method: POST
- Description: Adds a new expense along with expense-related details.
- Request Format:
{ "expense_type": "EQUAL", "desc": "electricity bill", "total_amount": 500, "paidBy": { "2": 200, "3": 300 } } - Response Format:
{ "message": "Expense split equally added successfully"// or details of any errors }
Exact Split
- Endpoint:
/add_expense - Method: POST
- Description: Adds a new expense along with expense-related details.
- Request Format:
{ "expense_type": "EXACT", "desc": "paytm", "total_amount": 600, "paidBy": { "1": 300, "3": 300 }, "owedBy": { "1": 100, "3": 200, "4": 300 } } - Response Format:
{ "message": "Expense split exactly added successfully"// or details of any errors }
Percent Split
Endpoint:
/add_expenseMethod: POST
Description: Adds a new expense along with expense-related details.
Request Format:
{ "expense_type": "PERCENT", "desc": "paytm", "total_amount": 700, "paidBy": { "1": 700 }, "owedBy": { "1": 20, "2": 33, "3": 47 } }Response Format:
{ "message": "Expense split by percentage added successfully"// or details of any errors }