Skip to content

Commit 8570593

Browse files
authored
Add package registry architecture overview (#23445)
As announced in #22810 I added a readme file to help understanding how the package registry archictecture works and how the go packages are related.
1 parent 8421b82 commit 8570593

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

routers/api/packages/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Gitea Package Registry
2+
3+
This document gives a brief overview how the package registry is organized in code.
4+
5+
## Structure
6+
7+
The package registry code is divided into multiple modules to split the functionality and make code reuse possible.
8+
9+
| Module | Description |
10+
| - | - |
11+
| `models/packages` | Common methods and models used by all registry types |
12+
| `models/packages/<type>` | Methods used by specific registry type. There should be no need to use type specific models. |
13+
| `modules/packages` | Common methods and types used by multiple registry types |
14+
| `modules/packages/<type>` | Registry type specific methods and types (e.g. metadata extraction of package files) |
15+
| `routers/api/packages` | Route definitions for all registry types |
16+
| `routers/api/packages/<type>` | Route implementation for a specific registry type |
17+
| `services/packages` | Helper methods used by registry types to handle common tasks like package creation and deletion in `routers` |
18+
| `services/packages/<type>` | Registry type specific methods used by `routers` and `services` |
19+
20+
## Models
21+
22+
Every package registry implementation uses the same underlaying models:
23+
24+
| Model | Description |
25+
| - | - |
26+
| `Package` | The root of a package providing values fixed for every version (e.g. the package name) |
27+
| `PackageVersion` | A version of a package containing metadata (e.g. the package description) |
28+
| `PackageFile` | A file of a package describing its content (e.g. file name) |
29+
| `PackageBlob` | The content of a file (may be shared by multiple files) |
30+
| `PackageProperty` | Additional properties attached to `Package`, `PackageVersion` or `PackageFile` (e.g. used if metadata is needed for routing) |
31+
32+
The following diagram shows the relationship between the models:
33+
```
34+
Package <1---*> PackageVersion <1---*> PackageFile <*---1> PackageBlob
35+
```
36+
37+
## Adding a new package registry type
38+
39+
Before adding a new package registry type have a look at the existing implementation to get an impression of how it could work.
40+
Most registry types offer endpoints to retrieve the metadata, upload and download package files.
41+
The upload endpoint is often the heavy part because it must validate the uploaded blob, extract metadata and create the models.
42+
The methods to validate and extract the metadata should be added in the `modules/packages/<type>` package.
43+
If the upload is valid the methods in `services/packages` allow to store the upload and create the corresponding models.
44+
It depends if the registry type allows multiple files per package version which method should be called:
45+
- `CreatePackageAndAddFile`: error if package version already exists
46+
- `CreatePackageOrAddFileToExisting`: error if file already exists
47+
- `AddFileToExistingPackage`: error if package version does not exist or file already exists
48+
49+
`services/packages` also contains helper methods to download a file or to remove a package version.
50+
There are no helper methods for metadata endpoints because they are very type specific.

0 commit comments

Comments
 (0)