How vatsalvarma/fg-test-2-pwa- works
1. Overall shape
- This is a two-tier product: a Spring Boot backend and a Next.js frontend, packaged for local/dev and Docker-based deployment.
- The backend owns business logic, persistence, security, integrations, and real-time messaging. The frontend is a role-based UI shell that consumes the backend API.
2. Backend core architecture
- The Java backend is a layered monolith under com.farmgearconnect.
- Main layers are: controllers for HTTP entry points, services for business workflows, repositories for database access, entities for JPA models, and DTOs for API input/output.
- FarmGearConnectApplication is the Spring Boot entry point; Flyway migrations initialize and evolve the schema on startup.
3. Primary domain boundaries
- The backend is organized around the product’s main business domains:
- Authentication & user management
- Equipment marketplace
- Bookings
- Chat / calling / notifications
- Payments / subscriptions
- Admin moderation
- Each domain has its own controller/service/repository slice rather than a separate service process.
4. Authentication and authorization flow
- Auth is JWT-based with refresh tokens, enforced by SecurityConfig, JwtAuthenticationFilter, JwtTokenProvider, and CustomUserDetailsService.
- The auth flow likely starts at AuthController and AuthService, persists tokens and OTPs in RefreshToken and OtpVerification, and uses User as the principal record.
- Role-based access is central: the UI and API both distinguish FARMER, OWNER, and ADMIN.
5. Marketplace and equipment management
- EquipmentController and EquipmentService handle listing lifecycle: create, update, submit for approval, and image upload.
- Equipment, EquipmentImage, and Coupon are key marketplace entities; EquipmentRepository and EquipmentImageRepository back the data access.
- The public marketplace and nearby search are distinct from owner/admin listing management, which matters for diagramming boundaries.
6. Booking workflow
- BookingController and BookingService coordinate the booking state machine: farmer creates a booking, owner approves/rejects, and bookings can be cancelled.
- Booking, BookingRequest, and BookingResponse define the contract.
- This domain is a core transaction boundary because it connects users, equipment, notifications, and payments.
7. Communication and real-time features
- Chat and notifications are separate but related subsystems:
- ChatController / ChatService with Message and MessageRepository
- NotificationController / NotificationService with Notification and NotificationRepository
- WebSocketConfig indicates real-time delivery via WebSocket + STOMP.
- MaskedCallingService suggests a protected calling flow that integrates with external telephony providers without exposing phone numbers.
8. Payments, subscriptions, and revenue
- PaymentController / PaymentService handle monetary workflows, especially subscriptions and deposits.
- Subscription, RefreshToken, and Coupon imply recurring plan management with promo support.
- The README references Razorpay as the payment provider; this is an external boundary worth showing as separate from core business data.
9. External integrations and infrastructure
- MailConfig + EmailService, SmsService, and StorageService point to external services for OTP email, SMS delivery, and file storage.
- StorageConfig indicates S3-compatible object storage, with the README naming MinIO locally and possibly AWS S3 in other environments.
- RestTemplateConfig suggests synchronous outbound HTTP calls for integrations such as telephony or payment verification.
10. Persistence model
- MySQL is the primary relational store, accessed through Spring Data repositories.
- Entities include operational records (Booking, Message, Notification, Review), identity records (User, RefreshToken, OtpVerification), and governance records (AuditLog, Subscription).
- AuditLog and the log files under backend/logs/ show that the system captures both application logs and database-level audit history.
11. Admin and moderation boundary
- AdminController is a separate boundary for listing approvals, user management, analytics, and moderation.
- This is not just another UI section; it represents a privileged workflow that sits above normal farmer/owner operations.
- In the architecture diagram, admin actions should be shown as directly acting on marketplace and user records, but through constrained endpoints and role checks.
12. Frontend structure
- The frontend is a Next.js 15 App Router application organized by route groups and role-based areas.
- Distinct route trees exist for auth, public, admin, farmer, owner, marketplace, and equipment detail pages.
- Shared client-side layers include src/lib/api for backend calls, src/lib/store for auth state, src/lib/i18n for English/Telugu translations, and ThemeProvider/UI components for app-wide presentation.
13. Frontend-to-backend data flow
- The frontend does not appear to own business state; it mainly reads/writes through Axios-based API clients in src/lib/api.
- Authentication state is centralized in Zustand (authStore), and route-specific pages likely consume role information to render the correct experience.
- The key data path is: browser UI → Next.js API client → Spring Boot REST API → JPA/MySQL, with WebSocket used for live events like notifications/chat.
14. Deployment and operational boundaries
- docker-compose.yml and Dockerfiles indicate a containerized deployment that can bring up backend, frontend, MySQL, Redis, and MinIO together.
- GitHub Actions workflows exist for frontend and deployment automation, so CI/CD is part of the repo’s operational architecture.
- Redis is referenced in the README as a cache/auxiliary store, but it is not the primary system of record.
15. What to emphasize in an architecture diagram
- Draw the backend as one monolithic application with clear internal modules, not as microservices.
- Show the main external dependencies separately: MySQL, Redis, MinIO/S3, SMTP/email, SMS provider, payment gateway, and telephony provider.
- Highlight the real-time channel (WebSocket/STOMP) as separate from normal REST traffic, since chat and notifications depend on it.
Main entry points: AuthService.java Services · client.ts API Client · layout.tsx Next.js App · WebSocketConfig.java Config Layer
Components 31
Backend
Spring Boot monolith with layered domain modules
- Spring Boot App · Application bootstrap and startup orchestration
backend/src/main/java/com/farmgearconnect/FarmGearConnectApplication.java - Security · JWT authentication, refresh tokens, and role checks
backend/src/main/java/com/farmgearconnect/config/SecurityConfig.java - Auth · Login, registration, verification, and token issuance
backend/src/main/java/com/farmgearconnect/controller/AuthController.java - Users · User profile and account data access
backend/src/main/java/com/farmgearconnect/controller/UserController.java - Equipment · Equipment lifecycle, images, and public listing flows
backend/src/main/java/com/farmgearconnect/controller/EquipmentController.java - Bookings · Booking state machine and reservation workflow
backend/src/main/java/com/farmgearconnect/controller/BookingController.java - Chat & Notify · Messages, notifications, and live delivery
backend/src/main/java/com/farmgearconnect/controller/ChatController.java - Calling · Masked calling and phone privacy workflow
backend/src/main/java/com/farmgearconnect/controller/CallingController.java - Payments · Payments, subscriptions, and coupon-supported billing
backend/src/main/java/com/farmgearconnect/controller/PaymentController.java - Admin · Privileged moderation, approvals, and user management
backend/src/main/java/com/farmgearconnect/controller/AdminController.java - Services · Core workflow layer for auth, bookings, marketplace, chat, notifications, and payments
backend/src/main/java/com/farmgearconnect/service/AuthService.java - Repositories · Spring Data persistence for domain records
backend/src/main/java/com/farmgearconnect/repository/UserRepository.java - Entities · JPA models for users, bookings, equipment, messages, notifications, and subscriptions
backend/src/main/java/com/farmgearconnect/entity/User.java - Config Layer · WebSocket, storage, mail, and HTTP client configuration
backend/src/main/java/com/farmgearconnect/config/WebSocketConfig.java - Migrations · Flyway schema initialization, seed data, and fixes
backend/src/main/resources/db/migration/V1__init_schema.sql
Frontend
Next.js role-based UI shell
- Next.js App · App Router frontend with role-based route trees
frontend/src/app/layout.tsx - Auth UI · Login, registration, and verification pages
frontend/src/app/(auth)/login/page.tsx - Role Areas · Admin, farmer, and owner dashboards and workflows
frontend/src/app/admin/dashboard/page.tsx - Marketplace UI · Public marketplace and equipment detail pages
frontend/src/app/marketplace/page.tsx - API Client · Axios-based backend API access and auth-aware requests
frontend/src/lib/api/client.ts - Auth Store · Centralized client auth state and role awareness
frontend/src/lib/store/authStore.ts
Infrastructure
Datastores, integrations, and deployment surfaces
- MySQL · Relational system of record for business data
backend/src/main/resources/application.yml - Redis · Cache and supporting runtime state
docker-compose.yml - MinIO / S3 · Image and file storage backing equipment media
backend/src/main/java/com/farmgearconnect/config/StorageConfig.java - Email · Outbound email delivery for OTPs and account flows
backend/src/main/java/com/farmgearconnect/config/MailConfig.java - SMS Provider · SMS delivery for verification and notifications
backend/src/main/java/com/farmgearconnect/service/SmsService.java - Razorpay · External payment and subscription provider
backend/src/main/java/com/farmgearconnect/service/PaymentService.java - Telephony · Provider used by masked calling flows
backend/src/main/java/com/farmgearconnect/service/MaskedCallingService.java - WebSocket/STOMP · Live transport for chat and notification delivery
backend/src/main/java/com/farmgearconnect/config/WebSocketConfig.java - CI/CD · GitHub Actions workflows for frontend and deployment automation
.github/workflows/nextjs.yml - Docker Compose · Container orchestration for backend, frontend, and supporting services
docker-compose.yml
Connections 37
- Auth UI → API Client: login/register · Auth pages submit credentials through the shared API client
- Role Areas → API Client: role actions · Dashboard areas call backend APIs for protected workflows
- Marketplace UI → API Client: browse/book · Public browsing and booking views use the API client
- API Client → Auth: REST · Frontend auth requests reach the backend auth controller
- API Client → Equipment: REST · Frontend marketplace requests reach equipment APIs
- API Client → Bookings: REST · Booking actions flow from the UI to booking APIs
- API Client → Chat & Notify: REST · Chat and notification screens fetch and mutate via APIs
- Auth Store → Role Areas: role state · Client auth state drives role-specific rendering
- Spring Boot App → Security: bootstraps · Application startup loads security and web infrastructure
- Spring Boot App → Migrations: runs · Flyway migrations run on backend startup
- Security → Auth: protects · Security config governs authentication endpoints and token handling
- Security → Admin: guards · Role-based access constrains privileged admin actions
- Auth → Services: uses · Auth controller delegates workflow logic to services
- Users → Services: uses · User profile operations are handled in the service layer
- Equipment → Services: uses · Equipment lifecycle endpoints delegate to marketplace services
- Bookings → Services: uses · Booking state transitions are orchestrated in services
- Chat & Notify → Services: uses · Chat and notification controllers use shared service workflows
- Calling → Services: uses · Masked calling is coordinated through service logic
- Payments → Services: uses · Payment endpoints delegate to billing and subscription workflows
- Admin → Services: uses · Admin moderation acts through backend services and constraints
- Services → Repositories: persists · Services read and write via Spring Data repositories
- Repositories → Entities: maps · Repositories operate on JPA entities
- Entities → MySQL: stored in · Entities are persisted in MySQL
- Services → WebSocket/STOMP: pushes events · Chat and notification services use the realtime channel
- Config Layer → MinIO / S3: connects · Storage configuration binds the app to object storage
- Config Layer → Email: connects · Mail configuration binds outbound email delivery
- Services → SMS Provider: sends · Verification and alerts can be delivered by SMS
- Payments → Razorpay: integrates · Billing workflow integrates with the payment gateway
- Calling → Telephony: integrates · Masked calling depends on an external telephony provider
- Config Layer → WebSocket/STOMP: configures · WebSocket configuration enables STOMP-based live traffic
- Services → Redis: optional cache · Redis supports auxiliary runtime state and caching
- Next.js App → Auth UI: routes to · Auth route group is part of the Next.js app
- Next.js App → Role Areas: routes to · Role dashboards are part of the Next.js app
- Next.js App → Marketplace UI: routes to · Marketplace routes are part of the Next.js app
- Docker Compose → Spring Boot App: runs · Compose brings up the backend container
- Docker Compose → Next.js App: runs · Compose brings up the frontend container
- CI/CD → Docker Compose: ships · CI/CD supports deployment and image publishing