Skip to content

TuanTran0168/golang-book-management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Book Management Backend

Book Management Backend is a RESTful API built with Golang following Clean Architecture.
It provides book, author, and user management with JWT authentication, uses PostgreSQL for data storage,
supports Cloudinary for image uploads, and includes Swagger for API documentation.


πŸš€ Demo & Swagger UI

You can see the live deployed version of the API and explore its endpoints on Swagger UI:

πŸ“– Book Management Backend Swagger API

Here you’ll find full API documentation, try out endpoints, check request/response schemas, etc.


Project Structure

β”œβ”€β”€ πŸ“ .git/ 🚫 (auto-hidden)              # Git metadata, do not touch
β”œβ”€β”€ πŸ“ book-management-backend/            # Main project source
β”‚   β”œβ”€β”€ πŸ“ cmd/                            # Application entry point
β”‚   β”‚   └── πŸ”΅ main.go                     # Main file, starts the server
β”‚   β”œβ”€β”€ πŸ“ configs/                        # Configuration management, loads from .env
β”‚   β”‚   └── πŸ”΅ config_env.go               # Loads env variables and configs
β”‚   β”œβ”€β”€ πŸ“ docs/                           # Auto-generated Swagger docs (do not edit manually)
β”‚   β”‚   β”œβ”€β”€ πŸ”΅ docs.go
β”‚   β”‚   β”œβ”€β”€ πŸ“„ swagger.json
β”‚   β”‚   └── βš™οΈ swagger.yaml
β”‚   β”œβ”€β”€ πŸ“ internal/                       # Business logic (Clean Architecture)
β”‚   β”‚   β”œβ”€β”€ πŸ“ handlers/                   # Controllers: handle requests β†’ call services
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ auth_handler.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ author_handler.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ book_handler.go
β”‚   β”‚   β”‚   └── πŸ”΅ genre_handler.go
β”‚   β”‚   β”œβ”€β”€ πŸ“ middlewares/                # Middleware (auth, logging, CORS, etc.)
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ auth_middleware.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ cors_middleware.go
β”‚   β”‚   β”‚   └── πŸ”΅ ip_middleware.go
β”‚   β”‚   β”œβ”€β”€ πŸ“ models/                     # Entities / structs mapping to DB
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ author.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ book.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ genre.go
β”‚   β”‚   β”‚   └── πŸ”΅ user.go
β”‚   β”‚   β”œβ”€β”€ πŸ“ repositories/               # Repository layer: DB queries
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ author_repository.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ book_repository.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ genre_repository.go
β”‚   β”‚   β”‚   └── πŸ”΅ user_repository.go
β”‚   β”‚   β”œβ”€β”€ πŸ“ routers/                    # HTTP route definitions
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ auth_routes.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ author_routes.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ book_routes.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ genre_routes.go
β”‚   β”‚   β”‚   └── πŸ”΅ router.go
β”‚   β”‚   β”œβ”€β”€ πŸ“ services/                   # Service layer: business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ author_service.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ book_service.go
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ”΅ genre_service.go
β”‚   β”‚   β”‚   └── πŸ”΅ user_service.go
β”‚   β”‚   └── πŸ“ wire/                       # Dependency injection (Google Wire / manual DI)
β”‚   β”œβ”€β”€ πŸ“ notes/                          # Development notes (internal docs)
β”‚   β”‚   β”œβ”€β”€ πŸ“ RUN.md                      # How to run the project
β”‚   β”‚   β”œβ”€β”€ πŸ“„ init.txt
β”‚   β”‚   β”œβ”€β”€ πŸ“„ lib.txt
β”‚   β”‚   β”œβ”€β”€ πŸ“„ run.txt
β”‚   β”‚   └── πŸ“„ structure.txt
β”‚   β”œβ”€β”€ πŸ“ pkg/                            # Reusable packages (utils, db, etc.)
β”‚   β”‚   β”œβ”€β”€ πŸ“ databases/
β”‚   β”‚   β”‚   └── πŸ”΅ postgresql.go           # PostgreSQL connection & migrations
β”‚   β”‚   └── πŸ“ utils/
β”‚   β”‚       β”œβ”€β”€ πŸ”΅ cloudinary.go           # Cloudinary image upload helper
β”‚   β”‚       └── πŸ”΅ jwt.go                  # JWT helper functions
β”‚   β”œβ”€β”€ πŸ“ tmp/ 🚫 (auto-hidden)           # Temporary files (e.g., from Air hot reload)
β”‚   β”œβ”€β”€ βš™οΈ .air.toml                       # Air configuration (hot reload)
β”‚   β”œβ”€β”€ πŸ”’ .env 🚫 (auto-hidden)           # Environment file (production/secret)
β”‚   β”œβ”€β”€ πŸ“„ .env.local 🚫 (auto-hidden)     # Local environment file (development)
β”‚   β”œβ”€β”€ πŸ“„ DockerFile.local                # Dockerfile for local development
β”‚   β”œβ”€β”€ βš™οΈ docker-compose-local.yaml       # Docker Compose (Go + PostgreSQL)
β”‚   β”œβ”€β”€ πŸ”΅ go.mod                          # Go module definition
β”‚   └── πŸ”΅ go.sum                          # Dependency checksums
β”œβ”€β”€ 🚫 .gitignore                          # Files ignored by Git
└── πŸ“– README.md                           # Main documentation (project overview)


Running the Project with Docker

  1. Build and start containers:
docker compose -f docker-compose-local.yaml up -d --build
  • Builds the book_app:dev image and starts the app + PostgreSQL containers.
  1. Subsequent runs:
docker compose -f docker-compose-local.yaml up -d
  • Starts containers without rebuilding.
  1. Stop containers:
docker compose -f docker-compose-local.yaml down
  • Stops and removes containers.

Notes

  • Database connection and migrations are handled automatically via GORM.
  • App runs on port 8080 inside Docker, accessible at http://localhost:8080/.

πŸ”§ Tech Stack

  • Golang 🟦
  • Gin ⚑ (HTTP web framework)
  • GORM πŸ“¦ (ORM for database)
  • PostgreSQL 🐘
  • JWT Authentication πŸ”‘
  • Cloudinary ☁️ (image upload)
  • Swagger πŸ“‘ (API docs)
  • Docker 🐳 (containerization)

Releases

No releases published

Packages

No packages published

Languages