How marcosd4h/mdmatador works
Project Type and Purpose
• MDMatador is a monolithic, full‑stack web application written in Go.
• It provides a web UI (HTML templates + CSS/JS assets) for administrators to enroll, manage, and issue commands to mobile devices (an MDM server).
• It persists data (users, enrollments, certificates, device settings, pending operations) in a SQL database via migration scripts.
High‑Level File Structure / Architectural Insights
• cmd/web: entrypoint Go code (main.go) that wires up HTTP server, routes, middleware, handlers.
• assets: all static resources (CSS, JS, fonts, images) and DB migration SQL.
• templates: HTML view templates (base, pages, partials).
• internal: core business logic modules:
• database: DB connection and data access (users, mdm tables).
• mdm: Apple MDM protocol handling (command manager, CSR generation, message types).
• token/password/validator: auth, credentials, request validation.
• request/response: HTTP request decoding and response encoding (JSON, templates, raw).
• version/common/helpers: utilities.
• go.mod / Makefile: build, test, migrate, run.
Key Components
a. Frontend Layer
• Web Browser (Admin UI)
• Static Assets Server (served by Go)
• HTML Templates Renderer
b. Backend Layer
• Go HTTP Server (cmd/web)
• Routing & Middleware (authentication, logging, error handling)
• Handler Functions (CRUD for users, devices, MDM operations)
• Business Modules (internal packages: mdm, token, validator, password)
c. Data Layer
• Relational Database (PostgreSQL / MySQL)
• Migration subsystem (assets/migrations)
d. External Services
• Apple Push Notification Service (APNs) for delivering MDM commands
• Enrolled Devices (iOS/Mac devices implementing MDM protocol)
Relationships and Data Flows
1. Admin interacts via Browser → sends HTTP requests to Go Server
2. Go Server:
• Serves static assets & renders templates
• Decodes JSON / form data via request/* packages
• Authorizes via token/password modules
• Validates via validator module
• Routes to appropriate handler (routes.go → handlers.go)
3. Handlers call internal/database to read/write schema tables
4. MDM handlers invoke internal/mdm to:
• Generate commands, build protocol messages
• Enqueue commands in pending_device_operations table
5. APNs Client in Go Server polls pending operations → pushes commands to devices via APNs
6. Devices consume commands and callback to Go Server’s MDM endpoints → processed again by internal/mdm modules
7. Updates persisted in DB; UI refreshed
Architectural Patterns & Design Principles
• Layered architecture: Presentation (templates/static), Application (handlers, middleware), Domain (internal modules), Persistence (database).
• MVC‑like: Templates + data models, Controllers = handlers.
• Single binary deployment: Go compiles into one executable.
• Dependency inversion: internal modules abstracted via interfaces (e.g., database/db.go).
• Migration‑driven schema management via assets/migrations.