Project Structure
This page explains the structure of the GoMFT codebase to help developers understand how the application is organized.
Overview
GoMFT is built using a combination of Go for the backend and web technologies for the frontend. The application follows a modular architecture to maintain separation of concerns and facilitate testing and maintenance.
Directory Structure
Here's the high-level directory structure of the GoMFT project:
.
├── components/ # Templ components for UI
├── internal/
│ ├── api/ # REST API handlers
│ ├── auth/ # Authentication/authorization
│ ├── config/ # Configuration management
│ ├── db/ # Database models and operations
│ ├── email/ # Email service for notifications and password resets
│ ├── scheduler/ # Job scheduling and execution
│ └── web/ # Web interface handlers
├── static/ # Static assets
│ ├── css/
│ └── js/
└── main.go # Application entry point
Core Components
Backend (Go)
GoMFT's backend is written in Go and structured around several key packages:
main.go
The entry point for the application. It initializes the application, loads configuration, sets up the database, and starts the web server.
internal/
Contains all internal packages that are not intended to be imported by other applications.
-
api/
: REST API implementationhandlers/
: API request handlersmiddleware/
: API middleware (authentication, logging, etc.)routes.go
: API route definitions
-
auth/
: Authentication and authorizationproviders/
: Authentication providers (local, LDAP, OAuth)middleware/
: Authentication middlewarerbac/
: Role-based access control
-
config/
: Configuration managementconfig.go
: Application configuration structureenv.go
: Environment variable loadingfile.go
: Configuration file loading
-
db/
: Database layermodels/
: Database model definitionsmigrations/
: Database schema migrationsrepositories/
: Data access methods
-
email/
: Email functionalitytemplates/
: Email templatessender.go
: Email sending service
-
scheduler/
: Job scheduling and executioncron.go
: Cron-based job schedulerexecutor.go
: Transfer job executorqueue.go
: Job queue management
-
web/
: Web interfacehandlers/
: Web request handlersmiddleware/
: Web middlewareroutes.go
: Web route definitions
components/
Contains templ components that define the UI. Templ is a Go HTML templating library that provides type-safe templates.
components/
├── layouts/ # Page layouts
├── partials/ # Reusable UI components
├── pages/ # Page templates
│ ├── dashboard/
│ ├── transfers/
│ ├── connections/
│ ├── schedules/
│ └── admin/
└── htmx/ # HTMX-specific components
Frontend
The frontend uses a combination of Tailwind CSS for styling and HTMX for dynamic interactions.
static/
Contains static assets for the web interface:
-
css/
: CSS filesmain.css
: Main stylesheet (compiled from Tailwind)
-
js/
: JavaScript fileshtmx.min.js
: HTMX libraryalpine.min.js
: Alpine.js for lightweight interactivityapp.js
: Application-specific JavaScript
-
img/
: Images and icons
Build System
GoMFT uses several tools to build and bundle the application:
- Go Build: Compiles the Go code
- Templ: Compiles templ templates to Go code
- esbuild: Bundles JavaScript files
- Tailwind CSS: Compiles CSS
The build process is orchestrated by a combination of Go commands and npm scripts defined in package.json
.
Configuration Files
.air.toml
: Configuration for Air, a live reload tool for Go.env.example
: Example environment variables configurationgo.mod
: Go module definitiongo.sum
: Go module checksumspackage.json
: npm package definition for frontend dependenciesDockerfile
: Docker container definitiondocker-compose.yaml
: Docker Compose configuration
Database Structure
GoMFT uses GORM (Go Object Relational Mapper) with SQLite as the default database. The main database models include:
User
: User account informationRole
: User roles for RBACPermission
: Individual permissionsConnection
: File transfer connection configurationsTransfer
: Transfer definitionsSchedule
: Transfer schedulesHistory
: Transfer execution historySetting
: Application settings
API Structure
The REST API follows a RESTful design with these main endpoints:
/api/auth
: Authentication endpoints/api/users
: User management/api/connections
: Connection management/api/transfers
: Transfer management/api/schedules
: Schedule management/api/history
: Transfer history
Each endpoint typically supports standard CRUD operations.
Web Routes
The web interface is organized around these main routes:
/
: Dashboard/connections
: Connection management/transfers
: Transfer management/schedules
: Schedule management/history
: Transfer history/admin
: Administrative functions
Authentication Flow
The authentication flow in GoMFT works like this:
- User submits credentials via the login form or API
- Credentials are validated against the configured authentication provider(s)
- On success, a session is created for web users or a JWT token is issued for API users
- The user's permissions are loaded based on their role
- Requests are then authenticated via session cookie or JWT token
Transfer Execution Flow
The transfer execution flow is as follows:
- Transfer job is initiated (manually or via scheduler)
- Job is added to the execution queue
- Executor picks up the job and prepares the transfer
- rclone is invoked with the appropriate parameters
- Progress is monitored and logged
- Results are recorded in the history
- Notifications are sent if configured
Testing Structure
GoMFT includes several types of tests:
- Unit Tests: Test individual functions and methods
- Integration Tests: Test interactions between components
- API Tests: Test API endpoints
- End-to-End Tests: Test complete user flows
Tests are organized alongside the code they're testing, following Go conventions.
Documentation
Documentation is provided in several formats:
- Code Comments: Go doc comments for packages and functions
- API Documentation: OpenAPI/Swagger documentation for the REST API
- User Documentation: User guides and tutorials (this documentation site)
- README: Project overview and quick start instructions