# kitabisa/buroq architecture

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

- Interactive diagram: https://gitdiagram.com/kitabisa/buroq
- Repository: https://github.com/kitabisa/buroq

## Overview

##### Main Components

a) API Layer:
- HTTP Server (using chi router)
- GraphQL Server
- Health Check Endpoint
- OpenAPI Specification (located in /api)

b) Core Application Components:
- Handler Layer
- Service Layer
- Repository Layer
- Cache Layer

c) Data Storage:
- MySQL Database
- PostgreSQL Database
- Redis Cache

d) Supporting Components:
- Migration System
- Seeding System
- Metrics Collection (InfluxDB - planned)

**┌─────────────────┐**
- Client Layer  │
- ┬────────┘
- ↓
**┌─────────────────┐**
- API Layer    │
- ┬────────┘
- ↓
**┌─────────────────┐**
- Service Layer  │
- ┬────────┘
- ↓
**┌─────────────────┐**
- Storage     │
- ┘

##### Detailed Component Representation

- Rectangles: Main service components
- Hexagons: External services/interfaces

- Blue: Core application components
- Green: Data storage
- Yellow: External interfaces
- Gray: Supporting systems

##### Component Relationships

Following flows:
- HTTP/GraphQL requests flow through the layers
- Database access patterns
- Cache interaction patterns
- Migration/Seeding flows

##### Key Architectural Patterns to Highlight

a) Clean Architecture Pattern:
- Clear separation between handlers, services, and repositories
- Demonstrate dependency flow from outer to inner layers

b) Repository Pattern:
- How the repository layer abstracts database operations
- Relationship between repositories and different database drivers

##### Implementation Details

**internal/app/**
- handler/
- service/
- repository/
- graphql/

##### Additional Elements

Annotations for:
- Configuration management
- Middleware chain
- Error handling flow
- Metrics collection points

##### Technical Stack Callouts

Technologies:
- Go-Chi Router
- GORP as ORM
- Redigo for Redis
- SQL-Migrate for migrations
- GraphQL implementation

Remember to include the planned/WIP features (like metrics and seeding) but mark them distinctly as future additions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph API_Layer
        HTTP[HTTP Server]:::server
        GQL[GraphQL Server]:::server
        HC[Health Check]:::server
        OAS[OpenAPI Spec]:::doc
    end

    subgraph Core_Components
        HL[Handler Layer]:::core
        SL[Service Layer]:::core
        RL[Repository Layer]:::core
        CL2[Cache Layer]:::core
    end

    subgraph Data_Storage
        MYSQL[(MySQL)]:::db
        PSQL[(PostgreSQL)]:::db
        REDIS[(Redis Cache)]:::db
    end

    subgraph Supporting_Systems
        MIG[Migration System]:::support
        SEED[Seeding System]:::support
        CONF[Configuration]:::support
        CTX[App Context]:::support
        REQRES[Request/Response]:::support
    end

    CL --> HTTP
    CL --> GQL
    
    HTTP --> HL
    GQL --> HL
    HC --> HL
    
    HL --> SL
    SL --> RL
    RL --> CL2
    
    CL2 --> REDIS
    RL --> MYSQL
    RL --> PSQL
    
    MIG --> MYSQL
    MIG --> PSQL
    SEED --> MYSQL
    SEED --> PSQL
    
    CONF --> CTX
    CTX --> HL

    %% Click Events
    click OAS "https://github.com/kitabisa/buroq/blob/master/api/buroq.yaml"
    click HTTP "https://github.com/kitabisa/buroq/blob/master/internal/app/server/router.go"
    click HC "https://github.com/kitabisa/buroq/blob/master/internal/app/handler/health_check.go"
    click GQL "https://github.com/kitabisa/buroq/blob/master/internal/app/graphql/init.go"
    click HL "https://github.com/kitabisa/buroq/blob/master/internal/app/handler/handler.go"
    click SL "https://github.com/kitabisa/buroq/blob/master/internal/app/service/service.go"
    click RL "https://github.com/kitabisa/buroq/blob/master/internal/app/repository/repository.go"
    click CL2 "https://github.com/kitabisa/buroq/blob/master/internal/app/repository/cache.go"
    click MYSQL "https://github.com/kitabisa/buroq/blob/master/internal/app/driver/mysql.go"
    click PSQL "https://github.com/kitabisa/buroq/blob/master/internal/app/driver/postgre.go"
    click REDIS "https://github.com/kitabisa/buroq/blob/master/internal/app/driver/redis.go"
    click MIG "https://github.com/kitabisa/buroq/blob/master/cmd/migration.go"
    click CONF "https://github.com/kitabisa/buroq/blob/master/config/config.go"
    click CTX "https://github.com/kitabisa/buroq/blob/master/internal/app/appcontext/appcontext.go"
    click REQRES "https://github.com/kitabisa/buroq/blob/master/internal/app/payload/request.go"

    classDef server fill:#6baed6,stroke:#2171b5
    classDef core fill:#74c476,stroke:#238b45
    classDef db fill:#fd8d3c,stroke:#d94701
    classDef support fill:#969696,stroke:#525252
    classDef doc fill:#9e9ac8,stroke:#6a51a3

    %% Legend
    subgraph Legend
        L1[API Components]:::server
        L2[Core Components]:::core
        L3[(Data Storage)]:::db
        L4[Support Systems]:::support
        L5[Documentation]:::doc
    end
```
