How sadja18/payment_flow_backend works
Project type and purpose
• This is a standalone Go‐based backend service (“payment_flow_backend”) that exposes HTTP endpoints for user and invoice management and handles payment flows. It follows a layered architecture (Router → Middleware → Controllers → Services → Models → Database/External Services).
File structure
• Top-level files:
• main.go – application entrypoint, starts HTTP server
• go.mod / go.sum – dependency management
• .env – environment variables (e.g., DB connection strings, API keys)
• Directories:
• config: database configuration and connection (config/db.go)
• routes: HTTP router setup (routes/router.go)
• middleware: request‐scoped logic, e.g., authentication (middleware/auth.go)
• controllers: HTTP handlers broken out by resource (controllers/user.go, controllers/invoice.go, plus a seed script)
• services: core business logic, e.g., payment processing (services/payment.go)
• models: data definitions, mapping to DB entities (models/user.go, models/invoice.go)
• utils: utility functions for external integrations (e.g., webhooks in utils/webhooks.go)
• Runtime artifacts:
• payments.db – SQLite (or similar) database file
• proj_dir_script.sh / run_ps.ps1 – convenience scripts for setup or run.
README for additional insights
• The README simply mirrors the file structure but confirms the layered design.
Main components and their interactions
a. HTTP Client (Postman, Web UI, Mobile App)
b. HTTP Server / API Layer
• main.go spins up the router defined in routes/router.go
• Routes are annotated with middleware (auth, logging, etc.)
c. Middleware Layer
• middleware/auth.go checks authentication/authorization tokens
d. Controller Layer
• controllers/user.go handles user CRUD
• controllers/invoice.go handles invoice CRUD
• (Optional) controllers/seed.go for database seeding
e. Service Layer
• services/payment.go contains payment‐flow logic (calling payment gateway APIs, orchestrating transactions)
f. Model / Persistence Layer
• models/*.go: Go structs for ORM or raw SQL mapping
• config/db.go: opens and configures the DB connection
• payments.db: on‐disk embedded database
g. External Services
• Payment gateways or webhook endpoints (abstracted by utils/webhooks.go)
Architectural patterns and principles
• Layered (n-tier) architecture: separates concerns horizontally
• Dependency injection via passing DB handle or configs down from main.go
• Single responsibility per package: controllers for HTTP, services for business logic, models for persistence
• Middleware for cross‐cutting concerns (auth, logging, metrics)