Prerequisites
- Golang
- Docker and Docker Compose
- Supported platforms:
- Linux-based environment
- macOS (Darwin)
- WSL under Windows
Quick Setup with Docker Compose
The easiest way to get started is using our Docker Compose setup:- Start all required infrastructure (PostgreSQL, Kafka, ClickHouse, Temporal)
- Build the Flexprice application image
- Run database migrations and initialize Kafka
- Start all Flexprice services (API, Consumer, Worker)
Accessing Services
Once setup is complete, you can access:- Flexprice API: http://localhost:8080
- Temporal UI: http://localhost:8088
- Kafka UI: http://localhost:8084 (with profile ‘dev’)
- ClickHouse UI: http://localhost:8123
Useful Commands
Running Without Docker
If you prefer to run the application directly:Project Structure
Flexprice follows a clean architecture pattern with clear separation of concerns:Layer Responsibilities
Domain Layer
- Contains core business logic and domain models
- Defines interfaces for repositories
- No dependencies on external packages or other layers
Repository Layer
- Implements data access interfaces defined in domain
- Handles database operations
Service Layer
- Orchestrates business operations
- Implements business logic
- Uses repository interfaces for data access
- Handles cross-cutting concerns
API Layer
- Handles HTTP requests/responses
- Converts between DTOs and domain models
- No business logic, only request validation and response formatting
Key Design Principles
- Dependency Rule: Dependencies only point inward. Domain layer has no outward dependencies.
- Interface Segregation: Repository interfaces are defined in domain layer but implemented in repository layer.
- Dependency Injection: Using fx for clean dependency management.
- Separation of Concerns: Each layer has a specific responsibility.
Example Flow
For an event ingestion:- API Layer (
/api/v1/events.go) receives HTTP request - Converts DTO to domain model
- Calls service layer
- Service layer (
/service/event_service.go) handles business logic - Repository layer persists data
- Response flows back through the layers
Adding New Features
- Define domain models and interfaces in domain layer
- Implement repository interfaces if needed
- Add service layer logic
- Create API handlers and DTOs
- Register routes and dependencies
Testing
We usetestutil package to create test data and setup test environment.
Testing Guidelines
Unit Tests
- Each package should have corresponding
*_test.gofiles - Use table-driven tests when testing multiple scenarios
- Mock external dependencies using interfaces
- Aim for >80% test coverage for critical paths
Integration Tests
- Place integration tests in a separate
integrationpackage - Use test containers for database tests
- Integration tests should use the same config structure as production
Running Tests
Use the following make commands:Development Credentials
PostgreSQL
- Host: localhost
- Port: 5432
- Database: flexprice
- Username: flexprice
- Password: flexprice123
ClickHouse
- Host: localhost
- Port: 9000
- Database: flexprice
- Username: flexprice
- Password: flexprice123
Kafka
- Bootstrap Server: localhost:29092
- UI: http://localhost:8084 (with profile ‘dev’)
API Documentation
The API documentation is available in OpenAPI 3.0 format atdocs/swagger/swagger-3-0.json.
Setting up Postman Collection
- Open Postman
- Click on “Import” in the top left
- Select “Import File”
-
Choose
docs/swagger/swagger-3-0.json - Click “Import”
-
Create a new environment for local development:
- Name: Local
-
Variable:
baseUrl -
Initial Value:
http://localhost:8080/v1 -
Current Value:
http://localhost:8080/v1 -
Variable:
apiKey -
Initial Value:
0cc505d7b917e0b1f25ccbea029dd43f4002edfea46b7f941f281911246768fe -
Current Value:
0cc505d7b917e0b1f25ccbea029dd43f4002edfea46b7f941f281911246768fe
Troubleshooting
Docker Issues
- Ensure Docker is running properly:
- Check the status of all containers:
- View logs for a specific service:
Database Connection Issues
- Check database logs:
- Verify the database is running:
Kafka Issues
- Verify Kafka is running:
- Check topic list:
- View Kafka UI at http://localhost:8084

