# zhashkevych/go-clean-architecture architecture

> Architecture diagram of the GitHub repository zhashkevych/go-clean-architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhashkevych/go-clean-architecture
- Repository: https://github.com/zhashkevych/go-clean-architecture

## Overview

##### Main Components

a) External Layer (Delivery):
- HTTP Handlers (auth & bookmark endpoints)
- Middleware (JWT authentication)

b) Use Case Layer:
- Auth Use Cases
- Bookmark Use Cases

c) Repository Layer:
- MongoDB Implementation
- Local Storage Implementation (for testing)

d) Core Domain Layer:
- User Model
- Bookmark Model

**┌─────────────────────────────────────────────┐**
- Delivery Layer (HTTP)                       │
- Auth Handlers                             │
- Bookmark Handlers                         │
- Middleware                                │
- ┤
- Use Case Layer                              │
- Auth Use Cases                            │
- Bookmark Use Cases                        │
- ┤
- Repository Layer                            │
- MongoDB Repositories                      │
- Local Storage Repositories                │
- ┤
- Domain Models                               │
- User                                      │
- Bookmark                                  │
- ┘

##### Key Elements to Highlight

a) Dependencies Flow:
- That inner layers don't depend on outer layers
- Use interfaces at boundaries between layers

b) External Components:
- MongoDB Database
- JWT Authentication System
- HTTP Server/Router

##### Important Details

a) API Endpoints:
- POST /auth/sign-up
- POST /auth/sign-in
- POST /api/bookmarks
- GET /api/bookmarks
- DELETE /api/bookmarks

b) Repository Implementations:
- Both MongoDB and Local Storage options
- Interface boundaries

c) Authentication Flow:
- JWT token generation and validation
- Middleware integration

##### Technical Stack Indicators

- Go 1.13
- MongoDB
- Docker/Docker Compose
- JWT Authentication

##### Database independence through repository interfaces

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions while avoiding implementation-specific details that don't contribute to understanding the system's structure.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        HTTP[HTTP Server]:::server
        click HTTP "https://github.com/zhashkevych/go-clean-architecture/blob/master/server/app.go"
        Main[Main Application]:::main
        click Main "https://github.com/zhashkevych/go-clean-architecture/blob/master/cmd/api/main.go"
        Config[Configuration]:::config
        click Config "https://github.com/zhashkevych/go-clean-architecture/blob/master/config/init.go"
    end

    subgraph "Delivery Layer"
        AuthHandler[Auth Handlers]:::handler
        click AuthHandler "https://github.com/zhashkevych/go-clean-architecture/blob/master/auth/delivery/http/handler.go"
        BookmarkHandler[Bookmark Handlers]:::handler
        click BookmarkHandler "https://github.com/zhashkevych/go-clean-architecture/blob/master/bookmark/delivery/http/handler.go"
        AuthMiddleware[JWT Middleware]:::middleware
        click AuthMiddleware "https://github.com/zhashkevych/go-clean-architecture/blob/master/auth/delivery/http/middleware.go"
    end

    subgraph "Use Case Layer"
        AuthUseCase[Auth Use Cases]:::usecase
        click AuthUseCase "https://github.com/zhashkevych/go-clean-architecture/blob/master/auth/usecase/usecase.go"
        BookmarkUseCase[Bookmark Use Cases]:::usecase
        click BookmarkUseCase "https://github.com/zhashkevych/go-clean-architecture/blob/master/bookmark/usecase/usecase.go"
    end

    subgraph "Repository Layer"
        MongoAuthRepo[MongoDB Auth Repository]:::repo
        click MongoAuthRepo "https://github.com/zhashkevych/go-clean-architecture/blob/master/auth/repository/mongo/user.go"
        MongoBookmarkRepo[MongoDB Bookmark Repository]:::repo
        click MongoBookmarkRepo "https://github.com/zhashkevych/go-clean-architecture/blob/master/bookmark/repository/mongo/bookmark.go"
        LocalAuthRepo[Local Storage Auth Repository]:::repo
        click LocalAuthRepo "https://github.com/zhashkevych/go-clean-architecture/blob/master/auth/repository/localstorage/user.go"
        LocalBookmarkRepo[Local Cache Bookmark Repository]:::repo
        click LocalBookmarkRepo "https://github.com/zhashkevych/go-clean-architecture/blob/master/bookmark/repository/localcache/bookmark.go"
    end

    subgraph "Domain Layer"
        UserModel[User Model]:::model
        click UserModel "https://github.com/zhashkevych/go-clean-architecture/blob/master/models/user.go"
        BookmarkModel[Bookmark Model]:::model
        click BookmarkModel "https://github.com/zhashkevych/go-clean-architecture/blob/master/models/bookmark.go"
    end

    subgraph "External Services"
        MongoDB[(MongoDB)]:::database
    end

    %% Connections
    Main --> HTTP
    HTTP --> Config
    HTTP --> AuthHandler
    HTTP --> BookmarkHandler
    
    AuthHandler --> AuthMiddleware
    BookmarkHandler --> AuthMiddleware
    
    AuthHandler --> AuthUseCase
    BookmarkHandler --> BookmarkUseCase
    
    AuthUseCase --> MongoAuthRepo
    AuthUseCase --> LocalAuthRepo
    BookmarkUseCase --> MongoBookmarkRepo
    BookmarkUseCase --> LocalBookmarkRepo
    
    MongoAuthRepo --> UserModel
    MongoBookmarkRepo --> BookmarkModel
    LocalAuthRepo --> UserModel
    LocalBookmarkRepo --> BookmarkModel
    
    MongoAuthRepo --> MongoDB
    MongoBookmarkRepo --> MongoDB

    %% Styles
    classDef server fill:#d4d4d4,stroke:#333,stroke-width:2px
    classDef main fill:#d4d4d4,stroke:#333,stroke-width:2px
    classDef config fill:#d4d4d4,stroke:#333,stroke-width:2px
    classDef handler fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef middleware fill:#b3e0ff,stroke:#333,stroke-width:2px
    classDef usecase fill:#b3ffb3,stroke:#333,stroke-width:2px
    classDef repo fill:#ffffb3,stroke:#333,stroke-width:2px
    classDef model fill:#ffb3b3,stroke:#333,stroke-width:2px
    classDef database fill:#e6e6e6,stroke:#333,stroke-width:2px
```
