Skip to content

Commit

Permalink
Release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
serdeliverance authored Feb 16, 2021
2 parents 2aa6bad + 62116d6 commit a5cf57d
Show file tree
Hide file tree
Showing 51 changed files with 2,218 additions and 14 deletions.
135 changes: 135 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,136 @@
# crypto-wallet

A demo crypto wallet app using with teaching purposes. This app allows clients to manage their crypto currency portfolio. It uses [Coinmarketcap API](https://coinmarketcap.com/api/) for getting the updated cryptocurrencies quotation.

It provides the following functionalities:

* managing users (CRUD operations, uses for admins)
* buy, sell and transfer crypto currencies
* allow users to see their portfolio balance (the quotation of their cryptocurrencies portfolio converted to USD)
* allows users to see their transaction history

## Tech Stack

* Java 11
* Spring Boot
* Postgres
* Kafka
* Docker

## Architecture

The following diagram shows the systems architecture:

![Alt text](diagrams/cw-architecture.png?raw=true "Architecture")

## Data Model

The following diagram shows the data model:

![Alt text](diagrams/cw-data-model.png?raw=true "Title")

## Run the app

1. Start containers using docker compose:

```
docker-compose up
```

2. Run the application

```
mvn spring-boot:run
```

It runs the application on http://localhost:8080

## API

* Healthcheck

```
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/healthcheck
```

* Get user by id

```
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/users/:userId
```

* Get all users

```
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/users
```

* Create user

```
curl -X POST -H "Content-Type: application/json" \
-d '{"username": "pepe", "password": "pass1234", "email": "[email protected]"}' \
http://localhost:8080/users
```

* Update user

```
curl -X PUT -H "Content-Type: application/json" \
-d '{"username": "pepe", "password": "pass1234", "email": "[email protected]"}' \
http://localhost:8080/users/:userId
```

* Delete user

```
curl -X "DELETE" http://localhost:8080/users/:userId
```

* Get quotes

```
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/cryptocurrencies/quotes
```

* Get portfolio

```
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/portfolios/:userId
```

* Get transaction history

```
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/transactions/8
```

* Transfer

```
curl -X POST -H "Content-Type: application/json" \
-d '{"issuer": "88", "receiver": "2", "cryptocurrency": "Huobi Token", "amount": 10}' \
http://localhost:8080/transactions/transferences
```

* Buy

```
curl -X POST -H "Content-Type: application/json" \
-d '{"userId": 3, "cryptocurrency": "Bitcoin", "amountInUsd": 100000}' \
http://localhost:8080/transactions/buys
```

* Sell

```
curl -X POST -H "Content-Type: application/json" \
-d '{"userId": 3, "cryptocurrency": "Bitcoin", "amount": 1}' \
http://localhost:8080/transactions/sells
```

## Extra notes

* A ready [docker-compose](docker-compose.yml) is provided. It contains all the components ready for local development. It also contains dummy data for playing around with the app.

* Also, a [postman collection](postman-collection/crypto.postman_collection.json) is provided.
Binary file added diagrams/cw-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/cw-data-model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3.7'

services:

cw-postgres:
image: postgres:latest
environment:
- "TZ=Europe/Amsterdam"
- "POSTGRES_USER=root"
- "POSTGRES_PASSWORD=root"
- "POSTGRES_DB=cryptodb"
ports:
- 45432:5432
volumes:
- ./sql:/docker-entrypoint-initdb.d

cw-adminer:
image: adminer
restart: always
ports:
- 8083:8080

cw-zookeeper:
image: wurstmeister/zookeeper
ports:
- 2181:2181

cw-kafka:
image: wurstmeister/kafka
ports:
- 9092:9092
environment:
KAFKA_BROKER_ID: 0
KAFKA_ZOOKEEPER_CONNECT: cw-zookeeper:2181
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: INSIDE://localhost:19092,OUTSIDE://localhost:9092
KAFKA_LISTENERS: INSIDE://0.0.0.0:19092,OUTSIDE://0.0.0.0:9092
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
KAFKA_LOG_DIRS: /kafka/kafka-logs
KAFKA_DELETE_TOPIC_ENABLE: "true"
KAFKA_DEFAULT_REPLICATION_FACTOR: 1
KAFKA_NUM_PARTITIONS: 3
links:
- cw-zookeeper
28 changes: 27 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,49 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading

0 comments on commit a5cf57d

Please sign in to comment.