How afloresc/e-commerce-api works
Purpose and Entry Point
This is a Go e-commerce HTTP API for authentication, product browsing/management, cart operations, and checkout/payment integration. The process starts at cmd/main.go, which is expected to assemble domain routers and middleware into the API server.
API Composition
Each major business domain follows a handler/router/service split:
• HTTP route registration and request handling: internal/auth/router.go, internal/cart/router.go, internal/product/router.go
• Business operations: internal/auth/service.go, internal/cart/service.go, internal/payment/service.go
• HTTP response/request boundary: internal/auth/handler.go, internal/payment/handler.go
This structure keeps transport concerns in handlers, orchestration in services, and domain persistence/model concerns localized.
Authentication and Authorization
Authentication is implemented as a dedicated module with JWT support:
• internal/auth/handler.go
• internal/auth/service.go
• internal/auth/jwt.go
JWT validation is also exposed as shared middleware in middleware/jwt.go. Protected cart, checkout, and administrative product-management routes should pass through this boundary, allowing services to operate on authenticated user context rather than raw credentials.
Product Catalog and Inventory Boundary
The product module owns catalog-oriented data and persistence access:
• internal/product/model.go
• internal/product/repository.go
• internal/product/service.go
The repository is the principal persistence boundary for products; handlers should call the service rather than access storage directly. Product routes in internal/product/router.go support the catalog flow, including viewing/searching products and likely privileged CRUD/inventory operations.
Cart Lifecycle
The cart module represents user shopping state and cart mutation workflows:
• internal/cart/model.go
• internal/cart/service.go
• internal/cart/handler.go
Requests enter through cart routes, are authenticated via JWT middleware, then invoke cart services to add or remove products. The cart service is the appropriate boundary for validating product availability, associating cart state with the current user, and calculating checkout-ready cart contents.
Checkout and Payment Integration
Payment is isolated from cart and product HTTP concerns:
• internal/payment/router.go
• internal/payment/handler.go
• internal/payment/service.go
The expected control flow is authenticated user → cart retrieval/validation → payment service → external payment gateway (such as Stripe, per the repository description). The payment service should contain gateway-specific interactions and translate external success/failure into application-level checkout outcomes.
Runtime and External Dependencies
The runtime is a Go API application, defined by go.mod and launched from cmd/main.go. JWT is the material security mechanism. A third-party payment gateway is the primary external-service boundary, mediated through internal/payment/service.go. Persistence technology is not identifiable from the provided tree; product storage is abstracted behind internal/product/repository.go.
Main entry points: main.go API Server · cart/service.go Cart Service · jwt.go JWT Middleware · payment/service.go Payment Service
Components 18
Authentication
- Auth Router
internal/auth/router.go - Auth Handler
internal/auth/handler.go - Auth Service
internal/auth/service.go - JWT Support
internal/auth/jwt.go - JWT Middleware · Authenticates protected requests and supplies user context.
middleware/jwt.go
Product Catalog
- Product Router
internal/product/router.go - Product Service
internal/product/service.go - Product Repository
internal/product/repository.go - Product Model
internal/product/model.go
Cart
- Cart Router
internal/cart/router.go - Cart Handler
internal/cart/handler.go - Cart Service · Maintains user carts and validates checkout-ready contents.
internal/cart/service.go - Cart Model
internal/cart/model.go
Checkout & Payment
- Payment Router
internal/payment/router.go - Payment Handler
internal/payment/handler.go - Payment Service · Translates gateway outcomes into checkout results.
internal/payment/service.go - Payment Gateway · Third-party payment provider such as Stripe.
Other components
- API Server · Assembles routers and middleware.
cmd/main.go
Connections 21
- API Server → Auth Router: registers
- API Server → Product Router: registers
- API Server → Cart Router: registers
- API Server → Payment Router: registers
- Auth Router → Auth Handler: dispatches
- Auth Handler → Auth Service: auth operations
- Auth Service → JWT Support: issues tokens
- JWT Middleware → JWT Support: validates
- Product Router → Product Service: catalog requests
- Product Service → Product Repository: reads and writes
- Product Repository → Product Model: persists
- JWT Middleware → Cart Router: protects
- Cart Router → Cart Handler: dispatches
- Cart Handler → Cart Service: cart mutations
- Cart Service → Cart Model: manages
- Cart Service → Product Service: validates availability
- JWT Middleware → Payment Router: protects
- Payment Router → Payment Handler: dispatches
- Payment Handler → Payment Service: checkout request
- Payment Service → Cart Service: retrieves cart
- Payment Service → Payment Gateway: charges