Backend-Frontend Integration (be-fe-integration)
A specialized workflow for connecting frontend components to backend services, focusing on frontend requirements while minimizing backend changes.
Quick Start
- •Analyze Frontend: Identify what the frontend needs (e.g., "User Profile", "Delete Post Form").
- •Search Backend: Locate the corresponding API endpoints or service methods.
- •Map Data: Ensure frontend props match backend response fields and form data matches backend request parameters.
- •Hook Up: Implement the
fetch/axioscalls or API client integration in the frontend. - •Minimal Backend Patch: If the backend is missing a specific field or endpoint required by the frontend, modify only that specific part.
Workflows
1. Frontend Requirement Analysis
- •Identify Data Needs: What fields are displayed? (e.g.,
user.avatar,post.title). - •Identify User Actions: What can the user do? (e.g., "Submit Order", "Cancel Subscription").
- •Examine Component Logic: Check
useEffect, form handlers, or state management (Redux, Zustand) for pending API integrations.
2. Backend Discovery & Alignment
- •Locate Endpoints: Search for route definitions (e.g.,
router.post('/orders'),app.get('/api/users')). - •Check Controllers/Services: verify the logic handling those routes.
- •Compare Payloads:
- •Frontend Request: Does it match the backend's expected JSON body or query params?
- •Backend Response: Does it contain all the fields the frontend UI needs to render?
3. Integration Implementation
- •Frontend Focus:
- •Update API client or service functions.
- •Wrap calls in
try/catchand handle loading/error states. - •Map backend field names to frontend-friendly names if they differ.
- •Backend Constraints:
- •Rule: Do NOT change the backend unless explicitly asked OR if the frontend requirement cannot be met without a change.
- •Specific Changes: If a change is needed, modify ONLY the specific endpoint or field required by the frontend task. Avoid refactoring unrelated backend code.
4. Verification
- •Run the App: Manually trigger the action in the browser.
- •Inspect Network: Monitor the Network tab to verify correct status codes (2xx, 4xx, 5xx) and payload structures.
- •Check Database: Use
managing-databasesto verify that POST/PUT/DELETE actions had the intended effect on the data.
Rules & Principles
- •Frontend Center: The frontend's UI and UX requirements drive the integration.
- •Stay Surgical: When modifying the backend, be a "surgeon," not a "renovator."
- •Handle Mismatches: Use transformation logic on the frontend to bridge minor naming differences between FE and BE.
Examples
Scenario: Hooking up a Contact Form
- •FE Analysis: Form has
name,email,message. - •BE Discovery: Endpoint
POST /api/contactexpects{ fullName, emailAddress, content }. - •Integration: Create a mapping in the FE call:
javascript
const submitForm = async (data) => { await api.post('/contact', { fullName: data.name, emailAddress: data.email, content: data.message }); };
Scenario: Missing Field in Backend
- •FE Analysis: UI needs
user_idto be returned on login to redirect to profile. - •BE Discovery:
POST /logincurrently only returns atoken. - •Action: Since the UI requires
user_idfor its logic, modify only the login response to includeuser_id.
Reference
- •API Testing: See testing-apis for verifying integration.
- •Database Management: See managing-databases for data verification.