Architecture
RocketMainta is a classic server-rendered application: one Go process serves the HTML pages, the JSON API and the static assets, and MySQL/MariaDB holds the state.
browser / mobile / third-party client
│ HTTP
┌──────────────▼───────────────────────────┐
│ cmd/server/main.go │
│ recover → logger → helmet → etag → gzip │
│ → static → locale → session → CSRF │
├──────────────────────────────────────────┤
│ internal/app │
│ routes.go 171 routes │
│ mw.go session, CSRF, guards │
│ handler_*.go public/auth/dashboard/ │
│ pay/admin/api/chat │
│ render.go html/template renderer │
│ views.go template helpers │
├──────────────────────────────────────────┤
│ internal/auth bcrypt · JWT · TOTP │
│ internal/paygate 44 gateways + drivers │
│ internal/notify SMTP · SMS · log │
│ internal/i18n DB-backed translator │
│ internal/pdf invoice writer │
└──────────────┬───────────────────────────┘
│ database/sql
┌──────────────▼───────────────────────────┐
│ internal/store schema · migrations · seed│
│ MySQL 8 / MariaDB 10.6+ (53 tables) │
└──────────────────────────────────────────┘
Request lifecycle
- Recover turns a panic into a 500 without killing the process.
- Logger writes one line per request with the method, path, status and duration.
- Helmet / ETag / Gzip add the usual security and caching headers.
- Static serves
web/staticunder/staticwith an ETag and a one-hour cache. - Locale picks the language from the
?lang=query, therm_localecookie, the
Accept-Language header and finally the default language. It also sets the text direction.
- Session reads the
rm_sessioncookie (or anAuthorization: Bearerheader for the API),
verifies the JWT, compares the embedded token_version with the users.token_version column and loads the user. A banned or re-roled account therefore loses its session immediately.
- CSRF issues a token in the
rm_csrfcookie and validates the_csrffield on every
POST/PUT/PATCH/DELETE. The API and the gateway webhooks are exempt.
- The router dispatches to the handler; the renderer renders
web/templates/<section>/<page>.html inside the matching layout.
Rendering
internal/app/render.go implements a small renderer instead of using Fiber's view engine:
- the root template is created as
template.New("rocketmainta-root")— naming itlayoutwould
make t.New("layout") return a detached copy and the partials would never be attached;
- every file in
web/templates/partials/is parsed into the set; - the layout of the requested section (
public,auth,dashboard,admin) is parsed and the
page template is added under the name content;
- helpers such as
raw,upper,splitandmoneyare registered on the function map.
Adding a page therefore only means dropping a file into web/templates/<section>/.
Data model
53 tables, created by an idempotent embedded schema (internal/store/schema.sql):
| Area | Tables |
|---|---|
| Identity | users, roles, permissions, role_permission, user_role, password_resets, verification_codes, twofa_challenges, login_attempts, social_accounts |
| Catalogue | categories, services, service_options, device_models, brands, technician_slots |
| Orders | orders, order_items, order_status_histories, reviews, coupons |
| Money | payment_gateways, payments, manual_payments, invoices |
| Support | tickets, ticket_messages, live_chats, chat_messages, contact_messages |
| Content | pages, sections, faqs, posts, post_categories, post_post_category |
| Platform | settings, languages, translations, email_templates, sms_templates, sms_providers, notification_events, notification_log, notifications, extensions, audit_logs, gdpr_consents, subscribers, sitemaps, server_metrics |
The schema uses portable MySQL/MariaDB SQL (CREATE TABLE IF NOT EXISTS, COALESCE instead of ISNULL, no vendor-specific functions) so it runs on both engines.
Seeding
internal/store/seed.go fills a fresh database with a realistic demo shop:
- 6 roles, 27 permissions
- 1 language (English) with RTL support, 72 settings in 8 groups
- 44 payment gateways (40 automated, 4 manual) with their logos and credential fields
- 15 e-mail templates, 6 SMS templates, 20 notification rules
- 8 extensions, 11 categories, 27 services, 33 brands, 24 FAQs, 9 pages, 5 blog posts
- 1 administrator (only when no administrator exists yet)
Every insert uses INSERT IGNORE, so seeding is idempotent and safe to re-run.
Security
| Concern | Mitigation |
|---|---|
| Password storage | bcrypt with a per-password salt |
| Session forgery | HS256 JWT + a token_version column checked on every request |
| CSRF | Per-session token, required on every state-changing form |
| Brute force | Login throttling per IP and per e-mail address, plus an arithmetic CAPTCHA on registration |
| Privilege escalation | Role guards on the admin group, ownership checks on customer resources |
| Input validation | Every write goes through explicit validation with field-level error messages |
| Auditability | audit_logs records the actor, the action, the entity and the IP |
| Privacy | gdpr_consents table, data export and deletion requests in the customer area |
Payments
internal/paygate/registry.go is the single source of truth for the gateway catalogue. Each gateway declares its driver, currency, fee, artwork and the credential fields the admin panel has to render. DriverFor maps a gateway to its implementation:
stripe→POST /v1/checkout/sessionswith basic auth (secret_key)paypal→ OAuth token +v2/checkout/ordersbank,cheque,moneygram,cash→ manual drivers that never leave the server- everything else → the generic hosted-checkout driver (
checkout_url+ optional HMAC secret)
A gateway without credentials falls back to the sandbox simulator, so the complete order → pay → confirm flow is always reachable. The webhook route /pay/webhook/:code verifies the signature before a payment is marked as paid.