How garytan/gophish works
Project type and purpose
• This is a full-stack web application written in Go, called Gophish, an open-source phishing toolkit.
• Its core purpose is to let operators create and launch phishing campaigns, track responses, and manage users/templates.
File structure
• Top-level Go modules:
• gophish.go (entry point)
• controllers/ (HTTP handlers, REST API)
• models/ (ORM-like data models)
• db/ (database drivers & migrations for MySQL and SQLite)
• auth/, config/, context/, middleware/ (request pipeline, sessions, rate-limiting)
• static/, templates/ (frontend assets and HTML templates)
• mailer/, dialer/, imap/ (components that send mail, manage SMTP/IMAP connections)
• worker/ (background job processing – scheduling campaigns, sending events)
• webhook/ (outgoing webhooks to report events)
• Deployment/config: Dockerfile, ansible-playbook/, webpack.config.js
README for additional insights
• Confirms Go v1.10+, binary release, Docker support, default UI on port 3333
a. Main components
1. Web UI & REST API
• Static Assets (JS, CSS) served from /static
• HTML templates in /templates
• Controllers (controllers/api/*.go + controllers/route.go)
2. Application Server
• Authentication & Session Management (auth/, middleware/)
• Business Logic (controllers/, worker/, webhook/)
3. Database
• Choose MySQL or SQLite (db/db_mysql or db/db_sqlite3)
• Migrations under db/…/migrations
• Models layer interacts with DB (models/*.go)
4. Mail Subsystems
• dialer/ (handles SMTP connections configured via controllers/api/smtp.go)
• mailer/ (constructs & sends email messages)
• imap/ (tracks inbound responses via IMAP polling)
5. Worker & Scheduler
• Background tasks (worker/worker.go) → enqueues/sends campaigns, processes results
6. External Services
• SMTP server (outbound mail)
• IMAP server (inbound tracking)
• Optional webhooks to external endpoints
b. Relationships and interactions
• User’s browser → HTTP(S) → Web UI / API endpoints
• API calls → Controllers → Models → Database
• Campaign scheduling → Worker pulls tasks → dialer/mailer → SMTP → Recipient inbox
• Response tracking → imap monitor polls IMAP → writes events → Database
• On certain events → webhook component → HTTP POST → External systems
• Ansible/Docker used to provision the entire stack (app + DB + reverse proxy)
c. Architectural patterns & design principles
• MVC-style separation: templates (view), controllers (controller), models (model)
• Layered architecture: HTTP layer → business logic → persistence layer
• Modular services for mail sending, IMAP processing, background work
• Configuration-driven (config.json, env vars, ansible, Docker)
• Extensible via REST API & webhooks
d. Key technologies & frameworks
• Go standard library net/http, html/template
• Gulp/Webpack for JS asset bundling
• MySQL or SQLite3 databases
• Ansible & Docker for deployment
• Third-party Go libraries for sessions, rate limiting
Elements
• Green for user-facing components (Browser, UI)
• Blue for backend services (API, worker, mailer)
• Orange for persistence (DB, migrations)
• Gray for external systems (SMTP & IMAP servers, webhook endpoints)