Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
70c80e1
Add Go module initialization with go.mod file
mohammad-farrokhnia May 18, 2026
e821712
Add API server with Gin router, config management, and graceful shutdown
mohammad-farrokhnia May 18, 2026
4943d6c
Add health endpoint, custom middleware, and standardized response uti…
mohammad-farrokhnia May 18, 2026
7faffb2
Add i18n support, refactor response utilities, and update health endp…
mohammad-farrokhnia May 18, 2026
91c35e4
Add Swagger/OpenAPI documentation with generated specs and UI endpoint
mohammad-farrokhnia May 18, 2026
b2edb5c
Merge pull request #1 from mohammad-farrokhnia/feature/scaffold
mohammad-farrokhnia May 18, 2026
d9ad65d
Add Docker support with multi-stage build, PostgreSQL integration, an…
mohammad-farrokhnia May 18, 2026
b7921b4
Add database connection pooling, migration CLI tool, and initial sche…
mohammad-farrokhnia May 18, 2026
ede88fd
Add Makefile with Docker and migration commands, integrate database c…
mohammad-farrokhnia May 18, 2026
2e112fe
Fix Makefile indentation and correct migrate package declaration
mohammad-farrokhnia May 18, 2026
0435927
Rename DockerFile to Dockerfile, update Go version to 1.25, and inclu…
mohammad-farrokhnia May 19, 2026
7481610
Add docker-psql command to Makefile for standalone PostgreSQL contain…
mohammad-farrokhnia May 19, 2026
dd72c57
Merge pull request #2 from mohammad-farrokhnia/feature/docker-postgres
mohammad-farrokhnia May 19, 2026
d6222b9
Add run-api command to Makefile for starting the API server
mohammad-farrokhnia May 19, 2026
9b3a9bc
Add books table migration with UUID primary key, copy tracking, and i…
mohammad-farrokhnia May 19, 2026
9303844
Add book CRUD endpoints with repository, service, and handler layers
mohammad-farrokhnia May 19, 2026
17a3ad4
Add Book domain model with CRUD operations across repository, service…
mohammad-farrokhnia May 19, 2026
a82adf4
Add copy management endpoints for books with add/remove operations an…
mohammad-farrokhnia May 19, 2026
302306a
Add Swagger documentation for book endpoints and update-swagger Makef…
mohammad-farrokhnia May 19, 2026
d9641d7
Merge pull request #4 from mohammad-farrokhnia/feature/books-crud
mohammad-farrokhnia May 19, 2026
f65a942
Add customers table migration with UUID primary key, unique constrain…
mohammad-farrokhnia May 19, 2026
ebb1f2f
Add Customer domain model with validation utilities and standardize J…
mohammad-farrokhnia May 19, 2026
e6ca603
Refactor repository error handling by moving ErrNotFound to centraliz…
mohammad-farrokhnia May 19, 2026
87fcc85
Rename phone field to mobile across Customer domain, repository, and …
mohammad-farrokhnia May 19, 2026
7d1a625
Add Customer service layer with password hashing, email/mobile unique…
mohammad-farrokhnia May 19, 2026
100b6d0
Add Customer handler with CRUD endpoints and validation, initialize e…
mohammad-farrokhnia May 19, 2026
96d85ed
Restrict customer updates to address and active fields only, refactor…
mohammad-farrokhnia May 20, 2026
2e27f0f
Change birth_date column type from INT to BIGINT in customers table m…
mohammad-farrokhnia May 20, 2026
8140ce6
Update Swagger documentation for customer endpoints and standardize f…
mohammad-farrokhnia May 20, 2026
83bc47b
Replace ShouldBindJSON with strict JSON decoder that disallows unknow…
mohammad-farrokhnia May 20, 2026
0a13c50
Add customer routes to API router, implement email normalization with…
mohammad-farrokhnia May 20, 2026
5a2fb63
Refactor router to extract handler registration into separate functio…
mohammad-farrokhnia May 20, 2026
15e6435
Add comprehensive i18n message codes for CRUD operations, HTTP errors…
mohammad-farrokhnia May 20, 2026
4f8ed11
Merge pull request #5 from mohammad-farrokhnia/feature/customers-vali…
mohammad-farrokhnia May 20, 2026
da721ff
Add employees table migration with role enum, unique constraints on e…
mohammad-farrokhnia May 20, 2026
972bf56
Add Employee domain model with Role enum, SafeEmployee projection, an…
mohammad-farrokhnia May 20, 2026
243be59
Add EmployeeRepository with CRUD operations, GetByEmail/Mobile method…
mohammad-farrokhnia May 20, 2026
065365a
Add AuthService with JWT token generation/validation and EmployeeServ…
mohammad-farrokhnia May 20, 2026
44c6e71
Add auth middleware with RequireAuth/RequireRole handlers, GetClaims …
mohammad-farrokhnia May 20, 2026
a0c1878
Rename files with _dom/_handler/_midl/_repo/_srv suffixes for consist…
mohammad-farrokhnia May 20, 2026
9f3eff7
Add EmployeeHandler with CRUD endpoints, email/mobile/national_code u…
mohammad-farrokhnia May 20, 2026
1b043af
Add JWT configuration with secret and expiry settings, fix indentatio…
mohammad-farrokhnia May 20, 2026
b9dbb26
Refactor router to support employee/auth endpoints with JWT middlewar…
mohammad-farrokhnia May 20, 2026
ef0c500
Add seed command with superAdmin role support, apply email normalizat…
mohammad-farrokhnia May 20, 2026
78992c5
Add stripEmailSymbols helper to normalize email in seed command, stor…
mohammad-farrokhnia May 23, 2026
57b5b90
Add GetByNationalCode to EmployeeRepository, refactor EmployeeService…
mohammad-farrokhnia May 23, 2026
6544620
Add pagination, sorting, and filtering to Book/Customer/Employee repo…
mohammad-farrokhnia May 23, 2026
26fbde4
Update Swagger docs with pagination/sorting/filtering for Book/Custom…
mohammad-farrokhnia May 23, 2026
7eaa4fb
Refactor email normalization in seed command to use util.StripEmailLo…
mohammad-farrokhnia May 23, 2026
6f3ef6d
Refactor error handling across all handlers and repositories to use c…
mohammad-farrokhnia May 23, 2026
24f53ef
Merge pull request #6 from mohammad-farrokhnia/feature/employees-auth
mohammad-farrokhnia May 23, 2026
e14354e
Simplify error checks in CustomerService.Create by removing redundant…
mohammad-farrokhnia May 23, 2026
5fe36b6
Add borrows table migration with borrow_status enum, foreign keys to …
mohammad-farrokhnia May 23, 2026
432052d
Add Borrow domain model with BorrowStatus enum (active/returned/overd…
mohammad-farrokhnia May 23, 2026
509f9d5
Rename error codes to semantic names across all repositories (ErrDBQu…
mohammad-farrokhnia May 23, 2026
3af7841
Add BorrowService with GetAll/GetByCustomer/Borrow/Return methods, im…
mohammad-farrokhnia May 23, 2026
3b0a8e9
Add BorrowHandler with ListAll/ListByCustomer/Borrow/Return endpoints…
mohammad-farrokhnia May 23, 2026
728b3a3
Add mobile/national-code parameters to seed command, change super_adm…
mohammad-farrokhnia May 23, 2026
3c68f90
Uncomment .vscode/ in .gitignore, rename StripEmailSymbols to StripEm…
mohammad-farrokhnia May 24, 2026
10b839e
Add Swagger docs for LoginViaPassword endpoint, implement email strip…
mohammad-farrokhnia May 24, 2026
d30a3a4
Change Customer.BirthDate from int to int64, Employee.BirthDate from …
mohammad-farrokhnia May 24, 2026
1ab607c
Move Swagger endpoint to /api/v1, group all routes under /api/v1/back…
mohammad-farrokhnia May 24, 2026
8662a8d
Change JWT_EXPIRY from duration string to integer hours, add Role.AtL…
mohammad-farrokhnia May 24, 2026
a003b0f
Add bin/ to .gitignore, add build targets to Makefile for api/seed/mi…
mohammad-farrokhnia May 24, 2026
aa644bb
Merge pull request #7 from mohammad-farrokhnia/feature/borrow-system
mohammad-farrokhnia May 24, 2026
33d125b
Replace direct sql.ErrNoRows equality checks with errors.Is across al…
mohammad-farrokhnia May 24, 2026
63dbcff
Change birthDate from int64/BIGINT Unix timestamp to time.Time/DATE a…
mohammad-farrokhnia May 24, 2026
fe3eafa
Remove migration file comments for birth_date type conversion in empl…
mohammad-farrokhnia May 24, 2026
28a8ecf
Remove migration 000006 for birth_date type conversion and update ini…
mohammad-farrokhnia May 24, 2026
a2a8b22
Merge pull request #8 from mohammad-farrokhnia/fix/error-check
mohammad-farrokhnia May 24, 2026
2c8aa6a
Add refresh_tokens table with user_id/user_type/token_hash/expires_at…
mohammad-farrokhnia May 24, 2026
f830fd6
Add Redis connection with retry logic, extend OAuth config with Googl…
mohammad-farrokhnia May 25, 2026
6a4b5ce
Add Redis-backed session store with JWT token lifecycle management, u…
mohammad-farrokhnia May 25, 2026
66dca50
Add OTP generation/verification with Redis store and mock mailer inte…
mohammad-farrokhnia May 25, 2026
347844f
Add auth_dom.go with token/claims/input types, add GoogleID/AuthProvi…
mohammad-farrokhnia May 25, 2026
29ebc25
Add OTP_EXPIRY config, create TokenRepository with refresh token CRUD…
mohammad-farrokhnia May 25, 2026
2205815
Add customer portal auth endpoints with OAuth support, refactor auth …
mohammad-farrokhnia May 25, 2026
af860d1
Refactor auth handlers into separate employee/customer handlers, stan…
mohammad-farrokhnia May 25, 2026
bbb3aff
Add employee password reset endpoints (forgot/reset), update login to…
mohammad-farrokhnia May 25, 2026
8c86bc6
Add customer profile update endpoint with birth date/national code fi…
mohammad-farrokhnia May 25, 2026
89e43fd
Merge pull request #9 from mohammad-farrokhnia/feature/auth-improvements
mohammad-farrokhnia May 25, 2026
a293fd3
Add Elasticsearch service to docker-compose with single-node config, …
mohammad-farrokhnia May 25, 2026
44aa2ea
Add docker-deps target to Makefile and change Redis port mapping from…
mohammad-farrokhnia May 25, 2026
4553575
Add Elasticsearch client with book indexing and search capabilities, …
mohammad-farrokhnia May 25, 2026
29c67bc
Add Elasticsearch integration with book search/suggest endpoints, wir…
mohammad-farrokhnia May 25, 2026
715d581
Add portal customer/book/borrow handlers with public-facing endpoints…
mohammad-farrokhnia May 26, 2026
c442185
Refactor router into separate backoffice/portal/public modules, move …
mohammad-farrokhnia May 26, 2026
cbb899e
Standardize environment variable naming to uppercase (AppName→APP_NAM…
mohammad-farrokhnia May 26, 2026
b3f7cbf
Merge pull request #10 from mohammad-farrokhnia/feature/elasticsearch…
mohammad-farrokhnia May 26, 2026
27b7f28
Add book recommendation endpoints with backoffice/portal/personal var…
mohammad-farrokhnia May 26, 2026
dd12896
Add item-based and profile-based recommendation endpoints to backoffi…
mohammad-farrokhnia May 26, 2026
49a05bb
Add recommendation-related i18n message codes and translations for En…
mohammad-farrokhnia May 26, 2026
f0d922d
Add recommendation system with item-based/profile-based/fallback stra…
mohammad-farrokhnia May 26, 2026
2c9a87b
Merge pull request #11 from mohammad-farrokhnia/feature/recommendations
mohammad-farrokhnia May 26, 2026
5eb2dac
Add force command to migrate tool, enable uuid-ossp extension, and ch…
mohammad-farrokhnia May 26, 2026
886f9ca
Add report domain models and cache package with Redis-backed generic …
mohammad-farrokhnia May 30, 2026
46c1196
Add ReportHandler with backoffice endpoints for borrow trends/top boo…
mohammad-farrokhnia May 30, 2026
e87ea42
Add ReportHandler to backoffice routes with endpoints for borrow tren…
mohammad-farrokhnia May 30, 2026
4b6935c
Add backoffice report endpoints with Swagger docs for borrow trends/t…
mohammad-farrokhnia May 30, 2026
5dae903
Merge pull request #12 from mohammad-farrokhnia/feature/reports-caching
mohammad-farrokhnia May 30, 2026
8a78e29
update make file to run tests
mohammad-farrokhnia May 30, 2026
2cdf805
test: Add domain model unit tests for book/borrow/customer/employee/q…
mohammad-farrokhnia May 31, 2026
d757bdd
test: Add handler and middleware unit tests
mohammad-farrokhnia May 31, 2026
6e75557
style: Fix indentation and add test helpers
mohammad-farrokhnia May 31, 2026
1cd6ee1
test: Add comprehensive unit and integration tests for search, servic…
mohammad-farrokhnia May 31, 2026
f06310d
Merge pull request #13 from mohammad-farrokhnia/feature/testing
mohammad-farrokhnia May 31, 2026
80292b4
tidy up the go mod
mohammad-farrokhnia May 31, 2026
6398e68
add github workflow ci
mohammad-farrokhnia May 31, 2026
17cb1a5
feat(middleware): Add security, CORS, rate limiting, and request time…
mohammad-farrokhnia May 31, 2026
ba2251b
chore: Refactor health check endpoint and improve Makefile with build…
mohammad-farrokhnia Jun 1, 2026
40c5918
docs: Add CONTRIBUTING.md with development setup and prerequisites
mohammad-farrokhnia Jun 1, 2026
09856a4
docs: Add architecture documentation and CI badge to README
mohammad-farrokhnia Jun 1, 2026
2ecf2b4
style: Fix indentation from spaces to tabs across configuration and r…
mohammad-farrokhnia Jun 1, 2026
4861c7d
style: Standardize comment formatting to use periods instead of colons
mohammad-farrokhnia Jun 1, 2026
b1d869c
refactor: Rename search types and improve error handling in config pa…
mohammad-farrokhnia Jun 1, 2026
b82b915
test: Replace unused context parameters with underscore across test f…
mohammad-farrokhnia Jun 1, 2026
f0948be
test: Add integration test for mockCustomerRepoForAuth to verify mock…
mohammad-farrokhnia Jun 1, 2026
6c837d9
test: Refactor integration tests and add infrastructure retry logic
mohammad-farrokhnia Jun 1, 2026
6a35cc3
chore: Add version injection to build process and improve Makefile he…
mohammad-farrokhnia Jun 1, 2026
6a6c91f
Merge pull request #14 from mohammad-farrokhnia/feature/ci-docs-polish
mohammad-farrokhnia Jun 1, 2026
a5fd763
docs: Add security considerations section to README and mark critical…
mohammad-farrokhnia Jun 1, 2026
3bb1b87
style: Remove redundant godot linter configuration setting
mohammad-farrokhnia Jun 1, 2026
b79f394
refactor: Clean up comments and add migrate-force command to Makefile
mohammad-farrokhnia Jun 1, 2026
e5d4239
docs: Update Swagger schema references to use fully qualified package…
mohammad-farrokhnia Jun 1, 2026
9aa9607
refactor: Standardize PORT environment variable and add version injec…
mohammad-farrokhnia Jun 1, 2026
94155b3
docs: Add configuration documentation for local vs Docker vs producti…
mohammad-farrokhnia Jun 1, 2026
624437d
refactor: Simplify .env.example and fix Docker port configuration
mohammad-farrokhnia Jun 1, 2026
a0f7b31
feat: Add nationalCode field to customer signup flow
mohammad-farrokhnia Jun 2, 2026
62b62ae
refactor: Make ISBN field optional and add database constraint handling
mohammad-farrokhnia Jun 2, 2026
e3a8f1f
refactor: Add PostgreSQL error mapping to RemoveCopies and improve er…
mohammad-farrokhnia Jun 2, 2026
25ab6a3
feat: Add unique constraint and error handling for customer national …
mohammad-farrokhnia Jun 2, 2026
def339d
refactor: Fix error context fields and add employee constraint handling
mohammad-farrokhnia Jun 2, 2026
d7e3d68
refactor: Remove customError alias and standardize error package imports
mohammad-farrokhnia Jun 2, 2026
bcd8598
refactor: Fix SQL parameter count and add constraint error handling t…
mohammad-farrokhnia Jun 2, 2026
02a8407
refactor: Make nationalCode optional in customer signup and change to…
mohammad-farrokhnia Jun 2, 2026
69241bc
refactor: Change customer and employee contact fields to optional poi…
mohammad-farrokhnia Jun 2, 2026
9dbc354
refactor: Add SuperAdmin role to backoffice routes and fix borrow end…
mohammad-farrokhnia Jun 2, 2026
24d4bf7
refactor: Standardize JSON field naming and improve code formatting
mohammad-farrokhnia Jun 2, 2026
6ca7966
fix get customer borrowed books
mohammad-farrokhnia Jun 2, 2026
569f140
refactor: Move borrow validation to repository layer with constraint …
mohammad-farrokhnia Jun 3, 2026
7460114
bugFix: fix incorrect id structure and type inputs in requests
mohammad-farrokhnia Jun 3, 2026
5f7825c
update git ignore to include jetbrains ide files
mohammad-farrokhnia Jun 3, 2026
59569c6
bugFix: fix borrow service test mismatch with new changes in borrow repo
mohammad-farrokhnia Jun 3, 2026
60763c9
bugFix: fix unit test problem
mohammad-farrokhnia Jun 3, 2026
63efd18
bugFix: fix lint and go version mismatch problems
mohammad-farrokhnia Jun 3, 2026
f4311e7
bugFix: update git ci to use latest version of golangci-lint so it wo…
mohammad-farrokhnia Jun 3, 2026
4c3da7b
bugFix: update git ci to use latest version of golangci-lint so it wo…
mohammad-farrokhnia Jun 3, 2026
af7f9ea
bugFix: fix lint problems and update golang ci to newest version
mohammad-farrokhnia Jun 3, 2026
b36af89
bugFix: fix lint problems and update golang ci to newest version
mohammad-farrokhnia Jun 3, 2026
d99e6a3
bugFix: fix lint problems and update golang ci to newest version
mohammad-farrokhnia Jun 3, 2026
1c86e0d
bugFix: fix lint problems and update golang ci to newest version
mohammad-farrokhnia Jun 3, 2026
0224f29
Merge pull request #15 from mohammad-farrokhnia/chore/clean-up
mohammad-farrokhnia Jun 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
APP_NAME=library
APP_VERSION=0.1.0
APP_ENV=development

# Application Port
# For local development (make run-api): the port your app listens on
# For Docker (make docker-up): container always listens on 8080 (hardcoded in docker-compose.yml)
PORT=8080

# Docker Host Port (optional, only used by docker-compose)
# Maps host port to container port 8080
# HOST_PORT=8080

DATABASE_URL=postgres://library:secret@localhost:5432/library?sslmode=disable
POSTGRES_USER=library
POSTGRES_PASSWORD=secret
POSTGRES_DB=library

# ⚠️ For local development (make run-api): use localhost:6380
# ⚠️ For Docker (make docker-up): IGNORED - hardcoded to redis://redis:6379 in docker-compose.yml
REDIS_URL=redis://localhost:6380

JWT_SECRET=secret
ACCESS_TOKEN_EXPIRY=30
REFRESH_TOKEN_EXPIRY=720

GOOGLE_CLIENT_ID=xxx
GOOGLE_CLIENT_SECRET=xxx
GOOGLE_REDIRECT_URL=http://localhost:8080/api/v1/portal/auth/google/callback

OTP_EXPIRY=1

# Elasticsearch Configuration
# ⚠️ For local development (make run-api): use localhost:9200
# ⚠️ For Docker (make docker-up): IGNORED - hardcoded to http://elasticsearch:9200 in docker-compose.yml
ELASTICSEARCH_URL=http://localhost:9200

REQUEST_TIMEOUT=30s
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1m
113 changes: 113 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: CI

on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m

test-unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true

- name: Download modules
run: go mod download

- name: Run unit tests
run: go test ./internal/... -v -race -count=1 -coverprofile=coverage.out

- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out

test-integration:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true

- name: Download modules
run: go mod download

- name: Run integration tests
run: go test ./tests/integration/... -v -race -count=1 -timeout 120s
env:
TESTCONTAINERS_RYUK_DISABLED: true

build:
name: Build
runs-on: ubuntu-latest
needs: [lint, test-unit, test-integration]
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true

- name: Build all binaries
run: make build

- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries
path: bin/

docker:
name: Docker Build
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4

- name: Build Docker image
run: docker build -t librecore:${{ github.sha }} .

- name: Smoke test image
run: |
docker run --rm -d \
-e APP_ENV=production \
-e DATABASE_URL=postgres://x:x@localhost/x \
-e REDIS_URL=redis://localhost:6379 \
-e JWT_SECRET=ci-test-secret \
-p 8080:8080 \
--name librecore_smoke \
librecore:${{ github.sha }} || true
sleep 3
docker stop librecore_smoke || true
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*.dll
*.so
*.dylib
bin/

# Test binary, built with `go test -c`
*.test
Expand All @@ -28,5 +29,5 @@ go.work.sum
.env

# Editor/IDE
# .idea/
# .vscode/
.idea/
.vscode/
50 changes: 50 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "2"
run:
timeout: 5m
go: '1.26'

linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused
- misspell
- revive
- exhaustive
- noctx
- bodyclose
settings:
revive:
rules:
- name: exported
disabled: true
- name: package-comments
disabled: true
- name: redefines-builtin-id
severity: warning
- name: unexported-return
severity: warning
- name: blank-imports
severity: warning
exhaustive:
default-signifies-exhaustive: true
exclusions:
rules:
- path: _test\.go
linters: [errcheck, noctx]
- path: tests/
linters: [errcheck, noctx, revive]
- path: docs/
linters: [all]
- path: pkg/i18n/fa\.go
linters: [staticcheck]

formatters:
enable:
- gofmt

issues:
max-issues-per-linter: 0
max-same-issues: 0
106 changes: 106 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Contributing to LibreCore

Thank you for considering contributing. This document covers everything
you need to get started.

---

## Development Setup

### Prerequisites
- Go 1.23+
- Docker + Docker Compose
- `golangci-lint` — `go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest`
- `swag` — `go install github.com/swaggo/swag/cmd/swag@latest`

### First-time setup
```bash
git clone https://github.com/mohammad-farrokhnia/library.git
cd library
cp .env.example .env
make docker-up
make migrate
make seed EMAIL=admin@library.com PASSWORD=secret MOBILE=09120000000 NATIONAL_CODE=1234567890
make run-api
```

---

## Git Flow

We follow trunk-based development with short-lived feature branches.

```
main ← production, protected, requires PR + review
develop ← integration branch, PRs target this
feature/* ← one branch per feature
hotfix/* ← emergency production fixes
release/* ← release stabilization
```

---

## Branch Naming

| Type | Pattern | Example |
|---|---|---|
| Feature | `feature/short-description` | `feature/book-recommendations` |
| Bug fix | `fix/what-was-broken` | `fix/borrow-transaction-race` |
| Hotfix | `hotfix/critical-issue` | `hotfix/jwt-validation` |
| Chore | `chore/what-changed` | `chore/update-go-1.24` |

---

## Commit Convention

We use [Conventional Commits](https://www.conventionalcommits.org/):

```
type(scope): short description

feat(books): add copy management endpoints
fix(auth): prevent session reuse after logout
docs(readme): update installation steps
test(borrow): add limit enforcement integration test
chore(deps): update golang-jwt to v5.2.1
refactor(cache): extract GetOrSet into generic helper
```

Types: `feat` `fix` `docs` `test` `chore` `refactor` `perf` `ci`

---

## Pull Request Process

1. Fork the repo and create your branch from `develop`
2. Write tests for any new behaviour
3. Ensure `make lint` and `make test` pass
4. Update Swagger docs if you changed any handler: `make swagger`
5. Open a PR targeting `develop` with a clear description

---

## Code Standards

- All repository methods must accept `context.Context` as the first parameter
- All errors must be `AppError` from `pkg/errors` — never raw `errors.New`
- Business rules belong in `service/`, never in `handler/` or `repository/`
- New i18n message codes must be added to all locale files (`en.go`, `fa.go`)
- Every new endpoint needs a Swagger annotation

---

## Running Tests

```bash
make test-unit # fast, no Docker
make test-integration # requires Docker
make test-coverage # generates coverage.html
```

---

## Project Structure

See the [architecture document](docs/architecture.md) for the full layered
architecture diagram and design decisions.
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.25-alpine AS builder

WORKDIR /app

RUN apk add --no-cache git

COPY go.mod go.sum ./

RUN go mod download

COPY . .

ARG VERSION=dev
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo \
-ldflags "-s -w -X main.Version=${VERSION}" \
-o main ./cmd/api

FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

COPY --from=builder /app/main .

COPY --from=builder /app/migrations ./migrations

EXPOSE 8080

CMD ["./main"]
Loading
Loading