How seal88241712-creator/backend works
1. Overall shape
- This is a single Spring Boot backend monolith for a campus second-hand trading platform.
- The application is organized in a classic layered architecture: controller → service → mapper → database, with DTO/VO objects separating API contracts from persistence models.
2. Primary business domains
- The codebase centers on nine functional areas: users, goods, categories, orders, chat, AI chat, evaluations, favorites, and announcements.
- Admin-oriented flows are present alongside student/user flows, especially for user audit, goods audit, and platform management.
3. API layer
- controller/ contains REST endpoints for each domain, such as UserController, GoodsController, OrderController, ChatController, AiChatController, and AdminController.
- Controllers accept DTOs, delegate to services, and return unified response wrappers rather than exposing entities directly.
4. Business logic layer
- service/ defines domain services and service/impl/ contains the implementations.
- This is where workflow rules live: publishing goods, approving audits, creating orders, recording evaluations, managing favorites, and assembling dashboard/statistics views.
5. Persistence boundary
- mapper/ holds MyBatis-Plus mappers for the main entities: User, Goods, Category, Order, ChatRecord, Evaluation, Favorite, Announcement, and AI chat history.
- entity/ models map to relational tables in MySQL, while vo/ models are used to shape responses for lists, details, stats, and dashboards.
6. Data flow and object boundaries
- Request payloads use dto/ types such as login/register, goods publish/query, order create/pay/query, audit actions, and chat messages.
- Responses use vo/ types such as UserVO, GoodsVO, OrderVO, ChatMessageVO, DashboardVO, and statistics VOs, which indicates a deliberate separation between storage schema and API output.
7. Security and identity
- Security is built with Spring Security plus JWT.
- The request path likely flows through JwtAuthenticationFilter, which authenticates incoming requests, with UserDetailsServiceImpl and CustomUserDetails backing user lookup and authorization.
- Roles and status are modeled explicitly in enums like UserRole, UserStatus, and GoodsStatus, supporting role-based access control for student/admin behavior.
8. Real-time communication
- Chat is not purely REST-based; it includes WebSocket support configured through WebSocketConfig, WebSocketHandshakeInterceptor, and ChatWebSocketHandler.
- This implies two parallel chat paths: persistent chat history in MySQL via ChatRecord, and real-time message exchange over WebSocket/STOMP.
9. External services and infrastructure
- Redis is configured as a secondary data store/cache, probably for session/token-related data, verification, or short-lived platform state.
- DashScopeConfig suggests integration with an external AI service for AiChatController/AiChatService, likely for AI conversation or recommendation features.
- File uploads are handled separately and stored under the local uploads/ directory, with image upload support exposed via FileUploadController.
10. Cross-cutting framework support
- common/ provides the standard API envelope (Result, PageResult) and centralized error handling via BusinessException and GlobalExceptionHandler.
- config/ contains CORS, Redis, WebSocket, MyBatis-Plus, file upload, and Knife4j/Swagger documentation setup.
- This indicates the backend is designed to be consumed by a separate frontend application and documented through generated API docs.
11. Domain-specific workflows
- Goods lifecycle: publish → audit/approval → browse/search/filter → favorite/chat/order.
- Order lifecycle: create → pay/mock payment → status tracking → evaluation.
- User lifecycle: register/login → JWT-authenticated access → audit/approval for role/status changes.
- Announcement and statistics flows support administrative oversight and platform-wide messaging.
12. Operational and schema concerns
- The repository includes Flyway-style SQL migrations under src/main/resources/db/migration, showing that schema evolution is part of the runtime model.
- Logging is configured via logback-spring.xml, and the build uses Maven with Spring Boot packaging.
- The presence of target/ and generated artifacts indicates a standard Java deployment model: build a runnable JAR, then run it with environment-specific YAML profiles.
13. What to show in an architecture diagram
- Draw one backend service boundary containing API controllers, service layer, persistence layer, security, and WebSocket handling.
- Show MySQL as the primary system of record, Redis as the auxiliary cache/state store, local file storage for uploads, and an external AI service connected to the AI chat module.
- Highlight the request entry points: REST endpoints, JWT-filtered HTTP traffic, and WebSocket connections for chat.
Main entry points: CampusTradingApplication.java CampusTrading · SecurityConfig.java Security · UserController.java Users · UserMapper.java Core mappers
Components 23
Spring Boot app
Single backend monolith for campus second-hand trading
- CampusTrading · Application bootstrap and runtime entrypoint
src/main/java/com/campus/trading/CampusTradingApplication.java
API layer
HTTP entry points and request/response contracts
- Users · Login, registration, and user audit APIs
src/main/java/com/campus/trading/controller/UserController.java - Goods · Goods publish, browse, and audit APIs
src/main/java/com/campus/trading/controller/GoodsController.java - Orders · Order create, pay, and query APIs
src/main/java/com/campus/trading/controller/OrderController.java - Chat · Persistent chat history APIs
src/main/java/com/campus/trading/controller/ChatController.java - AI chat · AI conversation and recommendation APIs
src/main/java/com/campus/trading/controller/AiChatController.java - Admin · Platform management and dashboard APIs
src/main/java/com/campus/trading/controller/AdminController.java
Business layer
Core workflows and domain services
- User service · Authentication, user status, and profile workflows
src/main/java/com/campus/trading/service/impl/UserServiceImpl.java - Goods service · Publish, audit, search, and lifecycle rules
src/main/java/com/campus/trading/service/impl/GoodsServiceImpl.java - Order service · Order creation, payment, and tracking rules
src/main/java/com/campus/trading/service/impl/OrderServiceImpl.java - Chat service · Chat history and conversation assembly
src/main/java/com/campus/trading/service/impl/ChatServiceImpl.java - AI service · External AI chat and recommendations
src/main/java/com/campus/trading/service/impl/AiChatServiceImpl.java - Support services · Categories, favorites, evaluations, announcements, files, admin
src/main/java/com/campus/trading/service/impl/AdminServiceImpl.java
Persistence layer
Database entities and MyBatis mappers
- MySQL · Primary relational database behind entities and mappers
src/main/resources/db/migration - Core entities · Users, goods, orders, categories, and announcements
src/main/java/com/campus/trading/entity/User.java - Interaction entities · Chat records, favorites, evaluations, and AI chat history
src/main/java/com/campus/trading/entity/ChatRecord.java - Core mappers · Persistence mappers for main business tables
src/main/java/com/campus/trading/mapper/UserMapper.java - Interaction mappers · Persistence mappers for chat, evaluation, favorite, and AI history
src/main/java/com/campus/trading/mapper/ChatRecordMapper.java
Infrastructure
Security, realtime, storage, and external integrations
- Security · JWT filter, user details, and authorization
src/main/java/com/campus/trading/security/SecurityConfig.java - WebSocket chat · Handshake and websocket message handling
src/main/java/com/campus/trading/handler/ChatWebSocketHandler.java - Redis · Secondary store for short-lived platform state
src/main/java/com/campus/trading/config/RedisConfig.java - DashScope · External AI provider used by AI chat
src/main/java/com/campus/trading/config/DashScopeConfig.java - Uploads · Local image and file upload storage
uploads/images
Connections 30
- CampusTrading → Security: HTTP security · All REST traffic passes through JWT authentication and authorization
- CampusTrading → Users: routes · Bootstraps user-facing REST endpoints
- CampusTrading → Goods: routes · Bootstraps goods-related REST endpoints
- CampusTrading → Orders: routes · Bootstraps order REST endpoints
- CampusTrading → Chat: routes · Bootstraps chat history REST endpoints
- CampusTrading → AI chat: routes · Bootstraps AI chat REST endpoints
- CampusTrading → Admin: routes · Bootstraps admin and dashboard REST endpoints
- Users → User service: delegates · Controllers pass request DTOs to domain services
- Goods → Goods service: delegates · Goods APIs delegate workflow rules to service layer
- Orders → Order service: delegates · Order APIs delegate business logic to service layer
- Chat → Chat service: delegates · Chat APIs read and assemble message history
- AI chat → AI service: delegates · AI chat APIs forward prompts and context
- Admin → Support services: delegates · Admin flows compose statistics and platform management views
- User service → Core mappers: persists · User service reads and writes core user records
- Goods service → Core mappers: persists · Goods service persists goods and category data
- Order service → Core mappers: persists · Order service persists order state
- Chat service → Interaction mappers: persists · Chat service stores chat history records
- AI service → DashScope: calls · AI service invokes external model provider
- Support services → Interaction mappers: persists · Favorites, evaluations, announcements, and admin summaries use supporting mappers
- Core mappers → MySQL: SQL · Core mappers operate on MySQL tables
- Interaction mappers → MySQL: SQL · Interaction mappers operate on MySQL tables
- Core entities → MySQL: maps to · Primary domain entities correspond to relational tables
- Interaction entities → MySQL: maps to · Interaction entities correspond to relational tables
- Security → Users: authenticates · JWT filter and user details protect API access
- Security → Admin: authorizes · Role-based access controls admin actions
- Security → Redis: uses · Security and short-lived state may rely on Redis
- WebSocket chat → Chat service: message flow · WebSocket handler exchanges live chat messages with chat service
- WebSocket chat → Redis: uses · Realtime coordination can use Redis-backed state
- Goods → Uploads: uploads · Goods images and related files are stored locally
- Users → Support services: shares · User-facing dashboards and counts are assembled from supporting services