Development Setup
Prerequisites
Install the following tools:
Go 1.21+
bash
# Linux
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
# macOS
brew install goDocker & Docker Compose
bash
# Linux
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# macOS
brew install --cask dockerbuf (Protocol Buffer tool)
bash
go install github.com/bufbuild/buf/cmd/buf@latestsqlc (SQL code generation)
bash
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latestNode.js 18+
bash
# Using nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 18
# Or using homebrew
brew install node@18uv (Python package manager)
bash
curl -LsSf https://astral.sh/uv/install.sh | shProject Structure
shinkansen-commerce/
├── proto/ # Protocol Buffers (source of truth)
│ ├── product/ # Product service definitions
│ ├── order/ # Order service definitions
│ ├── user/ # User service definitions
│ ├── payment/ # Payment service definitions
│ ├── inventory/ # Inventory service definitions
│ ├── delivery/ # Delivery service definitions
│ └── shared/ # Shared types
│
├── services/ # Service implementations
│ ├── gateway/ # HTTP API gateway
│ ├── product-service/ # Product catalog (Go)
│ ├── order-service/ # Order management (Go)
│ ├── user-service/ # User auth (Go)
│ ├── payment-service/ # Payment processing (Go)
│ ├── inventory-service/ # Stock management (Rust)
│ ├── delivery-service/ # Delivery logistics (Go)
│ └── analytics-worker/ # Data processing (Python)
│
├── gen/ # Generated code
│ └── proto/go/ # Go protobuf code
│
├── deploy/ # Deployment configs
│ ├── docker-compose.yml # Local development
│ ├── k8s/ # Kubernetes manifests
│ └── terraform/ # Infrastructure as code
│
├── docs/ # Documentation (VitePress)
├── scripts/ # Utility scripts
└── Makefile # Build automationQuick Start
1. Clone Repository
bash
git clone https://github.com/afasari/shinkansen-commerce.git
cd shinkansen-commerce2. Start Infrastructure
bash
make upThis starts PostgreSQL, Redis, and Kafka.
3. Generate Code
bash
make genGenerates:
- Go protobuf code from proto files
- SQL code from sqlc
- OpenAPI specs from proto files
4. Build Services
bash
make build-allBuilds all 7 services to bin/ directory.
5. Run Services
bash
# Option 1: Run all in Docker
make up
# Option 2: Run locally (requires infrastructure running)
./bin/gateway &
./bin/product-service &
./bin/order-service &
./bin/user-service &
./bin/payment-service &
./bin/inventory-service &
./bin/delivery-service &6. Test
bash
make test-integrationWorking with Protobufs
Add New Message Type
protobuf
// proto/product/product_messages.proto
message NewProductRequest {
string name = 1;
string description = 2;
shinkansen.common.Money price = 3;
}Add New RPC Method
protobuf
// proto/product/product_service.proto
service ProductService {
rpc GetFeaturedProducts(GetFeaturedProductsRequest) returns (GetFeaturedProductsResponse) {
option (google.api.http) = {
get: "/v1/products/featured"
};
}
}Regenerate Code
bash
make proto-genRegenerate OpenAPI Docs
bash
make proto-openapi-genWorking with Database Migrations
Add New Migration
sql
-- services/product-service/internal/migrations/001_new_table.sql
CREATE TABLE catalog.new_table (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL
);Run Migrations
bash
make db-migrateRollback Migration
bash
make db-rollbackRunning Tests
Unit Tests (Single Service)
bash
cd services/product-service
go test ./... -v -coverAll Unit Tests
bash
make testIntegration Tests
bash
make test-integrationTest with Coverage
bash
make test-coverageLocal Documentation
Generate API Docs
bash
make proto-openapi-genAccess Swagger UI at http://localhost:8080/swagger/
Run VitePress Dev Server
bash
cd docs
npm install
npm run devAccess documentation at http://localhost:5173
Environment Variables
Service configurations use environment variables. Create .env file:
bash
# Database
DATABASE_URL=postgres://shinkansen:shinkansen_dev_password@localhost:5432/shinkansen?sslmode=disable
# Redis
REDIS_URL=redis://localhost:6379
# JWT
JWT_SECRET=your-secret-key-change-in-production
# Service Addresses
PRODUCT_SERVICE_GRPC_ADDRESS=localhost:9091
ORDER_SERVICE_GRPC_ADDRESS=localhost:9092
USER_SERVICE_GRPC_ADDRESS=localhost:9103
PAYMENT_SERVICE_GRPC_ADDRESS=localhost:9104
INVENTORY_SERVICE_GRPC_ADDRESS=localhost:9105
DELIVERY_SERVICE_GRPC_ADDRESS=localhost:9106Debugging
View Service Logs
bash
# All services
make logs
# Specific service
docker-compose logs product-serviceConnect to PostgreSQL
bash
docker exec -it shinkansen-postgres psql -U shinkansen -d shinkansenConnect to Redis
bash
docker exec -it shinkansen-redis redis-cligRPC Debugging
bash
# List all gRPC methods
grpcurl -plaintext localhost:9091 list shinkansen.product.ProductService
# Call gRPC method
grpcurl -plaintext -d '{"page":1,"limit":20}' localhost:9091 shinkansen.product.ProductService/ListProductsCommon Issues
Port Already in Use
bash
# Find what's using the port
lsof -i :8080
# Kill the process
kill -9 <PID>Database Connection Failed
bash
# Check PostgreSQL is running
docker-compose ps postgres
# Check PostgreSQL logs
docker-compose logs postgres
# Restart PostgreSQL
docker-compose restart postgresBuild Errors
bash
# Clean and rebuild
make clean-all
make init-deps
make build-allIDE Setup
VS Code
Recommended extensions:
- Go (Google)
- Protobuf (pbkit.pro)
- Docker
- VitePress
- Mermaid Preview
GoLand (JetBrains)
- Open project as Go module
- Enable Go modules integration
- Configure workspace
Development Workflow
mermaid
graph LR
A[Edit Proto] --> B[Regenerate Code]
B --> C[Write Tests]
C --> D[Run Tests]
D --> E{Pass?}
E -->|Yes| F[Commit]
E -->|No| A