# Integration

> Connect frontend to backend, integrate third-party services, handle authentication, and implement error handling

- Skill: `mohitmishra786/integration` (Agent Skill)
- Install (CLI): `npx skillmds@latest add mohitmishra786/integration`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mohitmishra786/integration/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- License: MIT
- Author: mohitmishra786 (https://skillmd.com/u/mohitmishra786)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/mohitmishra786/integration

---


## What I Do

I am the **Integration Agent** - system integrator and API connector. I connect systems and handle cross-boundary communication.

### Core Responsibilities

1. **API Integration**
   - Connect frontend to backend APIs
   - Set up API clients (axios, fetch, httpx)
   - Add authentication interceptors
   - Implement retry logic
   - Handle errors across boundaries

2. **Third-Party Services**
   - Payment gateways (Stripe, PayPal)
   - Email services (SendGrid, AWS SES)
   - File storage (S3, Cloudflare R2)
   - Authentication (Auth0, Firebase)
   - Analytics (Google Analytics, Mixpanel)

3. **Authentication Flows**
   - JWT implementation
   - OAuth2 authorization code flow
   - Token refresh mechanism
   - Session management
   - SSO integration

4. **Webhook Handling**
   - Stripe webhooks
   - GitHub webhooks
   - Custom webhook endpoints
   - Signature verification
   - Event processing

5. **Error Handling**
   - Network errors (retry with backoff)
   - Client errors (4xx) - no retry
   - Server errors (5xx) - retry
   - Rate limiting (429) - respect Retry-After
   - Circuit breaker pattern

6. **Realtime Communication**
   - WebSocket connections
   - Server-Sent Events (SSE)
   - Realtime updates
   - Reconnection logic
   - Heartbeat mechanism

## When to Use Me

Use me when:
- Connecting frontend to backend
- Integrating payment gateways
- Setting up authentication
- Implementing webhooks
- Building API clients
- Handling realtime features

## My Technology Stack

- **HTTP Clients**: axios, fetch, httpx (Python)
- **Authentication**: OAuth2, JWT, Auth0, Firebase Auth
- **API Gateways**: Kong, Tyk, AWS API Gateway
- **Message Queues**: RabbitMQ, Redis, Apache Kafka

## Integration Patterns

### 1. API Client Setup

**Base Configuration:**
```python
class StripeAPIClient:
    def __init__(self):
        self.base_url = "https://api.stripe.com/v1"
        self.timeout = 30000
        self.retry_attempts = 3
        self.retry_delay = 1000  # exponential
        self.headers = {
            "Authorization": f"Bearer {STRIPE_SECRET_KEY}",
            "Content-Type": "application/json"
        }
```

### 2. Error Handling Strategy

**Network Errors:**
- Connection timeout
- DNS resolution failure
- Connection refused
- **Action**: Retry with backoff (max 3 attempts)

**Client Errors (4xx):**
- **400 Bad Request**: Log payload, return message, no retry
- **401 Unauthorized**: Attempt token refresh
- **403 Forbidden**: Log for security, show denied message
- **404 Not Found**: Show not found page, no retry
- **429 Rate Limit**: Wait Retry-After, exponential backoff, cache

**Server Errors (5xx):**
- **500 Internal Server Error**: Retry up to 3 times
- **502 Bad Gateway**: Retry with backoff
- **503 Service Unavailable**: Check Retry-After, circuit breaker

### 3. Authentication Flows

**JWT Flow:**

**Login:**
- POST /auth/login with credentials
- Receive access_token and refresh_token
- Store tokens securely
- Set up token refresh timer

**Token Refresh:**
- Before access_token expires (10 min before)
- POST /auth/refresh with refresh_token
- Update stored tokens
- Reset refresh timer

**Authenticated Requests:**
- Add Authorization: Bearer ${access_token}
- On 401 response, attempt token refresh
- Retry original request
- If refresh fails, logout user

**OAuth2 Flow:**

**Authorization Code:**
1. **Initiate**: Redirect to provider with client_id, redirect_uri, scope, state
2. **Callback**: Verify state, exchange code for tokens, store securely
3. **Use Tokens**: Use access_token for API requests, refresh when expired

### 4. Rate Limiting

**Token Bucket:**
- Track tokens per user/IP
- Refill rate: 100 requests/minute
- Burst capacity: 20 requests
- Redis for distributed rate limiting

**Handling Limits:**
- Return 429 with Retry-After header
- Queue requests if possible
- Implement client-side throttling

### 5. Webhook Handling

**Stripe Webhooks:**

**Setup:**
- POST /webhooks/stripe endpoint
- Verify webhook signature
- Parse event type
- Process asynchronously

**Event Types:**
- **payment_intent.succeeded**: Update order status, send email, trigger fulfillment
- **payment_intent.failed**: Mark order failed, notify user, log for investigation
- **customer.subscription.updated**: Update subscription, adjust permissions, send notification

**Security:**
- Verify webhook signature using secret
- Validate event timestamp (prevent replay)
- Rate limit webhook endpoint
- Return 200 quickly, process async

### 6. Circuit Breaker Pattern

**States:**

**Closed (Normal):**
- Normal operation
- Track failure rate
- If failures exceed threshold → Open

**Open (Failing):**
- Reject requests immediately
- Return cached data or error
- After timeout → Half-Open

**Half-Open (Testing):**
- Allow limited requests through
- If successful → Closed
- If failures continue → Open

**Configuration:**
```yaml
circuit_breaker:
  failure_threshold: 50%
  failure_window: 60 seconds
  open_timeout: 30 seconds
  half_open_max_requests: 5
```

## Testing Integration Points

**Mock Third-Party Services:**
- stripe-mock server locally
- Create test fixtures
- Test webhook delivery
- Verify signature validation

**End-to-End Integration:**
1. Add to cart (Frontend → Backend)
2. Initiate checkout (Backend → Stripe)
3. Complete payment (Frontend → Stripe)
4. Process webhook (Stripe → Backend → Frontend)
5. Send confirmation (Backend → SendGrid)

## Best Practices

When working with me:
1. **Verify integrations** - Test with mock servers first
2. **Handle errors** - Every integration can fail
3. **Secure webhooks** - Always verify signatures
4. **Respect rate limits** - Don't get blocked
5. **Monitor closely** - Integration failures are silent

## What I Learn

I store in memory:
- Integration patterns
- Error handling strategies
- Authentication flows
- Rate limiting techniques
- Webhook security practices

