This is a backend service for managing and sharing daily expenses between users. The application allows users to add expenses and split them in three different ways: equally, by exact amounts, or by percentage. It also manages user details, validates input, and generates a downloadable balance sheet.
- User Management: Create, retrieve, and manage users.
- Expense Management: Add expenses with various split methods.
- Balance Sheet: Track individual expenses, total expenses, and download balance sheets.
├── README.md
├── app
│ ├── api
│ │ ├── users.py # API logic for user management
│ │ ├── expenses.py # API logic for expenses
│ │ └── users.py # API logic for balance management
│ ├── core
│ │ └── database.py # Database connection setup
│ ├── main.py # Application entry point
│ ├── models
│ │ └── models.py # Database models for users, expenses, and balances
│ └── schemas
│ ├── users.py # Pydantic models for user creation
│ ├── expenses.py # Pydantic models for expense creation
│ └── balance.py # Pydantic models for balance creation
└── requirements.txt # Required Python packages
git clone <repository-url>
cd <repository-directory>
Ensure you have Python 3.9+ installed. Install the required packages:
pip install -r requirements.txt
This application uses PostgreSQL as the database. Make sure PostgreSQL is installed and running on your machine.
Create a new PostgreSQL database and update the SQLALCHEMY_DATABASE_URL
in app/core/database.py
to match your PostgreSQL credentials:
SQLALCHEMY_DATABASE_URL = "postgresql://<username>:<password>@localhost:5432/<database>"
Start the FastAPI server:
uvicorn app.main:app --reload
The application will be available at http://127.0.0.1:8000
.
- User: Contains
id
,name
,email
, andmobile
.
- Expense: Contains
id
,amount
,description
,paid_by
,split_method
, anduser_ids
.
- Balance: Tracks the balance for each user, including the
user_id
,user_name
, andamount_owed
.
The API endpoints are organized as follows:
POST /users/
: Create a new user.GET /users/{user_id}
: Retrieve details of a specific user.GET /users/
: Retrieve all users.
POST /expenses/
: Add a new expense.GET /expenses/{user_id}
: Retrieve individual expenses for a user.GET /expenses/
: Retrieve overall expenses.
GET /balance/{user_id}
: Retrieve the balance sheet for a specific user.GET /balance/
: Retrieve overall balances for all users.GET /download
: Download the balance sheet as a file.
To interact with the API, you can use the automatically generated FastAPI documentation, which provides a user-friendly interface to explore and test the endpoints.
FastAPI Documentation UI FastAPI provides an interactive documentation UI, which can be accessed at the following paths after running the application:
Swagger UI: Navigate to http://127.0.0.1:8000/docs to access Swagger, which allows you to interact with the API directly from your browser. ReDoc: Alternatively, you can use http://127.0.0.1:8000/redoc for a different style of documentation.
This project is licensed under the MIT License.