A comprehensive book management application built with Go backend and modern web technologies. The project features a robust API for book management and advanced URL cleaning capabilities.
- β‘ Next.js 15.3.3: with Turbopack
- π¨ Modern UI Components: Built with shadcn/ui (Radix UI) and Tailwind CSS
- π± Responsive Design: Mobile-first responsive layout
- π State Management: React Context and React Query for server state management
- π‘ API Integration: Axios-based service layer for backend communication
- π― TypeScript: Full type safety across the application
- π¨ Component Library: Reusable UI components with shadcn/ui
- π Book Management Pages: Create, view, and manage books
- Dynamic routing for book details
- Form validation and error handling
- Loading states and user feedback
-
π Book Management Module: Complete CRUD operations for book management
- Create, read, update, and delete books
- PostgreSQL database with UUID-based primary keys
- Comprehensive input validation
- Structured logging and error handling
-
π URL Cleaner Module: Advanced URL processing service
- Canonical URL cleaning (removes query parameters and fragments)
- Redirect resolution to final destinations
- Comprehensive cleaning operations
- Input validation and error handling
- π³ Docker Support: Containerized deployment with Docker Compose
- π Swagger Documentation: Interactive API documentation
- π§ͺ Comprehensive Testing: Unit tests for all services
- ποΈ Clean Architecture: Modular design with dependency injection
- οΏ½ Database Migrations: Automated PostgreSQL schema management
bybook/
βββ apps/
β βββ backend/ # Go backend API
β β βββ api/
β β β βββ docs/ # Generated Swagger documentation
β β β βββ docs.go
β β β βββ swagger.json
β β β βββ swagger.yaml
β β βββ bin/ # Compiled binaries (optional, usually in .gitignore)
β β βββ cmd/
β β β βββ main.go # Application entry point
β β βββ internal/ # Private application code
β β β βββ books/ # Book management module
β β β β βββ constants.go
β β β β βββ controller.go
β β β β βββ model.go
β β β β βββ repository.go
β β β β βββ routes.go
β β β β βββ service.go
β β β β βββ validator.go
β β β βββ urlcleaner/ # URL cleaning module
β β β β βββ constants.go
β β β β βββ controller.go
β β β β βββ errors.go
β β β β βββ model.go
β β β β βββ routes.go
β β β β βββ service.go
β β β β βββ validator.go
β β β βββ di/ # Dependency injection
β β β βββ books_di.go
β β β βββ container.go
β β β βββ urlcleaner_di.go
β β βββ migrations/ # Database migrations
β β β βββ 000_enable_extensions.up.sql
β β β βββ 000_enable_extensions.down.sql
β β β βββ 001_create_books.up.sql
β β β βββ 001_create_books.down.sql
β β βββ pkg/ # Shared packages
β β β βββ db/
β β β β βββ postgres.go
β β β βββ env/
β β β β βββ env.go
β β β βββ logger/
β β β β βββ logger.go
β β β βββ middleware/
β β β β βββ logging.go
β β β βββ routes/
β β β βββ routes.go
β β βββ tests/ # Unit & integration tests
β β β βββ api/
β β β βββ books/
β β β β βββ books_service_test.go
β β β βββ urlcleaner/
β β β βββ urlcleaner_test.go
β β βββ vendor/ # Vendored dependencies (optional)
β β βββ go.mod
β β βββ go.sum
β β βββ Makefile
β β βββ README.md # Backend-specific documentation
β βββ frontend/ # Next.js Frontend Application
β βββ src/
β β βββ app/ # Next.js App Router
β β β βββ page.tsx # Home page
β β β βββ layout.tsx # Root layout
β β β βββ loading.tsx # Loading UI
β β β βββ books/ # Book management pages
β β β βββ [id]/ # Dynamic book pages like detail and edit
β β β βββ create/ # Create book page
β β βββ components/ # Reusable UI components
β β β βββ common/ # Common components (BookCard, BookForm, etc.)
β β β βββ layout/ # Layout components
β β β βββ navigation/ # Navigation components
β β β βββ pages/ # Page-specific components
β β β βββ providers/ # Context providers
β β β βββ ui/ # shadcn/ui components
β β βββ contexts/ # React contexts
β β β βββ BookContext/ # Book state management
β β βββ hooks/ # Custom React hooks
β β β βββ useBookContext/ # Book context hook
β β β βββ useBookForm/ # Book form management
β β β βββ useBooks/ # Book data fetching
β β βββ lib/ # Utility libraries
β β β βββ routes.ts # Route definitions
β β β βββ utils.ts # Utility functions
β β βββ services/ # API service layer
β β β βββ bookService.ts # Book API calls
β β βββ types/ # TypeScript type definitions
β β βββ book.ts # Book type definitions
β βββ public/ # Static assets
β βββ package.json
β βββ next.config.ts
β βββ tailwind.config.js
β βββ tsconfig.json
β βββ README.md # Frontend-specific documentation
βββ docker-compose.yml # Docker orchestration for local dev
βββ Makefile # Root-level build automation
βββ .env # Environment variables
βββ README.md # Monorepo documentation (you are here)
- Docker & Docker Compose: For containerized deployment
- Go: 1.24.4+ (for local backend development)
- PostgreSQL: 12+ (for local database)
- Node.js: 18+ (for frontend development)
- pnpm: Package manager for frontend dependencies
-
Clone the repository:
git clone https://github.com/metecan/bybook.git cd bybook
-
Set up environment variables: Create a
.env
file in the root directory:# Database Configuration DB_USER=postgres DB_PASSWORD=1234 DB_NAME=postgres # Application Ports FRONTEND_PORT=3000 BACKEND_PORT=8080
-
Start the all applications: (It will build the images and start the containers) Using the provided Makefile:
make up
Or without make:
docker-compose up --build
-
Access the application:
- Backend API: http://localhost:8080
- Swagger Documentation: http://localhost:8080/swagger/index.html
- Frontend: http://localhost:3000
-
Navigate to frontend directory:
cd apps/frontend
-
Install dependencies:
pnpm install
-
Start the development server:
pnpm dev
-
Build for production:
pnpm build pnpm start
-
Navigate to backend directory:
cd apps/backend
-
Install dependencies:
go mod tidy
-
Set up PostgreSQL database:
# Using Docker docker run --name postgres-bybook \ -e POSTGRES_PASSWORD=1234 \ -e POSTGRES_DB=postgres \ -p 5432:5432 \ -d postgres:15
-
Run database migrations: (Dockerfile handles this automatically)
# Execute SQL files in order: # 1. migrations/000_enable_extensions.up.sql # 2. migrations/001_create_books.up.sql
-
Start the backend server:
make run-dev
Method | Endpoint | Description | Authentication |
---|---|---|---|
GET | /api/books |
Get all books | None |
GET | /api/books/:id |
Get book by ID | None |
POST | /api/books |
Create a new book | None |
PUT | /api/books/:id |
Update existing book | None |
DELETE | /api/books/:id |
Delete book | None |
Create Book:
curl -X POST http://localhost:8080/api/books \
-H "Content-Type: application/json" \
-d '{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"year": 1925
}'
Get All Books:
curl http://localhost:8080/api/books
Method | Endpoint | Description | Authentication |
---|---|---|---|
POST | /api/url/clean |
Clean and process URL | None |
- canonical: Removes query parameters and fragments
- redirect: Resolves redirects to final destination
- all: Applies both canonical and redirect operations
curl -X POST http://localhost:8080/api/url/clean \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/path?utm_source=google¶m=value",
"operation": "canonical"
}'
Response:
{
"data": {
"processed_url": "https://example.com/path"
},
"message": "URL cleaned successfully"
}
# Run all backend tests
cd apps/backend
go test ./...
# Run with verbose output
go test -v ./...
# Run specific module tests
go test ./tests/api/books/
go test ./tests/api/urlcleaner/
# Run with coverage
go test -cover ./...
- β Books Module: CRUD operations, validation, error handling
- β URL Cleaner Module: All cleaning operations, input validation
- β Service Layer: Business logic and data processing
- β Repository Layer: Data access and persistence
# Start all services
make up
# Stop all services
make down
# Restart services
make restart
# View logs
docker-compose logs -f
# View specific service logs
docker-compose logs -f backend
# Build backend image
docker build -f apps/backend/Dockerfile.backend -t bybook-backend apps/backend
# Run backend container
docker run -p 8080:8080 bybook-backend
# Run PostgreSQL
docker run --name postgres \
-e POSTGRES_PASSWORD=1234 \
-e POSTGRES_DB=postgres \
-p 5432:5432 \
-d postgres:15
Root Level:
make up # Start all services with Docker Compose
make down # Stop all services
make restart # Restart all services
Backend (apps/backend/
):
make build # Build the application
make run # Run in production mode
make run-dev # Run in development mode
make docs # Generate Swagger documentation
Variable | Description | Default | Required |
---|---|---|---|
DB_USER |
PostgreSQL username | postgres | Yes |
DB_PASSWORD |
PostgreSQL password | - | Yes |
DB_NAME |
PostgreSQL database name | postgres | Yes |
BACKEND_PORT |
Backend server port | 8080 | No |
FRONTEND_PORT |
Frontend server port | 3000 | No |
-- Books table
CREATE TABLE books (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
year INT NOT NULL,
created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
- Swagger UI: http://localhost:8080/swagger/index.html
- API Specification: Generated automatically from code annotations
The backend follows clean architecture principles:
- Controllers: HTTP request handling and response formatting
- Services: Business logic implementation
- Repositories: Data access layer abstraction
- Models: Data transfer objects and entities
- Dependency Injection: Modular component management
- Backend: Go 1.24.4, Fiber v2, PostgreSQL
- Frontend: Next.js 15.3.3, React 19, TypeScript 5
- UI/Styling: Tailwind CSS 4, Radix UI, shadcn/ui
- State Management: React Query (TanStack Query), React Context
- Development Tools: ESLint, Prettier, Turbopack
- Testing: Testify (Backend), custom mocks
- Documentation: Swagger/OpenAPI 3.0
- Database: PostgreSQL with UUID support
- Containerization: Docker, Docker Compose
- Environment Setup: Configure production environment variables
- Database: Use managed PostgreSQL service
- Application: Deploy using Docker containers
- Monitoring: Implement health checks and logging
- Security: Add authentication/authorization as needed