Book Rental System API
Book Rental System is a RESTful API that allows users to browse, borrow, and return books from a virtual library. The system tracks book inventory, user accounts, rental history, and fees.
Technology Stack
- Backend Language: Golang
- Database: PostgreSQL (running in Docker container)
- Web Framework: Gin
- Database Migration: go-migrate
- Testing: GoMock for mocking framework
- Configuration: .env file
- Build System: Makefile
Core Features
-
User Management
- User registration and authentication
- User profile management
- Role-based access control (Admin, Librarian, Member)
-
Book Catalog Management
- Add, update, and delete books
- Book categorization and metadata management
- Search and filter capabilities
- Book availability status
-
Rental Operations
- Book borrowing process
- Book return process
- Rental period extension
- Overdue book management
-
Fees and Payments
- Rental fee calculation
- Late return penalty calculation
- Payment processing
- Refund handling
-
Reporting and Analytics
- Usage statistics
- Popular book reports
- Revenue reports
- User activity reports
Installation
Requirements
- Go 1.21+
- Docker and Docker Compose
- Make
Development Environment Setup
-
Clone repository:
git clone https://github.com/yourusername/book-rental-system.git
cd book-rental-system
-
Install necessary tools:
make setup
-
Create .env file from .env.example:
cp .env.example .env
-
Start PostgreSQL using Docker:
make docker-db
-
Run database migrations:
make migrate-up
-
Run development server:
make run
Using Docker
To run the entire application in Docker:
make docker-run
API Endpoints
See the full API documentation in docs/prd.md.
Development
Project Structure
.
├── cmd/ # Application entry points
│ └── api/ # API server
├── docs/ # Documentation
├── internal/ # Internal code
│ ├── api/ # API handlers
│ ├── domain/ # Domain definitions and interfaces
│ ├── repository/ # Repository implementations
│ └── service/ # Service implementations
├── migrations/ # Database migrations
├── pkg/ # Reusable packages
│ ├── auth/ # Authentication and authorization
│ ├── config/ # Configuration
│ └── logger/ # Logging
├── .env.example # Example configuration file
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker configuration
├── go.mod # Go dependencies
├── go.sum # Go dependencies checksum
└── Makefile # Make commands
Useful Commands
make run: Run development server
make test: Run tests
make migrate-up: Run database migrations
make migrate-down: Rollback database migrations
make mock: Generate mocks for testing
make build: Build production binary
make docker-build: Build Docker image
make docker-run: Run Docker containers
make docker-stop: Stop Docker containers
make clean: Clean up
License
MIT