A RESTful API built with FastAPI to manage user accounts and transactions. It supports creating and updating accounts, recording deposit and withdrawal transactions, and retrieving transaction history. PostgreSQL is used as the database backend.
- Create an account (
POST /accounts/) - Update an account (
PUT /accounts/{account_id}) - Create a transaction (
POST /transactions/) - Get all transactions (
GET /transactions/) - FastAPI auto-generated Swagger UI (
/docs) and ReDoc (/redoc)
- Python
- FastAPI
- PostgreSQL
- SQLAlchemy
- Pydantic
- Docker & Docker Compose
- Pytest (for testing)
- Docker
- Docker Compose
makeor Unix-like shell (for scripts)
- Clone the repo:
git clone https://github.com/Zen121212/account-transaction-api.git
cd account-transaction-api- Start the containers:
./start.sh- Access API docs:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Access pgAdmin: http://localhost:5051
After starting the Docker containers, you can configure pgAdmin to interact with PostgreSQL database.
-
Access pgAdmin 4: Open your browser and go to http://localhost:5051.
-
Log in: The default credentials for pgAdmin 4 are:
- Username:
admin@admin.com - Password:
admin123
- Username:
-
Register Server:
- Name: Enter a name for your server, e.g.,
Postgres Server. - Connection Tab:
- Hostname/address: Enter
postgres_db. - Port: Enter
5432. - Maintenance database: Enter
postgres. - Username: Enter
postgres. - Password: Enter
mysecretpassword.
- Hostname/address: Enter
- Name: Enter a name for your server, e.g.,
-
Save: Click
Saveto register the server. You should now be able to interact with your PostgreSQL database via pgAdmin.
POST /accounts/
{
"name": "Zein",
"email": "zein@example.com",
"balance": 500.0,
"phone": "12345678",
"address": "Beirut"
}PUT /accounts/{account_id}
{
"name": "Zein Updated",
"email": "zein@example.com",
"balance": 1000.0
}POST /transactions/
{
"account_id": 1,
"amount": 200.0,
"transaction_type": "deposit"
}GET /transactions/
Optional query params: account_id, start_date, end_date
To run tests using pytest, use the following command:
docker-compose exec backend pytest app/test_main.pyTest coverage includes:
- Creating an account
- Updating an account
- Creating a transaction (deposit/withdrawal)
- Validating insufficient funds
- Retrieving all transactions
- Filtering transactions by account
- Used FastAPI for speed and automatic documentation generation.
- PostgreSQL chosen for reliability and compatibility with Docker.
- SQLAlchemy for ORM to ensure scalability and easier migration.
- Email is treated as a unique identifier for accounts.
- Transactions must link to a valid account.
Zein Kassem - zein.s.kassem@gmail.com