How dhvll/go-advance works
Project Type & Purpose
• Recognize that this is an advanced Golang project focusing on:
• API development (with endpoints for accounts, users, transfers)
• Database interaction (using migrations, SQL queries, and SQLC-generated code)
• Token-based authentication mechanisms (supporting both JWT and PASETO)
• Utility functions for configuration management, password handling, and currency operations
• The project is educational in nature, so the architecture emphasizes separation of concerns and clear modularity.
Main Components
• Client Interface (External or internal clients making API calls)
• API Server (Located in the api directory)
• Contains handlers (account.go, user.go, transfer.go), middleware (middleware.go), and tests.
• Handles HTTP requests and routes them to the appropriate business logic.
• Database Layer
• Migration Scripts (in db/migration) for initializing/updating the schema.
• Query Files (in db/query) that contain raw SQL scripts.
• SQLC-generated Code (in db/sqlc) acting as a data access layer (store, models, querier).
• A mock layer (db/mock) for testing database interactions.
• Token Management Module
• Implements token generation and validation using JWT and PASETO (in the token folder).
• Utility Package
• Provides configuration (util/config.go), currency conversion, password management (util/password.go), and randomness (util/random.go).
• Build & Deployment
• Makefile for build automation.
• GitHub workflows (.github/workflows/ci.yml) for continuous integration.
• Environment configurations (app.env, simplebank.sql for database seed/definitions).
Relationships & Interactions
• That the Client makes HTTP calls which reach the API Server.
• The API Server routes requests (using the middleware for authentication and validation) to specific endpoint handlers (for account, user, transfer operations).
• The handlers communicate with a database store that wraps interactions with the SQLC-generated modules.
• The Database, designed with clear migration scripts and query definitions, serves the persistent data needs.
• Token management is used by the API Server (particularly in middleware) to verify and issue authentication tokens.
• Utility functions are called by various modules (API, token, DB initialization) to manage configuration, security (password hashing), and other common tasks.
Architectural Patterns & Design Principles
• Emphasis on separation of concerns: API handling, database access, token management, and utility operations are kept in distinct modules.
• Use of automated database migrations and generated code (using SQLC) for robust database interfacing.
• Testing is integrated at multiple levels (with files ending in _test.go across several directories) to ensure code stability.
• The design supports high modularity which makes it easier to swap or upgrade parts (e.g., different token makers).