Skip to content

spaghetti-lover/simplebank

Repository files navigation

Simplebank

This project provides a simple banking service API. It allows users to create accounts, log in, and potentially perform transactions (though only user management is fully shown in the snippets). The core API is built using gRPC, and an HTTP Gateway translates requests for web clients. It uses a PostgreSQL database (managed by sqlc) for storing data, Redis for background task queuing (like sending verification emails), and Paseto/JWT for user authentication. Configuration is managed externally, and input data is validated before processing.

Source Repository: https://github.com/spaghetti-lover/simplebank

flowchart TD
    A0["Application Orchestration & Entrypoint
"]
    A1["Database Access Layer (sqlc)
"]
    A2["gRPC API Service
"]
    A3["HTTP Gateway
"]
    A4["Authentication & Authorization (Token-Based)
"]
    A5["Asynchronous Task Processing (Worker)
"]
    A6["Configuration Management
"]
    A7["Input Data Validation
"]
    A0 -- "Loads Configuration" --> A6
    A0 -- "Initializes DB Connection" --> A1
    A0 -- "Initializes & Manages Task ..." --> A5
    A0 -- "Initializes & Starts gRPC S..." --> A2
    A0 -- "Initializes & Starts HTTP G..." --> A3
    A2 -- "Executes DB Operations" --> A1
    A2 -- "Uses Token Creation/Verific..." --> A4
    A2 -- "Distributes Background Tasks" --> A5
    A2 -- "Validates Request Data" --> A7
    A3 -- "Forwards HTTP requests to gRPC" --> A2
    A5 -- "Executes DB Operations for ..." --> A1
    A5 -- "Uses Config (e.g., for Email)" --> A6
    A4 -- "Uses Config (e.g., for Toke...)" --> A6
Loading

Chapters

  1. gRPC API Service
  2. Database Access Layer (sqlc)
  3. Input Data Validation
  4. HTTP Gateway
  5. Authentication & Authorization (Token-Based)
  6. Asynchronous Task Processing (Worker)
  7. Configuration Management
  8. Application Orchestration & Entrypoint
  9. Database Design

Setup local development

Install tools

Setup infrastructure

  • Create the bank-network

    make network
  • Start postgres container:

    make postgres
  • Create simple_bank database:

    make createdb
  • Run db migration up all versions:

    make migrateup
  • Run db migration up 1 version:

    make migrateup1
  • Run db migration down all versions:

    make migratedown
  • Run db migration down 1 version:

    make migratedown1

Documentation

  • Generate DB documentation:

    make db_docs
  • Access the DB documentation at this address. Password: secret

How to generate code

  • Generate schema SQL file with DBML:

    make db_schema
  • Generate SQL CRUD with sqlc:

    make sqlc
  • Generate DB mock with gomock:

    make mock
  • Create a new db migration:

    make new_migration name=<migration_name>

How to run

  • Run server:

    make server
  • Run test:

    make test

Deploy to kubernetes cluster

  • Install nginx ingress controller:

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml
  • Install cert-manager:

    kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.yaml

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published