Skip to content

BaoHo205/Smart-Library-Platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

286 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Smart Library Platform

Version License Node TypeScript

A full-stack library management system for physical and digital libraries. Supports book search, borrowing, returning, reviews, staff administration, and analytics using MySQL and MongoDB.


๐Ÿš€ Tech Stack

  • Frontend: Next.js, React, TypeScript, Tailwind CSS
  • Backend: Express.js, Node.js, TypeScript
  • Databases: MySQL (relational), MongoDB (NoSQL)
  • Dev Tools: Docker, npm, ESLint, Prettier, Flyway

๐Ÿ“ Project Structure

Smart-Library-Platform/
โ”œโ”€โ”€ frontend/                   # Next.js frontend application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ app/               # Next.js app router
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx       # Home page
โ”‚   โ”‚   โ”œโ”€โ”€ components/        # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/             # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ services/          # API service layer
โ”‚   โ”‚   โ”œโ”€โ”€ store/             # State management
โ”‚   โ”‚   โ””โ”€โ”€ types/             # TypeScript type definitions
โ”‚   โ”œโ”€โ”€ public/                # Static assets
โ”‚   โ”œโ”€โ”€ package.json           # Frontend dependencies
โ”‚   โ”œโ”€โ”€ next.config.js         # Next.js configuration
โ”‚   โ””โ”€โ”€ tailwind.config.js     # Tailwind CSS configuration
โ”œโ”€โ”€ backend/                    # Express.js backend application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts           # Main application entry point
โ”‚   โ”‚   โ”œโ”€โ”€ controllers/       # Request handlers
โ”‚   โ”‚   โ”œโ”€โ”€ models/            # Database models
โ”‚   โ”‚   โ”œโ”€โ”€ routes/            # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/        # Custom middleware
โ”‚   โ”‚   โ”œโ”€โ”€ services/          # Business logic
โ”‚   โ”‚   โ””โ”€โ”€ database/          # Database connections
โ”‚   โ”œโ”€โ”€ compose.yaml           # Docker Compose for MySQL & Flyway
โ”‚   โ”œโ”€โ”€ flyway/                # Database migration files
โ”‚   โ”‚   โ”œโ”€โ”€ flyway.toml        # Flyway configuration
โ”‚   โ”‚   โ””โ”€โ”€ migrations/        # SQL migration scripts
โ”‚   โ”œโ”€โ”€ package.json           # Backend dependencies
โ”‚   โ”œโ”€โ”€ tsconfig.json          # TypeScript configuration
โ”‚   โ””โ”€โ”€ .env                   # Environment variables
โ”œโ”€โ”€ docs/                       # Documentation
โ”œโ”€โ”€ .env.sample                 # Environment configuration sample
โ”œโ”€โ”€ .gitignore                 # Git ignore rules
โ”œโ”€โ”€ README.md                  # Project documentation
---

## ๐Ÿ“‹ Prerequisites

- **Node.js** (v18+)
- **npm** (v9+)
- **Git** (v2+)
- **Docker** & **Docker Compose**
- **MongoDB** (local or Atlas)

---

## ๐Ÿš€ Installation

### 1. Clone the Repository

```bash
git clone https://github.com/BaoHo205/Smart-Library-Platform.git
cd Smart-Library-Platform

2. Start Docker Services (Database)

First, start the Docker services for the databases:

# Navigate to backend directory
cd backend

# Start Docker services (MySQL with Flyway migrations)
docker-compose up -d

# Verify containers are running
docker-compose ps

This will start:

  • MySQL Server on port 6446 (mapped from container port 3306)
  • Flyway Migration Service to set up the database schema automatically

3. Install Dependencies

# Install backend dependencies (if not already in backend directory)
cd backend
npm install

# Install frontend dependencies
cd ../frontend
npm install

4. Environment Configuration

Copy the sample environment file and configure your settings:

# Copy environment sample (backend)
cd backend
cp .env.sample .env

# Edit with your actual values
nano .env  # or use your preferred editor

Configure both database connections in your backend/.env file:

# Backend Configuration
PORT=5000
NODE_ENV=development
APP_NAME="Smart Library Platform Backend"
APP_VERSION=1.0.0

# MongoDB Configuration (with Connection Pool)
MONGODB_URI=mongodb+srv://username:[email protected]/?retryWrites=true&w=majority&appName=Cluster0
# Or local: mongodb://localhost:27017/library-platform

# MySQL Configuration (Dockerized Database)
MYSQL_HOST=localhost
MYSQL_PORT=6446
MYSQL_USER=root
MYSQL_PASSWORD=ftech2005
MYSQL_DATABASE=library_platform

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-min-32-characters-long
JWT_EXPIRE=7d
JWT_COOKIE_EXPIRE=7

# CORS Configuration
CORS_ORIGIN=http://localhost:3000,http://localhost:3001
CORS_CREDENTIALS=true

5. Database Setup

MongoDB Setup

# For development, you can use MongoDB Atlas (recommended)
# Update MONGODB_URI in your .env file with your Atlas connection string

# Or start MongoDB locally (if using local installation)
mongod

MySQL Setup (Dockerized)

The MySQL database is already running in Docker from step 2. The Docker setup includes:

  • MySQL Server: Running on port 6446
  • Database: library_platform (auto-created)
  • User: root with password ftech2005
  • Flyway Migrations: Automatically applied on startup

To verify the database is working:

# Connect to the dockerized MySQL database
mysql -h localhost -P 6446 -u root -pftech2005 library_platform

# Or check tables
mysql -h localhost -P 6446 -u root -pftech2005 -e "SHOW TABLES;" library_platform

๐ŸŽฎ Usage

Development Mode

Step 1: Ensure Docker services are running

cd backend
docker-compose ps  # Check if containers are running
# If not running: docker-compose up -d

Step 2: Start the backend server

# Terminal 1: Backend (make sure you're in backend directory)
cd backend
npm run dev

Step 3: Start the frontend

# Terminal 2: Frontend (in a new terminal)
cd frontend
npm run dev

Access the Application

Expected Output

When starting the backend, you should see:

๐Ÿš€ Starting Smart Library Platform Backend...
โœ… Connected to MongoDB successfully!
โœ… Connected to MySQL successfully!
๐Ÿ“‹ App: Smart Library Platform Backend
๐ŸŽ‰ Server running at http://localhost:5000

๐Ÿ”‘ Default Accounts

  • Staff:
    Username: staff
    Password: 123456

  • User:
    Username: user
    Password: 123456


Docker Management

Useful Docker commands:

# Check container status
docker-compose ps

# View container logs
docker-compose logs db
docker-compose logs flyway

# Stop all services
docker-compose down

# Restart services
docker-compose restart

# Stop and remove containers with volumes (โš ๏ธ This will delete data)
docker-compose down -v

Scripts Available

Backend:

npm run dev          # Start development server with nodemon
npm run build        # Build TypeScript to JavaScript
npm start            # Start production server
npm run lint         # Run ESLint
npm run lint:fix     # Fix ESLint issues

Frontend:

npm run dev          # Start development server (port 3000)
npm run build        # Build for production
npm start            # Start production server
npm run lint         # Run Next.js linting
npm run lint:fix     # Fix linting issues

Code Style

This project uses ESLint and Prettier for code formatting:

# Backend linting
cd backend
npm run lint
npm run lint:fix

# Frontend linting
cd frontend
npm run lint
npm run lint:fix

Git Workflow

  1. Create feature branch: git checkout -b feature/your-feature-name
  2. Make changes and commit: git commit -m "feat: add new feature"
  3. Push branch: git push origin feature/your-feature-name
  4. Create Pull Request

Commit Convention

Follow Conventional Commits:

  • feat: New features
  • fix: Bug fixes
  • docs: Documentation changes
  • style: Code style changes
  • refactor: Code refactoring
  • test: Test additions or modifications
  • chore: Maintenance tasks

๐Ÿงช Testing

# Run backend tests
cd backend
npm test

# Run frontend tests
cd frontend
npm test

# Run tests with coverage
npm run test:coverage

# Test database connections
curl http://localhost:5000/

๐Ÿš€ Deployment

Production Build

# Build backend
cd backend
npm run build

# Build frontend
cd frontend
npm run build

๐Ÿ“ Quick Start

  1. docker-compose up -d (in backend) โ€“ Start databases
  2. npm install (in backend & frontend) โ€“ Install dependencies
  3. cp .env.sample .env (in backend) โ€“ Configure environment
  4. Open two terminals:
    • Terminal 1: cd backend && npm run dev
    • Terminal 2: cd frontend && npm run dev
  5. Visit http://localhost:3000 for the app

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

๐Ÿ“„ License

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

๐Ÿ†˜ Support

Getting Help

Project Video Demo

https://jackydo2005.github.io/video_player_test/

Project Status

This project is actively maintained. For feature requests and bug reports, please use the GitHub Issues page.


Made with โค๏ธ by FTECH

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages