README
ΒΆ
WebCoreGo - Pluggable API Framework
A RESTful API framework built with Go and Fiber featuring a pluggable architecture that separates infrastructure from business logic.
ποΈ Architecture Overview
The WebCoreGo framework follows a Pluggable Architecture pattern that allows teams to work independently on isolated modules:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Main Repository (repo-utama-api) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β WebCore Engine β Global Middleware β Shared Libraries β
β - config β - auth.go β - database: β
| - logger | - logging.go | - postgres |
| - DI: | - rate_limit.go | - mysql |
| - libraries | | - sqlite |
| - modules | | - mongo |
β - middleware β β - redis β
β - helper β β - kafka β
β β β - pubsub β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Central Registry β
β (Module Management & DI) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Module Repositories β
β (Separate Git Repositories) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Module A β Module B β Module C β
β - config β - config β - config β
β - handler β - handler β - handler β
β - service β - service β - service β
β - repository β - repository β - repository β
β - module.go β - module.go β - module.go β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Features
Core Features
- Pluggable Architecture: Modules can be developed, tested, and deployed independently
- Central Registry: Automatic module registration and dependency injection
- Go-Fiber Framework: Fast, expressive, minimalist web framework for Go
- Shared Libraries: Common utilities, database connections, and Redis client
- Global Middleware: Authentication, logging, rate limiting, CORS
- CI/CD Ready: GitHub Actions workflows for testing and deployment
Module Features
- Isolated Development: Each module has its own repository
- Standard Interface: All modules implement the same interface
- Dependency Injection: Shared dependencies injected into modules
- Auto-Loading: Modules can be loaded from various sources
- Version Management: Module version tracking and compatibility
π Project Structure
webcore-go/
βββ webcore/
β βββ go.mod # Go module definition
β βββ go.sum # Go module checksums
β βββ main.go # Application entry point
β βββ deps/ # Application modules and dependencies Management
β β βββ libraries.go # List of library dependencies
β β βββ packages.go # List of module dependencies
β βββ app/ # Core application logic
β βββ config/ # Configuration management
β β βββ config.go # Configuration loading
β βββ core/ # Core logic
β β βββ app.go # Application main logic
β β βββ module.go # Central registry implementation
β β βββ loader.go # Module loader implementation
β βββ helper/ # Some helper functions
β β βββ api.go # API
β β βββ json.go # Override default JSON Encoding/Decoding using goccy-json
β β βββ log.go # Log
β β βββ string.go # String
β β βββ task.go # Task
β β βββ utils.go # Some utility functions
β βββ loader/ # Dependency Injection interface
β β βββ conn.go # Dependency Injection interface for Database, Kafka, Redis, PubSub etc
β βββ logger/ # Logger definition
β β βββ logger.go # Override default logger implementation
β βββ middleware/ # Global middleware
β βββ auth.go # Authentication middleware
β βββ logging.go # Logging middleware
β βββ rate_limit.go # Rate limiting middleware
β βββ middleware.go # Middleware registration
βββ libraries/ # Global Shared Libraries and implement DI interface for Database, Kafka, Redis, PubSub etc
β βββ db/ # Database
β β βββ mongo # MongoDB database implementation
β β βββ sql # Relational database abstraction
β β βββ mysql # MySQL database implementation
β β βββ sqlite # SQLite database implementation
β β βββ postgres # PostgreSQL database implementation
β βββ kafka/ # Kafka
β βββ pubsub/ # PubSub
β βββ redis/ # Redis
βββ modules/
β βββ module-a/ # Example module
β βββ go.mod # Go module definition
β βββ module.go # Module implementation
β βββ config/
β β βββ config.go # Module configuration
β βββ handler/
β β βββ handler.go # HTTP handlers
β βββ model/
β β βββ model1.go # Model
β β βββ model2.go # Model
β βββ service/
β β βββ service.go # Business logic
β βββ repository/
β βββ repository.go # Data access layer
βββ .github/
β βββ workflows/
β βββ ci.yml # CI pipeline
β βββ cd.yml # CD pipeline
βββ go.work # Go workspace configuration
βββ go.work.sum # Go workspace configuration checksum
βββ config.yaml # Configuration file
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose configuration
βββ run.sh # script to run go webcore/main.go
π οΈ Installation
Prerequisites
- Go 1.19 or higher
- PostgreSQL, MySQL, SQLite or MongoDB (for database)
- Redis (optional, for caching)
- Docker (optional, for containerization)
Local Development
- Clone the repository:
git clone <repository-url>
cd webcore-go
- Install dependencies:
go mod tidy
- Set up configuration:
cp config.yaml.example config.yaml
# Edit config.yaml with your settings
- Set up database (optional):
# Create PostgreSQL database
createdb konsolidator
# Run migrations (if any)
go run main.go migrate
- Run the application:
go run webcore/main.go
Or use run.sh from root directory
./run.sh
The application will start on http://localhost:7272
Using Docker
- Build and run with Docker Compose:
docker-compose up -d
- Build manually:
docker build -t konsolidator .
docker run -p 7272:7272 konsolidator
π Configuration
The application configuration is managed through config/config.yaml:
app:
name: "konsolidator-api"
version: "1.0.0"
environment: "development"
server:
host: "0.0.0.0"
port: 7272
read_timeout: 30
write_timeout: 30
database:
host: "localhost"
port: 5432
user: "postgres"
password: "password"
database: "konsolidator"
ssl_mode: "disable"
redis:
host: "localhost"
port: 6379
password: ""
db: 0
jwt:
secret_key: "your-secret-key"
expires_in: 86400 # 24 hours in seconds
modules:
base_path: "./modules"
disabled:
- "modulea"
π Development
Library Development
Learn how to develop shared libraries for the WebCoreGo framework. Libraries are reusable components that provide shared functionality across modules and the core application.
For detailed guidance on creating libraries, see Library Development Documentation.
Module Development
Learn how to develop pluggable modules for the WebCoreGo framework. Modules are self-contained units of functionality that can be developed, tested, and deployed independently.
For detailed guidance on creating modules, see Module Development Documentation.
- Create a new repository for your module:
cd modules
git clone <module-template> module-b
cd module-b
- Implement the Module interface:
package moduleb
import (
"github.com/gofiber/fiber/v2"
"github.com/webcore-go/webcore/app/registry"
)
type Module struct {
// Your module fields
}
func (m *Module) Name() string {
return "module-b"
}
func (m *Module) Version() string {
return "1.0.0"
}
// Dependencies returns the dependencies of the module to other modules
func (m *Module) Dependencies() []string {
return []string{}
}
func (m *Module) Init(app *fiber.App, deps *module.Context) error {
// Initialize your module
return nil
}
func (m *Module) Destroy() error {
return nil
}
func (m *Module) Config() appConfig.Configurable {
return m.config
}
func (m *Module) Routes() []*fiber.Route {
// Return your routes
return []*fiber.Route{}
}
func (m *Module) Middleware() []fiber.Handler {
// Return your middleware
return []fiber.Handler{}
}
func (m *Module) Services() map[string]any {
// Return your services
return map[string]any{}
}
func (m *Module) Repositories() map[string]any {
// Return your repositories
return map[string]any{}
}
- Register your module in the APP_PACKAGES located in deps/packages.go:
var APP_PACKAGES = []core.Module{
modulea.NewModule(),
// Add your packages here
moduleb.NewModule(), // your module
}
Module Structure
Each module should follow this structure:
module-b/
βββ go.mod # Go module definition
βββ module.go # Module implementation
βββ config/
β βββ config.go # Module configuration
βββ handler/
β βββ handler.go # HTTP handlers
βββ model/
β βββ model1.go # Model
β βββ model2.go # Model
βββ service/
β βββ service.go # Business logic
βββ repository/
βββ repository.go # Data access layer
Module Dependencies
Modules can depend on shared libraries:
import (
"github.com/webcore-go/webcore/modules/module-a/repository"
)
type Module struct {
db *port.IDatabase
redis *loader.IRedis
}
func (m *Module) Init(app *fiber.App, deps *module.Context) error {
m.db = deps.Database
m.redis = deps.Redis
m.logger = deps.Logger
return nil
}
π Module Loading
Auto-Loading
Modules can be automatically loaded from configured directories:
modules:
base_path: "./modules"
disabled:
- "modulea"
Manual Loading
Modules can also be loaded programmatically:
// Load from file path
err := manager.LoadModuleFromPath("/path/to/module.so")
// Load from git repository
err := manager.LoadModuleFromGit(
"https://github.com/user/module-b.git",
"main",
"./module-b",
)
// Load from go module path
err := manager.LoadModuleFromPackage("github.com/user/module-b")
π§ͺ Testing
Running Tests
# Run all tests
go test ./...
# Run tests with verbose output
go test -v ./...
# Run tests with coverage
go test -cover ./...
# Run tests for specific package
go test ./internal/registry
Testing Modules
Each module should have its own test suite:
# Test specific module
cd packages/module-a
go test ./...
π Deployment
Build for Production
# Build the application
go build -o konsolidator main.go
# Build with optimizations
go build -ldflags="-s -w" -o konsolidator main.go
Docker Deployment
# Build image
docker build -t konsolidator:latest .
# Run container
docker run -d -p 7272:7272 konsolidator:latest
Kubernetes Deployment
Example Kubernetes configuration:
apiVersion: apps/v1
kind: Deployment
metadata:
name: konsolidator
spec:
replicas: 3
selector:
matchLabels:
app: konsolidator
template:
metadata:
labels:
app: konsolidator
spec:
containers:
- name: konsolidator
image: konsolidator:latest
ports:
- containerPort: 7272
env:
- name: DB_HOST
value: "postgres-service"
- name: REDIS_HOST
value: "redis-service"
π API Documentation
Health Check
GET /health
Response:
{
"status": "ok",
"service": "konsolidator-api"
}
API Version
GET /api/v1
Response:
{
"version": "1.0.0",
"modules": ["module-a", "module-b"],
"environment": "development"
}
Module Endpoints
Each module can expose its own endpoints. For example, the module-a user management module:
# Get users with pagination
GET /api/v1/module-a/users?page=1&page_size=10
# Get user by ID
GET /api/v1/module-a/users/1
# Create user
POST /api/v1/module-a/users
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}
# Update user
PUT /api/v1/module-a/users/1
Content-Type: application/json
{
"name": "John Updated"
}
# Delete user
DELETE /api/v1/module-a/users/1
π Development Guidelines
Code Style
- Follow Go standard code style
- Use meaningful variable and function names
- Add comments for complex logic
- Use interfaces for dependency injection
Error Handling
- Use structured error responses
- Log errors appropriately
- Handle errors gracefully
- Provide meaningful error messages
Security
- Validate all input data
- Use parameterized queries for database operations
- Implement proper authentication and authorization
- Sanitize user input
Performance
- Use connection pooling for database and Redis
- Implement proper caching strategies
- Monitor and optimize database queries
- Use appropriate HTTP status codes
π€ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Support
For support and questions:
- Create an issue on GitHub
- Check the documentation
- Review the example modules
- Join the community discussions
πΊοΈ Roadmap
- Module hot-reloading
- Advanced dependency injection
- Configuration management for modules
- Monitoring and metrics
- Plugin marketplace
- API documentation generation
- GraphQL support
- WebSocket support