Sign inSign up

telemetryflow/order-service

By telemetryflow

Updated about 2 months ago

Order-Service (TelemetryFlow Generated with GO SDK RESTful API)

Image
Developer tools
Monitoring & observability
0

4.8K

telemetryflow/order-service repository overview

Order-Service

TelemetryFlow Logo

Version License Go Version OpenTelemetry Docker

[GENERATED TelemetryFlow SDK] Order-Service - RESTful API with DDD + CQRS Pattern


Architecture

This project follows Domain-Driven Design (DDD) with CQRS (Command Query Responsibility Segregation) pattern.

Order-Service/
├── cmd/
│   └── api/                    # Application entry point
├── internal/
│   ├── domain/                 # Domain Layer (Core Business Logic)
│   │   ├── entity/             # Domain entities
│   │   ├── repository/         # Repository interfaces
│   │   └── valueobject/        # Value objects
│   ├── application/            # Application Layer (Use Cases)
│   │   ├── command/            # Commands (write operations)
│   │   ├── query/              # Queries (read operations)
│   │   ├── handler/            # Command & Query handlers
│   │   └── dto/                # Data Transfer Objects
│   └── infrastructure/         # Infrastructure Layer
│       ├── persistence/        # Database implementations
│       ├── http/               # HTTP server & handlers
│       └── config/             # Configuration
├── pkg/                        # Shared packages
├── telemetry/                  # TelemetryFlow integration
├── config/                     # Service configurations
│   └── otel/                   # OpenTelemetry Collector config
├── docs/                       # Documentation
│   ├── api/                    # OpenAPI/Swagger specs
│   ├── diagrams/               # ERD, DFD diagrams
│   └── postman/                # Postman collections
├── migrations/                 # Database migrations
├── configs/                    # Application configuration files
└── tests/                      # Tests
    ├── unit/
    ├── integration/
    └── e2e/

Quick Start

Prerequisites
  • Go 1.22+
  • PostgreSQL 16+
  • Docker & Docker Compose (recommended)
Setup
  1. Clone the repository

  2. Copy environment file:

    cp .env.example .env
    
  3. Edit .env with your configuration

  4. Install dependencies:

    make deps
    
  5. Run migrations:

    make migrate-up
    
  6. Start the server:

    make run
    

Docker Compose

The easiest way to run the service with all dependencies:

# Start all services (PostgreSQL + API + OpenTelemetry Collector)
make docker-compose-up

# Or use profiles for selective startup
docker compose --profile all up -d        # Start everything
docker compose --profile db up -d         # Start only PostgreSQL
docker compose --profile app up -d        # Start only API
docker compose --profile monitoring up -d # Start only OTEL Collector

# Stop all services
make docker-compose-down

# View logs
docker logs -f order_service_api
docker logs -f order_service_postgres
docker logs -f order_service_otel
Services
ServiceContainerPortDescription
PostgreSQLorder_service_postgres5432Database
APIorder_service_api8080RESTful API
OTEL Collectororder_service_otel4317, 4318, 8889, 13133, 55679, 1777OpenTelemetry Collector
Jaegerorder_service_jaeger16686Distributed Tracing UI
OTEL Collector Ports
PortProtocolDescription
4317gRPCOTLP gRPC (v1 & v2)
4318HTTPOTLP HTTP (v1 & v2)
8889HTTPPrometheus metrics
13133HTTPHealth check
55679HTTPzPages (debugging)
1777HTTPpprof (profiling)
OTLP Endpoints (Dual Ingestion)

The collector supports both TelemetryFlow (v2) and OTEL Community (v1) endpoints:

TelemetryFlow Platform (Recommended):

POST http://localhost:4318/v2/traces
POST http://localhost:4318/v2/metrics
POST http://localhost:4318/v2/logs

OTEL Community (Backwards Compatible):

POST http://localhost:4318/v1/traces
POST http://localhost:4318/v1/metrics
POST http://localhost:4318/v1/logs

gRPC: localhost:4317 (both v1 and v2)

Network Configuration

All services run on a custom Docker network order_service_net with subnet 172.152.0.0/16:

ServiceIP Address
API172.152.152.10
PostgreSQL172.152.152.20
OTEL Collector172.152.152.30

Development

Running locally
# Build and run
make run

# Run with hot reload
make dev

# Run tests
make test

# Build binary
make build
Adding a new entity

Use the TelemetryFlow RESTful API Generator:

telemetryflow-restapi entity -n Product -f 'name:string,price:float64,stock:int'

This generates:

  • Domain entity
  • Repository interface & implementation
  • CQRS commands & queries
  • HTTP handlers
  • Database migration

API Documentation

DocumentationLocation
OpenAPI Specdocs/api/openapi.yaml
Swagger JSONdocs/api/swagger.json
ERD Diagramdocs/diagrams/ERD.md
DFD Diagramdocs/diagrams/DFD.md
Postman Collectiondocs/postman/collection.json
API Endpoints
MethodEndpointDescription
GET/healthHealth check
GET/api/v1/ordersList all orders
POST/api/v1/ordersCreate order
GET/api/v1/orders/:idGet order by ID
PUT/api/v1/orders/:idUpdate order
DELETE/api/v1/orders/:idDelete order
GET/api/v1/orderitemsList all order items
POST/api/v1/orderitemsCreate order item
GET/api/v1/orderitems/:idGet order item by ID
PUT/api/v1/orderitems/:idUpdate order item
DELETE/api/v1/orderitems/:idDelete order item

Configuration

Configuration is loaded from environment variables and .env file.

Application Configuration
VariableDescriptionDefault
SERVER_PORTHTTP server port8080
SERVER_READ_TIMEOUTRead timeout15s
SERVER_WRITE_TIMEOUTWrite timeout15s
ENVEnvironment (development/production)development
Database Configuration
VariableDescriptionDefault
DB_DRIVERDatabase driverpostgres
DB_HOSTDatabase hostlocalhost
DB_PORTDatabase port5432
DB_NAMEDatabase nameorders
DB_USERDatabase userpostgres
DB_PASSWORDDatabase password-
DB_SSL_MODESSL modedisable
DB_MAX_OPEN_CONNSMax open connections25
DB_MAX_IDLE_CONNSMax idle connections5
DB_CONN_MAX_LIFETIMEConnection max lifetime5m
JWT Configuration
VariableDescriptionDefault
JWT_SECRETJWT signing secret-
JWT_REFRESH_SECRETJWT refresh secret-
JWT_EXPIRATIONToken expiration24h
JWT_REFRESH_EXPIRATIONRefresh token expiration168h
TelemetryFlow / OpenTelemetry Configuration
VariableDescriptionDefault
TELEMETRYFLOW_API_KEY_IDTelemetryFlow API Key ID-
TELEMETRYFLOW_API_KEY_SECRETTelemetryFlow API Key Secret-
TELEMETRYFLOW_ENDPOINTOTLP endpointlocalhost:4317
TELEMETRYFLOW_SERVICE_NAMEService nameOrder-Service
TELEMETRYFLOW_SERVICE_VERSIONService version1.1.1
Docker Compose Configuration
VariableDescriptionDefault
POSTGRES_VERSIONPostgreSQL image version16-alpine
OTEL_VERSIONOTEL Collector image versionlatest
CONTAINER_POSTGRESPostgreSQL container nameorder_service_postgres
CONTAINER_APIAPI container nameorder_service_api
CONTAINER_OTELOTEL container nameorder_service_otel
PORT_OTEL_GRPCOTEL gRPC port4317
PORT_OTEL_HTTPOTEL HTTP port4318
PORT_OTEL_METRICSOTEL metrics port8889

Testing

# Run all tests
make test

# Run unit tests only
make test-unit

# Run integration tests
make test-integration

# Generate coverage report
make test-coverage

Docker

# Build image
make docker-build

# Run container
make docker-run

# Start all services (app + database + monitoring)
make docker-compose-up

# Stop all services
make docker-compose-down

Observability

The service is instrumented with OpenTelemetry for:

  • Traces: Distributed tracing for request flows
  • Metrics: Application and runtime metrics
  • Logs: Structured logging

The OpenTelemetry Collector receives telemetry data and can export to:

  • Jaeger (tracing)
  • Prometheus (metrics)
  • Any OTLP-compatible backend
Prometheus Metrics

Access metrics at: http://localhost:8889/metrics

License

Copyright (c) 2024-2026 TelemetryFlow. All rights reserved.

Tag summary

Content type

Image

Digest

sha256:30de7e8de

Size

21.7 MB

Last updated

about 2 months ago

docker pull telemetryflow/order-service