Skip to content

About

MicroBooks v2.0 is a production-grade, event-driven microservices system built with FastAPI, Next.js, and Apache Kafka. It features an automated CI/CD pipeline via GitHub Actions and a comprehensive observability stack. Containerized with Docker and Kubernetes-ready, it provides a robust, scalable environment for modern software development.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

97 Commits

Folders and files

Repository files navigation

πŸ“š MicroBooks β€” Bookstore Management System (v2.0)

MicroBooks v2.0 is a production-grade, event-driven microservices system built with FastAPI, Next.js, and Apache Kafka. It features an automated CI/CD pipeline via GitHub Actions and a comprehensive observability stack. Containerized with Docker and Kubernetes-ready, it provides a robust, scalable environment for modern software development.


Modern Microservices-based bookstore management system using Apache Kafka for asynchronous communication, MongoDB Atlas for cloud storage, and integrated automated CI/CD pipelines for local deployment.

CI/CD Pipeline Architecture

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     REST API     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend  │◄────────────────►│  order_service  β”‚
β”‚  (Next.js)  β”‚                  β”‚  (FastAPI:3001) β”‚
β”‚   :3000     β”‚     REST API     β”‚                 β”‚
β”‚             │◄──────┐         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚                  β”‚ Publish
                      β”‚                  β–Ό
               β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚ inventory_    │◄── Apache Kafka β”‚
               β”‚ service       β”‚  β”‚   :9092      β”‚
               β”‚ (FastAPI:3002)β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
               β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚ Monitor
                       β”‚          β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                       β”‚          β”‚   Kafka UI   β”‚
                       β”‚          β”‚    :8080     β”‚
                       β–Ό          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
               β”‚ MongoDB Atlasβ”‚
               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Full System Workflow

Below is a detailed diagram of the operational flow, from code push to user interaction and automated monitoring:

graph TD
    subgraph "1. Development & CI/CD (Automation)"
        Dev[Developer] -- "Push Code" --> GH[GitHub Repository]
        GH -- "Trigger" --> GHA[GitHub Actions]
        GHA -- "Deploy" --> SHR[Self-hosted Runner]
        SHR -- "docker-compose up" --> Docker[Docker Engine]
    end

    subgraph "2. Business Logic (Application Logic)"
        User[User] -- "Place Order" --> Frontend[Next.js Frontend]
        Frontend -- "POST /api/orders" --> OS[Order Service]
        OS -- "Save Order" --> DB[(MongoDB Atlas)]
        OS -- "Publish 'order_created'" --> Kafka{Apache Kafka}
        Kafka -- "Receive Event" --> IS[Inventory Service]
        IS -- "Update Stock" --> DB
    end

    subgraph "3. Monitoring & Observability"
        OS & IS & Frontend -- "Metrics/Traces" --> OTel[OpenTelemetry Collector]
        OTel -- "Metrics" --> Prom[Prometheus]
        OTel -- "Traces" --> Tempo[Tempo]
        Docker -- "Logs" --> Promtail[Promtail]
        Promtail -- "Logs" --> Loki[Loki]
        Prom & Loki & Tempo -- "Dashboard" --> Grafana[Grafana]
        Kafka -- "Monitor" --> KUI[Kafka UI]
    end

    %% Styling
    style GH fill:#24292e,color:#fff
    style Docker fill:#2496ed,color:#fff
    style Kafka fill:#000,color:#fff
    style DB fill:#47a248,color:#fff
    style Grafana fill:#f46800,color:#fff
    style GHA fill:#2088ff,color:#fff
Loading

πŸ› οΈ Tech Stack & DevOps

Component Technology
Frontend Next.js 15 (App Router), Tailwind CSS
Backend Python 3.10+, FastAPI
Database MongoDB Atlas (Cloud)
Message Broker Apache Kafka & Zookeeper
Monitoring Kafka UI (provectuslabs)
Infrastructure Docker & Docker Compose
CI/CD GitHub Actions (Self-hosted Runner)
Observability OpenTelemetry + Prometheus + Grafana + Loki + Tempo

πŸ“– Project Resources (Documentation & Slides)

For a comprehensive overview, detailed project reports, and presentation slides, please access our dedicated resources folder:

View Documentation

This folder contains:

  • πŸ“„ Detailed Project Report (Architecture, Design Decisions, Implementation).
  • πŸ“Š Presentation Slides for project demonstrations.
  • πŸ“ High-Resolution Diagrams of the system workflow and database schema.
  • πŸ“ Supplementary Technical Documentation.

πŸ“ Project Directory Structure

MicroBooks/
β”œβ”€β”€ .github/workflows/          # CI/CD Workflows (Local Deployment)
β”œβ”€β”€ frontend/                   # Next.js Frontend Application
β”œβ”€β”€ order_service/              # Order Management Service (Python)
β”œβ”€β”€ inventory_service/          # Inventory Management Service (Python)
β”œβ”€β”€ tests/                      # Integration Tests
β”œβ”€β”€ docs/                       # Design Documentation (PRD, Design)
β”œβ”€β”€ docs_self_host_runner/      # CI/CD Runner Configuration Docs
β”œβ”€β”€ k8s/                        # Kubernetes Manifests (Kustomize)
β”‚   └── base/                   # Base configuration
β”œβ”€β”€ .env                        # Environment Variables
└── README.md

πŸš€ CI/CD Workflow (Self-hosted Runner)

The system is integrated with a complete Automation workflow:

  1. Continuous Integration (CI): Automatically validates code and runs unit tests upon Pull Request or push to the main branch.
  2. Continuous Deployment (CD): Uses a GitHub Actions Self-hosted Runner installed directly on the local server.
    • Upon successful CI, the Runner automatically executes docker-compose pull and docker-compose up -d.
    • Ensures the local environment is always synchronized with the latest code on GitHub without manual intervention.

View details at: local-deploy.yml

CI/CD Status GitHub Issues Management

Self-hosted Runner Configuration Docker Hub Registry

πŸ› οΈ Installation Guide

Run with Docker Compose (Recommended)

# 1. Clone repo
git clone https://github.com/phatle224/micro_books.git
cd micro_books

# 2. Environment Configuration
cp .env.example .env
# Update MONGO_URI and DOCKER_HUB_USERNAME in .env

# 3. Launch
docker-compose up --build -d

Docker Containers Running

Run with Kubernetes (K8s)

Ensure Kubernetes is enabled in Docker Desktop or Minikube.

# 1. Deploy the entire system
kubectl apply -k k8s/base

# 2. Wait until all Pods are in Running state
kubectl get pods -n microbooks -w

<p align="center">
  <img src="image/readme/demo_k8s.png" width="49%" alt="Kubernetes Deployment Demo"/>
  <img src="image/readme/k8s_pods.png" width="49%" alt="Kubernetes Pods Status"/>
</p>


# 3. Port-forward to access the Frontend (run in a separate terminal)
kubectl port-forward svc/frontend 3000:3000 -n microbooks

# 4. Stop and remove all resources
kubectl delete -k k8s/base

Service Access

Service URL Description
Storefront http://localhost:3000 Shopping Interface
Admin Portal http://localhost:3000/admin System Administration
Kafka UI http://localhost:8080 Message Queue Monitoring
Order API Docs http://localhost:3001/docs Swagger UI (Order Service)
Inventory API Docs http://localhost:3002/docs Swagger UI (Inventory Service)

Client Interface Book Catalog View

Client Dashboard Preview

πŸ“Š Kafka Monitoring (User Access)

# Terminal 1: Order Service
cd order-service
pip install -r requirements.txt
uvicorn app.main:app --port 3001 --reload

# Terminal 2: Inventory Service
cd inventory-service
pip install -r requirements.txt
uvicorn app.main:app --port 3002 --reload

# Terminal 3: Frontend
cd frontend
npm install
npm run dev

Access URLs

Service URL
Frontend http://localhost:3000
Order Service API http://localhost:3001/api/orders (Docs: /docs)
Inventory Service API http://localhost:3002/api/books (Docs: /docs)
Kafka UI http://localhost:8080

πŸ“ˆ Monitoring & Observability

The observability stack is pre-configured using OpenTelemetry + Prometheus + Grafana + Loki + Tempo.

Access URLs

Service URL
Grafana http://localhost:3005 (admin / admin)
Prometheus http://localhost:9090
Loki http://localhost:3100
Tempo http://localhost:3200

Quick Notes

  • Order/Inventory services have OpenTelemetry enabled when running via Docker Compose.
  • Metrics are pushed through the OpenTelemetry Collector and scraped by Prometheus.
  • Logs are collected using Promtail (docker logs) and displayed via Loki.
  • Traces are stored in Tempo and can be viewed in Grafana Explore..

Grafana Monitoring Dashboard

Tempo Distributed Tracing

πŸ” Administration (Admin Portal)

You can access the admin portal to manage the bookstore, orders, and monitor Kafka:

  • URL: http://localhost:3000/admin/login
  • Username: [email protected]
  • Password: admin123
Page Description
/admin General Dashboard
/admin/books Book Inventory Management
/admin/orders Order Management
/admin/kafka Kafka Monitor (embedded Kafka UI)

Admin Dashboard Overview

Inventory Management System Order Management System

πŸ“‘ API Endpoints

Order Service (Port 3001)

Method Endpoint Description
GET /api/orders Get all orders
GET /api/orders/{id} Get order details
POST /api/orders Create new order
PATCH /api/orders/{id} Update status
GET /api/orders/stats/summary Order statistics (Admin)

Inventory Service (Port 3002)

Method Endpoint Description
GET /api/books Get all books
GET /api/books/{id} Get book details
POST /api/books Add new book
PUT /api/books/{id} Update book
DELETE /api/books/{id} Delete book
GET /api/books/categories Get book categories
GET /api/books/stats/summary Inventory statistics (Admin)

⚑ Event-Driven Workflow

  1. Client creates an order β†’ Order Service saves it to MongoDB Atlas.
  2. Order Service publishes an order_created event to the Kafka topic.
  3. Inventory Service subscribes to the topic and receives the event.
  4. Inventory Service automatically deducts stock for the corresponding book in MongoDB Atlas.
  5. All broker activity can be monitored real-time via Kafka UI at localhost:8080 or the /admin/kafka page.

πŸ“Š Kafka Monitoring

The system integrates Kafka UI for message flow observation:

  • Brokers β€” View broker status, replicas, and partitions.
  • Topics β€” Browse messages in the order_created topic.
  • Consumer Groups β€” Monitor lag for the inventory-service-group.
  • Schema Registry β€” Manage schemas (if applicable).

Kafka UI is embedded directly into the Admin page at /admin/kafka and can also be opened separately at http://localhost:8080.

We provide an intuitive interface for users and developers to track event-driven flows:

πŸ”— Authors & GitHub Profiles

header

Kiet Truong Phat Le
Fullstack Dev & DevOps Data Engineer & Backend

Typing SVG

SGU HCMC

πŸ›  Tech Stack

Tech Stack

🐳 MICROBOOKS IN DOCKER

Stars Forks Issues

Daily Quote

Thank you for stopping by! Don’t forget to give this repo a ⭐️ Star if you find it useful.

About

MicroBooks v2.0 is a production-grade, event-driven microservices system built with FastAPI, Next.js, and Apache Kafka. It features an automated CI/CD pipeline via GitHub Actions and a comprehensive observability stack. Containerized with Docker and Kubernetes-ready, it provides a robust, scalable environment for modern software development.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages