| layout | default |
|---|---|
| title | Development |
| nav_order | 8 |
| description | Development and contribution guide for SwiftLog |
Guide for developers who want to contribute to SwiftLog or modify it for their needs.
- Go 1.21+ - Backend services and CLI
- Node.js 20+ - Frontend development
- Docker 24+ & Docker Compose v2+ - Local infrastructure
- Protocol Buffers - gRPC code generation
- Git - Version control
- Make - Build automation
macOS:
brew install protobuf
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestLinux:
# Ubuntu/Debian
sudo apt install -y protobuf-compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestWindows:
# Using chocolatey
choco install protoc
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestswiftlog/
├── backend/ # Go backend services
│ ├── cmd/ # Service entry points
│ │ ├── ingestor/ # gRPC log ingestor
│ │ ├── api/ # REST API server
│ │ ├── websocket/ # WebSocket server
│ │ └── ai-worker/ # AI analysis worker
│ ├── internal/ # Internal packages
│ │ ├── auth/ # Authentication
│ │ ├── database/ # Database connection
│ │ ├── models/ # Data models
│ │ ├── repository/ # Data access layer
│ │ ├── loki/ # Loki client
│ │ ├── ingestor/ # Ingestor logic
│ │ ├── websocket/ # WebSocket hub
│ │ └── ai/ # AI analyzer
│ ├── migrations/ # SQL migrations
│ ├── proto/ # Protobuf definitions
│ └── go.mod # Go dependencies
├── cli/ # CLI tool
│ ├── cmd/ # CLI commands
│ ├── internal/ # CLI internals
│ └── proto/ # Generated protobuf code
├── frontend/ # Next.js frontend
│ ├── src/ # Source code
│ │ ├── app/ # Next.js 14 App Router
│ │ ├── components/ # React components
│ │ └── lib/ # Utilities
│ └── package.json # Node dependencies
├── docs/ # Documentation
├── tests/ # Integration tests
├── docker-compose.yaml # Production deployment
├── docker-compose.dev.yaml # Development deployment
├── Makefile # Build automation
└── .env.example # Environment template
git clone https://github.com/aliancn/swiftlog.git
cd swiftlog# Copy environment template
cp .env.example .env
# Edit for development
nano .envMinimal development configuration:
ENVIRONMENT=development
LOG_LEVEL=debug
POSTGRES_PASSWORD=devpassword
JWT_SECRET=dev-jwt-secret-at-least-32-chars-long
ENCRYPTION_KEY=dev-encryption-key-32-chars-abcStart only the infrastructure services (PostgreSQL, Loki, Redis):
make dev-upThis starts:
- PostgreSQL on port 5432
- Loki on port 3100
- Redis on port 6379
Open multiple terminal windows and run each service:
Terminal 1 - Ingestor:
cd backend/cmd/ingestor
go run main.goTerminal 2 - API:
cd backend/cmd/api
go run main.goTerminal 3 - WebSocket:
cd backend/cmd/websocket
go run main.goTerminal 4 - AI Worker:
cd backend/cmd/ai-worker
go run main.go- Define the route in
backend/cmd/api/main.go:
api := r.Group("/api/v1")
api.Use(authMiddleware)
{
api.GET("/your-endpoint", handlers.YourHandler)
}- Create the handler in
backend/internal/handlers/:
package handlers
func YourHandler(c *gin.Context) {
// Your logic here
c.JSON(200, gin.H{"message": "success"})
}- Add repository methods in
backend/internal/repository/if needed.
- Create directory:
backend/cmd/your-service/ - Create
main.gowith service logic - Add Dockerfile:
backend/Dockerfile.your-service - Update
docker-compose.yaml
# Backend tests
cd backend
go test ./...
# Run with coverage
go test -cover ./...
# Run specific package
go test ./internal/auth/...Go:
- Follow standard Go conventions
- Use
gofmtfor formatting - Use
golintfor linting
# Format code
gofmt -w .
# Run linter
golint ./...
# Run vet
go vet ./...cd frontend
# Install dependencies
npm install
# Start development server
npm run devFrontend will be available at http://localhost:3000.
frontend/src/
├── app/ # Next.js 14 App Router
│ ├── layout.tsx # Root layout
│ ├── page.tsx # Home page
│ ├── projects/ # Projects pages
│ └── runs/ # Runs pages
├── components/ # React components
│ ├── LogViewer.tsx # Log display component
│ ├── ProjectList.tsx # Project list
│ └── ...
└── lib/ # Utilities
├── api.ts # API client
└── utils.ts # Helper functions
- Create file in
frontend/src/app/your-page/page.tsx:
export default function YourPage() {
return <div>Your content</div>;
}- Add navigation link in layout or components.
- Create file in
frontend/src/components/YourComponent.tsx:
export function YourComponent() {
return <div>Your component</div>;
}- Import and use in pages:
import { YourComponent } from '@/components/YourComponent';# Run tests
npm test
# Run with coverage
npm test -- --coverage
# Type checking
npm run type-checkTypeScript/React:
- Use TypeScript for type safety
- Follow ESLint rules
- Use Prettier for formatting
# Lint code
npm run lint
# Format code
npm run formatcd cli
# Build
go build -o swiftlog
# Install locally
make cli# Configure CLI
./swiftlog config set --token test-token --server localhost:50051
# Test run command
./swiftlog run --project test --group dev -- echo "Hello"cli/
├── cmd/
│ ├── root.go # Root command
│ ├── run.go # Run command
│ ├── config.go # Config command
│ └── version.go # Version command
├── internal/
│ ├── config/ # Config management
│ │ └── config.go
│ └── client/ # gRPC client
│ └── client.go
└── proto/ # Generated protobuf
When you modify .proto files:
Backend:
cd backend
protoc --go_out=. --go-grpc_out=. proto/ingestor.protoCLI:
cd cli
protoc --go_out=. --go-grpc_out=. proto/ingestor.proto- Source:
backend/proto/ingestor.proto - Generated (backend):
backend/proto/*.pb.go - Generated (CLI):
cli/proto/*.pb.go
- Create file in
backend/migrations/:
-- backend/migrations/006_add_your_table.sql
CREATE TABLE IF NOT EXISTS your_table (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);- Update
backend/migrations/init.sqlto include your migration.
Migrations are automatically run on startup via Docker's docker-entrypoint-initdb.d.
For manual migration:
docker compose exec postgres psql -U swiftlog -d swiftlog -f /docker-entrypoint-initdb.d/006_add_your_table.sql# Build all images
make build
# Build specific service
docker compose build api
# Build with no cache
docker compose build --no-cache# All services
docker compose logs -f
# Specific service
docker compose logs -f api
# Last 100 lines
docker compose logs --tail=100 api# PostgreSQL shell
docker compose exec postgres psql -U swiftlog -d swiftlog
# Redis CLI
docker compose exec redis redis-cli
# Check Loki
curl http://localhost:3100/readyRun the included test suite:
cd tests
./run_all_tests.shIndividual tests:
./cli/swiftlog run --project test --group simple -- bash tests/01_simple_test.sh- Create test script in
tests/:
#!/bin/bash
echo "Running test..."
exit 0- Make executable:
chmod +x tests/05_your_test.sh- Add to
tests/run_all_tests.sh.
Use Delve debugger:
# Install Delve
go install github.com/go-delve/delve/cmd/dlv@latest
# Debug API service
cd backend/cmd/api
dlv debug
# Run with breakpoints
(dlv) break main.main
(dlv) continueCreate .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug API",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/backend/cmd/api",
"env": {
"LOG_LEVEL": "debug"
}
}
]
}# Backend service logs
docker compose logs -f api
# Database queries (if logging enabled)
docker compose logs -f postgres
# All logs
docker compose logs -fmain- Stable production branchdevelop- Development branchfeature/*- Feature branchesbugfix/*- Bug fix branches
Follow conventional commits:
feat: add new API endpoint for user settings
fix: resolve database connection leak
docs: update CLI documentation
refactor: simplify authentication logic
test: add integration tests for API
- Create feature branch:
git checkout -b feature/your-feature- Make changes and commit:
git add .
git commit -m "feat: add your feature"- Push and create PR:
git push origin feature/your-feature- Wait for review and CI checks.
make help # Show all commands
make dev-up # Start infrastructure only
make dev-down # Stop infrastructure
make start # Start all services
make stop # Stop all services
make restart # Restart all services
make build # Build all Docker images
make cli # Build CLI tool
make clean # Remove containers and volumes
make logs # View all logs
make test # Run tests- Create feature branch
- Add backend endpoint/logic
- Update frontend UI
- Add tests
- Update documentation
- Create PR
- Reproduce the bug
- Create bugfix branch
- Fix the issue
- Add test to prevent regression
- Create PR
Backend:
cd backend
go get -u ./...
go mod tidyFrontend:
cd frontend
npm update
npm audit fixCLI:
cd cli
go get -u ./...
go mod tidySwiftLog uses GitHub Actions for CI/CD. See .github/workflows/:
release.yml- Build and releasedeploy.yml- Deploy to serverstest.yml- Run tests (future)
Use act to test workflows locally:
# Install act
brew install act
# Run workflow
act pushWhen reviewing PRs:
- Functionality - Does it work as intended?
- Tests - Are there tests?
- Documentation - Is it documented?
- Code Quality - Is it clean and maintainable?
- Security - Are there security concerns?
- Performance - Are there performance implications?