How ayanahm4d/golang-bookstore-management-api works
Main Components
a) Client Layer:
• External API consumers
• Supported HTTP methods (GET, POST, PUT, DELETE)
b) API Layer:
• HTTP Server (using Gorilla Mux)
• Authentication Middleware
• Route Handlers (auth_handler, book_handler)
c) Business Logic Layer:
• Authentication Service (JWT)
• Book Management Service
• User Management Service
d) Data Access Layer:
• Repository Layer (book_repository, user_repository)
• Database (MySQL)
[Client Layer]
• ↓
[API Gateway/Load Balancer]
• ↓
[API Layer]
• ↓
[Business Logic Layer]
• ↓
[Data Access Layer]
• ↓
[Database Layer]
Component Relationships
• HTTP requests flow from clients through the API layer
• Authentication flow through middleware
• Data flow between repositories and database
• JWT token validation path
Detailed Component Breakdown
API Layer (Controllers):
/api
• Auth Routes
• POST /register
• POST /login
• Book Routes (Protected)
• GET /books
• GET /books/{id}
• POST /books
• PUT /books/{id}
• DELETE /books/{id}
Middleware Layer:
• Authentication Middleware (JWT Validation)
• Request/Response Handling
Business Logic:
• User Management
• Book Management
• JWT Token Generation/Validation
Data Layer:
• User Repository
• Book Repository
• MySQL Database (with tables: users, books)
Additional Elements
• Environment Configuration (.env)
• External Dependencies:
• jwt-go
• go-sql-driver/mysql
• gorilla/mux
• godotenv
• crypto (for password hashing)
Special Features to Highlight
• Pagination handling
• Search and filtering capabilities
• Sort functionality
• Security measures (password hashing, JWT)
Technical Details to Note
Database Schema:
[Users Table]
• id (BIGINT)
• username (VARCHAR)
• password (VARCHAR)
• email (VARCHAR)
• created_at (TIMESTAMP)
[Books Table]
• id (BIGINT)
• title (VARCHAR)
• author (VARCHAR)
• price (DECIMAL)
• stock (INT)
• created_at (TIMESTAMP)
• updated_at (TIMESTAMP)
Implementation Notes
• Clear separation of concerns between layers
• Where configuration is loaded
• Protected routes and authentication flow
• Error handling paths
• Where middleware intercepts requests
This project follows a clean architecture pattern, so emphasize the separation of concerns and the unidirectional flow of dependencies from external layers (API) to internal layers (business logic and data access).