Skip to content

Commit

Permalink
Release/1.0.0 (#3)
Browse files Browse the repository at this point in the history
* feat: Creates domain models.

* feat: Implements use cases, persistence, and HTTPS endpoints.

* refactor: Update driver layers and add integration tests.

* docs: Updates documentation and adjust validation rules.

* docs: Updates documentation.

* feat: Adds concurrency control for debit transactions with transaction-level locking.

* fix: Fixes makefile execution for cross-platform.

* fix: Adds .dockerignore.

* fix: Fixes docker volume mapping and adds application flow diagram to documentation.

* fix: Fixes diagram format.

* fix: Fixes phpmd.

* feat: Adds middleware for logging application flow.

* feat: Adds queries to retrieve balance and transactions.

* fix: Fixes lock for debit and withdrawal transactions on the account.

* fix: Fixes a PHP version for CI GitHub action.
  • Loading branch information
gustavofreze authored Nov 4, 2024
1 parent e45d95a commit 6665a00
Show file tree
Hide file tree
Showing 148 changed files with 10,532 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.idea
*.xml
*.lock
*.dist
.github
.phpunit.*
.gitignore

docs
tests
report

LICENSE
Makefile
README.md
22 changes: 22 additions & 0 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Auto assign issues

on:
issues:
types:
- opened

jobs:
run:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Assign issues
uses: gustavofreze/[email protected]
with:
assignees: '${{ secrets.ASSIGNEES }}'
github_token: '${{ secrets.GITHUB_TOKEN }}'
allow_self_assign: 'true'
allow_no_assignees: 'true'
assignment_options: 'ISSUE'
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
pull_request:

permissions:
contents: read

jobs:
auto-review:
name: Auto review
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Install dependencies
run: composer update --no-progress --optimize-autoloader

- name: Run review
run: composer review

tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Install dependencies
run: composer update --no-progress --optimize-autoloader

- name: Run tests
env:
XDEBUG_MODE: coverage
run: composer unit-test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
*.lock
.phpunit.*

vendor
report
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM gustavofreze/php:8.3-fpm

LABEL author="Gustavo Freze" \
maintainer="Gustavo Freze" \
org.label-schema.name="gustavofreze/account" \
org.label-schema.vcs-url="https://github.com/gustavofreze/account/blob/main/Dockerfile" \
org.label-schema.schema-version="1.0"

ARG FLYWAY_VERSION=10.20.1

RUN apk --no-cache add mysql-client openjdk21-jre \
&& mkdir -p /opt/flyway \
&& curl -L "https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/${FLYWAY_VERSION}/flyway-commandline-${FLYWAY_VERSION}-linux-x64.tar.gz" | tar -xz --strip-components=1 -C /opt/flyway \
&& rm -f /opt/flyway/jre/bin/java \
&& ln -s /usr/lib/jvm/java-11-openjdk/jre/bin/java /opt/flyway/jre/bin/java \
&& ln -s /opt/flyway/flyway /usr/local/bin/flyway

WORKDIR /var/www/html

COPY ./ /var/www/html
COPY ./config/database /database
COPY ./entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
72 changes: 72 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
ifeq ($(OS),Windows_NT)
PWD := $(shell cd)
else
PWD := $(shell pwd -L)
endif

PHP_IMAGE = gustavofreze/php:8.3
FLYWAY_IMAGE = flyway/flyway:10.20.1

APP_RUN = docker run -u root --rm -it --network=host -v ${PWD}:/app -w /app ${PHP_IMAGE}
APP_TEST_RUN = docker run -u root --rm -it --name account-test --link account-adm --network=account_default -v ${PWD}:/app -w /app ${PHP_IMAGE}

FLYWAY_RUN = docker run --rm -v ${PWD}/config/database/mysql/migrations:/flyway/sql --env-file=config/local.env --network=account_default ${FLYWAY_IMAGE}
MIGRATE_DB = ${FLYWAY_RUN} -locations=filesystem:/flyway/sql -schemas=account_adm -connectRetries=15
MIGRATE_TEST_DB = ${FLYWAY_RUN} -locations=filesystem:/flyway/sql -schemas=account_adm_test -connectRetries=15

.DEFAULT_GOAL := help
.PHONY: start stop configure migrate-database clean-database migrate-test-database test test-no-coverage review show-reports help show-logs

start: ## Start application containers
@docker-compose up -d --build

stop: ## Stop application containers
@docker-compose down

configure: ## Configure development environment
@${APP_RUN} composer update --optimize-autoloader

test: migrate-test-database ## Run all tests with coverage
@${APP_TEST_RUN} composer run tests

test-no-coverage: migrate-test-database ## Run all tests without coverage
@${APP_TEST_RUN} composer run tests-no-coverage

review: ## Run static code analysis
@${APP_RUN} composer review

show-reports: ## Open static analysis reports (e.g., coverage, lints) in the browser
@sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html

migrate-database: ## Run database migrations
@${MIGRATE_DB} migrate

clean-database: ## Clean database
@${MIGRATE_DB} clean

migrate-test-database: ## Run test database migrations
@${MIGRATE_TEST_DB} migrate

show-logs: ## Display application logs
@docker logs -f account

help: ## Display this help message
@echo "Usage: make [target]"
@echo ""
@echo "Setup and run"
@grep -E '^(start|stop|configure|migrate-database|clean-database):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Testing"
@grep -E '^(test|test-no-coverage):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Code review"
@grep -E '^(review):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Reports"
@grep -E '^(show-reports):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Observability"
@grep -E '^(show-logs):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Help"
@grep -E '^(help):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
152 changes: 150 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,150 @@
# account
Service responsible for managing account transactions.
# Account

[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

* [Overview](#overview)
- [Use cases](#use_cases)
- [Queries](#queries)
* [Installation](#installation)
- [Repository](#repository)
- [Configuration](#configuration)
- [Tests](#tests)
- [Review](#review)
- [Reports](#reports)
* [Environment setup](#environment_setup)
* [Observability](#observability)

<!--suppress HtmlDeprecatedAttribute -->
<div id="overview"></div>

## Overview

Each cardholder (holder) has an account with their information.
For each operation performed, a transaction is created and associated with the respective account.
Transactions have specific types, e.g., **Normal Purchase**, **Purchase with installments**, **Withdrawal**, and
**Credit Voucher**.
**Normal Purchase** and **Withdrawal** transactions are recorded with **negative** values, while **Credit Voucher**
transactions are recorded with **positive** values.

<p align="center">
<img src="./docs/excalidraw/account-flow.svg" alt="Account flow diagram" width="800">
</p>

<p align="center"><small>Figure 01: Account transaction flow diagram.</small></p>

<div id='use_cases'></div>

### Use cases

- [Account opening](docs/USE_CASES.md#account-opening)
- [Account crediting](docs/USE_CASES.md#account-crediting)
- [Account debiting](docs/USE_CASES.md#account-debiting)
- [Account withdrawal](docs/USE_CASES.md#account-withdrawal)

<div id='queries'></div>

### Queries

- [Retrieve account balance](docs/QUERIES.md#retrieve-account-balance)
- [Retrieve an account by id](docs/QUERIES.md#retrieve-an-account-by-id)
- [Retrieve account transactions](docs/QUERIES.md#retrieve-account-transactions)

<div id='installation'></div>

## Installation

<div id='repository'></div>

### Repository

To clone the repository using the command line, run:

```bash
git clone https://github.com/gustavofreze/account.git
```

<div id='configuration'></div>

### Configuration

To install project dependencies locally, run:

```bash
make configure
```

To start the application containers, run:

```bash
make start
```

To stop the application containers, run:

```bash
make stop
```

<div id='tests'></div>

### Tests

Run all tests with coverage:

```bash
make test
```

Run all tests without coverage:

```bash
make test-no-coverage
```

<div id='review'></div>

### Review

Run static code analysis:

```bash
make review
```

<div id='reports'></div>

### Reports

Open static analysis reports (e.g., coverage, lints) in the browser:

```bash
make show-reports
```

> You can check other available commands by running `make help`.
<div id='environment_setup'></div>

## Environment setup

### Access URLs

| Environment | DNS |
|:------------|:-------------------------|
| `Local` | http://account.localhost |

### Database

| Environment | URL | Port |
|:------------|:----------------------------|:----:|
| `Local` | jdbc:mysql://localhost:3307 | 3307 |

<div id='observability'></div>

## Observability

You can access the application logs using the following command:

```bash
make show-logs
```
Loading

0 comments on commit 6665a00

Please sign in to comment.