# cp-rektmart/pic-me-pls-backend architecture

> Architecture diagram of the GitHub repository cp-rektmart/pic-me-pls-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cp-rektmart/pic-me-pls-backend
- Repository: https://github.com/cp-rektmart/pic-me-pls-backend

## Overview

##### Project type and purpose
- This is a Golang monolithic backend service (“Pic-me-pls-backend”) providing REST+WebSocket APIs for a photo‑sharing/booking platform.
- Key features: authentication (JWT), chat (real‑time via WebSocket), media upload & object storage, user/photographer management, package & quotation workflows, reviews, reporting, Stripe‑based payments.
- Deployed locally via Docker Compose (Postgres, Redis, optional MinIO), with code generation for DTOs & Swagger docs.

##### File structure
- cmd/main.go: application entry point
- internal/…: core business logic
- server/ (register routes & docs)
- middlewares/ (auth, logging)
- services/ (one subfolder per domain: auth, user, category, media, message/chat, quotation, packages, review, report, stripe, etc.)
- database/store.go: persistence interface
- model + dto: domain models vs external data contracts
- jwt, validator, config, utils (pagination, etc.)
- pkg/…: shared infrastructure abstractions
- postgres, redis, storage, httpclient, logger, apperror, requestlogger
- doc/: Swagger/OpenAPI specs
- Dockerfile, docker-compose.yml, .env.docker: containerized infra

##### README for additional insights
- Confirms Docker Compose for Postgres/Redis
- “air” for hot‑reload, Makefile targets
- Pre‑commit, linting & codegen steps

##### Relationships & interactions
- Client → HTTP/WS → API Layer → Service → Persistence/Cache/Storage/External
- Service implementations depend on store interfaces (dependency inversion)
- Media & object flows go to object storage
- Real‑time chat uses WebSocket endpoint + Redis/pub‑sub or DB back‑end
- Stripe API calls for payment flows

##### Architectural patterns & principles
- Clean/Hexagonal architecture: clear separation between
- Adapters (HTTP, WebSocket)
- Use‑cases (services)
- Ports (store interfaces)
- Infrastructure (Postgres, Redis, Storage, Stripe client)
- DTOs shield internal models from API contracts
- Middlewares handle cross‑cutting concerns (auth, logging)

##### Detail
- Break out each major service folder rather than lumping “business logic” together
- Middleware pipeline before reaching route handlers
- Config loader & JWT signer as foundational components

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients" 
        direction TB
        ClientApps["Web/Mobile Clients"]:::external
    end

    %% API & Adapter Layer
    subgraph "API Layer" 
        direction TB
        Server["HTTP Server"]:::api
        Middleware["Middleware Chain"]:::api
        ConfigLoader["Config Loader"]:::api
        JWTGen["JWT Generator/Parser"]:::api
        Validator["Request Validator"]:::api
        DTOs["DTOs"]:::api
        Swagger["Swagger Docs"]:::api
    end

    ClientApps -->|"HTTP/WS"| Server
    Server -->|calls| Middleware
    Middleware -->|uses| ConfigLoader
    ConfigLoader -->|loads| JWTGen
    JWTGen -->|parses/signs| Validator
    Validator -->|validates| DTOs
    Server -->|serves specs| Swagger

    %% Service Layer
    subgraph "Use-Case Services" 
        direction TB
        AuthService["Authentication Service"]:::service
        UserService["User Service"]:::service
        CategoryService["Category Service"]:::service
        MediaService["Media Service"]:::service
        ChatService["Chat/Message Service"]:::service
        QuotationService["Quotation Service"]:::service
        PackageService["Package Service"]:::service
        ReviewService["Review Service"]:::service
        ReportService["Report Service"]:::service
        StripeService["Stripe Service"]:::service
    end

    Middleware --> AuthService
    Middleware --> UserService
    Middleware --> CategoryService
    Middleware --> MediaService
    Middleware --> ChatService
    Middleware --> QuotationService
    Middleware --> PackageService
    Middleware --> ReviewService
    Middleware --> ReportService
    Middleware --> StripeService

    %% Ports & Infrastructure
    StoreInterface["Persistence Interface"]:::infra
    Logger["Logger"]:::infra
    HTTPClient["HTTP Client"]:::infra
    AppError["App Error Handling"]:::infra

    AuthService -->|SQL/Cache| StoreInterface
    UserService -->|SQL| StoreInterface
    CategoryService -->|SQL| StoreInterface
    MediaService -->|SQL| StoreInterface
    MediaService -->|S3 PUT/GET| ObjectStorage
    ChatService -->|Pub/Sub| Redis
    ChatService -->|SQL| StoreInterface
    QuotationService -->|SQL| StoreInterface
    PackageService -->|SQL| StoreInterface
    ReviewService -->|SQL| StoreInterface
    ReportService -->|SQL| StoreInterface
    StripeService -->|HTTPS| StripeAPI
    StripeService -->|logs/errors| AppError

    %% Data Stores
    subgraph "Data Stores" 
        direction TB
        Postgres["PostgreSQL"]:::data
        Redis["Redis"]:::data
        ObjectStorage["S3/MinIO"]:::data
    end

    StoreInterface -->|connects| Postgres
    Redis -->|cache/pubsub| ChatService
    ObjectStorage -->|stores media| MediaService

    %% External Services
    subgraph "External Services"
        direction TB
        StripeAPI["Stripe API"]:::external
    end

    StripeAPI -->|webhooks| Server

    %% Shared Infra Dependencies
    AuthService --> Logger
    UserService --> Logger
    CategoryService --> Logger
    MediaService --> Logger
    ChatService --> Logger
    QuotationService --> Logger
    PackageService --> Logger
    ReviewService --> Logger
    ReportService --> Logger
    StripeService --> Logger
    StripeService --> HTTPClient

    %% Code Generation & Docs
    subgraph "Codegen & Documentation"
        direction TB
        Generate["generate.go"]:::infra
        SwaggerFile["swagger.yaml"]:::infra
    end

    Generate --> DTOs
    Generate --> Swagger

    %% Entry Point & Deployment
    Entry["Application Entry (cmd/main.go)"]:::infra
    Entry --> Server

    subgraph "Docker Compose"
        direction TB
        Compose["docker-compose.yml/.env.docker"]:::infra
        Dockerfile["Dockerfile"]:::infra
    end

    Entry --> Compose
    Compose --> Postgres
    Compose --> Redis
    Compose --> ObjectStorage

    %% Click events
    click Server "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/server/server.go"
    click Server "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/server/register_routes.go"
    click Middleware "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/middlewares/authentication/auth.go"
    click AuthService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/auth"
    click UserService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/user"
    click CategoryService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/category"
    click MediaService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/media"
    click ChatService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/message"
    click ChatService "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/chat/chat.go"
    click QuotationService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/quotation"
    click PackageService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/packages"
    click ReviewService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/review"
    click ReportService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/report"
    click StripeService "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/services/stripe"
    click StoreInterface "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/database/store.go"
    click Postgres "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/pkg/postgres/postgres.go"
    click Redis "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/pkg/redis/redis.go"
    click ObjectStorage "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/pkg/storage/storage.go"
    click Logger "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/pkg/logger/logger.go"
    click HTTPClient "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/pkg/httpclient/httpclient.go"
    click AppError "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/pkg/apperror/apperror.go"
    click ConfigLoader "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/config/config.go"
    click JWTGen "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/jwt/jwt.go"
    click Validator "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/validator/validator.go"
    click DTOs "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/internal/dto"
    click SwaggerFile "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/doc/swagger.yaml"
    click Swagger "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/internal/server/register_docs.go"
    click Generate "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/generate.go"
    click Entry "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/cmd/main.go"
    click Compose "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/docker-compose.yml"
    click Compose "https://github.com/cp-rektmart/pic-me-pls-backend/blob/main/.env.docker"
    click Dockerfile "https://github.com/cp-rektmart/pic-me-pls-backend/tree/main/Dockerfile"

    %% Styles
    classDef api fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef service fill:#DFF6E0,stroke:#28A745,color:#155724;
    classDef data fill:#FFEDCC,stroke:#E36209,color:#51300A, stroke-dasharray: 5 5;
    classDef infra fill:#F0F0F0,stroke:#6A737D,color:#24292E;
    classDef external fill:#E8E8E8,stroke:#8C8C8C,color:#333333;
```
