A modern, scalable, and production-ready backend API built with Go. Designed for enterprise-grade applications with a focus on performance, reliability, and developer experience.
Features β’ Quick Start β’ Architecture β’ Documentation
|
|
|
|
- Go 1.25.5 or higher
- Docker & Docker Compose (optional, for containerized development)
- PostgreSQL 17+ for database
- Redis 7+ for caching
- RabbitMQ 3.12+ for message queue (optional)
-
Clone the repository
git clone https://github.com/Harmeet10000/Fortress_API.git cd Fortress_API -
Set up environment variables
cp .env.example .env.dev # Edit .env.dev with your configuration -
Start services with Docker Compose
docker-compose up -d
-
Run database migrations
make migrate-up
-
Start the API server
make dev
The API will be available at http://localhost:8080
Fortress_API/
βββ src/
β βββ cmd/ # Entry points
β β βββ api/ # Main API server
β β βββ migrate/ # Migration utilities
β β βββ workers/ # Background workers
β βββ internal/ # Private application code
β βββ config/ # Configuration management
β βββ connections/ # Database & service connections
β βββ db/ # Database layer
β β βββ migrations/ # Goose migrations
β β βββ schema/ # SQLc generated code
β β βββ seeders/ # Database seeders
β βββ features/ # Feature modules
β β βββ controllers/ # HTTP handlers
β β βββ services/ # Business logic
β β βββ repository/ # Data access layer
β β βββ models/ # Domain models
β β βββ routes/ # Route definitions
β β βββ validations/ # Input validation
β β βββ controllers/ # HTTP handlers
β βββ middlewares/ # HTTP middleware (auth, logging, etc.)
β βββ helpers/ # Utility functions
β βββ utils/ # Common utilities
βββ pkg/ # Public packages
βββ tests/ # Test suites
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ e2e/ # End-to-end tests
β βββ performance/ # Performance benchmarks
βββ infra/ # Infrastructure as Code
β βββ aws/ # AWS CloudFormation/Terraform
β βββ azure/ # Azure Resource Manager templates
β βββ gcp/ # Google Cloud Deployment Manager
βββ docker/ # Docker configuration
βββ scripts/ # Utility scripts
βββ certs/ # SSL/TLS certificates
βββ docs/ # API documentation
Fortress API follows a clean, layered architecture pattern for optimal separation of concerns:
βββββββββββββββββββββββββββββββββββββββββββ
β HTTP Layer (Echo) β
β Controllers & Request/Response β
βββββββββββββββββββββββββββββββββββββββββββ€
β Business Logic Layer β
β Services & Domain Logic β
βββββββββββββββββββββββββββββββββββββββββββ€
β Data Access Layer β
β Repositories & SQLc Queries β
βββββββββββββββββββββββββββββββββββββββββββ€
β Database Layer β
β PostgreSQL + pgx driver β
βββββββββββββββββββββββββββββββββββββββββββ
- Separation of Concerns: Each layer has a single, well-defined responsibility
- Dependency Injection: All dependencies wired through Uber FX
- Type Safety: Leverages Go's type system and SQLc for compile-time guarantees
- Error Handling: Comprehensive error wrapping with context
- Testability: Interfaces and dependency injection enable easy testing
| Component | Technology | Purpose |
|---|---|---|
| Framework | Echo | Lightweight, high-performance HTTP server |
| Database | PostgreSQL + pgx | Reliable relational database |
| SQL Generation | SQLc | Type-safe SQL code generation |
| Migrations | Goose | Database schema versioning |
| Validation | go-playground/validator | Struct validation |
| Config | Viper + Koanf | Flexible configuration management |
| Logging | Zap | Structured logging |
| Cache | Redis | High-performance caching layer |
| Message Queue | RabbitMQ | Asynchronous task processing |
| gRPC | Protocol Buffers | High-performance RPC |
| DI Container | Uber FX | Dependency injection framework |
| APM | New Relic | Application performance monitoring |
# Development
make dev # Start development server with hot reload
make build # Build the application
make run # Run the built application
# Database
make migrate-up # Apply all pending migrations
make migrate-down # Rollback the last migration
make migrate-status # Show migration status
make seed-db # Run database seeders
# Testing
make test # Run all tests
make test-unit # Run unit tests only
make test-integration # Run integration tests
make test-coverage # Generate coverage report
make test-watch # Run tests in watch mode
# Code Quality
make lint # Run linters
make fmt # Format code
make vet # Run go vet
# Docker
make docker-build # Build Docker images
make docker-up # Start Docker containers
make docker-down # Stop Docker containers
# Utilities
make clean # Clean build artifacts
make help # Show all available commands# Install Go dependencies
go mod download
go mod tidy
# Generate code from SQLc
sqlc generate
# Set up pre-commit hooks (optional)
pre-commit installThe application loads configuration from multiple sources in this order (highest priority first):
- Environment Variables - Override everything
- .env - Local development overrides
- .env.dev - Default development configuration
Example .env file:
ENV=development
PORT=8080
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=fortress_dev
REDIS_ADDRESS=redis://localhost:6379
SECRET_KEY=your-secret-key
LEVEL=debugFortress API follows comprehensive testing practices:
- Unit Tests: Test individual functions and services
- Integration Tests: Test interactions between layers
- E2E Tests: Test complete workflows
- Performance Tests: Benchmark critical operations
# Run all tests with coverage
make test-coverage
# Run specific test suite
go test ./... -run TestUserService -v
# Run benchmarks
go test -bench=. ./...Target coverage: 80%+ on critical paths
All protected endpoints require a Bearer token in the Authorization header:
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8080/api/v1/protectedDocumentation structure - expand with your actual endpoints
GET /healthResponse:
{
"status": "healthy",
"timestamp": "2025-01-13T10:30:00Z"
}POST /api/v1/resources
Content-Type: application/json
{
"name": "Resource Name",
"description": "Resource Description"
}- Authentication: JWT-based authentication with configurable secret
- Input Validation: All inputs validated before processing
- SQL Injection Prevention: Type-safe SQLc queries prevent SQL injection
- CORS: Configurable CORS policy for frontend integration
- SSL/TLS: Support for HTTPS with certificate management
- Secrets Management: Environment-based secret handling
- Never commit
.envfiles with production secrets - Use strong
SECRET_KEYvalues in production - Enable HTTPS in production
- Regularly update dependencies:
go get -u ./... - Review security advisories:
go vulnerabilities ./...
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f api
# Stop all services
docker-compose down# Build using prod Dockerfile
docker build -f docker/prod.Dockerfile -t fortress-api:latest .
# Run container
docker run -p 8080:8080 \
-e PORT=8080 \
-e DATABASE_HOST=db \
fortress-api:latestStructured logging with Zap provides detailed insights:
logger.Info("user created",
zap.String("user_id", user.ID),
zap.String("email", user.Email),
)Configure health checks in your environment:
ENABLED=true
INTERVAL=30s
TIMEOUT=5s
CHECKS=database,redisEnable APM monitoring:
LICENSE_KEY=your-new-relic-license-key
APP_LOG_FORWARDING_ENABLED=true
DISTRIBUTED_TRACING_ENABLED=trueReady-to-use IaC templates for major cloud providers:
- AWS: CloudFormation & Terraform templates in
infra/aws/ - Azure: ARM templates in
infra/azure/ - GCP: Deployment Manager templates in
infra/gcp/
Configure different environments:
# Development
ENV=development LEVEL=debug make dev
# Staging
ENV=staging LEVEL=info make build && docker run ...
# Production
ENV=production LEVEL=warn make build && docker run ...We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow Effective Go conventions
- Run
make fmtbefore committing - Ensure
make lintpasses - Write tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
Please report security vulnerabilities to harmeetsinghfbd@gmail.com rather than using the issue tracker. See SECURITY.md for more details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: your-email@example.com
Made with β€οΈ by Harmeet