3.9 KiB
3.9 KiB
Project structure
Project uses domain-driven design with a pinch of clean architecture.
Typical structure should be like this:
.
├── cmd/
│ └── binaryname/
│ └── main.go # Binary entrypoint: domains registration, app start/shutdown.
└── internal/
├── application/
│ └── application.go # Application singleton.
├── constants/
│ └── version.go
└── domains/
└── core/ # Domain category.
└── config/ # Domain.
├── config.go # Domain service.
├── read.go
├── write.go
├── dto/ # DTOs for inter-domain API.
│ └── configvalue.go
├── models/ # Domain models.
│ └── configvalue.go
└── storage/
└── sqlite/ # Storage implementation.
├── storage.go
├── read.go
└── write.go
Where:
internal/applicationis an application singleton that is responsible for application's lifecycle (see below).- Every entity or business logic should be placed in own domain in
internal/domainsdirectory. - Every domain can be categorized in one category which is a directory in
internal/domains:core- for core functionality like GUI window, database, configuration management, etc.features- for features, like messages pane, channels list, etc.integrations- any other external integrations, like giphy, memegenerator, etc.- Any other category project might need.
- Every domain can contain zero or more DTOs that are placed in
dtodirectory in domain's root directory, e.g.internal/domains/core/config/dto. These DTOs are used for cross-domain calls. - Every domain can contain zero or more models that are placed in
modelsdirectory in domain's root directory, e.g.internal/domains/core/config/models. These models are used within domain and also contain converting functions between data types like DTOs, storage models, and so on. - Every domain can contain zero or more storages that are tied to some low-level storage defined as domain in
internal/domains/core. For example, SQLite database storage for configuration domain is placed ininternal/domains/core/config/storage/sqliteand usesinternal/domains/core/sqlitedomain for its low-level actions.- When applicable, migrations for that storage should be placed in
migrationsdirectory withembed.FSand applied on application's startup. For example, migrations for configuration storage should be placed ininternal/domains/core/config/storage/sqlite/migrations.
- When applicable, migrations for that storage should be placed in
- Domain in
protocolsorintegrationscategory should contain one or more clients to external services for which this domain is responsible. E.g.protocols/mattermostdomain should containclientpackage which is used as "proxy" between mattermost's Go client and protocol domain itself.
Lines sorting in files
Lines in files should be sorted like this:
- Imports first, split in 3 groups separated by blank line:
- First group of imports - stdlib.
- Second group of imports - external imports.
- Third group of imports - local dependencies.
- Constants (
const). - Variables (
var). - Structure definition (
type T struct). - Structure initializers (
New,Initializefirst class functions). - Functions that are tied to structure (
func (t *type) Name() string).
All these groups should be sorted alphabetically, like:
- Import
net/httpshould be afterlog/slog. - Variable
zetadatashould be aftermegadata. - Function
func (t *type) Initialize() errorshould be afterfunc (t *type) Configure() error.
For more information about every part of project see files in components directory.