# zhxauda9/staymate architecture

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

- Interactive diagram: https://gitdiagram.com/zhxauda9/staymate
- Repository: https://github.com/zhxauda9/staymate

## Overview

##### Main Components

a) Client Layer:
- Web Interface (represented by the /web directory)
- External API Clients

b) Application Layer:
- HTTP Server (from internal/server)
- Handlers Layer (internal/handler)
- Service Layer (internal/service)
- Data Access Layer (internal/dal)

c) Infrastructure:
- PostgreSQL Database
- Logging System (internal/myLogger)
- Configuration Management (internal/config)
- Email Service (indicated by mail_handler.go and mail_service.go)

**[Client Layer]**
- ↓
**[HTTP Server Layer]**
- ↓
**[Handler Layer]**
- ↓
**[Service Layer]**
- ↓
**[Data Access Layer]**
- ↓
**[Database Layer]**

##### Component Relationships

- HTTP requests from clients to handlers
- Handler calls to services
- Service calls to repositories
- Repository interactions with the database
- Cross-cutting concerns like logging and configuration

##### Detailed Component Breakdown

- BookingHandler
- RoomHandler
- UserHandler
- MailHandler

- BookingService
- RoomService
- UserService
- MailService

- BookingRepository
- RoomRepository
- UserRepository

##### Technical Details

A technical stack sidebar showing:
- Go 1.22.3
- PostgreSQL
- GORM
- Zerolog

##### API Layer Details

REST endpoints grouped by resource:
- /bookings endpoints
- /rooms endpoints
- /user endpoints

##### Additional Notes

- Clean architecture pattern implementation
- Separation of concerns between layers
- Dependency injection flow
- Configuration points and environment variable usage

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        WebUI["Web Interface"]
        APIClient["API Client"]
        Templates["HTML Templates"]
    end

    subgraph Server
        HTTPServer["HTTP Server"]
        Router["Router & Middleware"]
    end

    subgraph Handlers
        BookingHandler["Booking Handler"]
        RoomHandler["Room Handler"]
        UserHandler["User Handler"]
        MailHandler["Mail Handler"]
    end

    subgraph Services
        BookingService["Booking Service"]
        RoomService["Room Service"]
        UserService["User Service"]
        MailService["Mail Service"]
    end

    subgraph DAL["Data Access Layer"]
        BookingRepo["Booking Repository"]
        RoomRepo["Room Repository"]
        UserRepo["User Repository"]
    end

    subgraph Infrastructure
        DB[(PostgreSQL)]
        Logger["Logger System"]
        Config["Configuration"]
    end

    subgraph Models
        BookingModel["Booking Model"]
        RoomModel["Room Model"]
        UserModel["User Model"]
    end

    %% Client Layer Connections
    WebUI --> HTTPServer
    APIClient --> HTTPServer
    Templates --> HTTPServer

    %% Server Layer Connections
    HTTPServer --> Router
    Router --> BookingHandler
    Router --> RoomHandler
    Router --> UserHandler
    Router --> MailHandler

    %% Handler to Service Connections
    BookingHandler --> BookingService
    RoomHandler --> RoomService
    UserHandler --> UserService
    MailHandler --> MailService

    %% Service to Repository Connections
    BookingService --> BookingRepo
    RoomService --> RoomRepo
    UserService --> UserRepo

    %% Repository to Database Connections
    BookingRepo --> DB
    RoomRepo --> DB
    UserRepo --> DB

    %% Model Connections
    BookingModel --> BookingService
    RoomModel --> RoomService
    UserModel --> UserService

    %% Infrastructure Connections
    Logger -.- HTTPServer
    Logger -.- Services
    Logger -.- DAL
    Config -.- HTTPServer
    Config -.- Services

    %% Click Events
    click WebUI "https://github.com/zhxauda9/StayMate/tree/main/web"
    click Templates "https://github.com/zhxauda9/StayMate/blob/main/web/bookings.html"
    click HTTPServer "https://github.com/zhxauda9/StayMate/blob/main/internal/server/server.go"
    click BookingHandler "https://github.com/zhxauda9/StayMate/blob/main/internal/handler/booking_handler.go"
    click RoomHandler "https://github.com/zhxauda9/StayMate/blob/main/internal/handler/room_handler.go"
    click UserHandler "https://github.com/zhxauda9/StayMate/blob/main/internal/handler/user_handler.go"
    click MailHandler "https://github.com/zhxauda9/StayMate/blob/main/internal/handler/mail_handler.go"
    click BookingService "https://github.com/zhxauda9/StayMate/blob/main/internal/service/booking_service.go"
    click RoomService "https://github.com/zhxauda9/StayMate/blob/main/internal/service/room_service.go"
    click UserService "https://github.com/zhxauda9/StayMate/blob/main/internal/service/user_service.go"
    click MailService "https://github.com/zhxauda9/StayMate/blob/main/internal/service/mail_service.go"
    click BookingRepo "https://github.com/zhxauda9/StayMate/blob/main/internal/dal/postgres/booking_repository.go"
    click RoomRepo "https://github.com/zhxauda9/StayMate/blob/main/internal/dal/postgres/room_repository.go"
    click UserRepo "https://github.com/zhxauda9/StayMate/blob/main/internal/dal/postgres/user_repository.go"
    click Logger "https://github.com/zhxauda9/StayMate/blob/main/internal/myLogger/logger.go"
    click Config "https://github.com/zhxauda9/StayMate/blob/main/internal/config/config.go"
    click BookingModel "https://github.com/zhxauda9/StayMate/blob/main/models/bookings.go"
    click RoomModel "https://github.com/zhxauda9/StayMate/blob/main/models/rooms.go"
    click UserModel "https://github.com/zhxauda9/StayMate/blob/main/models/users.go"

    classDef client fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef server fill:#90EE90,stroke:#333,stroke-width:2px
    classDef handler fill:#98FB98,stroke:#333,stroke-width:2px
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px
    classDef repository fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef infrastructure fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef model fill:#DDA0DD,stroke:#333,stroke-width:2px

    class WebUI,APIClient,Templates client
    class HTTPServer,Router server
    class BookingHandler,RoomHandler,UserHandler,MailHandler handler
    class BookingService,RoomService,UserService,MailService service
    class BookingRepo,RoomRepo,UserRepo repository
    class DB,Logger,Config infrastructure
    class BookingModel,RoomModel,UserModel model
```
