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
Additional Resources
Optional S3 Setup
If you wish to enable S3 storage for your FlexPrice API, follow these steps to configure your AWS S3 access:1. Create an S3 Bucket
- Log in to your AWS Management Console.
- Navigate to the S3 service.
- Create a new bucket named
<YOUR BUCKET NAME>(or use an existing bucket). - Ensure that the bucket is in the desired region.
- It is highly recommended to disable public access to the bucket, the API generates presigned URLs in the response which can be used to download the invoice.
2. Configure Bucket Policy
To allow FlexPrice to access the S3 bucket, you need to set up a bucket policy. Use the following policy, remembering to replace the bucket name with the name of your bucket.3. Set Up AWS Credentials
Ensure that your AWS credentials are configured on the server where the FlexPrice API will run. You can set up your credentials in the~/.aws/credentials file as follows:
~/.aws/config file:
AWS_PROFILE environment variable to the profile name you just set up.
4. Configure the S3 Settings
Edit theinternal/config/config.yaml file and set the s3 section to the following:
5. Running the Application
Once you have configured the S3 bucket and set the necessary environment variables, you can start your FlexPrice API. The application will now be able to interact with the S3 bucket for storing and retrieving invoices.6. Troubleshooting
If you encounter issues with S3 access, check the following:- Ensure that the bucket policy is correctly applied to the bucket.
- Verify that your AWS credentials have the necessary permissions.
- Check the logs for any errors related to S3 operations.

