# Code walkthrough: Gitea data structures for repositories, issues, …

**URL:** <https://forum.gitea.com/t/code-walkthrough-gitea-data-structures-for-repositories-issues/4343>\
**Category:** Install/Maintain/Configure\
**Created:** [January 4, 2022, 11:45am UTC](https://forum.gitea.com/t/code-walkthrough-gitea-data-structures-for-repositories-issues/4343 "2022-01-04T11:45:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dachary](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/dachary/32/4990_2.png) [@dachary](https://forum.gitea.com/u/dachary)\
**Post date:** [January 4, 2022, 11:45am UTC](https://forum.gitea.com/t/code-walkthrough-gitea-data-structures-for-repositories-issues/4343/1 "2022-01-04T11:45:00Z")

</div>

_This is one of the [Code walkthrough](https://forum.gitea.com/search?q=code%20walkthrough%20in%3Atitle%20%40dachary%20order%3Alatest) I wrote while exploring the [Gitea codebase](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/)._

### Database / models

A Gitea project consists of a git repository and rows stored in a SQL database to represent the description of the project, issues, milestones, pull requests, etc. The entire database and the tables that contain these rows are created by [xorm](https://xorm.io/) from definitions from in the [models directory](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/models) for [issues](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/models/issue.go#L35-L79), [repository](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/models/repo/repo.go#L95-L155), etc.

### API / structs

The [Gitea API](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/routers/api/v1/api.go) is JSON based. The [endpoint to create an issue](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/routers/api/v1/repo/issue.go#L553) expects [a JSON description of the issue](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/routers/api/v1/repo/issue.go#L575) from the [structs directory](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/structs) that defines the [CreateIssueOption](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/structs/issue.go#L76-L92). It is also in the same structs directory that the [Issue data structure](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/structs/issue.go#L40-L74) will be found and [converted from the data found in the database](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/convert/issue.go#L25-L99) before it is returned from the [endpoint to get the full information about an issue](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/routers/api/v1/repo/issue.go#L536).

### Migrations

When migrating a project to or from Gitea, the information it contains is stored in [data structures dedicated to migration](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration) by the [downloader](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration/downloader.go) (for [issues](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration/issue.go), etc.). There exist [downloader implementations](https://github.com/go-gitea/gitea/tree/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations) for GitLab, GitHub, etc. These data structures are then fed to an [uploader](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration/uploader.go) to re-create / migrate the project from scratch. There currently exists only [one uploader for Gitea](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations/gitea_uploader.go).

The migration can use the originating forge API to [obtain information in memory using the downloader and send it to the uploader](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations/migrate.go#L110). It can also [dump the information obtained by the downloader to disk in YAML](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations/dump.go#L555), and, at a later time, [read the YAML files and feed them to the uploader](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations/dump.go#L609).

### Transformation paths

To summarize the above, the following paths exist to transform data structures in Gitea. Not all data structures representing a particular aspect of a project contain the same information. For instance in the case of an issue the [migration data structure](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration/issue.go) have much less information than the [model data structure](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/models/issue.go#L35-L79). It is however possible to transform each data structure into another (in some cases via an intermediary representation, for instance when dumping a project that resides in the database into migration files it is done via the API).

- [API](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/routers/api/v1/api.go) converts [structs data structures](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/structs) from and to [models](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/models).
- Migration [dump](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations/dump.go#L555) converts the content of other forges (GitLab, Gitea, GitHub) into [migration data structures](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration)
- Migration [restore](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/services/migrations/dump.go#L609) converts [migration data structures](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/modules/migration) to [models](https://github.com/go-gitea/gitea/blob/165346c15c6d021028a65121e692a17ffc927e2c/models).
