Integration Architecture
Hub for backend-frontend integration, API contracts, authentication flows, and cross-environment configuration.
What is βIntegrationβ Here?
Smart Supply Pro is a distributed system with clear separation of concerns:
graph LR
FrontendUser["π₯οΈ User
(React SPA)"] Frontend["π± Frontend
(React/TypeScript)"] Nginx["π Nginx
(Reverse Proxy)"] Backend["βοΈ Backend
(Spring Boot)"] DB[("ποΈ Database
(Oracle)")] OAuth["π OAuth2
(Google)"] FrontendUser -->|Browser| Frontend Frontend -->|HTTPS/REST| Nginx Nginx -->|Proxy to| Backend Backend -->|SQL| DB Backend -->|Oauth2 Flow| OAuth style Frontend fill:#61dafb,color:#000 style Backend fill:#6db33f,color:#fff style Nginx fill:#009639,color:#fff style OAuth fill:#4285f4,color:#fff style DB fill:#f80000,color:#fff style FrontendUser fill:#ff9900,color:#000
(React SPA)"] Frontend["π± Frontend
(React/TypeScript)"] Nginx["π Nginx
(Reverse Proxy)"] Backend["βοΈ Backend
(Spring Boot)"] DB[("ποΈ Database
(Oracle)")] OAuth["π OAuth2
(Google)"] FrontendUser -->|Browser| Frontend Frontend -->|HTTPS/REST| Nginx Nginx -->|Proxy to| Backend Backend -->|SQL| DB Backend -->|Oauth2 Flow| OAuth style Frontend fill:#61dafb,color:#000 style Backend fill:#6db33f,color:#fff style Nginx fill:#009639,color:#fff style OAuth fill:#4285f4,color:#fff style DB fill:#f80000,color:#fff style FrontendUser fill:#ff9900,color:#000
Integration Points:
- Frontend βοΈ Backend: REST API over HTTPS with session cookies (no JWT tokens)
- Backend βοΈ OAuth2 Provider: Google OAuth2 for authentication
- Backend βοΈ Database: Oracle Autonomous DB (wallet-secured)
- Nginx βοΈ Backend: Same container (localhost) reverse proxy for API routing
Architecture Overview: How They Talk
Data Flow: User Interaction
User clicks "Sign in with Google"
β
Frontend redirects to /oauth2/authorization/google (backend-initiated)
β
Backend + OAuth2 client redirects user to Google login
β
Google redirects back to backend with authorization code
β
Backend exchanges code for tokens (backend-to-backend, not visible to frontend)
β
Backend creates session cookie (HTTP-only, secure)
β
Backend redirects frontend to /dashboard
β
Frontend detects logged-in state via /api/auth/me endpoint
β
Frontend loads protected pages and calls APIs with automatic credential include
Responsibility Split
| Responsibility | Frontend | Backend |
|---|---|---|
| UI Rendering | β React components, routing, styling | β |
| State Management | β React Context/hooks, local storage | β |
| API Calls | β httpClient (axios wrapper) | β |
| Business Logic | β | β Spring Services, Java |
| Data Persistence | β | β JPA repositories, Oracle DB |
| Authentication | Detects session via /me probe | β OAuth2, session cookies |
| Authorization | Hides UI elements | β
@PreAuthorize annotations |
| Validation | Client-side hints | β JSR-380 constraints |
| Error Handling | Display toasts/messages | β
ErrorResponse DTOs |
Where Auth Lives
Backend (Source of Truth)
- OAuth2 Configuration:
src/main/java/config/SecurityConfig.java - Session Creation:
AuthController.handleOAuth2Login() - Authorization Checks:
@PreAuthorize("hasRole('ADMIN')")on controller methods - Session Validation: Spring Security
SecurityContext
Frontend (Detects Session)
- Auth Detection: Calls
GET /api/auth/meon app load - State Storage: React Context
(
AuthContext.tsxor similar) - Session Loss: 401 responses trigger
redirect to
/login - Demo Mode: Special flag in localStorage for read-only demo
Session Cookies
- Type: HTTP-only (not accessible via JavaScript)
- Secure: HTTPS-only in production
- SameSite: STRICT (prevents CSRF)
- Lifetime: Managed by Spring Security session timeout
- Domain: First-party (frontend and backend under same domain via Nginx)
File Organization
/docs/backend/architecture/integration/
βββ index.md (THIS FILE - Hub & overview)
βββ backend-frontend-overview.md (High-level architecture narrative)
βββ api-contract-and-endpoints.md (API surface, groups, centralized httpClient)
βββ auth-flow-frontend.md (Login, logout, session detection)
βββ error-handling-contract.md (ErrorResponse shape, status code mapping)
βββ cors-and-network.md (Origins, CORS rules, cookie config)
βββ environments-and-urls.md (Local, staging, production URLs & config)
βββ integration-testing.md (Backend + frontend integration test strategies)
βββ README.md (Quick start links)
Quick Links to Topics
π Backend-Frontend Overview
Understand how the two systems divide responsibilities and communicate.
- Architecture layers: Frontend (UI, routing), Backend (API, logic, data)
- Data flow: User β Frontend β Backend β DB
- DTOs as contracts
- Where each technology lives (
/srcvs/frontend)
π API Contract & Endpoints
Catalog of all API endpoints and frontend consumption patterns.
- Base URL:
/api/v1(versioned) - Endpoint groups: suppliers, inventory, stock history, analytics, auth
- Frontend centralized API client
(
httpClient.ts) - Authorization patterns (
@PreAuthorize) - Response pagination
π Authentication Flow (Frontend Perspective)
How login, logout, and session detection work from the frontend.
- βLogin with Googleβ OAuth2 flow
- Backend exchange of codes for session cookies
- Frontendβs
/api/auth/meprobe for logged-in state - Logout: calling backend, clearing session
- Demo mode (read-only without auth)
π Error Handling Contract
How backend errors map to frontend behavior and UI feedback.
- Standard
ErrorResponseshape:{ error, message, timestamp, correlationId } - HTTP status mapping: 400 (validation), 401 (auth), 403 (permission), 404 (not found), 409 (conflict), 500 (server)
- Frontend parsing: toasts, snackbars, inline form validation messages
- Correlation IDs for debugging
π CORS & Network Configuration
How origins, CORS rules, and cookies work across environments.
- Local dev:
http://localhost:3000(frontend) βοΈhttp://localhost:8080(backend) - Production: Frontend domain βοΈ Fly.io backend via Nginx proxy
withCredentials: truefor cookie inclusion- CORS rules in Spring Security
- SameSite and Secure cookie flags
π Environments & URLs
Map environment-specific configurations and API base URLs.
- Local development: Frontend Vite dev server, backend Maven dev
- Production: Frontend on Vercel/GitHub Pages, backend on Fly.io
- Frontend
.envvariables (VITE_API_BASE) - Backend
application-prod.ymlconfiguration - Fly.io environment secrets
π Integration Testing
Test strategies for backend-frontend integration.
- Backend integration tests: Spring Boot
@SpringBootTest, TestContainers - Frontend API mocks: MSW (Mock Service Worker) or Cypress fixtures
- End-to-end tests: Full user flows (if using Cypress, Playwright)
- Coverage of happy paths, auth-required flows, error scenarios
Related Architecture Docs
Backend Architecture
- Controller Layer - REST endpoints, request/response patterns
- DTO Layer - Data transfer objects, validation contracts
- Security Architecture - OAuth2, role-based access, encryption
- Exception Handling - ErrorResponse, GlobalExceptionHandler
- Service Layer - Business logic, transaction management
Configuration & Deployment
- Resources & Configuration - application-*.yml, environment variables
- Deployment - Docker, CI/CD, Fly.io, Nginx
- Logging & Observability - SLF4J/Logback, debugging
Key Takeaways
- Frontend and Backend are Decoupled
- Frontend is a standalone React SPA
- Backend is a stateless REST API
- No server-side templates; no server-side routing
- Authentication is Backend-Controlled
- OAuth2 exchange happens server-to-server
- Session cookies are HTTP-only (JS-inaccessible)
- Frontend detects auth state by probing
/api/auth/me
- APIs are Contract-Driven
- All calls go through centralized
httpClient.ts - Request/response shapes are DTOs
- Errors follow standard
ErrorResponseformat
- All calls go through centralized
- Configuration is Environment-Aware
- Frontend reads
VITE_API_BASEenv variable - Backend reads
application-{profile}.ymlconfiguration - Production: same-origin proxy via Nginx (cookies work naturally)
- Frontend reads
- Testing is Layered
- Backend: Unit + integration (Spring Boot, TestContainers)
- Frontend: Component + integration (React Testing Library, MSW)
- E2E: Full user flows (Cypress, Playwright) if implemented
Navigation
- β Back to Architecture Index
- β Back to Architecture Overview (English)
- β Back to Architektur-Γbersicht (German)
- Deployment & Infrastructure - How the system runs in the cloud
- Configuration & Resources - Environment-specific setup