Aller au contenu principal

projects

Status: implemented (services/projects, contract: docs/dev/phase4-contracts.md, Projects service; specs: features.md "Project management"). Runs in the apps profile of docker-compose.yml on port 8088 and is reached through the gateway route /v1/projects. Web screens: /app/projects.

Role: most activity is organised around projects (an order becomes a project). The service owns the project aggregate (lifecycle, details, members list), its needs, products to make and manual cost entries, and aggregates the costs. It bootstraps the default project roles in authz, which stays the source of truth for membership and rights.

Limits: no deadlines, no time tracking. Project roles, assignments and project API keys are managed through the authz project endpoints (/v1/authz/projects/{id}/roles, /v1/authz/projects/{id}/api-keys), not here. Files are stored by files; linked events, inventory items and borrowing sheets live in their own services and only reference the project ID. Finance purchases are an extension point of the cost aggregation.

Model​

  • Project (event sourced, aggregate project): name (1–200), description (≤ 5000), site_id (slug, fixed after creation), owner_id (Keycloak ID of the creator), owner_erased, status, customer_id (optional finance customer ULID, ID only), tags (≤ 20, ≤ 32 chars each), member_ids, roles (provisioning state), created_at, updated_at, status_changed_at, soft delete deleted_at / purge_at.
  • Lifecycle: draft → quoted → in_progress → delivered → invoiced → closed, plus cancelled from any non-final state.
FromAllowed targets
draftquoted, in_progress, cancelled
quoteddraft, in_progress, cancelled
in_progressdelivered, cancelled
deliveredinvoiced, closed, cancelled
invoicedclosed, cancelled
closed, cancelledfinal
  • Need: kind (material | tool | consumable | product), description, quantity (> 0), unit (default piece), optional item_id (inventory) and purchase_request_id, status (planned | requested | ordered | available).
  • Product to make: name, quantity (≥ 1), done_quantity (≤ quantity), notes.
  • Manual cost entry: label, amount_cents (non-zero, negative for refunds), currency (EUR only), date, created_by.
  • Search: normalised token index (search_terms, lowercased, accents removed) on the name and tags; q requires every query word to prefix-match a term.

ARNs: atl:projects:<site>:project/<id> (parent atl:settings:<site>:site/<site>), sub-resources .../need/<id>, .../product/<id>, .../cost/<id> (audit records).

Project roles and members​

On creation the service, acting as a service principal (token signed with PRINCIPAL_SIGNING_KEY), calls the authz REST API for the project (?site=<site>):

  1. lists the project roles and reuses those named Responsable / Participant (idempotent);
  2. creates the missing ones, grants on atl:projects:<site>:project/<id>/*:
    • Responsable: every project-scoped permission of the catalogue;
    • Participant: projects.project.read, projects.file.read, projects.file.write, events.event.create, inventory.issue.report, finance.purchase.request;
  3. assigns the owner to Responsable (existing assignments are kept).

While authz is unreachable the project is saved anyway with roles.state = pending (attempts, last_error, next_attempt_at with exponential backoff); the lease job projects-provision retries every PROJECTS_PROVISION_INTERVAL, and POST /v1/projects/{id}/provision retries immediately. Once done, roles.state = ready with manager_role_id / participant_role_id. The owner keeps every project permission on their project in the meantime (checked locally).

member_ids = the owner (unless erased) plus every user holding an active assignment on a role of the project. It is kept in sync by the consumer (group projects-sync):

  • authz.role.v1: project roles are recorded in project_roles (role → project); a deleted role deactivates its memberships;
  • authz.assignment.v1: user assignments are recorded in memberships; a role not seen yet is resolved through GET /v1/authz/roles/{id} with the service principal;
  • every change of the set publishes member_added / member_removed.

Authorization​

ActionRule
Read a project, its needs, products, costsowner, member, projects.project.read on the project, or projects.project.read_all (elevated, admin mode); otherwise 404
Createprojects.project.create on the new project ARN (site parent); the default Membre role has it everywhere
Edit details, change status, manual costs, retry provisioningowner or projects.project.update
Deleteowner or projects.project.delete
Edit needs and productsany project member or projects.project.update (no dedicated catalogue permission)
ListLookup scope of projects.project.read (+ read_all in admin mode), always including the caller's projects; mine=true keeps only them

GET /v1/projects/{id} returns capabilities (update, delete, manage_roles, manage_api_keys, files_read, files_write, edit_needs) so that the web app hides forbidden actions.

Files: owner atl:projects:<site>:project/<id> (projects.file.read / projects.file.write). The service is a files delegate (FILES_DELEGATES entry projects=http://projects:8088): POST /internal/v1/attachments/authorize allows reading to the owner and members and writing to the owner, so access works while roles are being provisioned.

HTTP API​

OpenAPI: API reference (services/projects/openapi.yaml). Lists are cursor paginated.

MethodPathNotes
GET/v1/projects?site&status&mine&q&tag&customervisible projects
POST/v1/projectscreates (draft) and provisions roles
GET, PATCH, DELETE/v1/projects/{id}detail with capabilities; patch name, description, customer, tags; soft delete
POST/v1/projects/{id}/statusvalidated transition
POST/v1/projects/{id}/provisionretry role provisioning
GET, POST/v1/projects/{id}/needsfilters status, kind
PATCH, DELETE/v1/projects/{id}/needs/{sub}
GET, POST/v1/projects/{id}/products
PATCH, DELETE/v1/projects/{id}/products/{sub}
GET/v1/projects/{id}/costsmanual + inventory consumption (+ purchases later) in cents
GET, POST/v1/projects/{id}/costs/entriesmanual entries
PATCH, DELETE/v1/projects/{id}/costs/entries/{sub}
POST/internal/v1/attachments/authorizefiles delegate, not routed by the gateway

Costs: inventory consumption comes from GET /v1/inventory/projects/{id}/costs called with the caller principal (euros converted to cents); when inventory is down or denies the caller, the section is returned with available: false and excluded from the total.

Kafka​

KindNameNotes
outprojects.project.v1created, updated (field names), status_changed (from, to), member_added, member_removed (user ID), deleted
outaudit.records.v1every write (projects.project.*, projects.need.*, projects.product.*, projects.cost.*), IDs only
inauthz.role.v1, authz.assignment.v1members sync (group projects-sync)
inmembers.member.v1members.member.erased: memberships removed, user removed from member_ids, owner flagged owner_erased

Data (MongoDB projects)​

CollectionContent
projectsproject state (indexes on site_id, status, member_ids, owner_id, tags, search_terms, customer_id with _id; provisioning and purge)
eventsevent log (eventstore)
needs, products, cost_entriessub-resources (project_id, _id)
project_rolesrole ID → project ID
membershipsassignment ID → project, role, user, active
outbox, leasespending Kafka messages, lease jobs

Jobs​

  • projects-provision (every PROJECTS_PROVISION_INTERVAL): retries pending role provisioning.
  • projects-purge (every PROJECTS_PURGE_INTERVAL): after PROJECTS_PURGE_DELAY, deletes the project roles in authz, then the state, needs, products and cost entries (the event log is kept). A failing authz call postpones the purge to the next run.

Configuration​

VariableDefaultDescription
HTTP_ADDR:8088Listen address
METRICS_ADDR:9188Prometheus listener
MONGO_URI, MONGO_DATABASEmongodb://localhost:27017/?directConnection=true, projectsMongoDB
KAFKA_BROKERSlocalhost:19092Outbox relay and consumer
PRINCIPAL_PUBLIC_KEYrequiredVerifies X-Atl-Principal
PRINCIPAL_SIGNING_KEYrequiredService identity for authz calls
AUTHZ_URLhttp://localhost:8081authz REST and ConnectRPC
INVENTORY_URLhttp://localhost:8085inventory costs
PROJECTS_PROVISION_INTERVAL30sprovisioning retry job period
PROJECTS_PURGE_DELAY720hsoft delete → purge delay
PROJECTS_PURGE_INTERVAL1hpurge job period

Plus the common APP_ENV, LOG_LEVEL, OTEL_EXPORTER_OTLP_ENDPOINT (see environment variables).