# megabre/megaforbb architecture

> Architecture diagram of the GitHub repository megabre/megaforbb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/megabre/megaforbb
- Repository: https://github.com/megabre/megaforbb

## Overview

#### Purpose and entry points
MegaforBB is a PHP 8+ community-forum platform: forums, topics/posts, articles, private messages, moderation, portal content, documentation, and an idea-voting module. HTTP enters through `public/index.php`, bootstraps the Forecor kernel, then dispatches route handlers from `Route/web.php`, `Route/admin.php`, `Route/api.php`, and module route files. Scheduled work enters through `public/cron.php`.

#### Kernel, request lifecycle, and rendering
Forecor is the application boundary between HTTP and app code. It supplies application bootstrap, routing, sessions, security headers, dependency injection, and event dispatch; controllers form the presentation/API boundary and use services/models underneath.
- `Forecor/Core/Application.php`
- `Forecor/Core/Router.php`
- `Forecor/Core/SecurityHeaders.php`
- `App/Controllers/BaseController.php`
- `App/Core/TemplateEngine.php`

Responses are primarily Twig-rendered, theme-selected frontend/admin pages, with distinct API controllers for programmatic responses. Theme assets and templates are deployable customization surfaces.
- `App/Controllers/ApiController.php`
- `Inc/Template/frontend/default/views/base.html.twig`
- `Inc/Template/admin/default/views/base.html.twig`

#### Core forum domain
The principal write/read flow is controller → request validation/service logic → Eloquent models → rendered forum/topic pages. The core graph centers on `User`, forum hierarchy (`Category`, `Forum`), `Topic`, and `Post`; auxiliary models support tags, polls, attachments, reads, subscriptions, reactions, reports, and moderation.
- `App/Controllers/ForumController.php`
- `App/Controllers/TopicController.php`
- `App/Services/TopicService.php`
- `App/Models/Topic.php`
- `App/Models/Post.php`

Authentication, profiles, authorization, private messaging, notifications, and user preferences cross-cut that flow. Permissions are implemented as roles/definitions/content permissions and a reusable permission trait.
- `App/Controllers/AuthController.php`
- `App/Services/AuthService.php`
- `App/Models/Role.php`
- `App/Traits/HasPermissions.php`

#### Persistence and background processing
Eloquent targets MySQL/MariaDB. The repository includes a baseline schema and chronological migrations; release installs may import the prepared schema, while upgrades use the migration runner.
- `App/Database/schema.sql`
- `App/Database/migrations/2025_01_01_000001_create_search_and_features_tables.php`
- `Forecor/bin/migrate.php`

Cron executes recurring publication, RSS import, and version/security-related maintenance. Importers provide staged ingestion from XenForo, MyBB, and other MegaforBB installations, with ID mapping and counter synchronization.
- `public/cron.php`
- `Forecor/cron/publish_scheduled_topics.php`
- `App/Services/Rss/RssFeedImportRunner.php`
- `App/Services/Import/MegaforBBImporter.php`

#### Events, plugins, and modules
Domain events decouple topic/post/user actions from side effects: indexing, activity logs, user alerts, webhooks, and cache purges. Plugin loading extends this same application surface; plugin routes, listeners, templates, and lifecycle scripts live outside core app code.
- `App/Events/TopicCreated.php`
- `App/Listeners/IndexTopicInMeilisearch.php`
- `App/Listeners/VarnishPurgeListener.php`
- `App/Services/PluginLoader.php`
- `Inc/Plugin/AiAutoReply/plugin.php`

Idelist is a bounded feature module with its own controllers, models, services, provider, routes, votes, comments, and status workflow rather than being embedded in the forum domain.
- `App/Modules/Idelist/Providers/IdealistServiceProvider.php`
- `App/Modules/Idelist/Services/IdeaStatusService.php`
- `Route/idelist.php`

#### Infrastructure, external boundaries, and administration
Operational services abstract cache (file/Redis), Meilisearch, local/S3-compatible storage, Varnish purge, mail, Telegram-style webhooks, captcha, Stop Forum Spam, and RSS HTTP fetches. Security includes rate/attack presets, audit logging, censorship, file verification, and admin 2FA.
- `App/Services/Cache.php`
- `App/Services/MeilisearchService.php`
- `App/Services/StorageService.php`
- `App/Services/SecurityService.php`
- `App/Config/SecurityAttackPresets.php`

The `/admin` route area is the control plane for content, users, roles, themes, plugins, imports, backups, security, and operational settings; it is intentionally separated into many specialized controllers.
- `App/Controllers/AdminController.php`
- `App/Controllers/AdminSecurityController.php`
- `App/Controllers/AdminImportController.php`
- `App/Controllers/AdminPluginsController.php`

Main entry points: [`Forecor/Core/Router.php`](https://github.com/megabre/megaforbb/blob/main/Forecor/Core/Router.php) (Route dispatch), [`App/Controllers/BaseController.php`](https://github.com/megabre/megaforbb/blob/main/App/Controllers/BaseController.php) (Application controllers), [`App/Controllers/AdminController.php`](https://github.com/megabre/megaforbb/blob/main/App/Controllers/AdminController.php) (Admin control plane), [`Forecor/Core/Application.php`](https://github.com/megabre/megaforbb/blob/main/Forecor/Core/Application.php) (Forecor kernel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Kernel"]
  node_http["HTTP entry<br/>PHP entry point<br/>[index.php]"]
  node_kernel{{"Forecor kernel<br/>application kernel<br/>[Application.php]"}}
  node_router["Route dispatch<br/>router<br/>[Router.php]"]
end

subgraph group_forum["Forum Application"]
  node_controllers["Application controllers<br/>presentation boundary<br/>[BaseController.php]"]
  node_templates["Twig themes<br/>rendering surface<br/>[base.html.twig]"]
  node_topic_service["Topic service<br/>domain service<br/>[TopicService.php]"]
  node_forum_models[("Forum domain models<br/>Eloquent models<br/>[Topic.php]")]
  node_auth_permissions["Auth &amp; permissions<br/>cross-cutting domain<br/>[AuthService.php]"]
end

subgraph group_extensions["Events &amp; Extensions"]
  node_events["Domain events<br/>event dispatch<br/>[TopicCreated.php]"]
  node_event_listeners["Side-effect listeners<br/>event listeners"]
  node_plugins["Plugin system<br/>extension loader<br/>[PluginLoader.php]"]
  node_idelist["Idelist module<br/>bounded feature module"]
end

subgraph group_operations["Operations &amp; Infrastructure"]
  node_database[("MySQL / MariaDB<br/>relational database<br/>[schema.sql]")]
  node_cron["Cron entry<br/>scheduled entry point<br/>[cron.php]"]
  node_scheduled_jobs["Scheduled jobs<br/>background jobs"]
  node_importers["Import pipeline<br/>migration service"]
  node_migration_runner["Migration runner<br/>schema upgrade tool<br/>[migrate.php]"]
  node_infra_services["Infrastructure services<br/>external integrations"]
  node_security["Security services<br/>security controls"]
end

subgraph group_admin["Administration"]
  node_admin_routes["Admin control plane<br/>administrative controllers"]
end

node_http -->|"bootstraps"| node_kernel
node_kernel -->|"configures"| node_router
node_router -->|"web / API routes"| node_controllers
node_router -->|"/admin routes"| node_admin_routes
node_router -->|"module routes"| node_idelist
node_controllers -->|"topic operations"| node_topic_service
node_controllers -->|"identity checks"| node_auth_permissions
node_controllers -->|"renders pages"| node_templates
node_topic_service -->|"reads / writes"| node_forum_models
node_auth_permissions -->|"users and roles"| node_forum_models
node_forum_models -->|"Eloquent persistence"| node_database
node_kernel -->|"dispatches"| node_events
node_events -->|"triggers"| node_event_listeners
node_event_listeners -->|"search, cache, webhooks"| node_infra_services
node_plugins -.->|"extends application"| node_kernel
node_idelist -->|"persists ideas"| node_database
node_cron -->|"executes"| node_scheduled_jobs
node_scheduled_jobs -->|"RSS / import work"| node_importers
node_importers -->|"imports data"| node_database
node_migration_runner -->|"upgrades schema"| node_database
node_admin_routes -->|"admin imports"| node_importers
node_admin_routes -->|"manages"| node_plugins
node_admin_routes -->|"security controls"| node_security
node_security -.->|"protects integrations"| node_infra_services

click node_http "https://github.com/megabre/megaforbb/blob/main/public/index.php"
click node_kernel "https://github.com/megabre/megaforbb/blob/main/Forecor/Core/Application.php"
click node_router "https://github.com/megabre/megaforbb/blob/main/Forecor/Core/Router.php"
click node_controllers "https://github.com/megabre/megaforbb/blob/main/App/Controllers/BaseController.php"
click node_templates "https://github.com/megabre/megaforbb/blob/main/Inc/Template/frontend/default/views/base.html.twig"
click node_topic_service "https://github.com/megabre/megaforbb/blob/main/App/Services/TopicService.php"
click node_forum_models "https://github.com/megabre/megaforbb/blob/main/App/Models/Topic.php"
click node_auth_permissions "https://github.com/megabre/megaforbb/blob/main/App/Services/AuthService.php"
click node_database "https://github.com/megabre/megaforbb/blob/main/App/Database/schema.sql"
click node_events "https://github.com/megabre/megaforbb/blob/main/App/Events/TopicCreated.php"
click node_event_listeners "https://github.com/megabre/megaforbb/blob/main/App/Listeners/IndexTopicInMeilisearch.php"
click node_plugins "https://github.com/megabre/megaforbb/blob/main/App/Services/PluginLoader.php"
click node_idelist "https://github.com/megabre/megaforbb/blob/main/App/Modules/Idelist/Providers/IdealistServiceProvider.php"
click node_cron "https://github.com/megabre/megaforbb/blob/main/public/cron.php"
click node_scheduled_jobs "https://github.com/megabre/megaforbb/blob/main/Forecor/cron/publish_scheduled_topics.php"
click node_importers "https://github.com/megabre/megaforbb/blob/main/App/Services/Import/MegaforBBImporter.php"
click node_migration_runner "https://github.com/megabre/megaforbb/blob/main/Forecor/bin/migrate.php"
click node_infra_services "https://github.com/megabre/megaforbb/blob/main/App/Services/MeilisearchService.php"
click node_admin_routes "https://github.com/megabre/megaforbb/blob/main/App/Controllers/AdminController.php"
click node_security "https://github.com/megabre/megaforbb/blob/main/App/Services/SecurityService.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_http,node_kernel,node_router toneBlue
class node_controllers,node_templates,node_topic_service,node_forum_models,node_auth_permissions toneAmber
class node_events,node_event_listeners,node_plugins,node_idelist toneMint
class node_database,node_cron,node_scheduled_jobs,node_importers,node_migration_runner,node_infra_services,node_security toneRose
class node_admin_routes toneIndigo
```

## Components

### Entry & Kernel

- [HTTP entry](https://github.com/megabre/megaforbb/blob/main/public/index.php): PHP entry point · `public/index.php`
- [Forecor kernel](https://github.com/megabre/megaforbb/blob/main/Forecor/Core/Application.php): application kernel · Bootstraps routing, DI, sessions, security headers, and events. · `Forecor/Core/Application.php`
- [Route dispatch](https://github.com/megabre/megaforbb/blob/main/Forecor/Core/Router.php): router · Dispatches web, admin, API, and module routes. · `Forecor/Core/Router.php`

### Forum Application

- [Application controllers](https://github.com/megabre/megaforbb/blob/main/App/Controllers/BaseController.php): presentation boundary · Forum, topic, auth, and API controllers handle requests. · `App/Controllers/BaseController.php`
- [Twig themes](https://github.com/megabre/megaforbb/blob/main/Inc/Template/frontend/default/views/base.html.twig): rendering surface · Frontend and admin templates are deployable customization surfaces. · `Inc/Template/frontend/default/views/base.html.twig`
- [Topic service](https://github.com/megabre/megaforbb/blob/main/App/Services/TopicService.php): domain service · Validates and coordinates core topic operations. · `App/Services/TopicService.php`
- [Forum domain models](https://github.com/megabre/megaforbb/blob/main/App/Models/Topic.php): Eloquent models · User, category, forum, topic, and post form the core domain. · `App/Models/Topic.php`
- [Auth & permissions](https://github.com/megabre/megaforbb/blob/main/App/Services/AuthService.php): cross-cutting domain · Authentication, roles, profiles, and content permissions. · `App/Services/AuthService.php`

### Events & Extensions

- [Domain events](https://github.com/megabre/megaforbb/blob/main/App/Events/TopicCreated.php): event dispatch · Decouples topic, post, and user side effects. · `App/Events/TopicCreated.php`
- [Side-effect listeners](https://github.com/megabre/megaforbb/blob/main/App/Listeners/IndexTopicInMeilisearch.php): event listeners · Indexes content, logs activity, alerts users, purges caches, and sends webhooks. · `App/Listeners/IndexTopicInMeilisearch.php`
- [Plugin system](https://github.com/megabre/megaforbb/blob/main/App/Services/PluginLoader.php): extension loader · Loads plugin routes, listeners, templates, and lifecycle code. · `App/Services/PluginLoader.php`
- [Idelist module](https://github.com/megabre/megaforbb/blob/main/App/Modules/Idelist/Providers/IdealistServiceProvider.php): bounded feature module · Own provider, routes, idea workflow, votes, and comments. · `App/Modules/Idelist/Providers/IdealistServiceProvider.php`

### Operations & Infrastructure

- [MySQL / MariaDB](https://github.com/megabre/megaforbb/blob/main/App/Database/schema.sql): relational database · Eloquent persistence for forum and module data. · `App/Database/schema.sql`
- [Cron entry](https://github.com/megabre/megaforbb/blob/main/public/cron.php): scheduled entry point · `public/cron.php`
- [Scheduled jobs](https://github.com/megabre/megaforbb/blob/main/Forecor/cron/publish_scheduled_topics.php): background jobs · Publishes scheduled topics, imports RSS, and performs maintenance. · `Forecor/cron/publish_scheduled_topics.php`
- [Import pipeline](https://github.com/megabre/megaforbb/blob/main/App/Services/Import/MegaforBBImporter.php): migration service · Imports external forums with ID mapping and counter synchronization. · `App/Services/Import/MegaforBBImporter.php`
- [Migration runner](https://github.com/megabre/megaforbb/blob/main/Forecor/bin/migrate.php): schema upgrade tool · Applies chronological database upgrades. · `Forecor/bin/migrate.php`
- [Infrastructure services](https://github.com/megabre/megaforbb/blob/main/App/Services/MeilisearchService.php): external integrations · Cache, search, storage, Varnish, mail, webhooks, captcha, and RSS HTTP. · `App/Services/MeilisearchService.php`
- [Security services](https://github.com/megabre/megaforbb/blob/main/App/Services/SecurityService.php): security controls · Rate protection, audit logging, censorship, file verification, and admin 2FA. · `App/Services/SecurityService.php`

### Administration

- [Admin control plane](https://github.com/megabre/megaforbb/blob/main/App/Controllers/AdminController.php): administrative controllers · Manages content, users, roles, themes, plugins, imports, security, and settings. · `App/Controllers/AdminController.php`

## Connections

- HTTP entry → Forecor kernel: bootstraps
- Forecor kernel → Route dispatch: configures
- Route dispatch → Application controllers: web / API routes
- Route dispatch → Admin control plane: /admin routes
- Route dispatch → Idelist module: module routes
- Application controllers → Topic service: topic operations
- Application controllers → Auth & permissions: identity checks
- Application controllers → Twig themes: renders pages
- Topic service → Forum domain models: reads / writes
- Auth & permissions → Forum domain models: users and roles
- Forum domain models → MySQL / MariaDB: Eloquent persistence
- Forecor kernel → Domain events: dispatches
- Domain events → Side-effect listeners: triggers
- Side-effect listeners → Infrastructure services: search, cache, webhooks
- Plugin system → Forecor kernel: extends application
- Idelist module → MySQL / MariaDB: persists ideas
- Cron entry → Scheduled jobs: executes
- Scheduled jobs → Import pipeline: RSS / import work
- Import pipeline → MySQL / MariaDB: imports data
- Migration runner → MySQL / MariaDB: upgrades schema
- Admin control plane → Import pipeline: admin imports
- Admin control plane → Plugin system: manages
- Admin control plane → Security services: security controls
- Security services → Infrastructure services: protects integrations
