How ngnhatthanh/linkway-socialnetwork works
Project Type & Purpose
• This is a full-stack web application built with Spring Boot, intended to serve as a social networking platform for developers.
• Its core functions include user authentication, post creation (with Markdown to HTML rendering), social interactions (comments, votes, tag management), real‐time chat and notifications (using WebSockets), and email integration (for features like forgot password).
Identifying the Main Components
a. Frontend Components:
– Views: Thymeleaf templates and static assets (CSS, JavaScript, and images) in the “src/main/resources/templates” and “src/main/resources/static” directories.
– Client-side interactions: JavaScript files (e.g., chatpage.js, navbar.js) that handle dynamic behavior, like real-time chat updates and UI events.
b. Backend Components:
– Controllers: Under “.../controller”, these manage incoming HTTP requests for authentication, posts, chats, notifications, and user operations.
– Service Layer: Contained within the “.../service” directory, where business logic is implemented. Services interact with controllers and the DAO layer.
– Data Access: The “.../dao” folder contains repositories (using Spring Data JPA conventions) to interact with the MySQL database.
– Entities & DTOs: “.../entity” defines the domain models (e.g. User, Post, Comment, Notification), while “.../dto” packages manage data transfer between layers.
– Configuration & Security: The “.../config” and subdirectories (e.g., for WebSocket, security, interceptors) configure Spring Security, session handling, cloud integrations (Cloudinary), and CORS/interception.
– Exception Handling: Organized within the “.../exception” package to manage errors uniformly.
– Utility Functions: In “.../util” for helper functions like Markdown conversion and password encoding (BCrypt).
c. External Dependencies:
– MySQL Database: As noted by the “create_tables_mysql.sql” script and the ERD in the README for persistent storage.
– Cloudinary: Configured via “CloudinaryConfig.java” to support image uploads.
– Email Service: Configured in Spring mail, as per the instructions in the README.
– WebSocket: Real-time communication for chat and notifications.
Mapping Relationships & Data Flow
• The Browser (with UI rendered using Thymeleaf) sends requests to the Controller layer.
• Controllers use Service components to apply business logic.
• Services then interact with Data Access Objects (DAO/repositories) which perform CRUD operations on the MySQL database.
• For real-time features, a dedicated WebSocket layer (configured via “WebSocketConfig.java”) manages persistent connections for chat and notifications.
• External service integrations (Cloudinary for images, email service for password resets) are invoked from their respective service components.
• How security is enforced:
• Spring Security configuration which intercepts requests, applies authentication/authorization (with components such as “CustomUserDetailService” and “CustomSuccessHandler”), and uses a set of interceptors as shown in the “interceptor” package.
Architectural Patterns & Design Principles
• MVC (Model-View-Controller) pattern:
• Model: Domain entities and DTOs.
• View: Thymeleaf templates and static resources.
• Controller: HTTP handling and routing.
• Layered Architecture:
• Separation of concerns between presentation (frontend), business logic (services), and data access (repositories/DAO).
• Dependency Injection via Spring Boot, enabling better testability and loose coupling.
• Real-time messaging using WebSockets, adding an event-driven aspect to the architecture.
• Follow with the Service layer, then the DAO/Data layer, culminating in the MySQL database.
• Off to the side (or connected appropriately), include external services like Cloudinary for image storage and the email server for notifications.