Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ services:
- "3000:3000"
volumes:
- ./services/dashboard/src:/app/src:ro
- ./services/dashboard/public:/app/public:ro
depends_on:
- api
networks:
Expand Down
48 changes: 24 additions & 24 deletions infrastructure/terraform/environments/dev/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ data "aws_availability_zones" "available" {
module "vpc_primary" {
source = "../../modules/vpc"

name_prefix = local.name_prefix
cidr_block = local.regions["us-east-1"].cidr_block
az_count = local.regions["us-east-1"].az_count
environment = local.environment
enable_nat = true # Single NAT for dev (cost optimization)
single_nat = true
name_prefix = local.name_prefix
cidr_block = local.regions["us-east-1"].cidr_block
az_count = local.regions["us-east-1"].az_count
environment = local.environment
enable_nat = true # Single NAT for dev (cost optimization)
single_nat = true

tags = local.common_tags
}
Expand All @@ -131,22 +131,22 @@ module "vpc_primary" {
module "rds_primary" {
source = "../../modules/rds"

name_prefix = local.name_prefix
vpc_id = module.vpc_primary.vpc_id
subnet_ids = module.vpc_primary.private_subnet_ids
security_group_ids = [module.vpc_primary.rds_security_group_id]
name_prefix = local.name_prefix
vpc_id = module.vpc_primary.vpc_id
subnet_ids = module.vpc_primary.private_subnet_ids
security_group_ids = [module.vpc_primary.rds_security_group_id]

instance_class = "db.t3.micro"
allocated_storage = 20
engine_version = "15"
multi_az = false # Single AZ for dev
backup_retention = 7
instance_class = "db.t3.micro"
allocated_storage = 20
engine_version = "15"
multi_az = false # Single AZ for dev
backup_retention = 7

database_name = "redisaas"
master_username = "redisaas_admin"
database_name = "redisaas"
master_username = "redisaas_admin"

environment = local.environment
tags = local.common_tags
environment = local.environment
tags = local.common_tags
}

# =============================================================================
Expand All @@ -161,12 +161,12 @@ module "elasticache_primary" {
subnet_ids = module.vpc_primary.private_subnet_ids
security_group_ids = [module.vpc_primary.redis_security_group_id]

node_type = "cache.t3.micro"
num_cache_nodes = 1 # Single node for dev
engine_version = "7.0"
node_type = "cache.t3.micro"
num_cache_nodes = 1 # Single node for dev
engine_version = "7.0"

environment = local.environment
tags = local.common_tags
environment = local.environment
tags = local.common_tags
}

# =============================================================================
Expand Down
92 changes: 46 additions & 46 deletions infrastructure/terraform/environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ data "aws_caller_identity" "current" {}
module "vpc_us" {
source = "../../modules/vpc"

name_prefix = "${local.name_prefix}-us"
cidr_block = local.regions["us-east-1"].cidr_block
az_count = local.regions["us-east-1"].az_count
environment = local.environment
enable_nat = true
single_nat = false # HA NAT for prod
name_prefix = "${local.name_prefix}-us"
cidr_block = local.regions["us-east-1"].cidr_block
az_count = local.regions["us-east-1"].az_count
environment = local.environment
enable_nat = true
single_nat = false # HA NAT for prod

tags = local.common_tags
}
Expand All @@ -141,12 +141,12 @@ module "vpc_eu" {
aws = aws.eu
}

name_prefix = "${local.name_prefix}-eu"
cidr_block = local.regions["eu-central-1"].cidr_block
az_count = local.regions["eu-central-1"].az_count
environment = local.environment
enable_nat = true
single_nat = false
name_prefix = "${local.name_prefix}-eu"
cidr_block = local.regions["eu-central-1"].cidr_block
az_count = local.regions["eu-central-1"].az_count
environment = local.environment
enable_nat = true
single_nat = false

tags = local.common_tags
}
Expand All @@ -161,12 +161,12 @@ module "vpc_ap" {
aws = aws.ap
}

name_prefix = "${local.name_prefix}-ap"
cidr_block = local.regions["ap-southeast-1"].cidr_block
az_count = local.regions["ap-southeast-1"].az_count
environment = local.environment
enable_nat = true
single_nat = false
name_prefix = "${local.name_prefix}-ap"
cidr_block = local.regions["ap-southeast-1"].cidr_block
az_count = local.regions["ap-southeast-1"].az_count
environment = local.environment
enable_nat = true
single_nat = false

tags = local.common_tags
}
Expand All @@ -178,22 +178,22 @@ module "vpc_ap" {
module "rds_primary" {
source = "../../modules/rds"

name_prefix = "${local.name_prefix}-us"
vpc_id = module.vpc_us.vpc_id
subnet_ids = module.vpc_us.private_subnet_ids
security_group_ids = [module.vpc_us.rds_security_group_id]
name_prefix = "${local.name_prefix}-us"
vpc_id = module.vpc_us.vpc_id
subnet_ids = module.vpc_us.private_subnet_ids
security_group_ids = [module.vpc_us.rds_security_group_id]

instance_class = "db.t3.small" # Upgraded for prod
allocated_storage = 50
engine_version = "15"
multi_az = true # HA for prod
backup_retention = 14
instance_class = "db.t3.small" # Upgraded for prod
allocated_storage = 50
engine_version = "15"
multi_az = true # HA for prod
backup_retention = 14

database_name = "redisaas"
master_username = "redisaas_admin"
database_name = "redisaas"
master_username = "redisaas_admin"

environment = local.environment
tags = local.common_tags
environment = local.environment
tags = local.common_tags
}

# =============================================================================
Expand All @@ -208,12 +208,12 @@ module "elasticache_us" {
subnet_ids = module.vpc_us.private_subnet_ids
security_group_ids = [module.vpc_us.redis_security_group_id]

node_type = "cache.t3.small" # Upgraded for prod
num_cache_nodes = 2 # Primary + replica
engine_version = "7.0"
node_type = "cache.t3.small" # Upgraded for prod
num_cache_nodes = 2 # Primary + replica
engine_version = "7.0"

environment = local.environment
tags = local.common_tags
environment = local.environment
tags = local.common_tags
}

# =============================================================================
Expand All @@ -231,12 +231,12 @@ module "elasticache_eu" {
subnet_ids = module.vpc_eu.private_subnet_ids
security_group_ids = [module.vpc_eu.redis_security_group_id]

node_type = "cache.t3.small"
num_cache_nodes = 2
engine_version = "7.0"
node_type = "cache.t3.small"
num_cache_nodes = 2
engine_version = "7.0"

environment = local.environment
tags = local.common_tags
environment = local.environment
tags = local.common_tags
}

# =============================================================================
Expand All @@ -254,12 +254,12 @@ module "elasticache_ap" {
subnet_ids = module.vpc_ap.private_subnet_ids
security_group_ids = [module.vpc_ap.redis_security_group_id]

node_type = "cache.t3.small"
num_cache_nodes = 2
engine_version = "7.0"
node_type = "cache.t3.small"
num_cache_nodes = 2
engine_version = "7.0"

environment = local.environment
tags = local.common_tags
environment = local.environment
tags = local.common_tags
}

# =============================================================================
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/terraform/modules/elasticache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# =============================================================================

resource "random_password" "auth_token" {
length = 32
special = false # ElastiCache auth token doesn't support all special chars
length = 32
special = false # ElastiCache auth token doesn't support all special chars
}

# =============================================================================
Expand Down
12 changes: 6 additions & 6 deletions infrastructure/terraform/modules/rds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ resource "aws_db_parameter_group" "main" {
# Performance parameters
parameter {
name = "shared_buffers"
value = "{DBInstanceClassMemory/4096}" # 25% of memory
value = "{DBInstanceClassMemory/4096}" # 25% of memory
}

parameter {
name = "effective_cache_size"
value = "{DBInstanceClassMemory*3/4096}" # 75% of memory
value = "{DBInstanceClassMemory*3/4096}" # 75% of memory
}

parameter {
name = "work_mem"
value = "65536" # 64MB
value = "65536" # 64MB
}

parameter {
name = "maintenance_work_mem"
value = "524288" # 512MB
value = "524288" # 512MB
}

# Logging
Expand All @@ -88,7 +88,7 @@ resource "aws_db_parameter_group" "main" {

parameter {
name = "log_min_duration_statement"
value = "1000" # Log queries > 1s
value = "1000" # Log queries > 1s
}

# Connection
Expand Down Expand Up @@ -191,7 +191,7 @@ resource "aws_cloudwatch_metric_alarm" "storage_low" {
namespace = "AWS/RDS"
period = 300
statistic = "Average"
threshold = 5368709120 # 5GB in bytes
threshold = 5368709120 # 5GB in bytes
alarm_description = "RDS free storage space is low"

dimensions = {
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/terraform/modules/s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ resource "aws_s3_bucket_policy" "static" {
Version = "2012-10-17"
Statement = [
{
Sid = "AllowCloudFrontOAC"
Effect = "Allow"
Sid = "AllowCloudFrontOAC"
Effect = "Allow"
Principal = {
Service = "cloudfront.amazonaws.com"
}
Expand Down
8 changes: 4 additions & 4 deletions infrastructure/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ variable "primary_region" {
variable "regions" {
description = "Map of regions with their configurations"
type = map(object({
enabled = bool
cidr_block = string
is_primary = bool
az_count = number
enabled = bool
cidr_block = string
is_primary = bool
az_count = number
}))
default = {
"us-east-1" = {
Expand Down
24 changes: 23 additions & 1 deletion services/api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,30 @@ func main() {
orgRepo := repository.NewOrganizationRepository(db)
dbRepo := repository.NewDatabaseRepository(db)
apiKeyRepo := repository.NewApiKeyRepository(db)
svcRepo := repository.NewServiceRepository(db)
engineRepo := repository.NewAvailableEngineRepository(db)

// Initialize services
jwtManager := auth.NewJWTManager(cfg)
authService := services.NewAuthService(userRepo, orgRepo, jwtManager)
dbService := services.NewDatabaseService(dbRepo, orgRepo, redisPool, cfg)
userService := services.NewUserService(userRepo, apiKeyRepo)
svcService := services.NewServiceService(svcRepo, engineRepo, orgRepo, cfg)

// Initialize handlers
authHandler := handlers.NewAuthHandler(authService)
dbHandler := handlers.NewDatabaseHandler(dbService)
redisProxyHandler := handlers.NewRedisProxyHandler(dbService, redisPool)
healthHandler := handlers.NewHealthHandler()
userHandler := handlers.NewUserHandler(userService)
serviceHandler := handlers.NewServiceHandler(svcService)

// Initialize rate limiters
rateLimiter := middleware.NewRateLimiter(cfg.RateLimitRequests, cfg.RateLimitWindow)
authRateLimiter := middleware.NewRateLimiter(cfg.AuthRateLimitRequests, cfg.AuthRateLimitWindow)

// Setup router
router := setupRouter(cfg, jwtManager, rateLimiter, authRateLimiter, authHandler, dbHandler, redisProxyHandler, healthHandler, userHandler)
router := setupRouter(cfg, jwtManager, rateLimiter, authRateLimiter, authHandler, dbHandler, redisProxyHandler, healthHandler, userHandler, serviceHandler)

// Start server
srv := &http.Server{
Expand Down Expand Up @@ -159,6 +163,7 @@ func setupRouter(
redisProxyHandler *handlers.RedisProxyHandler,
healthHandler *handlers.HealthHandler,
userHandler *handlers.UserHandler,
serviceHandler *handlers.ServiceHandler,
) *gin.Engine {
if cfg.IsProduction() {
gin.SetMode(gin.ReleaseMode)
Expand Down Expand Up @@ -229,6 +234,23 @@ func setupRouter(
tokenAPI.POST("/databases/:id", redisProxyHandler.UpstashCommand)
}

// Unified services endpoints (authenticated)
svcs := v1.Group("/services")
svcs.Use(middleware.AuthMiddleware(jwtManager))
{
// Public info endpoints (no auth needed, but keeping under /services for consistency)
svcs.GET("/types", serviceHandler.GetServiceTypes)
svcs.GET("/engines", serviceHandler.GetAvailableEngines)
svcs.GET("/regions", serviceHandler.GetRegions)

// Service CRUD
svcs.POST("", serviceHandler.Create)
svcs.GET("", serviceHandler.List)
svcs.GET("/:id", serviceHandler.Get)
svcs.DELETE("/:id", serviceHandler.Delete)
svcs.POST("/:id/reset-credentials", serviceHandler.ResetCredentials)
}

return router
}

Expand Down
Loading
Loading