This project is a Rails API application for managing library resources.
- Ruby: 3.3.0 (Managed via rbenv/rvm/asdf)
- SQLite3: For development/test databases
- Bundler: To manage gems
# Clone the repository
git clone <repository_url>
cd library_bla
# Install dependencies
bundle install
# Setup database
rails db:create db:migrate db:seedrails serverThe API will be available at http://localhost:3000.
bundle exec rspec
bundle exec rubocopngrok is pre-configured. Just run:
ngrok http 3000- Controllers: Thin layer, HTTP translation only. Delegate to
RequestEntryPointservices. - Services: Business logic in
app/interactors/request_entry_point/<domain>/<action>.rb. - Base Classes:
BaseService(single action),BasePipeline(organizers). - Authentication: Stateless JWT via
devise-jwt. Tokens expire in 30 minutes. - Authorization: Role-based access control via
Pundit. - Serialization:
Blueprinter. All responses:{ data: ..., errors: [] }.
app/
├── blueprints/ # Serializers (BookBlueprint, BorrowingBlueprint, etc.)
├── controllers/ # Thin controllers
├── interactors/ # BaseService, BasePipeline, RequestEntryPoint/*
├── models/errors/ # Domain-specific errors
└── policies/ # Pundit policies
- Create service in
app/interactors/request_entry_point/<domain>/<action>.rb - Inherit from
BaseService - Implement
def callmethod - Call from controller:
RequestEntryPoint::<Domain>::<Action>.call(...)
📄 API_SPEC.md - Complete API documentation with:
- All endpoints with curl examples
- Request/Response formats
- Error handling
- Quick start script
- Permissions matrix
Interactive API documentation available at:
http://localhost:3000/api-docs
| Method | Path | Description | Role |
|---|---|---|---|
| POST | /api/v1/auth/login |
Login | Public |
| DELETE | /api/v1/auth/logout |
Logout | Any |
| GET | /api/v1/dashboard |
Role-specific dashboard | Any |
| GET | /api/v1/books |
List/Search books | Any |
| GET | /api/v1/books/:id |
Show book | Any |
| POST | /api/v1/books |
Create book | Librarian |
| PATCH | /api/v1/books/:id |
Update book | Librarian |
| DELETE | /api/v1/books/:id |
Delete book | Librarian |
| GET | /api/v1/borrowings |
List borrowings | Any (scoped) |
| GET | /api/v1/borrowings/:id |
Show borrowing | Any (scoped) |
| POST | /api/v1/borrowings |
Borrow a book | Member |
| POST | /api/v1/borrowings/:id/return |
Return book | Librarian |
Errors use custom classes under app/models/errors/ and are rescued centrally in ErrorHandling concern.
| Role | Password | |
|---|---|---|
| Librarian | librarian@example.com | password |
| Member | member@example.com | password |
:librarian- Creates a librarian user:returned- Creates a returned borrowing:due_today- Creates a borrowing due today:overdue- Creates an overdue borrowing (acceptsdays_overduetransient)