How umarhadi/bank-server works
Main components
• API Server: Represent the “api” folder which contains endpoint logic (account, transfer, token, middleware, server). This is the entry point that handles HTTP requests and executes business logic.
• gRPC API: Use the “gapi” directory – this layer implements the gRPC endpoints and associated error/authorization handling.
• Database Module: Include the “db” directory (with migrations, SQLC-generated code, queries, and models) which represents all DB access and persistence. Denote PostgreSQL as the underlying database.
• Token Management: Show a dedicated component for authentication/authorization which comes from the “token” package (with JWT and PASETO makers).
• Email and Notification Service: Capture the “mail” module that sends emails (with its production and mock implementations) for functionalities like email verification.
• Worker/Asynchronous Task Processor: Represent the “worker” package that handles background tasks (e.g., sending verification emails) asynchronously.
• Utilities / Config & Validation: Include a “util” and “val/validator” component that provides configuration loading, currency and password utilities, and input validation.
Relationships and interactions
• The frontend (not part of the repo but implied by API consumption) communicates with the API Server (REST endpoints) and possibly the gRPC server.
• The API Server calls the Database Module to perform CRUD operations. Transactions (like money transfers) are executed to guarantee consistency.
• The Token Management component is used by the API layer to secure endpoints, validating and generating tokens for both REST and gRPC requests.
• When actions that require notifications occur (such as new user registration or email verification), the API Server enqueues tasks in the Worker. The Worker then calls the Mail Service to dispatch emails.
• Configuration (via “util/config”) and validation (from “val/validator” and “api/validator”) support the API’s functioning by ensuring proper request formats and data integrity.
• Deployment components (Dockerfile, docker-compose.yml, eks/ and fly.toml files) indicate containerized operations and cloud orchestration that wrap around the main server application and supporting services.
Architectural patterns and design principles
• Separation of concerns: Distinct modules for API, gRPC, DB access, background processing, and authentication.
• Use of transactional operations: Money.transfer is handled within a transaction to ensure consistency.
• Asynchronous processing: Worker processes tasks that need to run out-of-band (e.g., sending email verifications).
• Infrastructure as Code: Kubernetes manifests (eks/) and Fly.io configuration files support robust, scalable deployment.
• Testing emphasis: Every major module (API, DB, token, worker) includes corresponding test files, hinting at a design guided by testability.
Relevant technologies and tools
• Programming Language: Golang, as inferred from the go.mod and .go files.
• Database: PostgreSQL (with migration and SQLC integration).
• API Documentation: Swagger UI available through the “doc/swagger” directory.
• Containerization and Orchestration: Docker, Docker Compose, Kubernetes (eks/), and Fly.io.
• Code Generation: sqlc, DBML, and related tooling, as well as Gomock for mocking.