A comprehensive, production-ready REST API for managing database hosting services. DBHS provides a complete solution for database-as-a-service operations, including user management, project creation, schema management, analytics, and AI-powered assistance.
- 🔐 User Authentication & Authorization: JWT-based authentication with role-based access control
- 📊 Project Management: Create, manage, and organize database projects
- 🗄️ Database Schema Management: Dynamic schema creation, modification, and inspection
- 📋 Table Operations: Full CRUD operations for database tables with real-time schema synchronization
- 🔍 SQL Editor: Execute custom SQL queries with syntax validation and error handling
- 📈 Analytics & Monitoring: Real-time database usage statistics, storage monitoring, and cost analysis
- 🤖 AI Assistant: Intelligent database assistant powered by advanced AI for query optimization and suggestions
- ⚡ Caching: Redis-based caching for improved performance
- 🔒 Security: Rate limiting, input validation, and secure database connections
- 📊 Real-time Analytics: Track database usage, query performance, and storage metrics
- 🔄 Background Workers: Automated data collection and maintenance tasks
- 📖 API Documentation: Auto-generated Swagger/OpenAPI documentation
- 🐳 Containerized Deployment: Docker and Fly.io ready
- 📧 Email Integration: User verification and notification system
- 🛡️ Middleware Stack: Comprehensive security and logging middleware
The DBHS API follows a modular microservices-inspired architecture with the following components:
- API Gateway Layer: Gorilla Mux router with comprehensive middleware
- Service Layer: Business logic organized by domain (accounts, projects, tables, etc.)
- Data Access Layer: PostgreSQL with connection pooling and Redis caching
- Background Processing: Cron-based workers for analytics and maintenance
- External Integrations: AI services, email notifications, and monitoring
- Metadata Database: Stores user accounts, project configurations, and system metadata
- Dynamic User Databases: Isolated databases created per user project for data isolation
- Connection Pooling: Efficient database connection management with pgxpool
- Multi-tenancy: Secure isolation between user projects and data
├── main/ # Application entry point and routing
├── config/ # Configuration management and database connections
├── accounts/ # User authentication and profile management
├── projects/ # Project creation and management
├── tables/ # Database table operations and schema management
├── schemas/ # Database schema inspection and metadata
├── SqlEditor/ # SQL query execution and validation
├── AI/ # AI assistant and intelligent features
├── analytics/ # Usage analytics and monitoring
├── indexes/ # Database indexing operations
├── middleware/ # HTTP middleware (auth, rate limiting, CORS)
├── response/ # Standardized API response handling
├── utils/ # Shared utilities and helpers
├── workers/ # Background processing and cron jobs
├── caching/ # Redis caching implementation
├── test/ # Comprehensive test suites
├── docs/ # API documentation (Swagger/OpenAPI)
├── public/ # Static assets and diagrams
└── templates/ # Email and notification templates
- Language: Go 1.24.4
- Web Framework: Gorilla Mux
- Database: PostgreSQL 15+ with pgx driver
- Caching: Redis 7+
- Authentication: JWT with golang-jwt/jwt
- Documentation: Swagger/OpenAPI with go-swaggo
- Background Jobs: Robfig Cron
- Email: GoMail v2
- AI Integration: Custom AI agent for database assistance
- Monitoring: Real-time analytics and usage tracking
- Performance: Query optimization and caching strategies
- Go 1.24.4 or higher
- PostgreSQL 15+
- Redis 7+
- Docker (optional)
-
Clone the repository
git clone https://github.com/your-org/database-hosting-services-api.git cd database-hosting-services-api
-
Install dependencies
go mod download
-
Set up environment variables
cp .env.example .env # Edit .env with your configuration
-
Required Environment Variables
# Database Configuration DATABASE_URL=postgresql://user:password@localhost:5432/dbhs_main DATABASE_ADMIN_URL=postgresql://admin:password@localhost:5432/postgres TEST_DATABASE_URL=postgresql://user:password@localhost:5432/dbhs_test # Redis Configuration REDIS_URL=redis://localhost:6379 # JWT Configuration JWT_SECRET=your-super-secret-jwt-key # Email Configuration SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USERNAME=your-email@gmail.com SMTP_PASSWORD=your-app-password # AI Configuration AI_API_KEY=your-ai-api-key # Application Configuration API_PORT=8000 ENV=development
-
Run database migrations
# Set up main database schema psql -d $DATABASE_URL -f scripts/migrations/001_initial_schema.sql
-
Build and run the application
make build make run
- Scalar API Reference: https://orbix.fly.dev/reference
- Swagger UI: https://orbix.fly.dev/swagger/index.html
- ReDoc: https://orbix.fly.dev/redoc
make generate-docs
POST /api/user/sign-up
- User registrationPOST /api/user/sign-in
- User loginPOST /api/user/verify
- Email verificationPOST /api/user/resend-code
- Resend verification codePOST /api/user/forget-password
- Password reset requestPOST /api/user/forget-password/verify
- Password reset verification
GET /api/users/me
- Get current user profilePOST /api/users/update-password
- Update user passwordPATCH /api/users/{id}
- Update user profile
GET /api/projects
- List user projectsPOST /api/projects
- Create new projectGET /api/projects/{project_id}
- Get project detailsPATCH /api/projects/{project_id}
- Update projectDELETE /api/projects/{project_id}
- Delete project
GET /api/projects/{project_id}/tables
- List project tablesPOST /api/projects/{project_id}/tables
- Create new tableGET /api/projects/{project_id}/tables/{table_id}
- Get table data (with pagination)POST /api/projects/{project_id}/tables/{table_id}
- Insert row into tablePUT /api/projects/{project_id}/tables/{table_id}
- Update table schemaDELETE /api/projects/{project_id}/tables/{table_id}
- Delete tableGET /api/projects/{project_id}/tables/{table_id}/schema
- Get table schema
GET /api/projects/{project_id}/schema/tables
- Get database schemaGET /api/projects/{project_id}/schema/tables/{table_id}
- Get specific table schema
GET /api/projects/{project_id}/indexes
- List project indexesPOST /api/projects/{project_id}/indexes
- Create new indexGET /api/projects/{project_id}/indexes/{index_oid}
- Get specific indexPUT /api/projects/{project_id}/indexes/{index_oid}
- Update index nameDELETE /api/projects/{project_id}/indexes/{index_oid}
- Delete index
POST /api/projects/{project_id}/sqlEditor/run-query
- Execute SQL query
GET /api/projects/{project_id}/analytics/storage
- Database storage analyticsGET /api/projects/{project_id}/analytics/execution-time
- Query execution time statisticsGET /api/projects/{project_id}/analytics/usage
- Database usage statistics
GET /api/projects/{project_id}/ai/report
- Get AI-generated database reportPOST /api/projects/{project_id}/ai/chatbot/ask
- Chat with AI assistantPOST /api/projects/{project_id}/ai/agent
- AI agent for database operationsPOST /api/projects/{project_id}/ai/agent/accept
- Accept AI agent suggestionsPOST /api/projects/{project_id}/ai/agent/cancel
- Cancel AI agent operations
# Run all tests
make test
# Run specific test suite
go test ./test/accounts_test.go -v
go test ./test/projects_test.go -v
go test ./test/tables/ -v
# Run tests with coverage
go test -cover ./...
- Unit Tests: Individual component testing
- Integration Tests: End-to-end API testing
- Service Tests: Business logic validation
- Database Tests: Data access layer testing
- Database Usage: Query counts, execution time, resource usage
- Storage Metrics: Database size, growth trends, optimization suggestions
- Performance Monitoring: Query performance, connection pooling metrics
- User Analytics: Usage patterns, feature adoption
- Axiom: Advanced logging and analytics
- Health Checks: Application and database health monitoring
- Alerting: Automated alerts for critical issues
- JWT Tokens: Secure, stateless authentication
- Role-Based Access: Fine-grained permission control
- Project Isolation: Secure multi-tenancy
- Rate Limiting: API abuse prevention
- Input Validation: SQL injection and XSS protection
- CORS Configuration: Cross-origin request security
- Database Security: Connection encryption and access control