API: Projects & Teams
Relevant source files
The following files were used as context for generating this wiki page:- api/src/controllers/project.controller.ts
- api/src/controllers/project-user.controller.ts
- api/src/domain/http.ts
- api/test/project.e2e-spec.ts
- api/test/project-user.e2e-spec.ts
- webapp/src/app/projects/stores/projects.state.ts
- webapp/src/app/projects/components/team-overview/team-overview.component.ts
- api/test/project-client.e2e-spec.ts
Introduction
The Projects & Teams API provides the core functionality for managing translation projects and the teams of users who collaborate on them. It is the foundation of the application's multi-tenancy and collaborative features. This system allows authenticated users to create, read, update, and delete projects, as well as manage team member access through a role-based system.
The API is secured, requiring authentication for all endpoints. It handles the logic for project creation, user membership, role assignment, and programmatic access via API clients. The frontend web application interacts with these API endpoints through a state management layer (NGXS) to provide a seamless user experience for project and team administration.
Sources: api/src/controllers/project.controller.ts, api/src/controllers/project-user.controller.ts, webapp/src/app/projects/stores/projects.state.ts
Core Entities and Relationships
The system revolves around three main entities: User, Project, and the joining entity ProjectUser which defines a user's role within a specific project.
This diagram illustrates the relationship between users, projects, and their roles.
- A
USERcan be a member of multiplePROJECTs. - A
PROJECTcan have multipleUSERs. - The
PROJECT_USERentity links aUSERto aPROJECTand assigns them a specificProjectRole.
Sources: api/src/controllers/project.controller.ts:15-16, api/src/controllers/project-user.controller.ts:11
Project Management
Project management is handled by the ProjectController. It exposes a set of RESTful endpoints for all CRUD (Create, Read, Update, Delete) operations on projects. All endpoints require an authenticated user session.
Sources: api/src/controllers/project.controller.ts
Project API Endpoints
The following table summarizes the main endpoints for managing projects.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
GET | /api/v1/projects | Lists all projects the requesting user is a member of. | ListProjectsResponse |
POST | /api/v1/projects | Creates a new project. The creator is automatically assigned the 'Admin' role. | ProjectResponse |
GET | /api/v1/projects/:projectId | Retrieves a single project by its ID, if the user has access. | ProjectResponse |
PATCH | /api/v1/projects/:projectId | Updates a project's name or description. Requires 'Admin' or 'Editor' role. | ProjectResponse |
DELETE | /api/v1/projects/:projectId | Deletes a project. Requires 'Admin' role. | 204 No Content |
Sources: api/src/controllers/project.controller.ts:25-131, api/test/project.e2e-spec.ts
Project Creation Flow
When a user creates a new project, the API performs several actions within a single database transaction to ensure data integrity.
This sequence diagram shows the project creation process.
- The user sends a
POSTrequest with the project name. - The system checks if the user has exceeded the maximum number of projects allowed (
maxProjectsPerUser). - A transaction is initiated.
- A new
Projectentity is created and saved. - A
ProjectUserentity is created, linking the user to the new project with theAdminrole. - The default project
Planis fetched and assigned to the project. - The user's
numProjectsCreatedcounter is incremented. - The transaction is committed.
- The newly created project data is returned to the user.
Sources: api/src/controllers/project.controller.ts:54-81, api/test/project.e2e-spec.ts:15-28
Project Data Transfer Objects (DTOs)
CreateProjectRequest
This DTO is used as the body for the POST /api/v1/projects request.
| Field | Type | Constraints | Description |
|---|---|---|---|
name | string | 1-255 characters, not only whitespace | The name of the project. |
description | string | 0-255 characters (optional) | An optional project description. |
Sources: api/src/domain/http.ts:384-394
ProjectDTO
This DTO represents a project in API responses.
| Field | Type | Description |
|---|---|---|
id | string | The unique identifier of the project. |
name | string | The name of the project. |
description | string | The project description. |
localesCount | number | The number of locales in the project. |
termsCount | number | The number of terms in the project. |
role | ProjectRole | The requesting user's role in this project. |
date | AccessDatesDTO | Creation and modification timestamps. |
Sources: api/src/domain/http.ts:80-97
Team Management
Team management is handled by ProjectUserController. It allows project administrators to manage user access and roles within a project.
Sources: api/src/controllers/project-user.controller.ts, webapp/src/app/projects/components/team-overview/team-overview.component.ts
Team Management Endpoints
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
GET | /:projectId/users | Lists all users who are members of the project. | ListProjectUsersResponse |
PATCH | /:projectId/users/:userId | Updates the role of a specific user within the project. | ProjectUserResponse |
DELETE | /:projectId/users/:userId | Removes a user from the project, revoking their access. | 204 No Content |
POST | /:projectId/invites | Invites a new user to the project via email with a specified role. | ProjectInviteCreatedResponse |
Sources: api/src/controllers/project-user.controller.ts:18-120, api/test/project-user.e2e-spec.ts:46-55
User Roles (ProjectRole)
Access control within a project is governed by roles. The ProjectRole is an enum with three possible values.
| Role | Description |
|---|---|
Admin | Full access. Can manage project settings, team members, API clients, and delete the project. |
Editor | Can add/edit terms and translations. Can import/export data. Cannot manage settings or team members. |
Viewer | Read-only access. Can view terms and translations and export data. Cannot make any changes. |
Sources: api/src/domain/http.ts:14, webapp/src/app/projects/models/project-role.ts
Updating a User's Role
An admin can change another user's role. A user cannot change their own role.
This sequence diagram shows the process of updating a user's role.
API Clients
For programmatic access, the API supports project-specific API clients. These clients are managed via endpoints and can be used for CI/CD pipelines, scripts, or other integrations. Management is tested in project-client.e2e-spec.ts.
API Client Management
| Method | Endpoint | Description |
|---|---|---|
GET | /:projectId/clients | Lists all API clients for a project. |
POST | /:projectId/clients | Creates a new API client, returning its ID and a secret. |
PATCH | /:projectId/clients/:clientId | Updates the role of an API client. |
DELETE | /:projectId/clients/:clientId | Deletes an API client. |
Creating a client returns a secret that is only shown once. This secret is used with the client ID for authentication using the client_credentials grant type. Like users, API clients are assigned a ProjectRole that dictates their permissions.
Sources: api/test/project-client.e2e-spec.ts:114-131, api/test/project-client.e2e-spec.ts:222-243
Frontend Integration
The webapp module consumes these APIs to provide the user interface for project and team management. It uses the @ngxs/store library for state management.
ProjectsState: This state slice manages the lifecycle of projects, including fetching, creating, updating, and deleting them. It dispatches actions likeGetProjects,CreateProject, andSetCurrentProject.TeamOverviewComponent: This component displays the list of project members and invites. It allows admins to modify roles or remove users by dispatching actions likeUpdateProjectUserandRemoveProjectUserto the NGXS store, which in turn call the respective API endpoints.
Sources: webapp/src/app/projects/stores/projects.state.ts, webapp/src/app/projects/components/team-overview/team-overview.component.ts