This document provides essential context for AI agents working on the mailserver-admin project.
mailserver-admin is a web-based administration interface for docker-mailserver. It provides a comprehensive management interface for mail domains, users, aliases, DKIM settings, and fetchmail configurations.
- Domain Management: Add, edit, and delete mail domains
- User Management: Create, update, and remove mail users with password management
- Alias Management: Define mail aliases for email forwarding
- DKIM Management: Configure DKIM settings for email authenticity
- Fetchmail Configuration: Set up and manage Fetchmail for external email retrieval
- OAuth2 Integration: Secure authentication using OAuth2 providers
- DNS Setup Wizard: Interactive wizard for DNS record configuration
- Dashboard: Monitoring and statistics for Dovecot and Rspamd services
- PHP: >= 8.4 (strict types enabled)
- Symfony: 7.4.x (Framework Bundle, Console, Form, Security, Twig, etc.)
- EasyAdmin Bundle: v4.27.8 (admin interface)
- Doctrine ORM: 3.6.1 (database abstraction)
- Doctrine Migrations: 3.7.0 (database versioning)
- HWIOAuthBundle: v2.4.0 (OAuth2 authentication)
- Predis: v3.3.0 (Redis client)
- Symfony Asset Mapper: Modern asset management
- Symfony Stimulus Bundle: JavaScript framework integration
- Symfony UX Chart.js: Dashboard visualizations
- PHP CS Fixer: v3.93.0 (code style)
- PHPStan: Level 6 static analysis
- PHPUnit: ^12.0 (testing)
- Rector: 2.3.4 (code refactoring)
- devenv: Reproducible development environment (Nix-based)
- MySQL/MariaDB: Database (via Doctrine)
- Redis: Caching and data synchronization
- Caddy: Web server (development)
- PHP-FPM: PHP execution (development)
The application integrates with multiple external services:
-
docker-mailserver (via Dovecot)
- User authentication and management
- Mailbox operations
- Health checks via
doveadmHTTP API
-
Rspamd (Spam filtering)
- Statistics and monitoring
- Configuration management
- Health checks via HTTP API
-
Redis
- Data synchronization between admin interface and mailserver
- Caching for performance
- Runtime data storage
-
MySQL
- Primary data storage for domains, users, aliases
- Doctrine ORM for database operations
mailserver-admin/
├── src/ # Application source code
│ ├── Command/ # Symfony console commands
│ ├── Controller/ # HTTP controllers (Admin, User, Autoconfig, Security)
│ ├── Entity/ # Doctrine entities (Domain, User, Alias, etc.)
│ ├── Form/ # Symfony form types
│ ├── Repository/ # Doctrine repositories
│ ├── Service/ # Business logic services
│ │ ├── DKIM/ # DKIM key management and configuration
│ │ ├── Dovecot/ # Dovecot integration services
│ │ ├── Rspamd/ # Rspamd integration services
│ │ ├── FetchmailAccount/ # Fetchmail configuration
│ │ ├── DnsWizard/ # DNS validation wizard
│ │ └── Security/ # Authentication and authorization
│ ├── Subscriber/ # Doctrine event subscribers
│ ├── Validator/ # Custom validation constraints
│ └── Twig/ # Twig extensions
├── tests/ # Test suite
│ ├── Unit/ # Unit tests
│ └── Integration/ # Integration tests
├── config/ # Symfony configuration
├── migrations/ # Database migrations
├── templates/ # Twig templates
├── public/ # Web root
├── assets/ # Frontend assets (JavaScript, CSS)
└── bin/ # Executable scripts
- KeyGenerationService: Generates DKIM key pairs
- DKIMStatusService: Checks DKIM configuration status
- Config/Manager: Manages DKIM configuration files
- Config/MapGenerator: Generates configuration maps
- DoveadmHttpClient: HTTP client for Dovecot admin API
- User management operations
- Health check integration
- RspamdControllerClient: HTTP client for Rspamd API
- RspamdStatsService: Statistics and monitoring
- Health check integration
- OAuth User Provider: OAuth2 user authentication
- Role management (ROLE_ADMIN, ROLE_DOMAIN_ADMIN, ROLE_USER)
- Password hashing and validation
- Nix: Required for devenv
- direnv: Automatically loads development environment
- Composer: PHP dependency management
-
Start development environment:
devenv up
This starts:
- PHP 8.4 with Redis, PDO MySQL, Xdebug extensions
- MySQL database server
- Redis server
- Caddy web server on port 8000
-
Install dependencies:
composer install
-
Load environment (via direnv or manually):
eval "$(direnv export bash)"
CRITICAL: Always load the devenv environment before running commands:
eval "$(direnv export bash)" && <command>This ensures:
- Correct PHP version (8.4)
- All dependencies available
- Environment variables properly set
- Database and Redis connections configured
- Code Style:
composer run csfix(PHP CS Fixer) - Static Analysis:
composer run phpstan(PHPStan level 6) - Tests:
composer run test(PHPUnit) - Refactoring:
composer run rector(Rector) - Coverage:
composer run coverage(with Xdebug)
- PSR-2: Base coding standard
- Symfony: Symfony coding standards
- Strict Types:
declare(strict_types=1);required in all files - Header Comments: All files must include package header comment
- Array Syntax: Short array syntax
[]required - Ordered Imports: Alphabetically ordered imports
- Ordered Class Elements: Consistent class element ordering
- PHP CS Fixer:
.php-cs-fixer.dist.php - PHPStan: Level 6 analysis (
phpstan.dist.neon) - Rector: Automated refactoring (
rector.php)
- Namespace:
App\for all application code - Test Namespace:
Tests\for all test code - PSR-4 Autoloading: Standard PSR-4 structure
- Use Doctrine entities for all database models
- Repositories extend
ServiceEntityRepository - Use Doctrine migrations for schema changes
- Services are typically
readonlyclasses - Dependency injection via constructor
- Services handle business logic, not controllers
- Admin Controllers: EasyAdmin CRUD controllers
- User Controllers: User-facing functionality
- Autoconfig Controllers: Email client autoconfiguration
- Role Hierarchy:
ROLE_ADMIN > ROLE_DOMAIN_ADMIN > ROLE_USER - OAuth2: Configurable via environment variables
- CSRF Protection: Configurable via
CSRF_ENABLEDenv var - Form Login: Traditional username/password authentication
- Custom exceptions in
src/Exception/ - Domain-specific exceptions (DKIM, Dovecot, Domain)
- Proper exception hierarchy
- Unit Tests:
tests/Unit/- Isolated component testing - Integration Tests:
tests/Integration/- Full stack testing - Test Environment: Uses
.env.testconfiguration - Database: Uses
dama/doctrine-test-bundlefor transaction rollback
Key environment variables (see .env and config/services.yaml):
DATABASE_URL: MySQL connection stringREDIS_DSN: Redis connection stringOAUTH_ENABLED: Enable/disable OAuth2OAUTH_BUTTON_TEXT: OAuth button labelOAUTH_ADMIN_GROUP: OAuth group for admin roleCSRF_ENABLED: Enable/disable CSRF protectionRSPAMD_TIMEOUT_MS: Rspamd API timeoutRSPAMD_CACHE_TTL_SECONDS: Rspamd cache TTL
- Dovecot: User management, authentication, health checks
- Redis Sync: Synchronizes user/alias data to mailserver
- DKIM Keys: Manages DKIM private keys for mailserver
- Fetchmail: Configures fetchmail accounts
- OAuth2 Provider: Configurable OAuth2 authentication
- DNS: DNS validation wizard for mail server setup
- Mobile Config: Generates iOS/macOS email profiles
- Create entity class in
src/Entity/ - Create repository in
src/Repository/ - Generate migration:
php bin/console doctrine:migrations:generate - Create EasyAdmin CRUD controller in
src/Controller/Admin/ - Add tests in
tests/Unit/Entity/andtests/Integration/Controller/Admin/
- Create service class in appropriate
src/Service/subdirectory - Use constructor dependency injection
- Make service
readonlyif immutable - Add unit tests in
tests/Unit/Service/
- Generate:
php bin/console doctrine:migrations:generate - Edit migration in
migrations/ - Test:
php bin/console doctrine:migrations:migrate - Always test rollback:
php bin/console doctrine:migrations:migrate prev
- Project README:
README.md - Development Guide: https://jeboehm.github.io/docker-mailserver/development/mailserver-admin/
- Configuration Guide: https://jeboehm.github.io/docker-mailserver/configuration/mailserver-admin/
- Administration Docs: https://jeboehm.github.io/docker-mailserver/administration/
- Always use devenv: Commands must run within the devenv environment
- Strict Types: All PHP files must declare strict types
- Service Layer: Business logic belongs in services, not controllers
- Doctrine: Use Entity API, not direct database queries
- Testing: Maintain high test coverage, especially for services
- Code Style: Run
composer run csfixbefore committing - Static Analysis: Ensure PHPStan passes at level 6
- Redis Sync: Changes to users/aliases must sync to Redis for mailserver
- DKIM Keys: Private keys are stored securely, never expose in logs
- OAuth: OAuth integration is optional, check
OAUTH_ENABLEDbefore use
- British English: Use British spelling in documentation and comments
- Git Commits: Follow conventional commits (fix:, feat:, docs:, etc.)
- Code Quality: Follow clean code principles, DRY, single responsibility