119 lines
3.4 KiB
Markdown
119 lines
3.4 KiB
Markdown
# Intrasys - Internal Transfers System
|
|
|
|

|
|

|
|

|
|

|
|

|
|
|
|
Intrasys is an internal financial transfers application built with Rust and Axum, providing HTTP endpoints for account management and transaction processing with PostgreSQL as the backing database.
|
|
|
|
## Features
|
|
|
|
- Account creation with initial balance
|
|
- Account balance queries
|
|
- Secure transaction processing between accounts
|
|
- Atomic transaction handling with database integrity
|
|
- Precise decimal arithmetic for financial amounts
|
|
|
|
## Prerequisites
|
|
|
|
- Rust (latest stable version)
|
|
- Docker (for database provisioning)
|
|
- PostgreSQL client (optional)
|
|
|
|
## Quick Start
|
|
|
|
### Using docker compose
|
|
Just run
|
|
|
|
```bash
|
|
docker compose up
|
|
```
|
|
|
|
### Build locally
|
|
|
|
#### Ensure you have rust installed
|
|
Follow the steps described [here](https://www.rust-lang.org/tools/install) if you don't
|
|
|
|
#### Provision PostgreSQL Database
|
|
|
|
The easiest way is to run a PostgreSQL container with Docker:
|
|
|
|
```bash
|
|
docker run --name intrasys-pg -d -e POSTGRES_PASSWORD=password -p 127.0.0.1:5432:5432 postgres:alpine
|
|
```
|
|
|
|
#### Run the Application
|
|
|
|
```bash
|
|
cargo run
|
|
```
|
|
|
|
The application will be available at `http://localhost:8080`
|
|
|
|
## API Endpoints
|
|
|
|
### Account Management
|
|
|
|
- **Create Account**
|
|
`POST /accounts`
|
|
```json
|
|
{
|
|
"account_id": 123,
|
|
"initial_balance": "100.23344"
|
|
}
|
|
```
|
|
|
|
- **Get Account Balance**
|
|
`GET /accounts/{account_id}`
|
|
Response:
|
|
```json
|
|
{
|
|
"account_id": 123,
|
|
"balance": "100.23344"
|
|
}
|
|
```
|
|
|
|
### Transactions
|
|
|
|
- **Process Transaction**
|
|
`POST /transactions`
|
|
```json
|
|
{
|
|
"source_account_id": 123,
|
|
"destination_account_id": 456,
|
|
"amount": "50.12345"
|
|
}
|
|
```
|
|
|
|
## Configuration
|
|
The app can be configured using environmental variable that can also be provided through a `.dotenv` file.
|
|
The following variables affect the application behavior:
|
|
|
|
- `INTRASYS_LOG` changes the logging level, can be set to one of `trace`, `debug`, `info`, `warn`, `error`
|
|
- `INTRASYS_HOST` is the address the HTTP server will bind to
|
|
- `INTRASYS_PORT` is the port the HTTP server will listen to
|
|
- any of the environmental variables mentioned [here](https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgConnectOptions.html#method.options) affects the postgres database connection
|
|
|
|
## Running tests
|
|
|
|
Make sure you have an available postgres database and edit `DATABASE_URL` variable in the `.env` file accordingly. If you've used the docker command mentioned in the *Quickstart*
|
|
section you don't need to change anything.
|
|
|
|
Then run
|
|
|
|
```bash
|
|
cargo test
|
|
```
|
|
|
|
## Assumptions
|
|
|
|
- All accounts use the same currency
|
|
- No authentication or authorization is implemented
|
|
- Decimal precision of 2 decimal places is sufficient for financial amounts, maximum allowed monetary amount is (10^18 -0.01) and the minimum is (-10^18 + 0.01)
|
|
- Account IDs are positive integers
|
|
- Account creation must NOT be idempotent since it also sets the account balance (creating an account that already exists should fail)
|
|
- Transfer money to an account that does not exist should not create a new account, but fail with an error (to prevent users from accidentally locking their money forever)
|
|
|