How rsp-byte/frutosparaiso works
1. High-level shape
- This repository is a single Spring Boot 3 backend written in Java 21, built with Gradle.
- It is organized as a layered application: HTTP controllers → services → repositories/entities, with several outbound integrations for authentication, messaging, AI, Redis, and an external billing service.
2. Primary architectural boundary
- The main boundary is the REST API layer under controller/.
- Controllers expose endpoints for auth, chat, products, orders, items, Factus, and a WhatsApp webhook.
- Business logic is pushed into service/ and service/impl/, while persistence is isolated in repository/.
3. Domain and persistence model
- The app uses Spring Data JPA with entities such as User, ProfileEntity, ProductEntity, OrderEntity, Bill, DetailBill, Customer, RefreshToken, and ItemFPEntity.
- Repositories like UserRepository, ProductRepository, OrderRepository, BillRepository, and RefreshTokenRepository indicate a relational data model centered on users, commerce/order data, and token storage.
- src/main/resources/SQL_SC/FRUTOS_PARAISO_INSERT_PRODUCT.sql suggests the app can be bootstrapped with seed product data.
4. Authentication and session management
- Authentication is handled by AuthController, AuthService, JwtService, and JwtFilter, with SecurityConfig and CustomUserDetailsService forming the Spring Security boundary.
- JWT-related configuration lives in JWTProperties.
- Refresh and transient token state is split between the database (RefreshTokenRepository) and Redis-backed cache services (TokenCacheService, RedisService), which implies short-lived/session-like state outside the main JPA store.
5. Commerce workflows
- ProductController/ProductService manage catalog operations.
- OrderController/OrderService manage order lifecycle and likely assemble products/items into orders.
- ItemController and ItemFPService suggest a secondary item domain, likely tied to “Frutos Paraíso” business-specific products/items.
- These workflows are data-centric and persist through JPA repositories, with DTOs used to avoid exposing entities directly.
6. Billing / external invoicing integration
- FactusController and FactusService indicate an integration with an external Factus service.
- FactusProperties and entities like Factus, Bill, DetailBill, Customer, and Establishment suggest the service handles invoice/billing payloads and maps internal order data into an external billing format.
- ExternalServiceException implies outbound integration failures are treated as a distinct error class.
7. Chat, AI, and WhatsApp integration
- ChatController, ChatEventBus, OpenAiService, AgentMcpService, AgentPrompt, WhatsAppService, and WhatsappTwiloWebHook form a separate conversational subsystem.
- The likely flow is: incoming chat/WhatsApp message → webhook/controller → internal event bus/service orchestration → AI agent/OpenAI → reply back through WhatsApp.
- TwilioConfig and TwilioInitializer show WhatsApp messaging is mediated through Twilio.
- AiConfig and WebClientConfig suggest outbound AI calls are done over HTTP using Spring’s reactive client.
8. Redis as a supporting infrastructure component
- Redis is a first-class infrastructure dependency, configured in RedisConfig and monitored by RedisHealthCheck.
- RedisService and TokenCacheService indicate Redis is used for fast transient state, most visibly token/session caching and possibly chat context or other ephemeral coordination data.
- This creates a clear separation between durable data in the relational database and short-lived operational data in Redis.
9. API contract and mapping layer
- The dto/ package is extensive: auth requests, refresh/token payloads, order/product/user/profile data, chat context, and AI response/request models.
- This indicates the API does not expose JPA entities directly; instead it uses DTOs as the contract boundary for clients and external services.
- The presence of both entity/TokenResponse and dto/TokenResponse suggests separate shapes for persistence/internal use versus API response use.
10. Error handling and resilience
- GlobalExceptionHandler centralizes API error translation.
- ApiException is used for application-level failures, while ExternalServiceException captures integration problems.
- Supporting types like ErrorResponse and ErrorCode show the service returns structured error payloads rather than raw stack traces.
11. Configuration and cross-cutting concerns
- CorsConfig handles cross-origin access for client applications.
- WebClientConfig supports outbound HTTP integration.
- FactusProperties, JWTProperties, TwilioConfig, and RedisConfig externalize runtime configuration, making the app environment-driven.
- ChatEventBus is a notable internal coordination mechanism for decoupling chat message ingestion from response generation.
12. Runtime characteristics
- The application is a server-side monolith with multiple integration points, not a distributed set of services.
- Its core runtime dependencies are:
- a relational database via JPA,
- Redis for caching/transient state,
- Twilio for WhatsApp delivery,
- an AI provider via HTTP,
- and a billing/invoicing service via HTTP.
13. Testing and entry point
- FrutosparaisoApplication.java is the Spring Boot entry point.
- FrutosparaisoApplicationTests suggests at least a basic context-load test exists.
- Overall, the repository is structured for a conventional layered backend with several business domains sharing the same runtime and deployment boundary.
Main entry points: FrutosparaisoApplication.java App entry · ProductController.java Commerce API · AuthController.java Auth API · AuthService.java Auth service
Components 18
API layer
REST endpoints and webhook ingress
- App entry · Application bootstrap
src/main/java/com/plataforma/frutosparaiso/FrutosparaisoApplication.java - Auth API · Login, refresh, password and session endpoints
src/main/java/com/plataforma/frutosparaiso/controller/AuthController.java - Commerce API · Catalog, orders, items, and billing endpoints
src/main/java/com/plataforma/frutosparaiso/controller/ProductController.java - Chat API · Chat ingress and response endpoints
src/main/java/com/plataforma/frutosparaiso/controller/ChatController.java - Webhook · WhatsApp callback endpoint
src/main/java/com/plataforma/frutosparaiso/controller/WhatsappTwiloWebHook.java
Core services
Business workflows and orchestration
- Auth service · Authentication and token lifecycle
src/main/java/com/plataforma/frutosparaiso/service/AuthService.java - Catalog service · Product and item workflows
src/main/java/com/plataforma/frutosparaiso/service/impl/ProductService.java - Order service · Order lifecycle and assembly
src/main/java/com/plataforma/frutosparaiso/service/impl/OrderService.java - Billing service · Factus invoice generation and submission
src/main/java/com/plataforma/frutosparaiso/service/FactusService.java - Chat orchestrator · Agent coordination and message handling
src/main/java/com/plataforma/frutosparaiso/service/impl/AgentMcpService.java - WhatsApp service · Outbound WhatsApp messaging via Twilio
src/main/java/com/plataforma/frutosparaiso/service/impl/WhatsAppService.java - OpenAI service · LLM calls over HTTP
src/main/java/com/plataforma/frutosparaiso/service/impl/OpenAiService.java
Data model
JPA entities and repositories
- User data · Users, profiles, and refresh tokens
src/main/java/com/plataforma/frutosparaiso/repository/UserRepository.java - Commerce data · Products, orders, items, and bills
src/main/java/com/plataforma/frutosparaiso/repository/ProductRepository.java
Infrastructure
Security, caching, configuration, and outbound adapters
- Auth cache · Token and transient session storage
src/main/java/com/plataforma/frutosparaiso/service/TokenCacheService.java - Security core · JWT filter, user details, and config
src/main/java/com/plataforma/frutosparaiso/security/SecurityConfig.java - Redis infra · Redis configuration and health check
src/main/java/com/plataforma/frutosparaiso/config/RedisConfig.java - External adapters · Twilio, WebClient, AI, Factus, CORS, and event bus support
src/main/java/com/plataforma/frutosparaiso/config/WebClientConfig.java
Connections 23
- App entry → Auth API: exposes · Application starts the REST API stack
- App entry → Commerce API: exposes · Application starts commerce endpoints
- App entry → Chat API: exposes · Application starts chat endpoints
- App entry → Webhook: exposes · Application starts webhook ingress
- Auth API → Auth service: uses · Authentication controller delegates to auth services
- Auth API → Security core: secures · Auth endpoints participate in security boundary
- Commerce API → Catalog service: uses · Catalog endpoints delegate to product/item services
- Commerce API → Order service: uses · Order endpoints delegate to order workflow
- Commerce API → Billing service: uses · Billing endpoints delegate to Factus integration
- Chat API → Chat orchestrator: uses · Chat controller orchestrates agent flow
- Webhook → WhatsApp service: routes to · Webhook feeds WhatsApp message handling
- Auth service → User data: persists · Auth reads users and refresh tokens
- Auth service → Auth cache: caches · Session state and refresh tokens use Redis
- Catalog service → Commerce data: persists · Catalog data is stored in the commerce model
- Order service → Commerce data: persists · Orders are assembled from commerce entities
- Billing service → Commerce data: reads · Billing builds invoices from order and product data
- Chat orchestrator → OpenAI service: calls · Agent orchestration queries the AI provider
- Chat orchestrator → WhatsApp service: replies via · Generated responses are sent through WhatsApp
- WhatsApp service → External adapters: depends on · Twilio and HTTP client configuration support delivery
- OpenAI service → External adapters: depends on · OpenAI service uses outbound HTTP configuration
- Billing service → External adapters: depends on · Factus integration uses external client configuration
- Security core → Auth cache: integrates · Security works with token cache for transient state
- Auth cache → Redis infra: backed by · Redis service sits on Redis infrastructure