Skip to content

A robust RESTful API built with Go and MySQL for managing a bookstore's inventory. This project demonstrates clean architecture principles, comprehensive CRUD operations, and modern backend development practices.

License

Notifications You must be signed in to change notification settings

abhinav-phi/bookstore-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“š Bookstore Management API

A RESTful API built with Go and MySQL for managing a bookstore's inventory. This project demonstrates clean architecture, CRUD operations, and modern backend development practices.

๐Ÿš€ Features

  • Complete CRUD Operations - Create, Read, Update, Delete books
  • RESTful Architecture - Clean and intuitive API endpoints
  • MySQL Integration - Persistent data storage with GORM ORM
  • JSON API - Structured request/response handling
  • Modular Design - Well-organized package structure
  • Auto-Migration - Database schema management

OVERVIEW :

Demo Video

Watch a screen recording demonstration of the API in action:

2025-06-13.10-23-58.mp4

๐Ÿ› ๏ธ Tech Stack

  • Language: Go (Golang) 1.16
  • Database: MySQL
  • ORM: GORM
  • HTTP Router: Gorilla Mux
  • Data Format: JSON

๐Ÿ“‹ Prerequisites

Before running this project, make sure you have:

  • Go 1.16 or higher installed
  • MySQL server running
  • Git (for cloning the repository)

๐Ÿ”ง Installation & Setup

  1. Clone the repository

    git clone https://github.com/abhinav-phi/bookstore-api.git
    cd bookstore-api
  2. Install dependencies

    go mod tidy
  3. Configure MySQL Database

    • Create a MySQL database named bookstore
    • Update the database connection string in packages/config/app.go:
    d, err := gorm.Open("mysql", "username:password@tcp(127.0.0.1:3306)/bookstore?charset=utf8&parseTime=True&loc=Local")
  4. Run the application

    go run main.go

The server will start on http://localhost:9000

๐Ÿ“ก API Endpoints

Method Endpoint Description
GET /book/ Get all books
GET /book/{id} Get book by ID
POST /book/ Create a new book
PUT /book/{id} Update an existing book
DELETE /book/{id} Delete a book

๐Ÿ“ API Usage Examples

Create a Book

curl -X POST http://localhost:9000/book/ \
  -H "Content-Type: application/json" \
  -d '{
    "name": "The Go Programming Language",
    "author": "Alan Donovan",
    "publication": "Addison-Wesley"
  }'

Get All Books

curl -X GET http://localhost:9000/book/

Get Book by ID

curl -X GET http://localhost:9000/book/1

Update a Book

curl -X PUT http://localhost:9000/book/1 \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Book Title",
    "author": "Updated Author"
  }'

Delete a Book

curl -X DELETE http://localhost:9000/book/1

๐Ÿ—๏ธ Project Structure

bookstore-api/
โ”œโ”€โ”€ main.go                 # Application entry point
โ”œโ”€โ”€ go.mod                  # Go module dependencies
โ”œโ”€โ”€ go.sum                  # Dependency checksums
โ””โ”€โ”€ packages/
    โ”œโ”€โ”€ config/
    โ”‚   โ””โ”€โ”€ app.go          # Database configuration
    โ”œโ”€โ”€ controllers/
    โ”‚   โ””โ”€โ”€ book-controller.go  # HTTP handlers
    โ”œโ”€โ”€ models/
    โ”‚   โ””โ”€โ”€ book.go         # Database models
    โ”œโ”€โ”€ routes/
    โ”‚   โ””โ”€โ”€ bookstore-routes.go  # Route definitions
    โ””โ”€โ”€ utils/
        โ””โ”€โ”€ utils.go        # Utility functions

๐Ÿ“Š Database Schema

The Book model includes:

type Book struct {
    gorm.Model
    Name        string `json:"name"`
    Author      string `json:"author"`
    Publication string `json:"publication"`
}
  • ID: Auto-generated primary key
  • Name: Book title
  • Author: Book author
  • Publication: Publisher name
  • CreatedAt: Timestamp of creation
  • UpdatedAt: Timestamp of last update
  • DeletedAt: Soft delete timestamp

๐Ÿ” Key Features

Clean Architecture

  • Separation of Concerns: Each package has a specific responsibility
  • Dependency Injection: Database connection managed centrally
  • Error Handling: Proper error management throughout the application

Database Integration

  • GORM ORM: Simplified database operations
  • Auto-Migration: Automatic schema updates
  • Connection Pooling: Efficient database connections

HTTP Handling

  • Gorilla Mux: Powerful HTTP router
  • JSON Serialization: Automatic request/response handling
  • RESTful Design: Standard HTTP methods and status codes

๐Ÿšฆ Testing

You can test the API using:

  • Postman: Import the endpoints and test manually
  • cURL: Use the command-line examples above
  • Go Tests: Write unit tests for individual components

๐Ÿค Contributing

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

๐Ÿ“„ License

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

๐Ÿ”ฎ Future Enhancements

  • Authentication and authorization
  • Pagination for book listings
  • Search and filtering capabilities
  • Unit and integration tests
  • Docker containerization
  • API documentation with Swagger
  • Rate limiting
  • Logging middleware

๐Ÿ“ง Contact

GitHub : abhinav-phi

Project Link : click here


โญ If you found this project helpful, please give it a star!

About

A robust RESTful API built with Go and MySQL for managing a bookstore's inventory. This project demonstrates clean architecture principles, comprehensive CRUD operations, and modern backend development practices.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages