Skip to content

metecan/bybook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ByBook Monorepo Full Stack Project - Software Developer Assignment

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.

Frontend Application

  • ⚑ 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

Backend Application

  • πŸ“š 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

Backend Infrastructure

  • 🐳 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

πŸ“ Project Structure

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)

πŸ› οΈ Installation & Setup

Prerequisites

  • 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

Quick Start with Docker Compose

  1. Clone the repository:

    git clone https://github.com/metecan/bybook.git
    cd bybook
  2. 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
  3. 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
  4. Access the application:

Local Development Setup

Frontend Development

  1. Navigate to frontend directory:

    cd apps/frontend
  2. Install dependencies:

    pnpm install
  3. Start the development server:

    pnpm dev
  4. Build for production:

    pnpm build
    pnpm start

Backend Development

  1. Navigate to backend directory:

    cd apps/backend
  2. Install dependencies:

    go mod tidy
  3. 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
  4. 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
  5. Start the backend server:

    make run-dev

πŸ”Œ API Endpoints

Books Management API

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

Example Requests

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

URL Cleaner API

Method Endpoint Description Authentication
POST /api/url/clean Clean and process URL None

Cleaning Operations

  • canonical: Removes query parameters and fragments
  • redirect: Resolves redirects to final destination
  • all: Applies both canonical and redirect operations

Example Request

curl -X POST http://localhost:8080/api/url/clean \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/path?utm_source=google&param=value",
    "operation": "canonical"
  }'

Response:

{
  "data": {
    "processed_url": "https://example.com/path"
  },
  "message": "URL cleaned successfully"
}

πŸ§ͺ Testing

Running Tests

# 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 ./...

Test Coverage

  • βœ… 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

🐳 Docker Deployment

Docker Compose Commands

# 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

Manual Docker Commands

# 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

πŸ”§ Development

Available Make Commands

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

Environment Variables

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

Database Schema

-- 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
);

πŸ“– Documentation

πŸ—οΈ Architecture

Backend Architecture

The backend follows clean architecture principles:

  1. Controllers: HTTP request handling and response formatting
  2. Services: Business logic implementation
  3. Repositories: Data access layer abstraction
  4. Models: Data transfer objects and entities
  5. Dependency Injection: Modular component management

Technology Stack

  • 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

πŸš€ Deployment

Production Deployment

  1. Environment Setup: Configure production environment variables
  2. Database: Use managed PostgreSQL service
  3. Application: Deploy using Docker containers
  4. Monitoring: Implement health checks and logging
  5. Security: Add authentication/authorization as needed

Screenshots

Swagger Documentation

1


Frontend Application

2

3

4

5

6

7

8

9


URL Cleaner API

10


Deployment

11


Video

Watch Video

Last Updated (18 Jun 2025, 17:00)

About

Software Developer Assignment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published