Files

71 lines
3.9 KiB
Markdown
Raw Permalink Normal View History

2026-11-14 19:16:24 +05:00
# Project structure
Project uses domain-driven design with a pinch of clean architecture.
Typical structure should be like this:
```text
.
├── 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/application` is 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/domains` directory.
- 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 `dto` directory 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 `models` directory 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 in `internal/domains/core/config/storage/sqlite` and uses `internal/domains/core/sqlite` domain for its low-level actions.
- When applicable, migrations for that storage should be placed in `migrations` directory with `embed.FS` and applied on application's startup. For example, migrations for configuration storage should be placed in `internal/domains/core/config/storage/sqlite/migrations`.
- Domain in `protocols` or `integrations` category should contain one or more clients to external services for which this domain is responsible. E.g. `protocols/mattermost` domain should contain `client` package 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`, `Initialize` first class functions).
- Functions that are tied to structure (`func (t *type) Name() string`).
All these groups should be sorted alphabetically, like:
- Import `net/http` should be after `log/slog`.
- Variable `zetadata` should be after `megadata`.
- Function `func (t *type) Initialize() error` should be after `func (t *type) Configure() error`.
---
For more information about every part of project see files in components directory.