# dubjay18/qraven architecture

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

- Interactive diagram: https://gitdiagram.com/dubjay18/qraven
- Repository: https://github.com/dubjay18/qraven

## Overview

##### Main Components

A. API Layer
- Entry point through cmd/api/main.go
- REST endpoints organized by domain (auth, event, ticket)
- Swagger documentation integration (visible in docs directory)

B. Core Services Layer
- Authentication Service
- Event Service
- Ticket Service
- Payment Service
- Notification Service

C. Data Layer
- PostgreSQL Database
- Redis Cache

D. Middleware Layer
- Authorization
- Metrics
- Security
- Token Management

##### Component Relationships

**Client Requests**
- ↓
**API Gateway (Gin Framework)**
- ↓
**Middleware Layer**
- ↓
**Router Layer**
- ↓
**Controllers**
- ↓
**Services**
- ↓
**Repository Layer**
- ↙     ↘
**PostgreSQL  Redis**

##### Specific Implementation Details

- Rectangles: Core services (auth, event, ticket, payment, notification)
- Hexagons: Middleware components
- Rounded rectangles: Controllers and routers

- Blue: API and routing layers
- Green: Services
- Yellow: Middleware
- Red: Databases
- Purple: External services/utilities

##### Key Architectural Patterns to Highlight

A. Layer Separation:
- Clear separation between controllers, services, and repositories
- Repository pattern implementation for data access
- Service layer for business logic

B. Data Storage:
- PostgreSQL for persistent storage
- Redis for caching
- Different operations (CRUD) available in both storage types

##### Additional Elements

Supporting components:
- Configuration management (internal/config)
- Model definitions (internal/models)
- Utility functions (utils package)
- Migration handling (internal/models/migrations)

##### Flow Directions

- Request flow from client → API → Services → Data layer
- Response flow back to client
- Cache interaction flows
- Database transaction flows

**┌─ External Clients ─┐**
- REST / HTTP      │
- ┬────────┘
- ↓
**┌─── API Gateway ───┐**
- Gin Router     │
- ┬────────┘
- ↓
**┌─── Middleware ────┐**
- Auth | Metrics    │
- ┬────────┘
- ↓
**┌─── Controllers ───┐**
- Auth|Event|Ticket │
- ┬────────┘
- ↓
**┌──── Services ─────┐**
- Business Logic    │
- ┬────────┘
- ↓
**┌── Repository ─────┐**
- Data Access Layer │
- ┬─────┬─────┘
- ↓     ↓
- [PostgreSQL] [Redis]

##### Important Notes

- Clear boundaries between different layers
- Where middleware intercepts requests
- Caching strategy with Redis
- How authentication flows through the system
- Error handling flows
- Points of external service integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Requests]
    end

    subgraph API_Gateway
        API[API Entry Point]:::api
        DOCS[API Documentation]:::docs
        ROUTER[Router Layer]:::router
    end

    subgraph Middleware
        AUTH_MW[Authorization]:::middleware
        METRICS[Metrics]:::middleware
        SECURITY[Security]:::middleware
        TOKEN[Token Management]:::middleware
    end

    subgraph Controllers
        AUTH_C[Auth Controller]:::controller
        EVENT_C[Event Controller]:::controller
        TICKET_C[Ticket Controller]:::controller
    end

    subgraph Services
        AUTH_S[Authentication Service]:::service
        EVENT_S[Event Service]:::service
        TICKET_S[Ticket Service]:::service
        PAYMENT_S[Payment Service]:::service
        NOTIFY_S[Notification Service]:::service
    end

    subgraph Data_Layer
        subgraph Models
            USER_M[User Model]:::model
            EVENT_M[Event Model]:::model
            TICKET_M[Ticket Model]:::model
            PAYMENT_M[Payment Model]:::model
            NOTIFY_M[Notification Model]:::model
        end
        
        subgraph Storage
            POSTGRES[(PostgreSQL)]:::database
            REDIS[(Redis Cache)]:::database
        end
    end

    subgraph Configuration
        CONFIG[Main Config]:::config
        DB_CONFIG[Database Config]:::config
        SERVER_CONFIG[Server Config]:::config
    end

    subgraph Utils
        LOGGER[Logging]:::util
        PASSWORD[Password Handling]:::util
        RESPONSE[Response Handling]:::util
        VALIDATION[Validation]:::util
    end

    C --> API
    API --> ROUTER
    ROUTER --> |Routes Requests| AUTH_MW
    AUTH_MW --> METRICS
    METRICS --> SECURITY
    SECURITY --> TOKEN
    TOKEN --> AUTH_C & EVENT_C & TICKET_C
    
    AUTH_C --> AUTH_S
    EVENT_C --> EVENT_S
    TICKET_C --> TICKET_S
    
    AUTH_S & EVENT_S & TICKET_S & PAYMENT_S & NOTIFY_S --> POSTGRES
    AUTH_S & EVENT_S & TICKET_S & PAYMENT_S & NOTIFY_S --> REDIS

    classDef api fill:#1E88E5,stroke:#0D47A1,color:white
    classDef docs fill:#7E57C2,stroke:#4527A0,color:white
    classDef router fill:#42A5F5,stroke:#1976D2,color:white
    classDef middleware fill:#FFA726,stroke:#F57C00,color:white
    classDef controller fill:#66BB6A,stroke:#388E3C,color:white
    classDef service fill:#26A69A,stroke:#00796B,color:white
    classDef model fill:#EC407A,stroke:#C2185B,color:white
    classDef database fill:#EF5350,stroke:#D32F2F,color:white
    classDef config fill:#AB47BC,stroke:#7B1FA2,color:white
    classDef util fill:#8D6E63,stroke:#5D4037,color:white

    click API "https://github.com/Dubjay18/QRaven/blob/main/cmd/api/main.go"
    click DOCS "https://github.com/Dubjay18/QRaven/tree/main/docs/"
    click ROUTER "https://github.com/Dubjay18/QRaven/blob/main/pkg/router/router.go"
    click AUTH_S "https://github.com/Dubjay18/QRaven/blob/main/services/auth/authService.go"
    click EVENT_S "https://github.com/Dubjay18/QRaven/blob/main/services/event/eventService.go"
    click TICKET_S "https://github.com/Dubjay18/QRaven/blob/main/services/ticket/ticketService.go"
    click PAYMENT_S "https://github.com/Dubjay18/QRaven/blob/main/services/payment/paymentService.go"
    click NOTIFY_S "https://github.com/Dubjay18/QRaven/blob/main/services/notification/notificationService.go"
    click AUTH_C "https://github.com/Dubjay18/QRaven/blob/main/pkg/controller/auth/auth.go"
    click EVENT_C "https://github.com/Dubjay18/QRaven/blob/main/pkg/controller/event/event.go"
    click TICKET_C "https://github.com/Dubjay18/QRaven/blob/main/pkg/controller/ticket/ticket.go"
    click POSTGRES "https://github.com/Dubjay18/QRaven/tree/main/pkg/repository/storage/postgresql/"
    click REDIS "https://github.com/Dubjay18/QRaven/tree/main/pkg/repository/storage/redis/"
    click AUTH_MW "https://github.com/Dubjay18/QRaven/blob/main/pkg/middleware/authorize.go"
    click METRICS "https://github.com/Dubjay18/QRaven/blob/main/pkg/middleware/metrics.go"
    click SECURITY "https://github.com/Dubjay18/QRaven/blob/main/pkg/middleware/security.go"
    click TOKEN "https://github.com/Dubjay18/QRaven/blob/main/pkg/middleware/token.go"
    click USER_M "https://github.com/Dubjay18/QRaven/blob/main/internal/models/user.go"
    click EVENT_M "https://github.com/Dubjay18/QRaven/blob/main/internal/models/event.go"
    click TICKET_M "https://github.com/Dubjay18/QRaven/blob/main/internal/models/ticket.go"
    click PAYMENT_M "https://github.com/Dubjay18/QRaven/blob/main/internal/models/payments.go"
    click NOTIFY_M "https://github.com/Dubjay18/QRaven/blob/main/internal/models/notification.go"
    click CONFIG "https://github.com/Dubjay18/QRaven/blob/main/internal/config/config.go"
    click DB_CONFIG "https://github.com/Dubjay18/QRaven/blob/main/internal/config/databases.go"
    click SERVER_CONFIG "https://github.com/Dubjay18/QRaven/blob/main/internal/config/server.go"
    click LOGGER "https://github.com/Dubjay18/QRaven/blob/main/utils/logger.go"
    click PASSWORD "https://github.com/Dubjay18/QRaven/blob/main/utils/password.go"
    click RESPONSE "https://github.com/Dubjay18/QRaven/blob/main/utils/response.go"
    click VALIDATION "https://github.com/Dubjay18/QRaven/blob/main/utils/validation.go"
```
