How vinhtranphuc/spring-react-social works
Project type and purpose
• This is a full-stack web application demo showcasing social login via OAuth2.
• Frontend: React single-page-app (“react-social”)
• Backend: Spring Boot REST API with Spring Security and OAuth2 support (“spring-social”)
• Purpose: Allow users to sign up/login via username/password or Google/Facebook/GitHub OAuth2, persist users in MySQL, issue JWTs.
File structure
• react-social/
• public/: static HTML, manifest
• src/app: root App component & routing
• src/common: shared UI components (header, loading, PrivateRoute)
• src/home, src/user/{login, signup, profile, oauth2}: page components
• src/util/APIUtils.js: REST client wrappers
• spring-social/
• src/main/java/.../config: AppProperties, WebMvcConfig, SecurityConfig
• src/main/java/.../controller: REST endpoints (AuthController, UserController, OAuth2 callback logic)
• src/main/java/.../security: Spring Security filters, TokenProvider, OAuth2 handlers, CurrentUser annotation
• src/main/java/.../repository: JPA UserRepository
• src/main/java/.../model & payload: domain and DTOs
• src/main/resources/application.yml: DB and OAuth2 provider properties
README for additional insights
• MySQL database setup
• application.yml contains JDBC and OAuth2 client IDs/secrets
• Frontend served on localhost:3000, backend on 8080
• OAuth2 redirect URIs configured on providers
Main components and interactions
a. Components
• Browser / React Client (SPA at http://localhost:3000)
• Static Web Server (serving index.html, JS, CSS)
• REST API Server (Spring Boot on http://localhost:8080)
• MySQL Database (spring_social schema)
• OAuth2 Providers (Google, Facebook, GitHub)
b. Relationships
• Browser → React SPA HTTP GET (initial page load)
• React SPA ↔ REST API HTTP(S) calls /api/** for login, signup, profile, data
• SPA triggers OAuth2 login → Redirect browser to Provider’s auth URL
• OAuth2 Provider → Redirect back to /oauth2/callback/{provider} on API Server
• API Server uses OAuth2 filter chain → obtains user info → persists/updates in MySQL
• API Server issues JWT (in HTTP-Only cookie or JSON) → Browser stores token
• Browser includes JWT in Authorization header for protected REST calls
c. Architectural patterns & design principles
• Three-tier architecture: Presentation (React), Application (Spring Boot REST + Security), Data (MySQL)
• RESTful API with stateless JWT authentication
• OAuth2 Authorization Code grant flow
• Modular code organization: controllers, services, repositories, security filters
d. Key technologies
• Frontend: React, react-router (PrivateRoute), Axios/ fetch wrappers (APIUtils)
• Backend: Spring Boot, Spring MVC, Spring Security, OAuth2Client, Spring Data JPA, MySQL
• Security: JWT, CookieUtils, TokenAuthenticationFilter, CustomOAuth2UserService
1. Start by sketching three horizontal layers: Client, Server, Data/External.
3. In the Server layer, group Spring Boot modules:
• SecurityConfig & Filters (TokenAuthenticationFilter, OAuth2 handlers)
• Controllers (AuthController, UserController)
• Services (CustomOAuth2UserService, TokenProvider)
• Repositories (UserRepository)
4. In the Data/External layer, place MySQL and OAuth2 Providers.
• Browser → React SPA assets (static serve)
• React SPA ↔ Spring API (REST calls with JWT)
• Spring API ↔ MySQL (JDBC/JPA)
• Browser ↔ OAuth2 Providers (redirects, callback)