# sugarlabs/musicblocks-git-backend architecture

> Architecture diagram of the GitHub repository sugarlabs/musicblocks-git-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sugarlabs/musicblocks-git-backend
- Repository: https://github.com/sugarlabs/musicblocks-git-backend

## Overview

Music Blocks backend is an Express API that stores student projects as GitHub repositories and supports versioned project workflows plus browsing and community features. The principal workflow is project creation or editing, with ownership verified by a client key; users can also fork projects, inspect commit history, and load historical project data. Catalog search and project interactions use SQLite, which also holds thumbnail data. The graph includes documented capabilities whose handler implementations were not sampled; their internal calls are therefore not inferred beyond the route wiring shown.

Main entry points: [`src/routes/projectRoutes.ts`](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/routes/projectRoutes.ts) (Project routes), [`src/middleware/verifyOwner.ts`](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/middleware/verifyOwner.ts) (Owner verification), [`src/controllers/getThumbnail.ts`](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/getThumbnail.ts) (Thumbnail delivery), [`src/utils/db.ts`](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/db.ts) (SQLite project store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and authorization"]
  node_routes["Project routes<br/>[projectRoutes.ts]"]
  node_owner["Owner verification<br/>[verifyOwner.ts]"]
end

subgraph group_github["GitHub project workflows"]
  node_create["Create project<br/>[createProject.ts]"]
  node_create_repo["Create repository<br/>[createRepo.ts]"]
  node_edit["Edit project<br/>[editProject.ts]"]
  node_update_repo["Update repository<br/>[updateRepo.ts]"]
  node_fork["Fork project<br/>[forkProject.ts]"]
  node_fork_repo["Fork repository<br/>[forkRepo.ts]"]
  node_fork_history["Fork with history<br/>[forkWithHistory.ts]"]
  node_pull_request["Pull requests"]
  node_commit_history["Commit history"]
  node_project_data["Latest project data<br/>[getProjectData.ts]"]
  node_historical_data["Commit project data"]
  node_branch["Create branch<br/>[createBranch.ts]"]
end

subgraph group_catalog["Discovery and community"]
  node_search_controller["Search endpoint<br/>[searchProjects.ts]"]
  node_search_service["Project search<br/>[searchProjects.ts]"]
  node_pagination["Pagination<br/>[pagination.ts]"]
  node_thumbnail["Thumbnail delivery<br/>[getThumbnail.ts]"]
  node_catalog_handlers["Catalog and social handlers"]
end

subgraph group_storage["State and authentication"]
  node_sqlite[("SQLite project store<br/>[db.ts]")]
  node_repo_resolver["Repository resolver<br/>[resolveRepoName.ts]"]
  node_key_hash["Key hashing<br/>[hash.ts]"]
end

node_frontend(("Music Blocks frontend"))
node_github_app{{"GitHub App"}}
node_github_pat{{"GitHub PAT"}}

node_frontend -->|"calls API"| node_routes
node_routes -->|"routes create"| node_create
node_create -->|"creates repository"| node_create_repo
node_routes -->|"checks edit owner"| node_owner
node_owner -->|"authorizes edit"| node_edit
node_edit -->|"updates project"| node_update_repo
node_routes -->|"routes fork"| node_fork
node_fork -->|"creates fork"| node_fork_repo
node_routes -->|"routes history fork"| node_fork_history
node_fork_history -->|"creates and pushes"| node_github_app
node_fork_history -.->|"PAT optional"| node_github_pat
node_routes -->|"routes pull requests"| node_pull_request
node_routes -->|"routes commits"| node_commit_history
node_routes -->|"routes latest data"| node_project_data
node_routes -->|"routes historical data"| node_historical_data
node_routes -->|"routes branch creation"| node_branch
node_routes -->|"routes search"| node_search_controller
node_search_controller -->|"searches projects"| node_search_service
node_search_controller -->|"parses pagination"| node_pagination
node_search_service -->|"queries catalog"| node_sqlite
node_routes -->|"routes thumbnails"| node_thumbnail
node_thumbnail -->|"reads thumbnail"| node_sqlite
node_thumbnail -->|"fetches fallback image"| node_github_app
node_thumbnail -->|"resolves repository"| node_repo_resolver
node_repo_resolver -->|"looks up legacy ID"| node_sqlite
node_owner -->|"hashes key"| node_key_hash
node_owner -->|"reads metadata"| node_github_app
node_create_repo -->|"creates GitHub repo"| node_github_app
node_fork_repo -->|"forks GitHub repo"| node_github_app
node_routes -->|"routes catalog features"| node_catalog_handlers
node_catalog_handlers -.->|"uses catalog state"| node_sqlite

click node_routes "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/routes/projectRoutes.ts"
click node_owner "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/middleware/verifyOwner.ts"
click node_create "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/createProject.ts"
click node_create_repo "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/createRepo.ts"
click node_edit "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/editProject.ts"
click node_update_repo "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/updateRepo.ts"
click node_fork "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/forkProject.ts"
click node_fork_repo "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/forkRepo.ts"
click node_fork_history "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/forkWithHistory.ts"
click node_pull_request "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/pullRequestService.ts"
click node_commit_history "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/getCommitHistory.ts"
click node_project_data "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/getProjectData.ts"
click node_historical_data "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/getProjectDataAtCommit.ts"
click node_branch "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/createBranch.ts"
click node_search_controller "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/searchProjects.ts"
click node_search_service "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/searchProjects.ts"
click node_pagination "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/pagination.ts"
click node_thumbnail "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/getThumbnail.ts"
click node_catalog_handlers "https://github.com/sugarlabs/musicblocks-git-backend/tree/main/src/controllers"
click node_sqlite "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/db.ts"
click node_repo_resolver "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/resolveRepoName.ts"
click node_key_hash "https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/hash.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_routes,node_owner,node_frontend toneBlue
class node_create,node_create_repo,node_edit,node_update_repo,node_fork,node_fork_repo,node_fork_history,node_pull_request,node_commit_history,node_project_data,node_historical_data,node_branch toneAmber
class node_search_controller,node_search_service,node_pagination,node_thumbnail,node_catalog_handlers toneMint
class node_sqlite,node_repo_resolver,node_key_hash toneRose
class node_github_app,node_github_pat toneIndigo
```

## Components

### API and authorization

- [Project routes](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/routes/projectRoutes.ts): `src/routes/projectRoutes.ts`
- [Owner verification](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/middleware/verifyOwner.ts): `src/middleware/verifyOwner.ts`

### GitHub project workflows

- [Create project](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/createProject.ts): `src/controllers/createProject.ts`
- [Create repository](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/createRepo.ts): `src/services/createRepo.ts`
- [Edit project](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/editProject.ts): `src/controllers/editProject.ts`
- [Update repository](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/updateRepo.ts): `src/services/updateRepo.ts`
- [Fork project](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/forkProject.ts): `src/controllers/forkProject.ts`
- [Fork repository](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/forkRepo.ts): `src/services/forkRepo.ts`
- [Fork with history](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/forkWithHistory.ts): `src/services/forkWithHistory.ts`
- [Pull requests](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/pullRequestService.ts): `src/services/pullRequestService.ts`
- [Commit history](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/getCommitHistory.ts): `src/services/getCommitHistory.ts`
- [Latest project data](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/getProjectData.ts): `src/services/getProjectData.ts`
- [Commit project data](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/getProjectDataAtCommit.ts): `src/services/getProjectDataAtCommit.ts`
- [Create branch](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/createBranch.ts): `src/services/createBranch.ts`

### Discovery and community

- [Search endpoint](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/searchProjects.ts): `src/controllers/searchProjects.ts`
- [Project search](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/services/searchProjects.ts): `src/services/searchProjects.ts`
- [Pagination](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/pagination.ts): `src/utils/pagination.ts`
- [Thumbnail delivery](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/controllers/getThumbnail.ts): `src/controllers/getThumbnail.ts`
- [Catalog and social handlers](https://github.com/sugarlabs/musicblocks-git-backend/tree/main/src/controllers): `src/controllers`

### State and authentication

- [SQLite project store](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/db.ts): `src/utils/db.ts`
- [Repository resolver](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/resolveRepoName.ts): `src/utils/resolveRepoName.ts`
- [Key hashing](https://github.com/sugarlabs/musicblocks-git-backend/blob/main/src/utils/hash.ts): `src/utils/hash.ts`

### Other components

- **Music Blocks frontend**
- **GitHub App**
- **GitHub PAT**

## Connections

- Music Blocks frontend → Project routes: calls API
- Project routes → Create project: routes create (evidence: `src/routes/projectRoutes.ts`)
- Create project → Create repository: creates repository (evidence: `src/controllers/createProject.ts`)
- Project routes → Owner verification: checks edit owner (evidence: `src/routes/projectRoutes.ts`)
- Owner verification → Edit project: authorizes edit (evidence: `src/routes/projectRoutes.ts`)
- Edit project → Update repository: updates project (evidence: `src/controllers/editProject.ts`)
- Project routes → Fork project: routes fork (evidence: `src/routes/projectRoutes.ts`)
- Fork project → Fork repository: creates fork (evidence: `src/controllers/forkProject.ts`)
- Project routes → Fork with history: routes history fork (evidence: `src/routes/projectRoutes.ts`)
- Fork with history → GitHub App: creates and pushes (evidence: `src/services/forkWithHistory.ts`)
- Fork with history → GitHub PAT: PAT optional
- Project routes → Pull requests: routes pull requests (evidence: `src/routes/projectRoutes.ts`)
- Project routes → Commit history: routes commits (evidence: `src/routes/projectRoutes.ts`)
- Project routes → Latest project data: routes latest data (evidence: `src/routes/projectRoutes.ts`)
- Project routes → Commit project data: routes historical data (evidence: `src/routes/projectRoutes.ts`)
- Project routes → Create branch: routes branch creation (evidence: `src/routes/projectRoutes.ts`)
- Project routes → Search endpoint: routes search (evidence: `src/routes/projectRoutes.ts`)
- Search endpoint → Project search: searches projects (evidence: `src/controllers/searchProjects.ts`)
- Search endpoint → Pagination: parses pagination (evidence: `src/controllers/searchProjects.ts`)
- Project search → SQLite project store: queries catalog (evidence: `src/services/searchProjects.ts`)
- Project routes → Thumbnail delivery: routes thumbnails (evidence: `src/routes/projectRoutes.ts`)
- Thumbnail delivery → SQLite project store: reads thumbnail (evidence: `src/controllers/getThumbnail.ts`)
- Thumbnail delivery → GitHub App: fetches fallback image (evidence: `src/controllers/getThumbnail.ts`)
- Thumbnail delivery → Repository resolver: resolves repository (evidence: `src/controllers/getThumbnail.ts`)
- Repository resolver → SQLite project store: looks up legacy ID (evidence: `src/utils/resolveRepoName.ts`)
- Owner verification → Key hashing: hashes key (evidence: `src/middleware/verifyOwner.ts`)
- Owner verification → GitHub App: reads metadata (evidence: `src/middleware/verifyOwner.ts`)
- Create repository → GitHub App: creates GitHub repo
- Fork repository → GitHub App: forks GitHub repo
- Project routes → Catalog and social handlers: routes catalog features (evidence: `src/routes/projectRoutes.ts`)
- Catalog and social handlers → SQLite project store: uses catalog state (evidence: `src/controllers/getThumbnail.ts`)
