How fuzz-head/book-store works
Project Type and Purpose
• This is a backend API service written in Go (Golang).
• It exposes HTTP endpoints for user management, authentication (JWT), book resources, and password resets.
• It persists data to a relational database (via the database package/docker-compose.yml) and includes rate-limiting and role-based middleware.
File Structure
Top-Level Folders:
• cmd/server: application entrypoint (main.go)
• internal/api: HTTP layer
– handlers (auth, user, book, password reset)
– middleware (auth, rate limiting, roles)
– routes (router setup)
• domain/models: business entities (User, Book, Claims)
• database: DB connection and seeding logic
• pkg/jwtutils & pkg/utils: shared utilities (JWT, hashing)
• docker-compose.yml: brings up the Go service + database
• test files & stress tests: load-test scripts
README
• Contains only test/coverage instructions—no architecture details.
• All architectural insight must come from the code layout.
Main Components & Their Interactions
a. API Gateway / HTTP Server
• cmd/server → initializes HTTP router (Gorilla Mux or net/http)
• Routes configured in internal/api/routes/router.go
b. Middleware Layer
• AuthMiddleware: validates JWTs via pkg/jwtutils
• RateLimiter: enforces request quotas
• Roles: enforces RBAC
c. Handler Layer
• AuthHandler: login, token issue, password reset
• UserHandler: CRUD on users
• BookHandler: CRUD on books
d. Domain Layer
• domain/models: User, Book, Claims
• business logic lives in handlers calling models
e. Persistence Layer
• database/database.go: DB connection setup
• database/seed.go: initial data seeding
• Uses a SQL database (Postgres, MySQL, etc.) configured in docker-compose
f. Utility Libraries
• pkg/jwtutils/jwt.go: generate & verify JWTs
• pkg/utils/hash.go: password hashing
g. External Components
• Relational Database (Postgres/MySQL)
• (Optional) Email service for password reset
Architectural Patterns and Design Principles
• Clean-Layered Architecture:
– HTTP layer → Handlers → Domain models → Database
• Separation of Concerns: clear HTTP, business, persistence layers
• Middleware pipeline for cross-cutting concerns (auth, rate limit)
• Dependency Injection via constructor functions in cmd/server & routes
• Modular utilities under pkg/ for reuse and testing
Final Checklist
[ ] All major components (HTTP server, middleware, handlers, domain, DB, utils)
[ ] Notes about technologies (Go modules, Docker, SQL)