Directory Structure
The default Dracory application structure is intended to provide a great starting point for both large and small applications. But you are free to organize your application however you like. Dracory imposes almost no restrictions on where any given class is located - as long as Go can autoload the class.
The Root Directory
The root directory of a fresh Dracory installation contains various folders:
- app - Contains the core code of your application, including controllers, layouts, and middlewares.
- cmd - Contains command-line applications related to your project, such as deployment tools.
- config - Contains all of your application's configuration files.
- internal - Contains internal packages that are not meant to be imported by other projects.
- pkg - Contains packages that can be imported by other projects, such as themes and reusable components.
- resources - Contains assets such as JavaScript and other resources used by your application.
The App Directory
The app directory contains the core code of your application. We'll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.
- app/controllers - Contains the controllers for your application, which handle HTTP requests.
- app/layouts - Contains the layout templates used by your views.
- app/links - Contains URL constants and helper functions for generating links.
- app/middlewares - Contains the middleware for your application.
- app/routes - Contains all of the route definitions for your application.
- app/schedules - Contains scheduled tasks for your application.
- app/tasks - Contains background tasks for your application.
- app/widgets - Contains reusable UI components for your application.
The Controllers Directory
Controllers are the heart of your application, as they determine how HTTP requests should be handled. We've organized the controller directory to reflect the MVC pattern:
app/controllers/
├── admin/
│ ├── blog/
│ │ ├── post_controller.go
│ │ └── routes.go
│ ├── home/
│ │ └── home_controller.go
│ └── routes.go
├── shared/
│ └── page_not_found_controller.go
└── website/
├── home/
│ └── home_controller.go
├── seo/
│ ├── robots_txt_controller.go
│ ├── sitemap_xml_controller.go
│ └── routes.go
└── routes.go
The Internal Directory
The internal directory contains packages that are specific to your application and not intended to be imported by other projects:
- internal/cli - Contains CLI-related functionality.
- internal/cmds - Contains command handlers for your application.
- internal/emails - Contains email templates and functionality.
- internal/helpers - Contains helper functions used throughout your application.
- internal/testutils - Contains utilities for testing your application.
- internal/types - Contains custom type definitions for your application.
The Pkg Directory
The pkg directory contains packages that can be imported by other projects:
- pkg/blogblocks - Contains blog-related components.
- pkg/blogtheme - Contains blog theme components.
- pkg/pool - Contains connection pooling functionality.
- pkg/testimonials - Contains testimonial components.
- pkg/webtheme - Contains web theme components.
The Config Directory
The config directory, as the name implies, contains all of your application's configuration files. It's a great idea to read through all of these files and familiarize yourself with all of the options available to you.
The Resources Directory
The resources directory contains assets such as JavaScript and other resources used by your application.
The Cmd Directory
The cmd directory contains command-line applications related to your project, such as deployment tools and environment variable encryption utilities.