How techschool/simplebank works
Main Components
• Frontend: Represented by the “frontend” directory, using Vue.js. This portion handles the user interface and communicates with the backend (via RESTful APIs).
• API / HTTP Server: Sourced from the “api” directory (and its tests, middleware, server, etc.). This is the core of the backend service built using Gin.
• gRPC Service Layer: Indicated by the “gapi” directory along with “pb” and “proto” folders. This shows that the service also provides gRPC endpoints (with a gateway to serve HTTP requests concurrently).
• Database: Shown by the “db” directory and its subdirectories (migrations, query, sqlc). This component points to a PostgreSQL backend with migration scripts, SQLC-generated code and queries.
• Asynchronous Worker: Located in the “worker” directory. This is the background task processor (using Redis and Asynq) that takes care of tasks like sending verification emails.
• Auth and Token Management: The “token” folder handles the generation and validation of JWT/PASETO access tokens, supporting authentication for the API.
• Mail Service: The “mail” directory contains the email sender logic, which is integrated into either the API or the worker for sending out emails.
• Miscellaneous Utilities and Validators: Components like “util” and “val” provide application-wide utilities for configuration, password handling, and validation.
Relationships and Interactions
• The Frontend interacts directly with the API layer using HTTP (and possibly through gRPC gateway endpoints).
• The API server handles requests, performing actions like creating accounts, processing transfers, and authenticating users. It interfaces with the database for executing transactions and accessing persistent data.
• gRPC endpoints (documented in the gapi section) provide additional interfaces which could also be used internally or by external clients, and these relay requests to similar business logic as the REST endpoints.
• A background worker picks up asynchronous tasks (such as sending a verification email) from a message queue (Redis) and may further write to the database (for task status or updates).
• The Mail service is engaged by either the API or worker components, sending emails when a new verification is triggered.
Architectural Patterns and Design Principles
• Separation of Concerns: Different directories represent clear layers (e.g., API layer, database access layer, business logic, and asynchronous processing).
• Layered Architecture: One layer handles HTTP/gRPC requests, another handles database interactions (via sqlc and migrations), and yet another handles async tasks.
• Microservice-like Components: Although it is a single repository, the service clearly separates concerns like authentication, email processing, and API endpoints, which can be drawn as loosely coupled modules.
• Security and Reliable Transaction Handling: Include notes on transaction management in the database (using sqlc and migration scripts) and security aspects in authentication (JWT/PASETO, middleware).