Skip to content

Create Project

Method

REST method is adopted.

HTTP Method

POST: Create a new project

Naming Convention

To unify naming of query parameters and nodes and improve readability, snake_case is used for URIs and nodes in JSON during requests.

Request and Response

Headers

Meta information is set in HTTP headers rather than in the response body.

Request Headers

  • Authorization: Bearer <access_token>
  • Content-Type: application/json

Response Headers

  • Content-Type: application/json

Create Project

URI

/api/v1/projects

Request Body

Request body is JSON.

{
  "name": "New Project",
  "organizationId": 1
}

Validation Rules

Field Rule
name Required. 1-255 characters.
organizationId Required. Must be a positive integer referencing an existing organization.

Response (201 Created)

Response is JSON.

{
  "id": 1,
  "organizationId": 1,
  "name": "New Project",
  "createdAt": 1640995200000,
  "updatedAt": 1640995200000,
  "createdBy": "1111-aaaa-2222-bbbb",
  "updatedBy": "1111-aaaa-2222-bbbb",
  "deletedAt": null,
  "deletedBy": null
}

Authentication

Authentication is performed using JSON Web Tokens (JWT) issued by Amazon Cognito. A valid Bearer token is required in the Authorization header.

Exception Handling

Exception handling status codes are as follows.

Description Status Code Status Name
Missing or invalid token 401 Unauthorized
Organization not found 404 Not Found
Internal server error 500 Internal Server Error

Process Flow

Sequence Diagram

sequenceDiagram
    participant Client
    participant Middleware as Protected Route Middleware
    participant API as Hono Router
    participant Service as Project Service
    participant DB as PostgreSQL Database

    Client->>Middleware: POST /api/v1/projects
    Middleware->>Middleware: Verify JWT & session

    alt Token Valid
        Middleware-->>API: Auth info (sub)
        API->>Service: create({ name, organizationId, actorSub })
        Service->>DB: Find organization by ID

        alt Organization Found
            Service->>DB: Create project record
            DB-->>Service: Project record
            Service-->>API: Project
            API-->>Client: 201 Created
        else Organization Not Found
            DB-->>Service: null
            Service-->>API: throw NotFoundError
            API-->>Client: 404 Not Found
        end
    else Token Invalid
        Middleware-->>Client: 401 Unauthorized
    end

Routes Layer

API routing is performed here. The protectedRoute middleware validates the JWT token. The handler validates the request body via Zod schema, extracts the actor's Cognito sub, and delegates to the project service.

Source: apps/admin/src/routes/v1/project.ts

Services Layer

This section describes business logic. It validates the organization exists, then creates the project record with the actor's Cognito sub as the creator.

Source: apps/admin/src/services/project.ts

Repositories Layer

This section describes access to databases. It handles organization lookup and project record creation.

Source: apps/admin/src/repositories/project.ts

Security

  • Token validated by protectedRoute middleware before handler execution
  • Organization existence validated before project creation