This project is a microservice-style library management API built with Flask. It is designed to manage a library system using a modular, enterprise-standard structure. The application uses SQLAlchemy for ORM, integrates with NATS JetStream for asynchronous messaging, and follows the application factory pattern for scalability and maintainability.
-
Add Book to library: POST /api/admin/books
-
Get unavailable books: GET /api/admin/books/unavailable
-
Get users in the library: GET /api/admin/users
-
Remove book from library: DELETE /api/admin/books/:id
-
Get users and the books borrowed: GET /api/admin/users_borrowed
-
Get available books users: GET /api/frontend/books
-
Borrow any available book: POST /api/frontend/books/:id/borrow
-
Enroll: POST /api/frontend/users
-
Get book by ID: GET /api/frontend/books/1
This project contains two microservices—admin-api and frontend-api—that communicate with a NATS Jetstream server. You can run the entire stack using one of two approaches:
- Kubernetes with Skaffold
- Docker Compose (easiest to run)
- Python 3.9+
- pip (Python package manager)
- Docker: Installed and running.
- Kubernetes Cluster: (For Skaffold option)
- You can use Minikube or any other Kubernetes provider.
- Skaffold: Installed. See the Skaffold installation guide for details.
- kubectl: Installed and configured to communicate with your Kubernetes cluster (if using the Skaffold option).
.
├── admin-api
│ ├── Dockerfile
│ └── ... (source code)
├── frontend-api
│ ├── Dockerfile
│ └── ... (source code)
├── infra
│ └── k8s
│ ├── admin_depl.yaml
│ ├── frontend_depl.yaml
│ ├── nats_depl.yaml
│ └── ingress-srv.yaml
├── docker-compose.yaml
└── skaffold.yaml
- Clone the repository:
git clone https://github.com/HARRIFIED/Library-microservice.gitThis method deploys the services to your Kubernetes cluster and continuously rebuilds the images when you change the source code.
In the project root, run:
skaffold dev- Watch for file changes.
- Build the Docker images defined in the skaffold.yaml.
- Deploy the Kubernetes manifests located in ./infra/k8s/*.
- The Ingress resource is configured to route requests: a. library.dev/api/admin routes to the admin-api (port 5001). b. library.dev/api/frontend routes to the frontend-api (port 5000).
- You might need to update your /etc/hosts (or local DNS) to point library.dev to your cluster’s IP (e.g., the Minikube IP).
This method builds the images locally using your Dockerfiles and runs all services on a single host.
- Build and Start the Containers In the project root, run:
docker-compose up