This directory contains practical examples demonstrating various features and use cases of the modular framework. Each example is a complete, working application that showcases different aspects of building modular applications.
Basic App - Foundation Example
Demonstrates: Core modular application concepts
- Basic application setup with
modular.NewStdApplication() - Configuration management with YAML and environment variables
- Custom module creation and registration
- Service dependencies between modules
- Configuration validation and defaults
- Application lifecycle management
Best for: Getting started with the modular framework
Reverse Proxy - Networking Example
Demonstrates: HTTP reverse proxy with routing
- ChiMux router integration with CORS middleware
- Reverse proxy configuration and backend services
- HTTP server module usage
- Multi-module composition
- Graceful shutdown handling
Best for: Building API gateways and service proxies
HTTP Client - Client Integration Example
Demonstrates: Advanced HTTP client configuration
- HTTP client module with connection pooling
- Integration with reverse proxy modules
- Performance tuning and timeout configuration
- Module service dependencies
- Basic HTTP client logging
Best for: High-performance HTTP client applications
Advanced Logging - Debugging Example
Demonstrates: Comprehensive HTTP client logging
- Detailed request/response logging
- File-based logging with organized structure
- Header and body logging capabilities
- Configurable logging levels and limits
- Real-world HTTP traffic logging
Best for: Debugging, monitoring, and compliance requirements
Each example is self-contained and can be run independently:
# Navigate to any example directory
cd examples/basic-app
# Build the example
go build .
# Run the example
./basic-appEach example follows a consistent structure:
example-name/
├── README.md # Detailed documentation
├── go.mod # Go module configuration
├── config.yaml # Application configuration
├── main.go # Main application file
└── [additional files] # Example-specific code
All examples are automatically validated through CI/CD to ensure they:
- ✅ Build successfully with
go build - ✅ Start without immediate errors
- ✅ Have proper module configuration
- ✅ Follow framework best practices
Recommended order for learning:
- Basic App - Start here to understand core concepts
- Reverse Proxy - Learn about networking modules
- HTTP Client - Explore client-side functionality
- Advanced Logging - Master debugging and monitoring
Use these examples as templates for your own applications:
- Copy an example that closely matches your use case
- Modify the configuration in
config.yaml - Add your custom modules following the patterns shown
- Update the dependencies in
go.modas needed
All examples use YAML configuration with support for:
- Environment variable overrides
- Default values
- Required field validation
- Type conversion and validation
Configuration files follow the pattern:
# Module configurations
modulename:
setting1: value1
setting2: value2
# Application-specific settings
app:
name: "My App"
environment: "dev"Examples demonstrate these module categories:
| Category | Examples | Modules Used |
|---|---|---|
| Web Servers | basic-app, reverse-proxy | httpserver, chimux |
| HTTP Clients | http-client, advanced-logging | httpclient |
| Routing & Middleware | reverse-proxy, http-client | chimux, reverseproxy |
| Custom Modules | basic-app | webserver, router, api |
The examples demonstrate these important patterns:
- Module Registration Order: Dependencies first, consumers second
- Configuration Structure: Module-specific sections in YAML
- Service Dependencies: How modules provide services to each other
- Lifecycle Management: Proper startup, running, and shutdown
- Error Handling: Graceful error handling and logging
When adding new examples:
- Follow the established directory structure
- Include comprehensive README documentation
- Add proper go.mod configuration with replace directives
- Ensure the example builds and runs successfully
- Update this main README with the new example
Each example includes detailed documentation and can serve as a reference for building your own modular applications.