-
Notifications
You must be signed in to change notification settings - Fork 9
project tree
This document provides a comprehensive overview of the IMS PocketBase BaaS Starter project structure, explaining the purpose and organization of each directory and key files.
ims-pocketbase-baas-starter/
βββ π cmd/ # Application entry points
βββ π docs/ # Project documentation
βββ π internal/ # Private application code
βββ π monitoring/ # Monitoring configurations (Prometheus, Grafana)
βββ π pb_data/ # PocketBase data directory
βββ π pb_public/ # PocketBase public assets
βββ π pkg/ # Reusable packages
βββ π scripts/ # Build and setup scripts
βββ π templates/ # Template files (email templates, etc.)
βββ π tmp/ # Temporary files (git ignored)
βββ π³ Dockerfile # Production container definition
βββ π³ docker-compose.yml # Production container orchestration
βββ πΉ go.mod # Go module definition
βββ βοΈ makefile # Development commands
βββ π README.md # Main project documentation
Contains the main application executables following Go project layout standards.
cmd/
βββ migrate-gen/ # Migration CLI generator
β βββ main.go # CLI entry point
β βββ cli.go # Command-line interface logic
β βββ cli_test.go # CLI tests
β βββ template.go # Migration template generation
β βββ template_test.go # Template generation tests
β βββ types.go # CLI-specific types
βββ server/ # Main application server
βββ main.go # Server entry point
Purpose: Separates different executable commands, making the project modular and following Go conventions.
Contains application-specific code that should not be imported by other projects.
internal/
βββ app/ # Application setup and configuration
β βββ app.go # Main app initialization and DI orchestration
β βββ app_test.go # Application setup tests
βββ commands/ # CLI commands registration
β βββ commands.go # CLI command registration and configuration
βββ crons/ # Cron job definitions
β βββ crons.go # Cron job registration and configuration
βββ database/ # Database-related code
β βββ migrations/ # Database schema migrations
β βββ schema/ # PocketBase schema JSON files
β βββ seeders/ # Data seeding utilities
βββ handlers/ # Business logic handlers
β βββ cron/ # Cron job handlers
β βββ export/ # Data export handlers
β βββ hook/ # Event hook handlers
β βββ jobs/ # Job queue handlers
β βββ route/ # Custom route handlers
βββ hooks/ # Event hook registration
β βββ hooks.go # Hook registration orchestration
β βββ hooks_test.go # Hook system tests
βββ jobs/ # Job management
β βββ jobs.go # Job handler registration (new pattern)
β βββ manager.go # Job manager singleton
βββ middlewares/ # HTTP middlewares
β βββ middlewares.go # Middleware registration (new pattern)
β βββ auth.go # Authentication middleware
β βββ metrics.go # Metrics collection middleware
β βββ permission.go # Permission-based access control
βββ routes/ # Custom API routes
β βββ routes.go # Route registration (new pattern)
βββ apidoc/ # API documentation generation
βββ generator.go # OpenAPI spec generation
βββ discovery.go # Collection discovery
βββ schema.go # Schema generation
βββ endpoints.go # API docs endpoints
Contains reusable packages that could potentially be imported by other projects.
pkg/
βββ cache/ # Caching system
β βββ cache.go # Cache service with TTL support
β βββ cache_test.go # Cache system tests
βββ common/ # Common utilities
β βββ env.go # Environment variable utilities
β βββ response.go # HTTP response utilities
β βββ route.go # Route configuration
βββ cronutils/ # Cron execution utilities
β βββ utils.go # Cron validation and execution context
β βββ utils_test.go # Cron utilities tests
βββ jobutils/ # Job processing utilities
β βββ processor.go # Job processor implementation
β βββ types.go # Job-related types and interfaces
β βββ payload.go # Job payload parsing utilities
β βββ file.go # File handling for jobs
β βββ worker_pool.go # Concurrent job processing
βββ logger/ # Centralized logging system
β βββ logger.go # Logger singleton implementation
β βββ utils.go # Logger utilities
β βββ logger_test.go # Logger tests
βββ metrics/ # Metrics and observability
β βββ metrics.go # Main metrics interface and factory
β βββ config.go # Configuration management
β βββ prometheus.go # Prometheus implementation
β βββ opentelemetry.go # OpenTelemetry implementation
β βββ noop.go # No-op implementation
β βββ instrumentation.go # Helper functions
β βββ types.go # Metric types and constants
β βββ *_test.go # Comprehensive test suite
βββ migration/ # Migration utilities
β βββ scanner.go # Migration file scanning
β βββ filesystem.go # File system operations
β βββ *_test.go # Migration tests
βββ permission/ # Permission system
β βββ permissions.go # Permission constants and definitions
β βββ permissions_test.go # Permission tests
βββ response/ # HTTP response utilities
βββ response.go # Standardized HTTP response helpers
βββ response_test.go # Response utility tests
Contains monitoring infrastructure configurations for both development and production environments.
monitoring/
βββ local/ # Development monitoring setup
β βββ grafana/ # Grafana configuration
β β βββ dashboards/ # Pre-built dashboards
β β βββ provisioning/ # Grafana provisioning config
β βββ prometheus/ # Prometheus configuration
β βββ prometheus.yml # Local metrics scraping
βββ production/ # Production monitoring setup
βββ grafana/ # Production Grafana config
βββ prometheus/ # Production Prometheus config
βββ alertmanager/ # Alert management configuration
Comprehensive documentation for all aspects of the project.
docs/
βββ README.md # Documentation index
βββ dependency-injection.md # DI patterns and strategies
βββ cron-jobs.md # Job queue and cron system
βββ hooks.md # Event hooks system
βββ logger.md # Logging system
βββ middleware.md # Custom middleware
βββ migrations.md # Database migrations
βββ apidoc.md # API documentation
βββ cli-commands.md # CLI commands and usage
βββ git-hooks.md # Git hooks setup
βββ project-tree.md # This file - project structure
Contains template files used by the application.
templates/
βββ emails/ # Email templates
βββ welcome.html # HTML welcome email template
βββ welcome.txt # Plain text welcome email template
Purpose: Stores template files that can be used by the application for generating dynamic content, such as emails or documents.
- Clear separation between
internal/(private) andpkg/(public) code - Layered architecture with proper dependency flow
- Domain-driven design with focused packages
-
Singleton Pattern: Shared services (
pkg/metrics,pkg/logger,pkg/cache) -
Constructor Injection: Business logic components (
internal/handlers) -
Factory Pattern: Configurable implementations (
pkg/metrics/config.go) - Interface-Based: Loose coupling throughout the application
- Co-located test files following Go conventions (
*_test.go) - Comprehensive test coverage for all packages
- Mock-friendly architecture with interface-based design
- Singleton reset functionality for isolated testing
- Environment-driven configuration (
.envfiles) - Centralized environment utilities (
pkg/common/env.go) - Sensible defaults with override capabilities
- Production and development configurations
-
*.go- Implementation files -
*_test.go- Test files (co-located with implementation) -
types.go- Type definitions and constants -
config.go- Configuration structures and loading
-
README.md- Main documentation or directory index -
*.md- Specific topic documentation -
CONTRIBUTING.md- Contribution guidelines -
LICENSE.md- License information
-
.env- Environment variables (not in version control) -
.env.example- Environment template -
.env.production- Production environment template -
docker-compose.yml- Production container configuration -
docker-compose.dev.yml- Development container configuration -
Dockerfile- Production container definition -
makefile- Development commands
-
tmp/- Temporary files and directories (git ignored) -
tmp/- Temporary files directory (git ignored)
-
monitoring/local/- Development monitoring setup -
monitoring/production/- Production monitoring deployment -
monitoring/*/prometheus/- Prometheus configurations -
monitoring/*/grafana/- Grafana dashboards and provisioning
internal/app/ (orchestrates everything)
β
internal/middlewares/ (HTTP layer)
β
internal/handlers/ (business logic)
β
pkg/ (utilities and services)
-
internal/app/app.goorchestrates all dependency injection -
pkg/metrics/provides observability across all layers -
pkg/logger/provides logging across all components -
pkg/cache/provides caching for performance optimization -
internal/middlewares/provides cross-cutting concerns -
internal/handlers/implements business logic
-
.air.toml- Air configuration for hot reload -
docker-compose.dev.yml- Development environment with volume mounts -
Dockerfile.dev- Development container with Air
-
makefile- Standardized development commands -
.githooks/- Pre-commit and pre-push validation -
scripts/- Setup and utility scripts
- Comprehensive test coverage across all packages
- Benchmark tests for performance-critical components
- Integration tests for complex workflows
- Mock-friendly architecture for isolated testing
- Multi-stage Docker builds for optimized production images
- Separate development and production configurations
- Volume mounts for persistent data (
pb_data/) - Health checks and monitoring endpoints
-
Local Development:
monitoring/local/- Prometheus + Grafana for development -
Production Deployment:
monitoring/production/- Scalable monitoring infrastructure - Metrics Collection: Prometheus scraping with configurable intervals
- Visualization: Grafana dashboards with pre-built PocketBase metrics
- Alerting: Alertmanager integration for production notifications
- Structured Logging: Multiple log levels with centralized collection
- Go Project Layout: Follows standard Go project structure
- Separation of Concerns: Clear boundaries between layers
- Dependency Injection: Multiple strategies for different use cases
- Testing: Comprehensive test coverage with proper isolation
- Documentation: Extensive documentation for all components
- Configuration: Environment-driven with sensible defaults
- Containerization: Production-ready Docker setup
- Code Quality: Linting, formatting, and Git hooks
-
Start with
README.mdfor project overview -
Explore
internal/app/app.goto understand application initialization -
Review
pkg/packages to understand core utilities -
Check
docs/for detailed guides on specific topics -
Use
makefilecommands for development workflow -
Refer to
.env.examplefor configuration options
- Home - IMS PocketBase BaaS Starter Documentation
- Project Structure - Project organization and architecture
- Environment Configuration - Configuration setup
- Makefile Commands - Development commands
- Database Migrations - Schema management
- Database Seeders - CLI database seeder for dev
- Custom Routes - API endpoints and handlers
- Event Hooks System - PocketBase event handling
- Custom Middleware - Authentication and middleware
- Cron Jobs & Job Queue - Background task processing
- Custom Email System - Email templates and sending
- CLI commands - Command-line interface support for custom scripts and tasks
- Caching System - TTL caching implementation
- Metrics Collection - Application metrics and monitoring
- Centralized Logger - Logging system and configuration
- API Documentation - API documentation generation
- Local Metrics Setup - Development monitoring setup
- Git Hooks Setup - Code quality automation
- Dependency Injection - DI patterns and architecture