simplebank

module
v0.0.0-...-8414c70 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: Apache-2.0

README

simplebank

About

This is a fullstack application that implements a simple banking system, where users can create accounts, deposit and withdraw money, and transfer money between accounts.

Features

CRUD operations

CRUD operations are implemented for the following domains:

  • user:
    • POST /signup: create user
  • account:
    • GET /accounts, GET /accounts/{id} and GET /accounts/search: query account by username (from bearer token), id or account name.

    • POST /accounts/create: create accounts

    • PATCH /accounts/{id}: update account

  • transfer:
    • POST /trasnfer: transfer money between accounts, update account balance and create entry records
  • entry:
    • GET /entries: list entries
  • friendship:
    • GET /friend/list: query incoming and outgoing friendship requests for account
    • POST /friend/create: create friendship requests
    • PATCH /friend/{id}: update friendship request status
Authentication and authorization

Routes for querying and mutating resources require a bearer token, which can be obtained from the POST /signin route. The token is a paseto token that carries the username and a role. User can either be a regular end user or an admin. Currently, there is only one route GET /accounts/all that requires admin access.

Asynchronous processing

The API provides two options for asynchronous task processing that is configured via the TASK_MANAGER env variable:

  • "simple": using a simple goroutine and channel based task queue

  • "asynq": using the asynq library which is backed by redis.

Email Sending

The /send-email route supports sending emails to an authenticated user. You can specify subject=verify subject=welcome, and subject=report in the request body to send emails of different types.

Development

If you have docker-compose installed, simply run

docker compose up

To run it without docker, first install the go dependencies

go mod tidy

Start the backend with

make run-local
# or
go run app/services/bank-api/main.go | go run app/tooling/logfmt/main.go
Documentation

The backend serves a swagger documentation at /swagger/index.html

To update the swagger docs, make sure you have swag installed

go install github.com/swaggo/swag/cmd/swag@latest

Then run

make docs

Design Details

Folder structure

Each folder represents a different layer of concerns

  • app application-level code. Consists of the the Next.js frontend app and the backend RESTful API.

  • zarf configuration files and static assets

Routing
Authentication and Authorization
Error Handling
Asynchronous Processing
Logging

foundation/logger exports a customized slog-based logger.

app/tooling/logfmt is a simple program that converts the JSON logs output by foundation/logger to human-readable logs.

Directories

Path Synopsis
app
services/bank-api/docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
services/bank-api/routes/accountgrp
Package accountgrp provides account-related handlers, starting with the /accounts subpath.
Package accountgrp provides account-related handlers, starting with the /accounts subpath.
services/bank-api/routes/authgrp
Package authgrp provides handlers for user registration and signin
Package authgrp provides handlers for user registration and signin
services/bank-api/routes/checkgrp
Package checkgrp provides status check handlers
Package checkgrp provides status check handlers
services/bank-api/routes/docsgrp
Package docsgrp serves the swagger documentation at /swagger/index.html
Package docsgrp serves the swagger documentation at /swagger/index.html
services/bank-api/routes/entrygrp
Package entrygrp provides entry-related handlers
Package entrygrp provides entry-related handlers
services/bank-api/routes/friendgrp
Package friendgrp provides friendship-related handlers
Package friendgrp provides friendship-related handlers
services/bank-api/routes/taskgrp
Package taskgrp provides handlers for inspecting tasks
Package taskgrp provides handlers for inspecting tasks
tooling/k8sfmt
This programs formats the output of `kubectl get` commands into a table
This programs formats the output of `kubectl get` commands into a table
tooling/logfmt
This program takes the structured log output and makes it readable.
This program takes the structured log output and makes it readable.
business
auth
Package auth provides authentication and authorization support.
Package auth provides authentication and authorization support.
data/order
Package order provides support for describing the ordering of data.
Package order provides support for describing the ordering of data.
db/core
package db defines the interface to interact with the database, and its implementations
package db defines the interface to interact with the database, and its implementations
db/mock
Package mockdb is a generated GoMock package.
Package mockdb is a generated GoMock package.
email
Package email provides email sending functionality.
Package email provides email sending functionality.
task
Package task supports asynchronous task processing
Package task supports asynchronous task processing
web/debug
Package debug provides handler support for the debugging endpoints.
Package debug provides handler support for the debugging endpoints.
foundation
validate
Package validate contains the support for validating models.
Package validate contains the support for validating models.
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL