Skip to content

Kitty-Hivens/Pharmacy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

183 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ Haru Pharmacy Management System

Spring Boot Angular Java TypeScript Docker CI/CD Live License

Enterprise-Grade Point of Sale & Inventory Management System
A production-ready fullstack application demonstrating modern software architecture, clean code practices, and advanced Spring Boot 4 / Angular 21 features.

πŸ”— Live Demo: https://pharmacy.hivens.dev


🎯 Project Highlights

Created by a Backend Developer who decided to master the full stack β€” this project showcases end-to-end ownership from database design to pixel-perfect UI.

Why This Project Stands Out

✨ Bleeding-Edge Stack β€” Built with Spring Boot 4.0.1 and Angular 21.2.5 (latest stable releases as of Q1 2026)
πŸ—οΈ Production Architecture β€” Contract-First API design, CQRS patterns, optimistic locking, RBAC security
πŸ§ͺ Test Coverage β€” Comprehensive JUnit tests with Mockito for business-critical logic
πŸ“¦ Docker Ready β€” Full containerization with multi-stage builds and health checks
πŸš€ CI/CD Pipeline β€” Automated deployment to VPS via GitHub Actions on every push
🌍 i18n Support β€” Bilingual interface (English/Russian) with dynamic language switching
🎨 Professional UI β€” Built with PrimeNG, responsive design, and modern UX patterns


πŸ“Έ Screenshots

Dashboard POS Terminal
Dashboard POS
Inventory Management Sales History
Medicines Sales

πŸš€ Key Features

πŸ›’ Point of Sale (POS) Terminal

  • Real-time stock validation β€” Server-side checks prevent overselling
  • Customer discount management β€” Automatic price calculations
  • Receipt generation β€” Print-ready transaction summaries
  • Cart persistence β€” LocalStorage backup for session recovery

πŸ“¦ Inventory Management

  • FEFO Algorithm (First Expired, First Out) β€” Smart batch rotation for pharmaceutical compliance
  • Batch tracking β€” Full traceability with expiration date monitoring
  • Low-stock alerts β€” Proactive notifications for reordering
  • Supplier integration β€” Manage supply chain relationships

πŸ“Š Business Intelligence

  • Sales analytics β€” Revenue tracking with growth metrics
  • Customer insights β€” Registration trends and loyalty tracking
  • Inventory health β€” Stock status visualization
  • Historical reporting β€” Paginated sales history with date filtering

πŸ” Security & Access Control

  • JWT Authentication β€” Stateless token-based security
  • Role-Based Access Control β€” Admin vs Pharmacist permissions
  • Password encryption β€” BCrypt hashing with Spring Security
  • CORS configuration β€” Secure cross-origin request handling

🎨 Modern Frontend

  • Zoneless Angular 21 β€” Signals-based reactivity for optimal performance
  • PrimeNG UI Framework β€” Enterprise-grade components
  • Auto-generated API Client β€” TypeScript SDK from OpenAPI spec
  • Responsive Design β€” Mobile-first approach with PrimeFlex

πŸ› οΈ Technology Stack

Backend (Spring Boot 4 + Java 21)

βœ“ Spring Boot 4.0.1         β†’ Virtual Threads, Structured Logging
βœ“ Java 21 (LTS)             β†’ Records, Pattern Matching, Sequenced Collections
βœ“ Spring Data JPA           β†’ Database abstraction with Hibernate
βœ“ Spring Security 7         β†’ JWT + RBAC implementation
βœ“ Flyway 10+                β†’ Versioned database migrations
βœ“ MapStruct 1.5.5           β†’ Compile-time DTO mapping
βœ“ SpringDoc OpenAPI 2.7     β†’ API documentation generation
βœ“ MariaDB 10.11             β†’ Relational database with advanced features
βœ“ JUnit 5 + Mockito         β†’ Comprehensive unit testing

Frontend (Angular 21 + TypeScript 5)

βœ“ Angular 21.2.5            β†’ Zoneless change detection, Signals API
βœ“ PrimeNG 21.1.3            β†’ UI component library
βœ“ RxJS 7.8                  β†’ Reactive programming
βœ“ OpenAPI Generator         β†’ Auto-generated TypeScript client
βœ“ ngx-translate             β†’ Internationalization (i18n)
βœ“ TypeScript 5.9            β†’ Type safety with strict mode

DevOps & Tools

βœ“ Docker Compose            β†’ Multi-container orchestration
βœ“ GitHub Actions            β†’ CI/CD β€” auto deploy on push to main
βœ“ Nginx + Let's Encrypt     β†’ Reverse proxy with HTTPS
βœ“ Gradle 8.14               β†’ Build automation
βœ“ npm 11.7.0                β†’ Frontend package management
βœ“ Git                       β†’ Version control with conventional commits

πŸ›οΈ Architecture Decisions

1️⃣ Contract-First Development (OpenAPI)

Instead of manually syncing frontend/backend types, the API specification is the single source of truth.

Benefits:

  • Zero type mismatches at runtime
  • Breaking changes caught at compile time
  • Auto-generated, always up-to-date client SDK

Implementation:

# Backend exposes /v3/api-docs
# Frontend generates client:
npm run generate-api

2️⃣ FEFO Inventory Algorithm

Pharmaceutical compliance requires selling items closest to expiration first.

Query Strategy:

SELECT * FROM inventory
WHERE medicine_id = :id
  AND stock_quantity > 0
  AND expiration_date >= CURRENT_DATE
ORDER BY expiration_date ASC

Atomic Transaction:

@Transactional
public void createSale(SaleCreateDto dto, String username) {
    // 1. Fetch valid batches (FEFO)
    List<Inventory> batches = inventoryRepo.findValidBatchesForSale(medicineId, LocalDate.now());
    
    // 2. Validate total stock
    int totalStock = batches.stream().mapToInt(Inventory::getStockQuantity).sum();
    if (totalStock < requestedQty) throw new InsufficientStockException();
    
    // 3. Deduct from batches (oldest first)
    for (Inventory batch : batches) {
        // Optimistic locking (@Version) prevents race conditions
    }
}

3️⃣ Optimistic Locking for Concurrency

High-traffic POS scenarios require safe concurrent stock updates.

Implementation:

@Entity
public class Inventory {
    @Version
    private Long version; // Hibernate automatic versioning
}

Behavior: If two cashiers sell the same item simultaneously, the second transaction will fail with OptimisticLockingFailureException, triggering a retry.

4️⃣ DTO Projection Queries

Avoid N+1 queries by fetching aggregated data in a single SQL query.

Before (N+1 Problem):

// 1 query for medicines + N queries for stock
for (Medicine m : medicines) {
    int stock = inventoryRepo.sumByMedicine(m.getId());
}

After (Single Query):

@Query("""
    SELECT new MedicineResponseDto(
        m.id, m.name, m.price, 
        COALESCE(SUM(i.stockQuantity), 0L)
    )
    FROM Medicine m
    LEFT JOIN Inventory i ON i.medicine.id = m.id
    GROUP BY m.id
""")
List<MedicineResponseDto> findAllSummarized();

5️⃣ Flyway Database Versioning

All schema changes are tracked in migration files.

Example:

backend/src/main/resources/db/migration/
β”œβ”€β”€ V1__init_schema.sql       β†’ Initial tables
β”œβ”€β”€ V2__add_version_column.sql β†’ Add optimistic locking
└── V3__create_indexes.sql     β†’ Performance optimization

Result: Identical database structure across Dev/Test/Prod environments.


πŸ“¦ Getting Started

Prerequisites

Java 21 JDK       β†’ https://adoptium.net/
Node.js 22+       β†’ https://nodejs.org/
Docker & Compose  β†’ https://www.docker.com/

πŸš€ Quick Start (Docker)

# Clone repository
git clone https://github.com/Kitty-Hivens/Pharmacy.git
cd Pharmacy

# Start all services (DB + Backend + Frontend)
docker-compose up -d

# Access application
🌐 Frontend β†’ http://localhost
πŸ“š API Docs β†’ http://localhost:8080/swagger-ui.html
πŸ—„οΈ Database β†’ localhost:3307 (root/root)

πŸ”‘ Default Credentials

Username: admin
Password: Set via ADMIN_INITIAL_PASSWORD environment variable

πŸ’» Local Development

# Terminal 1: Database
docker-compose up -d db

# Terminal 2: Backend
cd backend
./gradlew bootRun

# Terminal 3: Frontend
cd frontend
npm install
ng serve

# Docker: http://localhost
# Local dev: http://localhost:4200

πŸ”„ Regenerate API Client

After modifying backend DTOs/Controllers:

cd frontend
npm run generate-api

πŸ“‚ Project Structure

pharmacy-management/
β”œβ”€β”€ backend/                    # Spring Boot 4 Application
β”‚   β”œβ”€β”€ src/main/java/
β”‚   β”‚   └── haru/pharmacy/
β”‚   β”‚       β”œβ”€β”€ config/         # Security, OpenAPI, CORS
β”‚   β”‚       β”œβ”€β”€ controller/     # REST endpoints
β”‚   β”‚       β”œβ”€β”€ dto/            # Request/Response objects
β”‚   β”‚       β”œβ”€β”€ exception/      # Custom exceptions
β”‚   β”‚       β”œβ”€β”€ mapper/         # MapStruct interfaces
β”‚   β”‚       β”œβ”€β”€ model/          # JPA entities
β”‚   β”‚       β”œβ”€β”€ repository/     # Spring Data repositories
β”‚   β”‚       └── service/        # Business logic
β”‚   β”œβ”€β”€ src/main/resources/
β”‚   β”‚   β”œβ”€β”€ db/migration/       # Flyway SQL scripts
β”‚   β”‚   β”œβ”€β”€ messages.properties # i18n (EN)
β”‚   β”‚   └── messages_ru.properties # i18n (RU)
β”‚   └── src/test/java/          # JUnit + Mockito tests
β”‚
β”œβ”€β”€ frontend/                   # Angular 21 Application
β”‚   β”œβ”€β”€ src/app/
β”‚   β”‚   β”œβ”€β”€ api/                # Auto-generated OpenAPI client
β”‚   β”‚   β”œβ”€β”€ core/               # Guards, Interceptors
β”‚   β”‚   β”œβ”€β”€ layout/             # Main layout component
β”‚   β”‚   └── pages/              # Feature modules
β”‚   β”‚       β”œβ”€β”€ dashboard/
β”‚   β”‚       β”œβ”€β”€ pos/            # Point of Sale
β”‚   β”‚       β”œβ”€β”€ medicines/
β”‚   β”‚       β”œβ”€β”€ inventory/
β”‚   β”‚       β”œβ”€β”€ sales-history/
β”‚   β”‚       β”œβ”€β”€ customers/
β”‚   β”‚       β”œβ”€β”€ suppliers/
β”‚   β”‚       └── users/
β”‚   └── public/i18n/            # Translation files
β”‚
β”œβ”€β”€ .github/workflows/
β”‚   └── deploy.yml              # GitHub Actions CI/CD
└── docker-compose.yml          # Multi-container setup

πŸ“š API Documentation

Live Interactive Docs

πŸ”— Swagger UI: https://pharmacy.hivens.dev/swagger-ui.html

Sample Endpoints

POST /auth/login                β†’ Authenticate user
GET  /api/medicines             β†’ List all medicines
POST /api/inventory/restock     β†’ Add stock (ADMIN only)
POST /api/sales                 β†’ Process sale transaction
GET  /api/sales?from=&to=       β†’ Sales history with filters
POST /api/customers             β†’ Register customer
GET  /api/users                 β†’ List employees (ADMIN only)

Authentication Flow

// 1. Login
POST /auth/login
{
  "username": "admin",
  "password": "your_password"
}
// Response: { "token": "eyJhbGc...", "role": "ADMIN" }

// 2. Use token in subsequent requests
GET /api/medicines
Headers: { Authorization: "Bearer eyJhbGc..." }

πŸ§ͺ Testing

Backend Unit Tests

cd backend
./gradlew test

# Coverage Report
./gradlew test jacocoTestReport
open build/reports/jacoco/test/html/index.html

Test Examples:

  • βœ… Medicine CRUD operations
  • βœ… FEFO algorithm correctness
  • βœ… Stock validation (insufficient stock scenarios)
  • βœ… Optimistic locking conflict handling
  • βœ… User authentication & authorization

Frontend E2E Tests (Playwright)

cd frontend
npm run test:e2e

🚒 Deployment

Production Build

# Backend JAR
cd backend
./gradlew bootJar
# Output: build/libs/Pharmacy-0.0.2-SNAPSHOT.jar

# Frontend (Static Assets)
cd frontend
npm run build
# Output: dist/frontend/browser/

Environment Variables

# Backend (.env or docker-compose)
DB_URL=jdbc:mariadb://db:3306/pharmacy_db
DB_USERNAME=root
DB_PASSWORD=secure_password
JWT_SECRET=YourVeryLongSecretKey...
APP_CORS_ALLOWED_ORIGINS=https://yourdomain.com
ADMIN_INITIAL_PASSWORD=ChangeMe123!

# Frontend (environment.prod.ts)
apiUrl=https://api.yourdomain.com

CI/CD Pipeline

Every push to the Central-Workflow branch triggers automatic deployment:

# .github/workflows/deploy.yml
on:
  push:
    branches: [Central-Workflow]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: appleboy/ssh-action@v1
        with:
          script: |
            cd /root/Pharmacy
            git pull
            docker compose up --build -d

Docker Production

# docker-compose.yml
services:
  backend:
    image: pharmacy-backend:latest
    environment:
      - SPRING_PROFILES_ACTIVE=prod
  
  frontend:
    image: pharmacy-frontend:latest
    
  nginx:
    image: nginx:alpine
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“§ Contact

Vitalii (Haru)
πŸ”— GitHub: @Kitty-Hivens
πŸ“§ Email: vitalii.vakar@proton.me
πŸ’Ό LinkedIn: Vitalii Vakar


πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

  • Spring Team β€” For the incredible framework and documentation
  • Angular Team β€” For pushing the boundaries of frontend development
  • PrimeNG β€” For the professional UI component library
  • OpenAPI Initiative β€” For standardizing API specifications

⭐ If this project helped you, please consider giving it a star!

About

Enterprise-grade Pharmacy Management System & POS built with Spring Boot 4 and Angular 21. Features FEFO inventory logic, optimistic locking, and contract-first OpenAPI architecture.

Topics

Resources

License

Stars

Watchers

Forks

Contributors