A comprehensive library management system built with Java, featuring a JavaFX desktop client and a Socket-based server. The system provides complete book management, borrowing operations, user management, AI-powered recommendations, and real-time chat functionality.
- Book Management: Add, update, delete, and search books with ISBN, title, author, category
- Borrowing System: Borrow and return books with automatic due date tracking
- User Management: Support for both regular users and administrators
- AI Recommendations: Intelligent book recommendations based on user preferences and reading history
- Real-time Chat: User-to-user messaging system
- Fine Management: Automatic fine calculation with configurable rate tiers
- Statistics Dashboard: Comprehensive statistics for administrators
- Trending Books: Display popular books based on borrowing frequency
- Java: JDK 17 or higher
- Maven: 3.6 or higher
- PostgreSQL: 12 or higher
- pgvector Extension (optional): For enhanced AI recommendation features
- Install PostgreSQL and create a database:
CREATE DATABASE library_db;- Execute the database schema:
psql -U postgres -d library_db -f database/schema.sql- Initialize admin user (optional):
psql -U postgres -d library_db -f database/init_admin.sql- Import demo data (optional):
psql -U postgres -d library_db -f database/import_demo_data.sqlEdit server/src/main/resources/application.properties to configure database connection:
# Database Configuration
db.url=jdbc:postgresql://localhost:5432/library_db
db.username=postgres
db.password=your_password
db.pool.size.minimum=5
db.pool.size.maximum=20
# Server Configuration
server.port=9090
server.threadPoolSize=20mvn clean compileOr use the provided batch script (Windows):
完整部署.batOption 1: Using batch script (Windows)
start-server.batOption 2: Using Maven
mvn -pl server compile exec:java -Dexec.mainClass="com.library.server.ServerMain" -Dexec.args="9090"Option 3: Using command line arguments
java -cp target/classes com.library.server.ServerMain [port] [threadPoolSize]The server will start on port 9090 by default (or the port specified in application.properties).
Option 1: Using batch script (Windows)
start-client.batOption 2: Using Maven
mvn -pl client compile javafx:runAfter running init_admin.sql, you can login with:
- Admin: username and password as configured in the SQL script
- Demo Users: Use
create_demo_users.sqlto create test accounts
Regular Users can:
- Search and browse books
- Borrow and return books
- View borrowing history
- Receive AI-powered book recommendations
- Chat with other users
- View personal fines
Administrators can:
- Manage books (add, update, delete, import from CSV)
- View all borrowing records
- Manage users (freeze/unfreeze accounts)
- Configure fine rate tiers
- View system statistics
- Send reminders to users
- Manage all user fines
library-system/
├── client/ # JavaFX client application
│ ├── src/main/java/ # Client source code
│ └── src/main/resources/ # UI resources (CSS, images)
├── server/ # Socket server application
│ ├── src/main/java/ # Server source code
│ └── src/main/resources/ # Configuration files
├── common/ # Shared code between client and server
│ └── src/main/java/ # Common protocols and utilities
├── database/ # SQL scripts
│ ├── schema.sql # Main database schema
│ ├── init_admin.sql # Admin user initialization
│ └── *.sql # Additional migration scripts
└── pom.xml # Maven parent POM
- Client-Server Architecture: Socket-based communication using TCP
- Protocol: Custom JSON-based protocol for request/response
- Database: PostgreSQL with connection pooling (HikariCP)
- UI Framework: JavaFX 17
- Build Tool: Maven 3.x
-
Backend:
- Java 17
- PostgreSQL 12+
- HikariCP (Connection Pooling)
- Jackson (JSON Processing)
- SLF4J + Logback (Logging)
-
Frontend:
- JavaFX 17
- CSS for styling
-
AI/ML Features:
- Vector embeddings for book recommendations
- Graph-based recommendation algorithms
- pgvector extension support (optional)
-
Protocol Layer (
common/protocol/):OpCode: Operation codes for all system operationsRequest/Response: JSON-based communication protocolErrorCode: Standardized error handling
-
Server Services (
server/service/):UserService: User authentication and managementBookService: Book CRUD operationsBorrowService: Borrowing and returning logicAIRecommendService: AI-powered recommendationsChatService: Real-time messagingFineService: Fine calculation and management
-
Data Access Layer (
server/dao/):- DAO pattern for database operations
- Connection pooling with HikariCP
- Prepared statements for SQL injection prevention
-
Client Views (
client/view/):LoginView: User authenticationUserHomeView: Regular user dashboardAdminHomeView: Administrator dashboardChatView: Messaging interfaceReaderDashboardView: Reading recommendations
- users: User accounts with roles (USER/ADMIN) and status (ACTIVE/FROZEN)
- books: Book information with inventory tracking
- borrow_records: Borrowing history and status
- messages: User-to-user chat messages
- book_embeddings: Vector embeddings for AI recommendations (optional)
- fine_rate_config: Configurable fine rate tiers
- Password hashing (stored as hash, never plain text)
- SQL injection prevention (PreparedStatement)
- User role-based access control
- Account freeze/unfreeze functionality
- Database connection pooling (HikariCP)
- Indexed database queries
- Thread pool for concurrent client connections
- Efficient JSON serialization (Jackson)
# Clean and compile all modules
mvn clean compile
# Package as JAR files
mvn clean package
# Run tests
mvn testmvn test- Follow Java naming conventions
- Use meaningful variable and method names
- Add JavaDoc comments for public APIs
- Maintain consistent indentation (4 spaces)
- Check if port 9090 is already in use:
netstat -ano | findstr :9090-
Verify database connection settings in
application.properties -
Ensure PostgreSQL is running and database exists
- Verify server is running and listening on the correct port
- Check firewall settings
- Verify server address in client code (default: localhost:9090)
- Verify PostgreSQL is running
- Check database credentials in
application.properties - Ensure database
library_dbexists - Verify user has proper permissions
The project uses UTF-8 encoding. If you encounter encoding problems:
- Ensure your terminal supports UTF-8
- Check file encoding settings in your IDE
- Windows batch scripts use
chcp 65001to set UTF-8
This project is for educational purposes.
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For questions or issues, please open an issue on GitHub.