Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aniketwdubey/expense-sharing-application-using-fastapi

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.
https://github.com/aniketwdubey/expense-sharing-application-using-fastapi

api apidevelopment expense expense-management expense-tracker-app fastapi sqlalchemy sqlalchemy-orm

Last synced: 3 months ago
JSON representation

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.

Awesome Lists containing this project

README

        

# Daily Expenses Sharing Application

## Overview
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.

### Key Features:
- **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.

## Project Structure
```
├── 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
```

## Setup and Installation

### 1. Clone the repository
```
git clone
cd
```

### 2. Install dependencies
Ensure you have Python 3.9+ installed. Install the required packages:
```
pip install -r requirements.txt
```

### 3. Database Setup
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:
```python
SQLALCHEMY_DATABASE_URL = "postgresql://:@localhost:5432/"
```

### 4. Run the Application
Start the FastAPI server:
```
uvicorn app.main:app --reload
```

The application will be available at `http://127.0.0.1:8000`.

### 6. Data Models
#### Users
- **User**: Contains `id`, `name`, `email`, and `mobile`.

#### Expenses
- **Expense**: Contains `id`, `amount`, `description`, `paid_by`, `split_method`, and `user_ids`.

#### Balance
- **Balance**: Tracks the balance for each user, including the `user_id`, `user_name`, and `amount_owed`.

### 5. API Endpoints
The API endpoints are organized as follows:

#### User Endpoints:
- `POST /users/`: Create a new user.
- `GET /users/{user_id}`: Retrieve details of a specific user.
- `GET /users/`: Retrieve all users.

#### Expense Endpoints:
- `POST /expenses/`: Add a new expense.
- `GET /expenses/{user_id}`: Retrieve individual expenses for a user.
- `GET /expenses/`: Retrieve overall expenses.

#### Balance Sheet Endpoints:
- `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.

### 6. Example Usage

#### Add Users
![alt text]()

#### Users Table
![alt text]()

#### Add Expenses
![alt text]()
![alt text]()
![alt text]()

#### Expenses Table
![alt text]()

#### Retrieve overall expenses.
![alt text]()

#### Retrieve individual user expenses.
![alt text]()

#### Balance Table
![alt text]()

#### Balance Sheet - Show overall expenses for all users.
![alt text]()

#### Download Balance Sheet
![alt text]()

### 7. Interacting with the API
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.

## License
This project is licensed under the MIT License.