How rifkiilmi/golang-restfullapi works
Project type and purpose
• This is a backend‐only RESTful microservice written in Go for a simple banking system (“Simple Bank”).
• It exposes HTTP endpoints to create users, manage accounts, perform transfers, and handle authentication via JWT or PASETO tokens.
File structure
• Top level:
• main.go – service entrypoint
• go.mod/go.sum – dependency management
• makefile, .github/workflows/ci.yaml – build & CI/CD orchestration
• sqlc.yaml – SQLC code‐generation config
• app.env – environment variables for DB, token keys, etc.
• api/ – HTTP layer: server setup, request handlers (user.go, account.go, transfer.go), middleware, validation, and associated tests
• db/ – data‐access layer:
• migration/ – raw SQL migration scripts
• query/ – SQL raw queries (for manual use or reference)
• sqlc/ – code generated by SQLC (querier, store, models, tests)
• mock/ – store mocks for unit tests
• token/ – token generation/verification implementations (JWT and PASETO) and tests
• util/ – shared helpers: config loader, password hashing, random data, currency utilities
README for additional insights
• (Empty here, but file names and test coverage imply a strong emphasis on layered architecture, testing, and configuration.)
a. Main components
• API Server (api/server.go & routes)
• Business Logic / Store (db/sqlc/store.go + mock store)
• Database (PostgreSQL with migration scripts)
• Token Service (token package: JWT & PASETO maker)
• Utilities (util package: config, password, random, currency)
• CI/CD Pipeline (GitHub Actions + Makefile)
b. Relationships & interactions
1. Client (e.g., curl, Postman, frontend) → HTTP request
2. API Server
– Loads config via util/config
– Passes request through middleware (authentication, validation)
– Calls token.Maker for login/signup or authorization checks
– Invokes Store methods to read/write data
3. Store (SQLC) → executes SQL against PostgreSQL
4. Database → returns rows → Store → API → HTTP response to client
5. CI/CD → on each push/PR runs tests, lint, build (configured in .github/workflows/ci.yaml & makefile)
c. Architectural patterns
– Layered architecture (Presentation → Application/Service → Data Access)
– Dependency Inversion: handlers depend on interfaces (store, token.Maker), allowing mock injection for tests
– Configuration via environment variables
– Code generation (SQLC) for safe, type‑checked DB access
d. Key technologies & frameworks
– Go standard library (net/http) or lightweight router in api/server.go
– SQLC for type‑safe SQL bindings
– PostgreSQL (migration scripts in db/migration)
– JWT and PASETO in token/
– GitHub Actions for CI
Elements
• Client → API Server
• API Server → Token Maker
• API Server → SQLC Store → PostgreSQL
• CI/CD → Build & Test → Deployment (optional)
Final recommendations
• Be exhaustive: break down the API layer into subcomponents (middleware, handlers) if detail is required.
• External dependencies (PostgreSQL, GitHub Actions).
• Important configurations (e.g., which env vars govern DB connection, token secrets).