优化结构
This commit is contained in:
@@ -6,15 +6,22 @@ agents must follow when changing the template.
|
||||
## Project structure
|
||||
|
||||
```
|
||||
api/<domain>/<version>/ Proto sources and generated stubs. Public contract.
|
||||
cmd/<app>/ Entrypoint, Wire injector, main.go.
|
||||
cmd/ Entrypoint, Wire injector, main.go.
|
||||
configs/ Runtime config (config.yaml). No secrets.
|
||||
internal/config/ Viper config models, loading, snapshots, and reloads.
|
||||
internal/global/ Process-wide shared runtime resources.
|
||||
internal/server/ HTTP/gRPC server wiring.
|
||||
internal/service/ Transport adapters; one file per resource.
|
||||
internal/biz/ Domain models, usecases, repo interfaces, errors.
|
||||
internal/data/ Repo implementations and storage clients.
|
||||
internal/server/ Gin/Kratos handlers, middleware, routers, static files.
|
||||
internal/service/dto/ Hand-written request and response DTOs.
|
||||
internal/service/ DTO/DO transport adapters.
|
||||
internal/biz/ Domain models, usecases, repo interfaces, errors.
|
||||
internal/data/ Repo implementations, database clients, migrations.
|
||||
internal/initialize/ First-install and configuration orchestration.
|
||||
internal/integration/ External I/O adapters (cache, email, payment, storage).
|
||||
internal/modules/ Built-in module schema, seed, menu, API, and task contributions.
|
||||
internal/routecatalog/ HTTP route metadata and runtime policies.
|
||||
internal/worker/ Timed-task runtime and scheduler.
|
||||
internal/utils/ Stateless internal helpers.
|
||||
pkg/ Reusable infrastructure packages.
|
||||
web/ Vue administration frontend.
|
||||
```
|
||||
|
||||
## Layering & dependency rules
|
||||
@@ -28,7 +35,7 @@ owns the PO; `service` is a pass-through that converts at its boundary.
|
||||
│ declares │ implements
|
||||
└─── repo IF ────┘
|
||||
|
||||
DTO Data Transfer Object — proto request / response.
|
||||
DTO Data Transfer Object — hand-written HTTP request / response.
|
||||
DO Domain Object — pure biz model, no proto, no storage tags.
|
||||
PO Persistent Object — storage shape, owned by `data`.
|
||||
```
|
||||
@@ -39,11 +46,13 @@ owns the PO; `service` is a pass-through that converts at its boundary.
|
||||
| biz | DO | DO | DTO, PO, storage client |
|
||||
| data | PO | DO ↔ PO | DTO |
|
||||
|
||||
- `service` imports `api/...` (DTO) and `biz` (DO). Never `data`.
|
||||
- `biz` imports `api/...` only for error reason enums. Never `service`,
|
||||
never `data`. The repo interface declared here is the inversion seam.
|
||||
- `service` imports `internal/service/dto` (DTO) and `biz` (DO). Never `data`.
|
||||
- `biz` never imports `service` or `data`. The repo interface declared here is
|
||||
the inversion seam.
|
||||
- `data` imports `biz` to implement the repo interface. Never `service`,
|
||||
never DTOs.
|
||||
- `integration` implements external I/O boundaries and may import `biz` and
|
||||
provider SDKs; it is not a utility layer.
|
||||
- `cmd` is the only place that wires all layers via Wire.
|
||||
|
||||
A change crossing these arrows the wrong way is a layering bug; fix the
|
||||
|
||||
Reference in New Issue
Block a user