How moolair/simplebank-golang-backend works
Based on our analysis of the complete file structure and the README, the project is a full-stack banking service built in Golang. It exposes RESTful APIs (using the Gin framework), provides gRPC endpoints, manages database interactions (with PostgreSQL via migrations and SQLC), and incorporates asynchronous processing (using background workers and email sending). It also includes a CI/CD pipeline (with GitHub Actions), containerization (Docker), and deployment manifests for Kubernetes (AWS).
Main Components
• API Service: Represented by the “api” directory, this component contains the main HTTP server, middleware, account, user, transfer, and token handling.
• gRPC Service: In the “gapi” folder, which handles gRPC calls and RPC logic. The related protobuf definitions in the “proto” and “pb” directories should be noted.
• Database: The “db” folder holds the migration scripts (SQL), mocks, SQL query files, and SQLC autogenerated code. Indicate PostgreSQL as the primary persistent store.
• Asynchronous Worker: The “worker” directory includes distributors and processors to handle tasks like sending verification emails.
• Authentication & Token Management: The “token” directory contains code for JWT and PASETO token creation and tests.
• Email Service: The “mail” directory handles email sending logic which connects with the asynchronous workers.
• Utility & Validation: The “util” and “val” directories provide essential helper functions like configuration, password hashing, currency management, and role management.
• Deployment & Infrastructure: Include elements from “Dockerfile”, “docker-compose.yaml”, and Kubernetes manifests in the “eks” directory showing AWS-specific deployment, as well as GitHub Actions workflows (.github/workflows) used in CI/CD.
• Documentation: The “doc” directory includes the DBML, SQL schema, and Swagger UI, which help showcase the API definitions and database schema.
Relationships and Interactions
• The API Service interacts with the Authentication component (token creation/validation) for managing secure access, as indicated by the “api/token.go” and “token” directories.
• The Asynchronous Worker processes background jobs (like email verification tasks) which are triggered by events in the API layer. Indicate data flows such as “queue” or “message passing” to denote async processing.
• The Email Service (mail) gets invoked by the worker process. Clearly mark this linkage.
• External Systems: Denote external integrations, including Docker containers, Kubernetes clusters for deployment, and potential external services (e.g., Redis for caching/session management, Let's Encrypt for HTTPS).
• CI/CD: Represent GitHub Actions for testing and deployment pipelines (workflow files) that integrate into the process.
Architectural Patterns and Design Principles
• Separation of Concerns: Different components are split by their function – API layer, gRPC services, background workers, and database access.
• Microservices/MVC-like Flow: Although the entire service is part of a single repository, the separation between API endpoints, authentication, and background processing reflects a decoupled architecture.
• Transactional Database Interactions: Highlight proper usage of migrations, SQLC for safe type-checked database interactions, and structured SQL query management.
• Containerization & Orchestration: Emphasize that the project uses Docker and Kubernetes for deployment.
• Testing & CI/CD: Capture that extensive unit tests and CI pipelines (GitHub Actions) support continuous development.
• Drill down into each major component, showing sub-components when necessary (for example, inside the API Service, you might detail endpoints for account creation, transfers, etc.).
• Significant interactions with notes on key technologies like Gin, SQLC, Docker, Kubernetes, JWT/PASETO, and gRPC.