# febriaricandra/book-shop architecture

> Architecture diagram of the GitHub repository febriaricandra/book-shop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/febriaricandra/book-shop
- Repository: https://github.com/febriaricandra/book-shop

## Overview

##### Project Type Analysis
This is a REST API backend service for a book shop, built using Go, following a clean architecture pattern with clear separation of concerns.

##### Main Components

A. External Layer (Client Interface)
- REST API Endpoints
- Authentication Layer (JWT-based)

B. Application Core Layers (arranged in hierarchical order):
1. Handlers Layer (Controllers)
- Book Handler
- Order Handler
- User Handler
- RajaOngkir Handler (External shipping service integration)

2. Services Layer (Business Logic)
- Book Services
- Order Services
- User Services

3. Repository Layer (Data Access)
- Book Repository
- Order Repository
- User Repository

C. Infrastructure Components:
- Database (indicated by db package)
- R2 Storage (for image storage)
- Docker Container

**[Client] → [API Gateway/Router] → [Auth Middleware] → [Handlers] → [Services] → [Repositories] → [Database]**

**[Login/Register Endpoints] → [Auth Middleware] → [JWT Token Generation] → [Token Validation]**

**[Book Endpoints] → [Book Handler] → [Book Service] → [Book Repository] → [Database]**
- ↘ [R2 Storage] (for cover images)

**[Order Endpoints] → [Order Handler] → [Order Service] → [Order Repository] → [Database]**
- ↘ [RajaOngkir Service] (for shipping)

##### Important Details

- Authentication points
- Database relationships
- External service integration points
- Docker container boundary
- API endpoints grouping
- Middleware placement

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client]
    end

    subgraph API_Layer
        API["API Router/Gateway"]:::router
        Auth["Authentication Middleware"]:::middleware
    end

    subgraph Handlers_Layer
        BH["Book Handler"]:::handler
        OH["Order Handler"]:::handler
        UH["User Handler"]:::handler
        RH["RajaOngkir Handler"]:::handler
    end

    subgraph Services_Layer
        BS["Book Service"]:::service
        OS["Order Service"]:::service
        US["User Service"]:::service
    end

    subgraph Repository_Layer
        BR["Book Repository"]:::repo
        OR["Order Repository"]:::repo
        UR["User Repository"]:::repo
    end

    subgraph Models
        BM["Book Model"]:::model
        OM["Order Model"]:::model
        UM["User Model"]:::model
    end

    subgraph External_Services
        R2["R2 Storage"]:::external
        RO["RajaOngkir Service"]:::external
    end

    subgraph Infrastructure
        DB[(Database)]:::db
        DC["Docker Container"]:::infra
        PG["Pagination Utility"]:::util
    end

    %% Connections
    CL --> API
    API --> Auth
    Auth --> |Authenticated| BH & OH & UH & RH
    
    BH --> BS
    OH --> OS
    UH --> US
    RH --> OS

    BS --> BR
    OS --> OR
    US --> UR

    BR --> BM
    OR --> OM
    UR --> UM

    BR & OR & UR --> DB
    BS --> R2
    OS --> RO

    %% Click Events
    click API "https://github.com/febriaricandra/book-shop/blob/main/internal/routers/router.go"
    click Auth "https://github.com/febriaricandra/book-shop/blob/main/internal/middlewares/auth-middleware.go"
    click BH "https://github.com/febriaricandra/book-shop/blob/main/internal/handlers/book-handler.go"
    click OH "https://github.com/febriaricandra/book-shop/blob/main/internal/handlers/order-handler.go"
    click UH "https://github.com/febriaricandra/book-shop/blob/main/internal/handlers/user-handler.go"
    click RH "https://github.com/febriaricandra/book-shop/blob/main/internal/handlers/rajaongkir-handler.go"
    click BS "https://github.com/febriaricandra/book-shop/blob/main/internal/services/book-services.go"
    click OS "https://github.com/febriaricandra/book-shop/blob/main/internal/services/order-services.go"
    click US "https://github.com/febriaricandra/book-shop/blob/main/internal/services/user-services.go"
    click BR "https://github.com/febriaricandra/book-shop/blob/main/internal/repositories/book-repository.go"
    click OR "https://github.com/febriaricandra/book-shop/blob/main/internal/repositories/order-repository.go"
    click UR "https://github.com/febriaricandra/book-shop/blob/main/internal/repositories/user-repository.go"
    click BM "https://github.com/febriaricandra/book-shop/blob/main/internal/models/book_model.go"
    click OM "https://github.com/febriaricandra/book-shop/blob/main/internal/models/order_model.go"
    click UM "https://github.com/febriaricandra/book-shop/blob/main/internal/models/user_model.go"
    click DB "https://github.com/febriaricandra/book-shop/blob/main/pkg/db/db.go"
    click R2 "https://github.com/febriaricandra/book-shop/blob/main/config/r2.go"
    click DC "https://github.com/febriaricandra/book-shop/tree/main/Dockerfile"
    click PG "https://github.com/febriaricandra/book-shop/blob/main/internal/utils/pagination.go"

    %% Styles
    classDef router fill:#6495ED
    classDef middleware fill:#FF6B6B
    classDef handler fill:#4CAF50
    classDef service fill:#9C27B0
    classDef repo fill:#FF9800
    classDef model fill:#795548
    classDef external fill:#607D8B
    classDef db fill:#FFC107,stroke:#000
    classDef infra fill:#3F51B5
    classDef util fill:#8BC34A

    %% Legend
    subgraph Legend
        L1["API Component"]:::router
        L2["Middleware"]:::middleware
        L3["Handler"]:::handler
        L4["Service"]:::service
        L5["Repository"]:::repo
        L6["Model"]:::model
        L7["External Service"]:::external
        L8[(Database)]:::db
        L9["Infrastructure"]:::infra
        L10["Utility"]:::util
    end
```
