How mohamedhussieen/go-task works
Project type and purpose
• This is a Go-based, Dockerized RESTful API for an e-commerce platform.
• It handles user authentication (JWT + role-based), product CRUD, order processing, credit-card storage, and Stripe payment integration.
• Persistence is via PostgreSQL; the service is orchestrated with Docker Compose.
File structure
• cmd/api/main.go: application entrypoint (HTTP server).
• internal/api/handlers: HTTP handlers grouped by resource (auth, products, orders, credit cards, Stripe).
• internal/api/middleware: auth middleware (JWT enforcement, role checks).
• internal/models: domain models (User, Product, Order, CreditCard, etc.).
• internal/db/postgres: DB connection setup and SQL helpers.
• migrations/: SQL scripts for schema evolution.
• Dockerfile & docker-compose.yml: container build & orchestration.
• postman/: API collection for testing/documentation.
README for additional insights
• Tech stack: Go 1.19+, PostgreSQL 15, Stripe Go SDK, JWT for auth.
• Runtime env via .env; Docker Compose spins up api + postgres.
• API endpoints are grouped into public, user-protected, and admin-protected.
• Database schema tables: users, products, orders (+ items), credit_cards.
Main components & their interactions
a. API Server Container (Go)
• HTTP Router → Middleware (JWT auth, role checks) → Handlers → internal/db → PostgreSQL
• Handlers use models, validate input, orchestrate business logic
• Stripe client invoked by the “process-payment” handler for external payment API calls
b. PostgreSQL Container
• Hosts persistent data (users, products, orders, cards)
• Initialized/migrated via migrations on startup
c. External Services & Clients
• Stripe API (HTTPS) for payment processing
• Clients (Web/Mobile/Postman) make HTTP calls to API endpoints
d. Docker Compose
• Defines and links the api and postgres containers, injects environment variables
Architectural patterns & design principles
• Layered architecture:
1) Routing & HTTP layer
2) Middleware (cross-cutting concerns)
3) Handler layer (resource-specific controllers)
4) Data access layer (internal/db with SQL helpers)
5) Domain models
• Separation of concerns: auth vs business logic vs data access
• Security: JWT stateless auth, role-based authorization in middleware
• Infrastructure as code: Docker + Docker Compose + SQL migrations
How to represent this
1) Client (Browser/Mobile/Postman)
2) API Service (Go)
3) PostgreSQL Database
4) External Payment Gateway (Stripe)
• HTTP Router
• Auth Middleware (JWT, role check)
• Handlers (Auth, Products, Orders, CreditCards, Stripe)
• Data Access Layer (internal/db/postgres)
• Models
– Client → HTTP Router (port 8080)
– HTTP Router → Middleware → Handlers
– Handlers → Data Access Layer → Database
– Payment Handler → Stripe API
– Database responses flow back up to the client
– Containers (bold outline) vs internal modules (thin outline)