Compare commits
No commits in common. "main" and "organisation_display" have entirely different histories.
main
...
organisati
@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
name: "source-command-explore-and-plan"
|
|
||||||
description: "Explore codebase, create implementation plan, code, and test following EPCT workflow"
|
|
||||||
---
|
|
||||||
|
|
||||||
# source-command-explore-and-plan
|
|
||||||
|
|
||||||
Use this skill when the user asks to run the migrated source command `explore-and-plan`.
|
|
||||||
|
|
||||||
## Command Template
|
|
||||||
|
|
||||||
# Explore, Plan, Code, Test Workflow
|
|
||||||
|
|
||||||
At the end of this message, I will ask you to do something.
|
|
||||||
Please follow the "Explore, Plan, Code, Test" workflow when you start.
|
|
||||||
|
|
||||||
## Explore
|
|
||||||
|
|
||||||
First, use parallel subagents to find and read all files that may be useful for implementing the ticket, either as examples or as edit targets. The subagents should return relevant file paths, and any other info that may be useful.
|
|
||||||
|
|
||||||
## Plan
|
|
||||||
|
|
||||||
Next, think hard and write up a detailed implementation plan. Don't forget to include tests, lookbook components, and documentation. Use your judgement as to what is necessary, given the standards of this repo.
|
|
||||||
|
|
||||||
If there are things you are not sure about, use parallel subagents to do some web research. They should only return useful information, no noise.
|
|
||||||
|
|
||||||
If there are things you still do not understand or questions you have for the user, pause here to ask them before continuing.
|
|
||||||
|
|
||||||
## Code
|
|
||||||
|
|
||||||
When you have a thorough implementation plan, you are ready to start writing code. Follow the style of the existing codebase (e.g. we prefer clearly named variables and methods to extensive comments). Make sure to run our autoformatting script when you're done, and fix linter warnings that seem reasonable to you.
|
|
||||||
|
|
||||||
## Test
|
|
||||||
|
|
||||||
Use parallel subagents to run tests, and make sure they all pass.
|
|
||||||
|
|
||||||
If your changes touch the UX in a major way, use the browser to make sure that everything works correctly. Make a list of what to test for, and use a subagent for this step.
|
|
||||||
|
|
||||||
If your testing shows problems, go back to the planning stage and think ultrahard.
|
|
||||||
|
|
||||||
## Write up your work
|
|
||||||
|
|
||||||
When you are happy with your work, write up a short report that could be used as the PR description. Include what you set out to do, the choices you made with their brief justification, and any commands you ran in the process that may be useful for future developers to know about.
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
name: "source-command-fix-pr-comments"
|
|
||||||
description: "Fetch all comments for the current pull request and fix them."
|
|
||||||
---
|
|
||||||
|
|
||||||
# source-command-fix-pr-comments
|
|
||||||
|
|
||||||
Use this skill when the user asks to run the migrated source command `fix-pr-comments`.
|
|
||||||
|
|
||||||
## Command Template
|
|
||||||
|
|
||||||
Workflow:
|
|
||||||
|
|
||||||
1. Use `gh cli` to fetch the comments that are NOT resolved from the pull request.
|
|
||||||
2. Define all the modifications you should actually make.
|
|
||||||
3. Act and update the files.
|
|
||||||
4. Create a commit and push.
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
---
|
|
||||||
name: "source-command-quick-commit"
|
|
||||||
description: "Quickly commit all changes with an auto-generated message"
|
|
||||||
---
|
|
||||||
|
|
||||||
# source-command-quick-commit
|
|
||||||
|
|
||||||
Use this skill when the user asks to run the migrated source command `quick-commit`.
|
|
||||||
|
|
||||||
## Command Template
|
|
||||||
|
|
||||||
Workflow for quick Git commits:
|
|
||||||
|
|
||||||
1. Check git status to see what changes are present
|
|
||||||
2. Analyze changes to generate a short, clear commit message
|
|
||||||
3. Stage all changes (tracked and untracked files)
|
|
||||||
4. Create the commit with DH7789-dev signature
|
|
||||||
5. Optionally push to remote if tracking branch exists
|
|
||||||
|
|
||||||
The commit message will be automatically generated by analyzing:
|
|
||||||
- Modified files and their purposes (components, configs, tests, docs, etc.)
|
|
||||||
- New files added and their function
|
|
||||||
- Deleted files and cleanup operations
|
|
||||||
- Overall scope of changes to determine action verb (add, update, fix, refactor, remove, etc.)
|
|
||||||
|
|
||||||
Commit message format: `[action] [what was changed]`
|
|
||||||
Examples:
|
|
||||||
- `add user authentication system`
|
|
||||||
- `fix navigation menu responsive issues`
|
|
||||||
- `update API endpoints configuration`
|
|
||||||
- `refactor database connection logic`
|
|
||||||
- `remove deprecated utility functions`
|
|
||||||
|
|
||||||
This command is ideal for:
|
|
||||||
- Quick iteration cycles
|
|
||||||
- Work-in-progress commits
|
|
||||||
- Feature development checkpoints
|
|
||||||
- Bug fix commits
|
|
||||||
|
|
||||||
The commit will include your custom signature:
|
|
||||||
```
|
|
||||||
Signed-off-by: DH7789-dev
|
|
||||||
```
|
|
||||||
@ -36,9 +36,7 @@
|
|||||||
"Bash(xargs -r docker rm:*)",
|
"Bash(xargs -r docker rm:*)",
|
||||||
"Bash(npm run migration:run:*)",
|
"Bash(npm run migration:run:*)",
|
||||||
"Bash(npm run dev:*)",
|
"Bash(npm run dev:*)",
|
||||||
"Bash(npm run backend:dev:*)",
|
"Bash(npm run backend:dev:*)"
|
||||||
"Bash(env -i PATH=\"$PATH\" HOME=\"$HOME\" node:*)",
|
|
||||||
"Bash(PGPASSWORD=xpeditis_dev_password psql -h localhost -U xpeditis -d xpeditis_dev -c:*)"
|
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"hooks": {
|
|
||||||
"PreToolUse": [
|
|
||||||
{
|
|
||||||
"matcher": "Bash",
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "bun /Users/david/.claude/scripts/validate-command.js"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Stop": [
|
|
||||||
{
|
|
||||||
"hooks": [
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "afplay /Users/david/.claude/song/finish.mp3"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
# All jobs use the existing ubuntu-latest runner label.
|
|
||||||
{}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
name: Notify security gate failure
|
|
||||||
description: Posts a Discord alert when the Security gate fails and stops the pipeline.
|
|
||||||
inputs:
|
|
||||||
webhook-url:
|
|
||||||
description: Discord webhook URL.
|
|
||||||
required: true
|
|
||||||
pipeline:
|
|
||||||
description: Human-readable pipeline name shown in the alert.
|
|
||||||
required: true
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- name: Discord
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
WEBHOOK_URL: ${{ inputs.webhook-url }}
|
|
||||||
PIPELINE: ${{ inputs.pipeline }}
|
|
||||||
REF_NAME: ${{ github.ref_name }}
|
|
||||||
ACTOR: ${{ github.actor }}
|
|
||||||
SHA: ${{ github.sha }}
|
|
||||||
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
||||||
run: |
|
|
||||||
# Payload built with json.dumps: branch or author names cannot break the JSON.
|
|
||||||
payload=$(python3 - <<'PY'
|
|
||||||
import json, os
|
|
||||||
print(json.dumps({
|
|
||||||
"content": "@here Security gate en échec — pipeline arrêté",
|
|
||||||
"embeds": [{
|
|
||||||
"title": f"🔒 Security gate en échec — {os.environ['PIPELINE']}",
|
|
||||||
"description": "Aucun lint, test, build ni déploiement n'a été lancé. Consultez l'artefact `security-reports`.",
|
|
||||||
"color": 15158332,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Branche", "value": f"`{os.environ['REF_NAME']}`", "inline": True},
|
|
||||||
{"name": "Auteur", "value": os.environ["ACTOR"], "inline": True},
|
|
||||||
{"name": "Commit", "value": f"`{os.environ['SHA'][:7]}`", "inline": True},
|
|
||||||
{"name": "Workflow", "value": f"[Voir le run]({os.environ['RUN_URL']})", "inline": False},
|
|
||||||
],
|
|
||||||
"footer": {"text": f"Xpeditis CI/CD • {os.environ['PIPELINE']}"},
|
|
||||||
}],
|
|
||||||
}))
|
|
||||||
PY
|
|
||||||
)
|
|
||||||
curl -fsS --max-time 15 -H "Content-Type: application/json" -d "$payload" "$WEBHOOK_URL" \
|
|
||||||
|| echo "::warning::Notification Discord non envoyée."
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
name: Security gate
|
|
||||||
description: Dependency, secrets, infrastructure and workflow checks for Gitea 1.22.
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- name: Install Trivy
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
trivy_bin=$(bash scripts/ci/install-tool.sh trivy)
|
|
||||||
"$trivy_bin" --version
|
|
||||||
- name: Validate workflows and deployment checks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
actionlint_bin=$(bash scripts/ci/install-tool.sh actionlint)
|
|
||||||
ACTIONLINT_BIN="$actionlint_bin" bash scripts/ci/validate-workflows.sh
|
|
||||||
- name: Audit dependencies, secrets and infrastructure
|
|
||||||
shell: bash
|
|
||||||
run: bash scripts/ci/security-audit.sh
|
|
||||||
- name: Show security results
|
|
||||||
if: always()
|
|
||||||
shell: bash
|
|
||||||
run: python3 scripts/ci/summarize-security.py
|
|
||||||
- name: Save security reports on Gitea
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: security-reports
|
|
||||||
path: ${{ runner.temp }}/security-reports/*.json
|
|
||||||
retention-days: 7
|
|
||||||
if-no-files-found: error
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
name: Install and activate Node 22
|
|
||||||
description: Set up Node and verify the executable selected by the Gitea runner.
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
|
||||||
with:
|
|
||||||
node-version: '22'
|
|
||||||
- name: Activate and verify Node 22
|
|
||||||
shell: bash
|
|
||||||
run: bash scripts/ci/activate-node.sh
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
name: Install verified Trivy
|
|
||||||
description: Install a pinned native scanner with a checked SHA256.
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- shell: bash
|
|
||||||
run: |
|
|
||||||
trivy_bin=$(bash scripts/ci/install-tool.sh trivy)
|
|
||||||
"$trivy_bin" --version
|
|
||||||
@ -1,269 +0,0 @@
|
|||||||
name: Rollback
|
|
||||||
|
|
||||||
# Emergency rollback — production (Hetzner k3s) and preprod (Portainer).
|
|
||||||
#
|
|
||||||
# Production strategies:
|
|
||||||
# previous — kubectl rollout undo (fastest, reverts to previous ReplicaSet)
|
|
||||||
# specific-version — kubectl set image to a specific prod-SHA tag
|
|
||||||
#
|
|
||||||
# Preprod strategy:
|
|
||||||
# Re-tags a preprod-SHA image back to :preprod, triggers Portainer webhook.
|
|
||||||
#
|
|
||||||
# Secrets required:
|
|
||||||
# REGISTRY_TOKEN — Scaleway registry
|
|
||||||
# HETZNER_KUBECONFIG — base64 kubeconfig (production only)
|
|
||||||
# PORTAINER_WEBHOOK_BACKEND — Portainer webhook preprod backend
|
|
||||||
# PORTAINER_WEBHOOK_FRONTEND — Portainer webhook preprod frontend
|
|
||||||
# PROD_BACKEND_URL — https://api.xpeditis.com
|
|
||||||
# PROD_FRONTEND_URL — https://app.xpeditis.com
|
|
||||||
# PREPROD_BACKEND_URL — https://api.preprod.xpeditis.com
|
|
||||||
# PREPROD_FRONTEND_URL — https://preprod.xpeditis.com
|
|
||||||
# DISCORD_WEBHOOK_URL
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
environment:
|
|
||||||
description: 'Target environment'
|
|
||||||
required: true
|
|
||||||
type: choice
|
|
||||||
options: [production, preprod]
|
|
||||||
strategy:
|
|
||||||
description: 'Strategy (production only — "previous" = instant kubectl undo)'
|
|
||||||
required: true
|
|
||||||
type: choice
|
|
||||||
options: [previous, specific-version]
|
|
||||||
version_tag:
|
|
||||||
description: 'Tag for specific-version (e.g. prod-a1b2c3d or preprod-a1b2c3d)'
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
reason:
|
|
||||||
description: 'Reason (audit trail)'
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: rg.fr-par.scw.cloud/weworkstudio
|
|
||||||
K8S_NAMESPACE: xpeditis-prod
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
validate:
|
|
||||||
name: Validate Inputs
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Check inputs
|
|
||||||
run: |
|
|
||||||
ENV="${{ github.event.inputs.environment }}"
|
|
||||||
STRATEGY="${{ github.event.inputs.strategy }}"
|
|
||||||
TAG="${{ github.event.inputs.version_tag }}"
|
|
||||||
|
|
||||||
if [ "$STRATEGY" = "specific-version" ] && [ -z "$TAG" ]; then
|
|
||||||
echo "ERROR: version_tag is required for specific-version strategy."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$ENV" = "production" ] && [ "$STRATEGY" = "specific-version" ]; then
|
|
||||||
if [[ ! "$TAG" =~ ^prod- ]]; then
|
|
||||||
echo "ERROR: Production tag must start with 'prod-' (got: $TAG)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$ENV" = "preprod" ]; then
|
|
||||||
if [[ ! "$TAG" =~ ^preprod- ]]; then
|
|
||||||
echo "ERROR: Preprod tag must start with 'preprod-' (got: $TAG)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Validated — env: $ENV | strategy: $STRATEGY | tag: ${TAG:-N/A} | reason: ${{ github.event.inputs.reason }}"
|
|
||||||
|
|
||||||
# ── Production rollback via kubectl ──────────────────────────────────
|
|
||||||
rollback-production:
|
|
||||||
name: Rollback Production
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: validate
|
|
||||||
if: github.event.inputs.environment == 'production'
|
|
||||||
environment:
|
|
||||||
name: production
|
|
||||||
url: https://app.xpeditis.com
|
|
||||||
steps:
|
|
||||||
- name: Configure kubectl
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.kube
|
|
||||||
echo "${{ secrets.HETZNER_KUBECONFIG }}" | base64 -d > ~/.kube/config
|
|
||||||
chmod 600 ~/.kube/config
|
|
||||||
kubectl cluster-info
|
|
||||||
|
|
||||||
- name: Rollback — previous version
|
|
||||||
if: github.event.inputs.strategy == 'previous'
|
|
||||||
run: |
|
|
||||||
kubectl rollout undo deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }}
|
|
||||||
kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
|
|
||||||
kubectl rollout undo deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }}
|
|
||||||
kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
|
|
||||||
kubectl get pods -n ${{ env.K8S_NAMESPACE }}
|
|
||||||
|
|
||||||
- name: Login to Scaleway (for image verification)
|
|
||||||
if: github.event.inputs.strategy == 'specific-version'
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
- uses: docker/setup-buildx-action@v3
|
|
||||||
if: github.event.inputs.strategy == 'specific-version'
|
|
||||||
|
|
||||||
- name: Rollback — specific version
|
|
||||||
if: github.event.inputs.strategy == 'specific-version'
|
|
||||||
run: |
|
|
||||||
TAG="${{ github.event.inputs.version_tag }}"
|
|
||||||
BACKEND="${{ env.REGISTRY }}/xpeditis-backend:${TAG}"
|
|
||||||
FRONTEND="${{ env.REGISTRY }}/xpeditis-frontend:${TAG}"
|
|
||||||
|
|
||||||
echo "Verifying images exist..."
|
|
||||||
docker buildx imagetools inspect "$BACKEND" || { echo "ERROR: $BACKEND not found"; exit 1; }
|
|
||||||
docker buildx imagetools inspect "$FRONTEND" || { echo "ERROR: $FRONTEND not found"; exit 1; }
|
|
||||||
|
|
||||||
kubectl set image deployment/xpeditis-backend backend="$BACKEND" seed-rates="$BACKEND" -n ${{ env.K8S_NAMESPACE }}
|
|
||||||
kubectl rollout status deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
|
|
||||||
|
|
||||||
kubectl set image deployment/xpeditis-frontend frontend="$FRONTEND" -n ${{ env.K8S_NAMESPACE }}
|
|
||||||
kubectl rollout status deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} --timeout=180s
|
|
||||||
|
|
||||||
kubectl get pods -n ${{ env.K8S_NAMESPACE }}
|
|
||||||
|
|
||||||
- name: Rollout history
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
kubectl rollout history deployment/xpeditis-backend -n ${{ env.K8S_NAMESPACE }} || true
|
|
||||||
kubectl rollout history deployment/xpeditis-frontend -n ${{ env.K8S_NAMESPACE }} || true
|
|
||||||
|
|
||||||
# ── Preprod rollback via Portainer ───────────────────────────────────
|
|
||||||
rollback-preprod:
|
|
||||||
name: Rollback Preprod
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: validate
|
|
||||||
if: github.event.inputs.environment == 'preprod'
|
|
||||||
steps:
|
|
||||||
- uses: docker/setup-buildx-action@v3
|
|
||||||
|
|
||||||
- uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
- name: Verify target image exists
|
|
||||||
run: |
|
|
||||||
TAG="${{ github.event.inputs.version_tag }}"
|
|
||||||
docker buildx imagetools inspect "${{ env.REGISTRY }}/xpeditis-backend:${TAG}" || \
|
|
||||||
{ echo "ERROR: backend image not found: $TAG"; exit 1; }
|
|
||||||
docker buildx imagetools inspect "${{ env.REGISTRY }}/xpeditis-frontend:${TAG}" || \
|
|
||||||
{ echo "ERROR: frontend image not found: $TAG"; exit 1; }
|
|
||||||
|
|
||||||
- name: Re-tag as preprod
|
|
||||||
run: |
|
|
||||||
TAG="${{ github.event.inputs.version_tag }}"
|
|
||||||
docker buildx imagetools create \
|
|
||||||
--tag ${{ env.REGISTRY }}/xpeditis-backend:preprod \
|
|
||||||
${{ env.REGISTRY }}/xpeditis-backend:${TAG}
|
|
||||||
docker buildx imagetools create \
|
|
||||||
--tag ${{ env.REGISTRY }}/xpeditis-frontend:preprod \
|
|
||||||
${{ env.REGISTRY }}/xpeditis-frontend:${TAG}
|
|
||||||
|
|
||||||
- name: Deploy backend (Portainer)
|
|
||||||
run: curl -sf -X POST "${{ secrets.PORTAINER_WEBHOOK_BACKEND }}"
|
|
||||||
- run: sleep 20
|
|
||||||
- name: Deploy frontend (Portainer)
|
|
||||||
run: curl -sf -X POST "${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}"
|
|
||||||
|
|
||||||
# ── Smoke Tests ───────────────────────────────────────────────────────
|
|
||||||
smoke-tests:
|
|
||||||
name: Smoke Tests Post-Rollback
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [rollback-production, rollback-preprod]
|
|
||||||
if: always() && (needs.rollback-production.result == 'success' || needs.rollback-preprod.result == 'success')
|
|
||||||
steps:
|
|
||||||
- name: Set URLs
|
|
||||||
id: urls
|
|
||||||
run: |
|
|
||||||
if [ "${{ github.event.inputs.environment }}" = "production" ]; then
|
|
||||||
echo "backend=${{ secrets.PROD_BACKEND_URL }}/api/v1/health" >> $GITHUB_OUTPUT
|
|
||||||
echo "frontend=${{ secrets.PROD_FRONTEND_URL }}" >> $GITHUB_OUTPUT
|
|
||||||
echo "wait=30" >> $GITHUB_OUTPUT
|
|
||||||
else
|
|
||||||
echo "backend=${{ secrets.PREPROD_BACKEND_URL }}/api/v1/health" >> $GITHUB_OUTPUT
|
|
||||||
echo "frontend=${{ secrets.PREPROD_FRONTEND_URL }}" >> $GITHUB_OUTPUT
|
|
||||||
echo "wait=60" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
- run: sleep ${{ steps.urls.outputs.wait }}
|
|
||||||
|
|
||||||
- name: Health — Backend
|
|
||||||
run: |
|
|
||||||
for i in {1..12}; do
|
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
|
|
||||||
"${{ steps.urls.outputs.backend }}" 2>/dev/null || echo "000")
|
|
||||||
echo " Attempt $i: HTTP $STATUS"
|
|
||||||
if [ "$STATUS" = "200" ]; then echo "Backend OK."; exit 0; fi
|
|
||||||
sleep 15
|
|
||||||
done
|
|
||||||
echo "Backend unhealthy after rollback."
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
- name: Health — Frontend
|
|
||||||
run: |
|
|
||||||
for i in {1..12}; do
|
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
|
|
||||||
"${{ steps.urls.outputs.frontend }}" 2>/dev/null || echo "000")
|
|
||||||
echo " Attempt $i: HTTP $STATUS"
|
|
||||||
if [ "$STATUS" = "200" ]; then echo "Frontend OK."; exit 0; fi
|
|
||||||
sleep 15
|
|
||||||
done
|
|
||||||
echo "Frontend unhealthy after rollback."
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
# ── Notifications ─────────────────────────────────────────────────────
|
|
||||||
notify:
|
|
||||||
name: Notify
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [rollback-production, rollback-preprod, smoke-tests]
|
|
||||||
if: always()
|
|
||||||
steps:
|
|
||||||
- name: Success
|
|
||||||
if: needs.smoke-tests.result == 'success'
|
|
||||||
run: |
|
|
||||||
curl -s -H "Content-Type: application/json" -d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "↩️ Rollback Successful",
|
|
||||||
"color": 16776960,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Environment", "value": "`${{ github.event.inputs.environment }}`", "inline": true},
|
|
||||||
{"name": "Strategy", "value": "`${{ github.event.inputs.strategy }}`", "inline": true},
|
|
||||||
{"name": "Version", "value": "`${{ github.event.inputs.version_tag || 'previous' }}`", "inline": true},
|
|
||||||
{"name": "By", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "Reason", "value": "${{ github.event.inputs.reason }}", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI/CD • Rollback"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
|
|
||||||
- name: Failure
|
|
||||||
if: needs.smoke-tests.result != 'success'
|
|
||||||
run: |
|
|
||||||
curl -s -H "Content-Type: application/json" -d '{
|
|
||||||
"content": "@here ROLLBACK FAILED — MANUAL INTERVENTION REQUIRED",
|
|
||||||
"embeds": [{
|
|
||||||
"title": "🔴 Rollback Failed",
|
|
||||||
"color": 15158332,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Environment", "value": "`${{ github.event.inputs.environment }}`", "inline": true},
|
|
||||||
{"name": "Attempted", "value": "`${{ github.event.inputs.version_tag || 'previous' }}`", "inline": true},
|
|
||||||
{"name": "By", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "Reason", "value": "${{ github.event.inputs.reason }}", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI/CD • Rollback"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
@ -1,414 +0,0 @@
|
|||||||
name: CD Production
|
|
||||||
|
|
||||||
# Pipeline de production — Hetzner k3s (infra/prod/).
|
|
||||||
#
|
|
||||||
# Enchaînement : sécurité → qualité → vérification → promotion/rebuild → déploiement → contrôle
|
|
||||||
#
|
|
||||||
# TROIS RÈGLES STRUCTURANTES
|
|
||||||
#
|
|
||||||
# 1. Le BACKEND est PROMU depuis la preprod, jamais reconstruit.
|
|
||||||
# Promouvoir garantit que le binaire déployé en production est exactement
|
|
||||||
# celui qui a passé la chaîne de preprod (lint, tests unitaires, tests
|
|
||||||
# d'intégration, build). Un rebuild casserait cette garantie.
|
|
||||||
#
|
|
||||||
# 2. Le FRONTEND est RECONSTRUIT pour la production.
|
|
||||||
# next.config.js fige NEXT_PUBLIC_API_URL au moment du build. Promouvoir
|
|
||||||
# l'image de preprod livrerait une application qui appelle
|
|
||||||
# api.preprod.xpeditis.com en production. C'est la raison pour laquelle ce
|
|
||||||
# workflow ne peut pas se contenter de re-taguer.
|
|
||||||
#
|
|
||||||
# 3. Le déploiement passe par SSH, pas par l'API Kubernetes.
|
|
||||||
# L'API k3s (6443) n'est ouverte qu'aux IP d'administration. Les runners
|
|
||||||
# Gitea n'ont pas d'IP fixe : le job ouvre le port 22 pour la seule IP du
|
|
||||||
# runner via un firewall Hetzner dédié, puis le referme systématiquement.
|
|
||||||
#
|
|
||||||
# Secrets, runners et limites Gitea : voir docs/CI-CD-SECURITY.md
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: rg.fr-par.scw.cloud/weworkstudio
|
|
||||||
K8S_NAMESPACE: xpeditis-prod
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
name: Security gate
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- name: Install Trivy
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
trivy_bin=$(bash scripts/ci/install-tool.sh trivy)
|
|
||||||
"$trivy_bin" --version
|
|
||||||
- name: Validate workflows and deployment checks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
actionlint_bin=$(bash scripts/ci/install-tool.sh actionlint)
|
|
||||||
ACTIONLINT_BIN="$actionlint_bin" bash scripts/ci/validate-workflows.sh
|
|
||||||
- name: Audit dependencies, secrets and infrastructure
|
|
||||||
shell: bash
|
|
||||||
run: bash scripts/ci/security-audit.sh
|
|
||||||
- name: Show security results
|
|
||||||
if: always()
|
|
||||||
shell: bash
|
|
||||||
run: python3 scripts/ci/summarize-security.py
|
|
||||||
- name: Save security reports on Gitea
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: security-reports
|
|
||||||
path: ${{ runner.temp }}/security-reports/*.json
|
|
||||||
retention-days: 7
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Notify Discord
|
|
||||||
if: failure()
|
|
||||||
uses: ./.gitea/actions/notify-security-failure
|
|
||||||
with:
|
|
||||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
pipeline: Production
|
|
||||||
|
|
||||||
# ═══ 1. Qualité ══════════════════════════════════════════════════════════
|
|
||||||
backend-quality:
|
|
||||||
name: Backend — Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint -- --no-fix
|
|
||||||
|
|
||||||
frontend-quality:
|
|
||||||
name: Frontend — Lint & Type-check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint
|
|
||||||
- run: npm run type-check
|
|
||||||
|
|
||||||
backend-tests:
|
|
||||||
name: Backend — Tests unitaires
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: backend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
frontend-tests:
|
|
||||||
name: Frontend — Tests unitaires
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: frontend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
# ═══ 2. Vérification de la provenance ════════════════════════════════════
|
|
||||||
# Exige un pipeline preprod réussi ET un arbre Git identique au code testé ici.
|
|
||||||
verify-image:
|
|
||||||
name: Vérifier l'image de preprod
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, backend-tests, frontend-tests]
|
|
||||||
outputs:
|
|
||||||
sha: ${{ steps.sha.outputs.short }}
|
|
||||||
backend_digest: ${{ steps.sha.outputs.backend_digest }}
|
|
||||||
log_exporter_digest: ${{ steps.sha.outputs.log_exporter_digest }}
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- name: Resolve validated preprod release
|
|
||||||
id: sha
|
|
||||||
run: bash scripts/ci/resolve-release.sh
|
|
||||||
|
|
||||||
# ═══ 3b. Reconstruction du frontend avec les URLs de production ══════════
|
|
||||||
build-frontend:
|
|
||||||
name: Reconstruire le frontend (URLs de production)
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: verify-image
|
|
||||||
outputs:
|
|
||||||
digest: ${{ steps.build.outputs.digest }}
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
# Cet arbre Git est identique à celui de la release preprod vérifiée.
|
|
||||||
ref: ${{ github.sha }}
|
|
||||||
- uses: https://github.com/docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
|
|
||||||
with:
|
|
||||||
platforms: amd64,arm64
|
|
||||||
cache-image: false
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- id: build
|
|
||||||
uses: https://github.com/docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
|
|
||||||
with:
|
|
||||||
context: ./apps/frontend
|
|
||||||
file: ./apps/frontend/Dockerfile
|
|
||||||
push: true
|
|
||||||
platforms: linux/amd64
|
|
||||||
tags: |
|
|
||||||
${{ env.REGISTRY }}/xpeditis-frontend:candidate-prod-${{ github.sha }}-${{ github.run_id }}
|
|
||||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache-prod
|
|
||||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache-prod,mode=max
|
|
||||||
build-args: |
|
|
||||||
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL_PROD }}
|
|
||||||
NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL_PROD }}
|
|
||||||
|
|
||||||
- name: Contrôle — l'URL de preprod ne doit pas figurer dans le bundle
|
|
||||||
run: |
|
|
||||||
IMAGE="${{ env.REGISTRY }}/xpeditis-frontend@${{ steps.build.outputs.digest }}"
|
|
||||||
CID=$(docker create --platform linux/amd64 "$IMAGE")
|
|
||||||
trap 'docker rm "$CID" >/dev/null' EXIT
|
|
||||||
docker cp "$CID:/app/.next" /tmp/next-check
|
|
||||||
test -d /tmp/next-check
|
|
||||||
trap - EXIT
|
|
||||||
docker rm "$CID" >/dev/null
|
|
||||||
if grep -rq "api.preprod.xpeditis.com" /tmp/next-check 2>/dev/null; then
|
|
||||||
echo "::error::L'URL de preprod est figée dans le bundle de production."
|
|
||||||
echo "Vérifiez le secret NEXT_PUBLIC_API_URL_PROD."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Aucune URL de preprod dans le bundle."
|
|
||||||
|
|
||||||
image-security:
|
|
||||||
name: Image security (${{ matrix.service }}, ${{ matrix.arch }})
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [verify-image, build-frontend]
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
service: [backend, frontend, log-exporter]
|
|
||||||
arch: [amd64]
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-trivy
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- name: Scan the exact image before deployment
|
|
||||||
env:
|
|
||||||
IMAGE: ${{ env.REGISTRY }}/xpeditis-${{ matrix.service }}@${{ matrix.service == 'frontend' && needs.build-frontend.outputs.digest || (matrix.service == 'backend' && needs.verify-image.outputs.backend_digest || needs.verify-image.outputs.log_exporter_digest) }}
|
|
||||||
PLATFORM: linux/${{ matrix.arch }}
|
|
||||||
run: |
|
|
||||||
trivy image --platform "$PLATFORM" --scanners vuln --severity HIGH,CRITICAL \
|
|
||||||
--ignore-unfixed=false --exit-code 1 --timeout 15m --no-progress --format json \
|
|
||||||
--output "$RUNNER_TEMP/image-security.json" "$IMAGE"
|
|
||||||
- name: Show image scan results
|
|
||||||
if: always()
|
|
||||||
run: python3 scripts/ci/summarize-image-security.py
|
|
||||||
- name: Save image report
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: image-security-${{ matrix.service }}-${{ matrix.arch }}
|
|
||||||
path: ${{ runner.temp }}/image-security.json
|
|
||||||
retention-days: 14
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
# ═══ 4. Déploiement ══════════════════════════════════════════════════════
|
|
||||||
deploy:
|
|
||||||
name: Déployer en production
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [verify-image, build-frontend, image-security]
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- name: Publish scanned production images
|
|
||||||
env:
|
|
||||||
IMAGE_SHA: ${{ needs.verify-image.outputs.sha }}
|
|
||||||
BACKEND_DIGEST: ${{ needs.verify-image.outputs.backend_digest }}
|
|
||||||
FRONTEND_DIGEST: ${{ needs.build-frontend.outputs.digest }}
|
|
||||||
LOG_EXPORTER_DIGEST: ${{ needs.verify-image.outputs.log_exporter_digest }}
|
|
||||||
run: |
|
|
||||||
for service in backend frontend log-exporter; do
|
|
||||||
case "$service" in
|
|
||||||
backend) digest="$BACKEND_DIGEST" ;;
|
|
||||||
frontend) digest="$FRONTEND_DIGEST" ;;
|
|
||||||
log-exporter) digest="$LOG_EXPORTER_DIGEST" ;;
|
|
||||||
esac
|
|
||||||
docker buildx imagetools create \
|
|
||||||
--tag "$REGISTRY/xpeditis-$service:prod-$IMAGE_SHA" \
|
|
||||||
--tag "$REGISTRY/xpeditis-$service:latest" \
|
|
||||||
"$REGISTRY/xpeditis-$service@$digest"
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Installer le client Hetzner
|
|
||||||
run: |
|
|
||||||
hcloud_bin=$(bash scripts/ci/install-tool.sh hcloud)
|
|
||||||
"$hcloud_bin" version
|
|
||||||
|
|
||||||
- name: Ouvrir le port 22 pour l'IP de ce runner
|
|
||||||
env:
|
|
||||||
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN_CICD }}
|
|
||||||
run: |
|
|
||||||
RUNNER_IP="$(curl -fsS --max-time 10 https://ifconfig.me)"
|
|
||||||
echo "IP du runner : ${RUNNER_IP}"
|
|
||||||
cat > /tmp/fw-open.json <<JSON
|
|
||||||
[{
|
|
||||||
"direction": "in",
|
|
||||||
"protocol": "tcp",
|
|
||||||
"port": "22",
|
|
||||||
"source_ips": ["${RUNNER_IP}/32"],
|
|
||||||
"description": "Gitea Actions run ${{ github.run_id }}"
|
|
||||||
}]
|
|
||||||
JSON
|
|
||||||
hcloud firewall replace-rules "${{ vars.HCLOUD_CICD_FIREWALL }}" --rules-file /tmp/fw-open.json
|
|
||||||
|
|
||||||
- name: Préparer SSH
|
|
||||||
env:
|
|
||||||
DEPLOY_SSH_KEY: ${{ secrets.PROD_SSH_KEY }}
|
|
||||||
DEPLOY_KNOWN_HOSTS: ${{ secrets.PROD_SSH_KNOWN_HOSTS }}
|
|
||||||
run: |
|
|
||||||
mkdir -p "$RUNNER_TEMP/deploy-ssh" && chmod 700 "$RUNNER_TEMP/deploy-ssh"
|
|
||||||
printf '%s\n' "$DEPLOY_SSH_KEY" > "$RUNNER_TEMP/deploy-ssh/id_ed25519"
|
|
||||||
chmod 600 "$RUNNER_TEMP/deploy-ssh/id_ed25519"
|
|
||||||
# Empreinte épinglée : un détournement DNS ou BGP ne peut pas
|
|
||||||
# rediriger le déploiement vers une machine tierce.
|
|
||||||
printf '%s\n' "$DEPLOY_KNOWN_HOSTS" > "$RUNNER_TEMP/deploy-ssh/known_hosts"
|
|
||||||
chmod 600 "$RUNNER_TEMP/deploy-ssh/known_hosts"
|
|
||||||
|
|
||||||
- name: Synchroniser infra/prod sur le serveur
|
|
||||||
run: |
|
|
||||||
rsync -az --delete \
|
|
||||||
--exclude '.terraform' --exclude '*.tfstate*' --exclude '*.tfvars' \
|
|
||||||
-e "ssh -o StrictHostKeyChecking=yes -o UserKnownHostsFile=\"$RUNNER_TEMP/deploy-ssh/known_hosts\" -i \"$RUNNER_TEMP/deploy-ssh/id_ed25519\"" \
|
|
||||||
infra/prod/ \
|
|
||||||
"${{ secrets.PROD_SSH_USER }}@${{ secrets.PROD_SSH_HOST }}:/opt/xpeditis/infra-prod/"
|
|
||||||
|
|
||||||
- name: Déployer
|
|
||||||
id: deploy
|
|
||||||
run: |
|
|
||||||
SHA="${{ needs.verify-image.outputs.sha }}"
|
|
||||||
ssh -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$RUNNER_TEMP/deploy-ssh/known_hosts" -i "$RUNNER_TEMP/deploy-ssh/id_ed25519" \
|
|
||||||
"${{ secrets.PROD_SSH_USER }}@${{ secrets.PROD_SSH_HOST }}" \
|
|
||||||
"deploy prod-${SHA}"
|
|
||||||
|
|
||||||
- name: Tests de fumée depuis l'extérieur
|
|
||||||
id: smoke
|
|
||||||
env:
|
|
||||||
PROD_API_URL: ${{ vars.PROD_API_URL }}
|
|
||||||
PROD_APP_URL: ${{ vars.PROD_APP_URL }}
|
|
||||||
run: bash infra/prod/scripts/smoke-test.sh
|
|
||||||
|
|
||||||
- name: Retour arrière si le déploiement a échoué
|
|
||||||
if: failure() && (steps.deploy.conclusion == 'failure' || steps.smoke.conclusion == 'failure')
|
|
||||||
run: |
|
|
||||||
ssh -o StrictHostKeyChecking=yes -o UserKnownHostsFile="$RUNNER_TEMP/deploy-ssh/known_hosts" -i "$RUNNER_TEMP/deploy-ssh/id_ed25519" \
|
|
||||||
"${{ secrets.PROD_SSH_USER }}@${{ secrets.PROD_SSH_HOST }}" \
|
|
||||||
"rollback" || true
|
|
||||||
|
|
||||||
- name: Refermer le firewall
|
|
||||||
# `always()` : la fenêtre d'exposition se referme même si le
|
|
||||||
# déploiement a échoué, si le job a été annulé ou s'il a expiré.
|
|
||||||
if: always()
|
|
||||||
env:
|
|
||||||
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN_CICD }}
|
|
||||||
run: |
|
|
||||||
echo '[]' > /tmp/fw-close.json
|
|
||||||
hcloud firewall replace-rules "${{ vars.HCLOUD_CICD_FIREWALL }}" --rules-file /tmp/fw-close.json
|
|
||||||
echo "Firewall CI refermé."
|
|
||||||
|
|
||||||
- name: Effacer la clé SSH
|
|
||||||
if: always()
|
|
||||||
run: shred -u "$RUNNER_TEMP/deploy-ssh/id_ed25519" 2>/dev/null || rm -f "$RUNNER_TEMP/deploy-ssh/id_ed25519"
|
|
||||||
|
|
||||||
# ═══ 5. Notifications ════════════════════════════════════════════════════
|
|
||||||
notify-success:
|
|
||||||
name: Notifier le succès
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [verify-image, deploy]
|
|
||||||
if: success()
|
|
||||||
steps:
|
|
||||||
- run: |
|
|
||||||
curl -sf -H "Content-Type: application/json" -d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "Production déployée et saine",
|
|
||||||
"color": 3066993,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Auteur", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "Version", "value": "`prod-${{ needs.verify-image.outputs.sha }}`", "inline": true},
|
|
||||||
{"name": "Cible", "value": "Hetzner k3s — xpeditis-prod", "inline": false},
|
|
||||||
{"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI/CD - Production"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
|
|
||||||
notify-failure:
|
|
||||||
name: Notifier l'échec
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, backend-quality, frontend-quality, backend-tests, frontend-tests, verify-image, build-frontend, image-security, deploy]
|
|
||||||
# Security gate failures are already reported by the security job itself.
|
|
||||||
if: failure() && needs.security.result != 'failure'
|
|
||||||
steps:
|
|
||||||
- run: |
|
|
||||||
curl -sf -H "Content-Type: application/json" -d '{
|
|
||||||
"content": "@here ECHEC DU PIPELINE DE PRODUCTION",
|
|
||||||
"embeds": [{
|
|
||||||
"title": "Pipeline de production en échec",
|
|
||||||
"description": "Un retour arrière a été tenté si l échec est survenu pendant le déploiement. Vérifiez l état réel avant toute nouvelle tentative.",
|
|
||||||
"color": 15158332,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Auteur", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false},
|
|
||||||
{"name": "A vérifier", "value": "Le firewall CI est-il bien refermé ? `hcloud firewall describe xpeditis-prod-fw-cicd`", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI/CD - Production"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
@ -1,451 +0,0 @@
|
|||||||
name: CD Preprod
|
|
||||||
|
|
||||||
# Full pipeline triggered on every push to preprod.
|
|
||||||
# Flow: security gate → lint → unit tests → integration tests → docker build → deploy → notify
|
|
||||||
#
|
|
||||||
# Secrets required:
|
|
||||||
# REGISTRY_TOKEN — Scaleway registry (read/write)
|
|
||||||
# NEXT_PUBLIC_API_URL — https://api.preprod.xpeditis.com
|
|
||||||
# NEXT_PUBLIC_APP_URL — https://preprod.xpeditis.com
|
|
||||||
# PORTAINER_WEBHOOK_BACKEND — Portainer webhook (preprod backend)
|
|
||||||
# PORTAINER_WEBHOOK_FRONTEND— Portainer webhook (preprod frontend)
|
|
||||||
# DISCORD_WEBHOOK_URL
|
|
||||||
# Optional health URL overrides (secrets, then repository variables):
|
|
||||||
# PREPROD_BACKEND_URL — defaults to https://api.preprod.xpeditis.com
|
|
||||||
# PREPROD_FRONTEND_URL — defaults to https://app.preprod.xpeditis.com
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [preprod]
|
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: rg.fr-par.scw.cloud/weworkstudio
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
name: Security gate
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- name: Install Trivy
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
trivy_bin=$(bash scripts/ci/install-tool.sh trivy)
|
|
||||||
"$trivy_bin" --version
|
|
||||||
- name: Validate workflows and deployment checks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
actionlint_bin=$(bash scripts/ci/install-tool.sh actionlint)
|
|
||||||
ACTIONLINT_BIN="$actionlint_bin" bash scripts/ci/validate-workflows.sh
|
|
||||||
- name: Audit dependencies, secrets and infrastructure
|
|
||||||
shell: bash
|
|
||||||
run: bash scripts/ci/security-audit.sh
|
|
||||||
- name: Show security results
|
|
||||||
if: always()
|
|
||||||
shell: bash
|
|
||||||
run: python3 scripts/ci/summarize-security.py
|
|
||||||
- name: Save security reports on Gitea
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: security-reports
|
|
||||||
path: ${{ runner.temp }}/security-reports/*.json
|
|
||||||
retention-days: 7
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Notify Discord
|
|
||||||
if: failure()
|
|
||||||
uses: ./.gitea/actions/notify-security-failure
|
|
||||||
with:
|
|
||||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
pipeline: Preprod
|
|
||||||
|
|
||||||
# ── 1. Lint ─────────────────────────────────────────────────────────
|
|
||||||
backend-quality:
|
|
||||||
name: Backend — Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint -- --no-fix
|
|
||||||
|
|
||||||
frontend-quality:
|
|
||||||
name: Frontend — Lint & Type-check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint
|
|
||||||
- run: npm run type-check
|
|
||||||
|
|
||||||
# ── 2. Unit Tests ────────────────────────────────────────────────────
|
|
||||||
backend-tests:
|
|
||||||
name: Backend — Unit Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: backend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
frontend-tests:
|
|
||||||
name: Frontend — Unit Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: frontend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
# ── 3. Integration Tests ─────────────────────────────────────────────
|
|
||||||
integration-tests:
|
|
||||||
name: Backend — Integration Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [backend-tests, frontend-tests]
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:15-alpine
|
|
||||||
env:
|
|
||||||
POSTGRES_USER: xpeditis_test
|
|
||||||
POSTGRES_PASSWORD: xpeditis_test_password
|
|
||||||
POSTGRES_DB: xpeditis_test
|
|
||||||
options: >-
|
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 5s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 10
|
|
||||||
redis:
|
|
||||||
image: redis:7-alpine
|
|
||||||
options: >-
|
|
||||||
--health-cmd "redis-cli ping"
|
|
||||||
--health-interval 5s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 10
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- name: Run integration tests
|
|
||||||
env:
|
|
||||||
NODE_ENV: test
|
|
||||||
TEST_DB_HOST: postgres
|
|
||||||
TEST_DB_PORT: 5432
|
|
||||||
TEST_DB_USER: xpeditis_test
|
|
||||||
TEST_DB_PASSWORD: xpeditis_test_password
|
|
||||||
TEST_DB_NAME: xpeditis_test
|
|
||||||
DATABASE_HOST: postgres
|
|
||||||
DATABASE_PORT: 5432
|
|
||||||
DATABASE_USER: xpeditis_test
|
|
||||||
DATABASE_PASSWORD: xpeditis_test_password
|
|
||||||
DATABASE_NAME: xpeditis_test
|
|
||||||
DATABASE_SYNCHRONIZE: 'false'
|
|
||||||
REDIS_HOST: redis
|
|
||||||
REDIS_PORT: 6379
|
|
||||||
REDIS_PASSWORD: ''
|
|
||||||
JWT_SECRET: test-secret-key-ci
|
|
||||||
SMTP_HOST: localhost
|
|
||||||
SMTP_PORT: 1025
|
|
||||||
SMTP_FROM: test@xpeditis.com
|
|
||||||
run: npm run test:integration -- --ci --runInBand
|
|
||||||
|
|
||||||
# ── 4. Docker Build & Push ───────────────────────────────────────────
|
|
||||||
# Tags: preprod (latest for this env) + preprod-SHA (used by prod for exact promotion)
|
|
||||||
build-backend:
|
|
||||||
name: Build Backend
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, integration-tests]
|
|
||||||
outputs:
|
|
||||||
sha: ${{ steps.sha.outputs.short }}
|
|
||||||
digest: ${{ steps.build.outputs.digest }}
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Short SHA
|
|
||||||
id: sha
|
|
||||||
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
|
||||||
- uses: https://github.com/docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
|
|
||||||
with:
|
|
||||||
platforms: amd64,arm64
|
|
||||||
cache-image: false
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- id: build
|
|
||||||
uses: https://github.com/docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
|
|
||||||
with:
|
|
||||||
context: ./apps/backend
|
|
||||||
file: ./apps/backend/Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.REGISTRY }}/xpeditis-backend:preprod-${{ steps.sha.outputs.short }}
|
|
||||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache
|
|
||||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache,mode=max
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
|
|
||||||
build-frontend:
|
|
||||||
name: Build Frontend
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, integration-tests]
|
|
||||||
outputs:
|
|
||||||
sha: ${{ steps.sha.outputs.short }}
|
|
||||||
digest: ${{ steps.build.outputs.digest }}
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Short SHA
|
|
||||||
id: sha
|
|
||||||
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
|
||||||
- uses: https://github.com/docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
|
|
||||||
with:
|
|
||||||
platforms: amd64,arm64
|
|
||||||
cache-image: false
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- id: build
|
|
||||||
uses: https://github.com/docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
|
|
||||||
with:
|
|
||||||
context: ./apps/frontend
|
|
||||||
file: ./apps/frontend/Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.REGISTRY }}/xpeditis-frontend:preprod-${{ steps.sha.outputs.short }}
|
|
||||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache
|
|
||||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache,mode=max
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
build-args: |
|
|
||||||
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}
|
|
||||||
NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL }}
|
|
||||||
|
|
||||||
build-log-exporter:
|
|
||||||
name: Build Log Exporter
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, integration-tests]
|
|
||||||
outputs:
|
|
||||||
sha: ${{ steps.sha.outputs.short }}
|
|
||||||
digest: ${{ steps.build.outputs.digest }}
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- name: Short SHA
|
|
||||||
id: sha
|
|
||||||
run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
|
|
||||||
- uses: https://github.com/docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
|
|
||||||
with:
|
|
||||||
platforms: amd64,arm64
|
|
||||||
cache-image: false
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- id: build
|
|
||||||
uses: https://github.com/docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6
|
|
||||||
with:
|
|
||||||
context: ./apps/log-exporter
|
|
||||||
file: ./apps/log-exporter/Dockerfile
|
|
||||||
push: true
|
|
||||||
tags: |
|
|
||||||
${{ env.REGISTRY }}/xpeditis-log-exporter:preprod-${{ steps.sha.outputs.short }}
|
|
||||||
cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-log-exporter:buildcache
|
|
||||||
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-log-exporter:buildcache,mode=max
|
|
||||||
platforms: linux/amd64,linux/arm64
|
|
||||||
|
|
||||||
image-security:
|
|
||||||
name: Image security (${{ matrix.service }}, ${{ matrix.arch }})
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [build-backend, build-frontend, build-log-exporter]
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
service: [backend, frontend, log-exporter]
|
|
||||||
arch: [amd64, arm64]
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-trivy
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- name: Scan the exact image before deployment
|
|
||||||
env:
|
|
||||||
IMAGE: ${{ env.REGISTRY }}/xpeditis-${{ matrix.service }}@${{ needs[format('build-{0}', matrix.service)].outputs.digest }}
|
|
||||||
PLATFORM: linux/${{ matrix.arch }}
|
|
||||||
run: |
|
|
||||||
trivy image --platform "$PLATFORM" --scanners vuln --severity HIGH,CRITICAL \
|
|
||||||
--ignore-unfixed=false --exit-code 1 --timeout 15m --no-progress --format json \
|
|
||||||
--output "$RUNNER_TEMP/image-security.json" "$IMAGE"
|
|
||||||
- name: Show image scan results
|
|
||||||
if: always()
|
|
||||||
run: python3 scripts/ci/summarize-image-security.py
|
|
||||||
- name: Save image report
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: image-security-${{ matrix.service }}-${{ matrix.arch }}
|
|
||||||
path: ${{ runner.temp }}/image-security.json
|
|
||||||
retention-days: 14
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
# ── 5. Deploy via Portainer ──────────────────────────────────────────
|
|
||||||
deploy:
|
|
||||||
name: Deploy to Preprod
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [build-backend, build-frontend, build-log-exporter, image-security]
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: https://github.com/docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
|
|
||||||
- uses: https://github.com/docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
|
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
username: nologin
|
|
||||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
||||||
- name: Publish scanned preprod images
|
|
||||||
env:
|
|
||||||
BACKEND_DIGEST: ${{ needs.build-backend.outputs.digest }}
|
|
||||||
FRONTEND_DIGEST: ${{ needs.build-frontend.outputs.digest }}
|
|
||||||
LOG_EXPORTER_DIGEST: ${{ needs.build-log-exporter.outputs.digest }}
|
|
||||||
run: |
|
|
||||||
for service in backend frontend log-exporter; do
|
|
||||||
case "$service" in
|
|
||||||
backend) digest="$BACKEND_DIGEST" ;;
|
|
||||||
frontend) digest="$FRONTEND_DIGEST" ;;
|
|
||||||
log-exporter) digest="$LOG_EXPORTER_DIGEST" ;;
|
|
||||||
esac
|
|
||||||
docker buildx imagetools create \
|
|
||||||
--tag "$REGISTRY/xpeditis-$service:preprod" \
|
|
||||||
"$REGISTRY/xpeditis-$service@$digest"
|
|
||||||
done
|
|
||||||
- name: Deploy backend
|
|
||||||
run: |
|
|
||||||
HTTP_CODE=$(curl --connect-timeout 10 --max-time 30 -s -o /dev/null -w "%{http_code}" -X POST "${{ secrets.PORTAINER_WEBHOOK_BACKEND }}")
|
|
||||||
echo "Portainer response: HTTP $HTTP_CODE"
|
|
||||||
if [[ "$HTTP_CODE" != "2"* ]]; then
|
|
||||||
echo "ERROR: Portainer webhook failed with HTTP $HTTP_CODE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Backend webhook triggered."
|
|
||||||
- name: Wait for backend startup
|
|
||||||
run: sleep 20
|
|
||||||
- name: Deploy frontend
|
|
||||||
run: |
|
|
||||||
HTTP_CODE=$(curl --connect-timeout 10 --max-time 30 -s -o /dev/null -w "%{http_code}" -X POST "${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}")
|
|
||||||
echo "Portainer response: HTTP $HTTP_CODE"
|
|
||||||
if [[ "$HTTP_CODE" != "2"* ]]; then
|
|
||||||
echo "ERROR: Portainer webhook failed with HTTP $HTTP_CODE"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Frontend webhook triggered."
|
|
||||||
|
|
||||||
- name: Verify backend health
|
|
||||||
env:
|
|
||||||
BASE_URL: ${{ secrets.PREPROD_BACKEND_URL || vars.PREPROD_BACKEND_URL || 'https://api.preprod.xpeditis.com' }}
|
|
||||||
run: bash scripts/ci/health-check.sh "${BASE_URL%/}/api/v1/health"
|
|
||||||
- name: Verify frontend health
|
|
||||||
env:
|
|
||||||
BASE_URL: ${{ secrets.PREPROD_FRONTEND_URL || vars.PREPROD_FRONTEND_URL || 'https://app.preprod.xpeditis.com' }}
|
|
||||||
run: bash scripts/ci/health-check.sh "${BASE_URL%/}/api/health"
|
|
||||||
|
|
||||||
- name: Mark successfully deployed preprod images
|
|
||||||
env:
|
|
||||||
BACKEND_DIGEST: ${{ needs.build-backend.outputs.digest }}
|
|
||||||
LOG_EXPORTER_DIGEST: ${{ needs.build-log-exporter.outputs.digest }}
|
|
||||||
run: |
|
|
||||||
docker buildx imagetools create \
|
|
||||||
--tag "$REGISTRY/xpeditis-backend:validated-preprod-$GITHUB_SHA" \
|
|
||||||
"$REGISTRY/xpeditis-backend@$BACKEND_DIGEST"
|
|
||||||
docker buildx imagetools create \
|
|
||||||
--tag "$REGISTRY/xpeditis-log-exporter:validated-preprod-$GITHUB_SHA" \
|
|
||||||
"$REGISTRY/xpeditis-log-exporter@$LOG_EXPORTER_DIGEST"
|
|
||||||
|
|
||||||
# ── Notifications ────────────────────────────────────────────────────
|
|
||||||
notify-success:
|
|
||||||
name: Notify Success
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [build-backend, build-frontend, deploy]
|
|
||||||
if: success()
|
|
||||||
steps:
|
|
||||||
- run: |
|
|
||||||
curl -s -H "Content-Type: application/json" -d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "✅ Preprod Deployed & Healthy",
|
|
||||||
"color": 3066993,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Author", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "SHA", "value": "`${{ needs.build-backend.outputs.sha }}`", "inline": true},
|
|
||||||
{"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI/CD • Preprod"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
|
|
||||||
notify-failure:
|
|
||||||
name: Notify Failure
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, backend-quality, frontend-quality, backend-tests, frontend-tests, integration-tests, build-backend, build-frontend, build-log-exporter, image-security, deploy]
|
|
||||||
# Security gate failures are already reported by the security job itself.
|
|
||||||
if: failure() && needs.security.result != 'failure'
|
|
||||||
steps:
|
|
||||||
- run: |
|
|
||||||
curl -s -H "Content-Type: application/json" -d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "❌ Preprod Pipeline Failed",
|
|
||||||
"description": "Pipeline en échec. Vérifiez les rapports et l état réel des services avant de relancer.",
|
|
||||||
"color": 15158332,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Author", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI/CD • Preprod"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
@ -1,131 +0,0 @@
|
|||||||
name: Dev CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [dev]
|
|
||||||
pull_request:
|
|
||||||
branches: [dev]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
name: Security gate
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- name: Install Trivy
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
trivy_bin=$(bash scripts/ci/install-tool.sh trivy)
|
|
||||||
"$trivy_bin" --version
|
|
||||||
- name: Validate workflows and deployment checks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
actionlint_bin=$(bash scripts/ci/install-tool.sh actionlint)
|
|
||||||
ACTIONLINT_BIN="$actionlint_bin" bash scripts/ci/validate-workflows.sh
|
|
||||||
- name: Audit dependencies, secrets and infrastructure
|
|
||||||
shell: bash
|
|
||||||
run: bash scripts/ci/security-audit.sh
|
|
||||||
- name: Show security results
|
|
||||||
if: always()
|
|
||||||
shell: bash
|
|
||||||
run: python3 scripts/ci/summarize-security.py
|
|
||||||
- name: Save security reports on Gitea
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: security-reports
|
|
||||||
path: ${{ runner.temp }}/security-reports/*.json
|
|
||||||
retention-days: 7
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Notify Discord
|
|
||||||
if: failure()
|
|
||||||
uses: ./.gitea/actions/notify-security-failure
|
|
||||||
with:
|
|
||||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
pipeline: Dev
|
|
||||||
|
|
||||||
backend-quality:
|
|
||||||
name: Backend — Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint -- --no-fix
|
|
||||||
|
|
||||||
frontend-quality:
|
|
||||||
name: Frontend — Lint & Type-check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint
|
|
||||||
- run: npm run type-check
|
|
||||||
|
|
||||||
backend-tests:
|
|
||||||
name: Backend — Unit Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: backend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
frontend-tests:
|
|
||||||
name: Frontend — Unit Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: frontend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
notify-failure:
|
|
||||||
name: Notify Failure
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [security, backend-quality, frontend-quality, backend-tests, frontend-tests]
|
|
||||||
# Security gate failures are already reported by the security job itself.
|
|
||||||
if: failure() && needs.security.result != 'failure'
|
|
||||||
steps:
|
|
||||||
- name: Discord
|
|
||||||
run: |
|
|
||||||
curl -s -H "Content-Type: application/json" -d '{
|
|
||||||
"embeds": [{
|
|
||||||
"title": "❌ Dev CI Failed",
|
|
||||||
"color": 15158332,
|
|
||||||
"fields": [
|
|
||||||
{"name": "Branch", "value": "`${{ github.ref_name }}`", "inline": true},
|
|
||||||
{"name": "Author", "value": "${{ github.actor }}", "inline": true},
|
|
||||||
{"name": "Workflow", "value": "[${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})", "inline": false}
|
|
||||||
],
|
|
||||||
"footer": {"text": "Xpeditis CI • Dev"}
|
|
||||||
}]
|
|
||||||
}' ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
@ -1,169 +0,0 @@
|
|||||||
name: PR Checks
|
|
||||||
|
|
||||||
# Required status checks — configure these in branch protection rules.
|
|
||||||
# PRs to preprod : lint + type-check + unit tests + integration tests
|
|
||||||
# PRs to main : same checks, including integration and security
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches: [preprod, main]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
security:
|
|
||||||
name: Security gate
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- name: Install Trivy
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
trivy_bin=$(bash scripts/ci/install-tool.sh trivy)
|
|
||||||
"$trivy_bin" --version
|
|
||||||
- name: Validate workflows and deployment checks
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
actionlint_bin=$(bash scripts/ci/install-tool.sh actionlint)
|
|
||||||
ACTIONLINT_BIN="$actionlint_bin" bash scripts/ci/validate-workflows.sh
|
|
||||||
- name: Audit dependencies, secrets and infrastructure
|
|
||||||
shell: bash
|
|
||||||
run: bash scripts/ci/security-audit.sh
|
|
||||||
- name: Show security results
|
|
||||||
if: always()
|
|
||||||
shell: bash
|
|
||||||
run: python3 scripts/ci/summarize-security.py
|
|
||||||
- name: Save security reports on Gitea
|
|
||||||
if: always()
|
|
||||||
uses: https://github.com/actions/upload-artifact@ff15f0306b3f739f7b6fd43fb5d26cd321bd4de5 # v3, Gitea artifact protocol
|
|
||||||
with:
|
|
||||||
name: security-reports
|
|
||||||
path: ${{ runner.temp }}/security-reports/*.json
|
|
||||||
retention-days: 7
|
|
||||||
if-no-files-found: error
|
|
||||||
- name: Notify Discord
|
|
||||||
if: failure()
|
|
||||||
uses: ./.gitea/actions/notify-security-failure
|
|
||||||
with:
|
|
||||||
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
|
|
||||||
pipeline: PR Checks
|
|
||||||
|
|
||||||
backend-quality:
|
|
||||||
name: Backend — Lint
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint -- --no-fix
|
|
||||||
|
|
||||||
frontend-quality:
|
|
||||||
name: Frontend — Lint & Type-check
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: security
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm run lint
|
|
||||||
- run: npm run type-check
|
|
||||||
|
|
||||||
backend-tests:
|
|
||||||
name: Backend — Unit Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: backend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
frontend-tests:
|
|
||||||
name: Frontend — Unit Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: frontend-quality
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/frontend
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- run: npm test -- --ci --runInBand
|
|
||||||
|
|
||||||
# Integration tests validate the actual merge candidate for both branches.
|
|
||||||
integration-tests:
|
|
||||||
name: Backend — Integration Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: backend-tests
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: apps/backend
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:15-alpine
|
|
||||||
env:
|
|
||||||
POSTGRES_USER: xpeditis_test
|
|
||||||
POSTGRES_PASSWORD: xpeditis_test_password
|
|
||||||
POSTGRES_DB: xpeditis_test
|
|
||||||
options: >-
|
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 5s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 10
|
|
||||||
redis:
|
|
||||||
image: redis:7-alpine
|
|
||||||
options: >-
|
|
||||||
--health-cmd "redis-cli ping"
|
|
||||||
--health-interval 5s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 10
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
- uses: ./.gitea/actions/setup-node
|
|
||||||
- run: npm ci --legacy-peer-deps
|
|
||||||
- name: Run integration tests
|
|
||||||
env:
|
|
||||||
NODE_ENV: test
|
|
||||||
TEST_DB_HOST: postgres
|
|
||||||
TEST_DB_PORT: 5432
|
|
||||||
TEST_DB_USER: xpeditis_test
|
|
||||||
TEST_DB_PASSWORD: xpeditis_test_password
|
|
||||||
TEST_DB_NAME: xpeditis_test
|
|
||||||
DATABASE_HOST: postgres
|
|
||||||
DATABASE_PORT: 5432
|
|
||||||
DATABASE_USER: xpeditis_test
|
|
||||||
DATABASE_PASSWORD: xpeditis_test_password
|
|
||||||
DATABASE_NAME: xpeditis_test
|
|
||||||
DATABASE_SYNCHRONIZE: 'false'
|
|
||||||
REDIS_HOST: redis
|
|
||||||
REDIS_PORT: 6379
|
|
||||||
REDIS_PASSWORD: ''
|
|
||||||
JWT_SECRET: test-secret-key-ci
|
|
||||||
SMTP_HOST: localhost
|
|
||||||
SMTP_PORT: 1025
|
|
||||||
SMTP_FROM: test@xpeditis.com
|
|
||||||
run: npm run test:integration -- --ci --runInBand
|
|
||||||
372
.github/workflows/ci.yml
vendored
Normal file
372
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,372 @@
|
|||||||
|
name: CI/CD Pipeline
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- preprod
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: rg.fr-par.scw.cloud/weworkstudio
|
||||||
|
NODE_VERSION: '20'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# ============================================
|
||||||
|
# Backend Build, Test & Deploy
|
||||||
|
# ============================================
|
||||||
|
backend:
|
||||||
|
name: Backend - Build, Test & Push
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: apps/backend
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install --legacy-peer-deps
|
||||||
|
|
||||||
|
- name: Lint code
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: npm test -- --coverage --passWithNoTests
|
||||||
|
|
||||||
|
- name: Build application
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Scaleway Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: rg.fr-par.scw.cloud/weworkstudio
|
||||||
|
username: nologin
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/xpeditis-backend
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
- name: Build and push Backend Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ./apps/backend
|
||||||
|
file: ./apps/backend/Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache
|
||||||
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-backend:buildcache,mode=max
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Frontend Build, Test & Deploy
|
||||||
|
# ============================================
|
||||||
|
frontend:
|
||||||
|
name: Frontend - Build, Test & Push
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: apps/frontend
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: apps/frontend/package-lock.json
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci --legacy-peer-deps
|
||||||
|
|
||||||
|
- name: Lint code
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: npm test -- --passWithNoTests || echo "No tests found"
|
||||||
|
|
||||||
|
- name: Build application
|
||||||
|
env:
|
||||||
|
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL || 'http://localhost:4000' }}
|
||||||
|
NEXT_PUBLIC_APP_URL: ${{ secrets.NEXT_PUBLIC_APP_URL || 'http://localhost:3000' }}
|
||||||
|
NEXT_TELEMETRY_DISABLED: 1
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Scaleway Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: rg.fr-par.scw.cloud/weworkstudio
|
||||||
|
username: nologin
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/xpeditis-frontend
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
- name: Build and push Frontend Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ./apps/frontend
|
||||||
|
file: ./apps/frontend/Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache
|
||||||
|
cache-to: type=registry,ref=${{ env.REGISTRY }}/xpeditis-frontend:buildcache,mode=max
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
build-args: |
|
||||||
|
NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL || 'http://localhost:4000' }}
|
||||||
|
NEXT_PUBLIC_APP_URL=${{ secrets.NEXT_PUBLIC_APP_URL || 'http://localhost:3000' }}
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Integration Tests (Optional)
|
||||||
|
# ============================================
|
||||||
|
integration-tests:
|
||||||
|
name: Integration Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [backend, frontend]
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: apps/backend
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:15-alpine
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: xpeditis
|
||||||
|
POSTGRES_PASSWORD: xpeditis_dev_password
|
||||||
|
POSTGRES_DB: xpeditis_test
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
options: >-
|
||||||
|
--health-cmd "redis-cli ping"
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
ports:
|
||||||
|
- 6379:6379
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install --legacy-peer-deps
|
||||||
|
|
||||||
|
- name: Run integration tests
|
||||||
|
env:
|
||||||
|
DATABASE_HOST: localhost
|
||||||
|
DATABASE_PORT: 5432
|
||||||
|
DATABASE_USER: xpeditis
|
||||||
|
DATABASE_PASSWORD: xpeditis_dev_password
|
||||||
|
DATABASE_NAME: xpeditis_test
|
||||||
|
REDIS_HOST: localhost
|
||||||
|
REDIS_PORT: 6379
|
||||||
|
JWT_SECRET: test-secret-key-for-ci
|
||||||
|
run: npm run test:integration || echo "No integration tests found"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Deployment Summary
|
||||||
|
# ============================================
|
||||||
|
deployment-summary:
|
||||||
|
name: Deployment Summary
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [backend, frontend]
|
||||||
|
if: success()
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Summary
|
||||||
|
run: |
|
||||||
|
echo "## 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "### Backend Image" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "- Registry: \`${{ env.REGISTRY }}/xpeditis-backend\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "- Branch: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "### Frontend Image" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "- Registry: \`${{ env.REGISTRY }}/xpeditis-frontend\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "- Branch: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "- Commit: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "### Pull Commands" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull ${{ env.REGISTRY }}/xpeditis-backend:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "docker pull ${{ env.REGISTRY }}/xpeditis-frontend:${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Deploy to Portainer via Webhooks
|
||||||
|
# ============================================
|
||||||
|
deploy-portainer:
|
||||||
|
name: Deploy to Portainer
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [backend, frontend]
|
||||||
|
if: success() && github.ref == 'refs/heads/preprod'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Trigger Backend Webhook
|
||||||
|
run: |
|
||||||
|
echo "🚀 Deploying Backend to Portainer..."
|
||||||
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"data": "backend-deployment"}' \
|
||||||
|
${{ secrets.PORTAINER_WEBHOOK_BACKEND }}
|
||||||
|
echo "✅ Backend webhook triggered"
|
||||||
|
|
||||||
|
- name: Wait before Frontend deployment
|
||||||
|
run: sleep 10
|
||||||
|
|
||||||
|
- name: Trigger Frontend Webhook
|
||||||
|
run: |
|
||||||
|
echo "🚀 Deploying Frontend to Portainer..."
|
||||||
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"data": "frontend-deployment"}' \
|
||||||
|
${{ secrets.PORTAINER_WEBHOOK_FRONTEND }}
|
||||||
|
echo "✅ Frontend webhook triggered"
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Discord Notification - Success
|
||||||
|
# ============================================
|
||||||
|
notify-success:
|
||||||
|
name: Discord Notification (Success)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [backend, frontend, deploy-portainer]
|
||||||
|
if: success()
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Send Discord notification
|
||||||
|
run: |
|
||||||
|
curl -H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"embeds": [{
|
||||||
|
"title": "✅ CI/CD Pipeline Success",
|
||||||
|
"description": "Deployment completed successfully!",
|
||||||
|
"color": 3066993,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Repository",
|
||||||
|
"value": "${{ github.repository }}",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Branch",
|
||||||
|
"value": "${{ github.ref_name }}",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Commit",
|
||||||
|
"value": "[${{ github.sha }}](${{ github.event.head_commit.url }})",
|
||||||
|
"inline": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Backend Image",
|
||||||
|
"value": "`${{ env.REGISTRY }}/xpeditis-backend:${{ github.ref_name }}`",
|
||||||
|
"inline": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Frontend Image",
|
||||||
|
"value": "`${{ env.REGISTRY }}/xpeditis-frontend:${{ github.ref_name }}`",
|
||||||
|
"inline": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Workflow",
|
||||||
|
"value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})",
|
||||||
|
"inline": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"timestamp": "${{ github.event.head_commit.timestamp }}",
|
||||||
|
"footer": {
|
||||||
|
"text": "Xpeditis CI/CD"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}' \
|
||||||
|
${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Discord Notification - Failure
|
||||||
|
# ============================================
|
||||||
|
notify-failure:
|
||||||
|
name: Discord Notification (Failure)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [backend, frontend, deploy-portainer]
|
||||||
|
if: failure()
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Send Discord notification
|
||||||
|
run: |
|
||||||
|
curl -H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"embeds": [{
|
||||||
|
"title": "❌ CI/CD Pipeline Failed",
|
||||||
|
"description": "Deployment failed! Check the logs for details.",
|
||||||
|
"color": 15158332,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Repository",
|
||||||
|
"value": "${{ github.repository }}",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Branch",
|
||||||
|
"value": "${{ github.ref_name }}",
|
||||||
|
"inline": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Commit",
|
||||||
|
"value": "[${{ github.sha }}](${{ github.event.head_commit.url }})",
|
||||||
|
"inline": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Workflow",
|
||||||
|
"value": "[${{ github.workflow }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})",
|
||||||
|
"inline": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"timestamp": "${{ github.event.head_commit.timestamp }}",
|
||||||
|
"footer": {
|
||||||
|
"text": "Xpeditis CI/CD"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}' \
|
||||||
|
${{ secrets.DISCORD_WEBHOOK_URL }}
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -44,9 +44,6 @@ lerna-debug.log*
|
|||||||
|
|
||||||
# Docker
|
# Docker
|
||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
stack-portainer.yaml
|
|
||||||
tmp.stack-portainer.yaml
|
|
||||||
stack-portainer-preprod.yaml
|
|
||||||
|
|
||||||
# Uploads
|
# Uploads
|
||||||
uploads/
|
uploads/
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
# Approved monitoring exceptions, reviewed 2026-09-24. No dependency/secret exclusions.
|
|
||||||
misconfigurations:
|
|
||||||
- id: AVD-KSV-0047
|
|
||||||
paths: [infra/prod/k8s/monitoring/03-prometheus.yaml]
|
|
||||||
expired_at: 2026-10-24
|
|
||||||
statement: Prometheus scrapes kubelet cAdvisor through the API server node proxy; retain until direct authenticated kubelet scraping is validated.
|
|
||||||
- id: AVD-KSV-0009
|
|
||||||
paths: [infra/prod/k8s/monitoring/04-node-exporter.yaml]
|
|
||||||
expired_at: 2026-10-24
|
|
||||||
statement: Node exporter observes host network metrics; isolated to the monitoring DaemonSet.
|
|
||||||
- id: AVD-KSV-0010
|
|
||||||
paths: [infra/prod/k8s/monitoring/04-node-exporter.yaml]
|
|
||||||
expired_at: 2026-10-24
|
|
||||||
statement: Node exporter observes host processes; runs as non-root with all capabilities dropped.
|
|
||||||
- id: AVD-KSV-0024
|
|
||||||
paths: [infra/prod/k8s/monitoring/04-node-exporter.yaml]
|
|
||||||
expired_at: 2026-10-24
|
|
||||||
statement: Existing host-network exporter listens on port 9101; access remains constrained by infrastructure firewall rules.
|
|
||||||
- id: AVD-KSV-0121
|
|
||||||
paths: [infra/prod/k8s/monitoring/04-node-exporter.yaml]
|
|
||||||
expired_at: 2026-10-24
|
|
||||||
statement: Host proc/sys/root mounts provide disk and system metrics and are read-only; required for disk-full alerts.
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 MiB After Width: | Height: | Size: 11 MiB |
277
AGENTS.md
277
AGENTS.md
@ -1,277 +0,0 @@
|
|||||||
# AGENTS.md
|
|
||||||
|
|
||||||
This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
|
|
||||||
|
|
||||||
## Project Overview
|
|
||||||
|
|
||||||
**Xpeditis** is a B2B SaaS maritime freight booking platform. Freight forwarders search and compare real-time shipping rates, book containers, and manage shipments. Monorepo with NestJS 10 backend (Hexagonal Architecture) and Next.js 14 frontend.
|
|
||||||
|
|
||||||
## Development Commands
|
|
||||||
|
|
||||||
All commands run from repo root unless noted otherwise.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Infrastructure (PostgreSQL 15 + Redis 7 + MinIO)
|
|
||||||
docker-compose up -d
|
|
||||||
|
|
||||||
# Install all dependencies
|
|
||||||
npm run install:all
|
|
||||||
|
|
||||||
# Environment setup (required on first run)
|
|
||||||
cp apps/backend/.env.example apps/backend/.env
|
|
||||||
cp apps/frontend/.env.example apps/frontend/.env
|
|
||||||
|
|
||||||
# Database migrations (from apps/backend/)
|
|
||||||
cd apps/backend && npm run migration:run
|
|
||||||
|
|
||||||
# Development servers
|
|
||||||
npm run backend:dev # http://localhost:4000, Swagger: /api/docs
|
|
||||||
npm run frontend:dev # http://localhost:3000
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Backend (from apps/backend/)
|
|
||||||
npm test # Unit tests (Jest)
|
|
||||||
npm test -- booking.entity.spec.ts # Single file
|
|
||||||
npm test -- --testNamePattern="should create" # Filter by test name
|
|
||||||
npm run test:cov # With coverage
|
|
||||||
npm run test:integration # Integration tests (needs DB/Redis, 30s timeout)
|
|
||||||
npm run test:e2e # E2E tests
|
|
||||||
|
|
||||||
# Frontend (from apps/frontend/)
|
|
||||||
npm test
|
|
||||||
npm run test:e2e # Playwright (chromium, firefox, webkit + mobile)
|
|
||||||
|
|
||||||
# From root
|
|
||||||
npm run backend:test
|
|
||||||
npm run frontend:test
|
|
||||||
```
|
|
||||||
|
|
||||||
Backend test config is in `apps/backend/package.json` (Jest). Integration test config: `apps/backend/jest-integration.json` (covers infrastructure layer, setup in `test/setup-integration.ts`). Frontend E2E config: `apps/frontend/playwright.config.ts`.
|
|
||||||
|
|
||||||
### Linting, Formatting & Type Checking
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run backend:lint # ESLint backend
|
|
||||||
npm run frontend:lint # ESLint frontend
|
|
||||||
npm run format # Prettier (all files)
|
|
||||||
npm run format:check # Check formatting
|
|
||||||
# From apps/frontend/
|
|
||||||
npm run type-check # TypeScript checking (frontend only)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Database Migrations
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd apps/backend
|
|
||||||
npm run migration:generate -- src/infrastructure/persistence/typeorm/migrations/MigrationName
|
|
||||||
npm run migration:run
|
|
||||||
npm run migration:revert
|
|
||||||
```
|
|
||||||
|
|
||||||
### Build
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run backend:build # NestJS build with tsc-alias for path resolution
|
|
||||||
npm run frontend:build # Next.js production build (standalone output)
|
|
||||||
npm run clean # Remove all node_modules, dist, .next directories
|
|
||||||
```
|
|
||||||
|
|
||||||
## Local Infrastructure
|
|
||||||
|
|
||||||
Docker-compose defaults (no `.env` changes needed for local dev):
|
|
||||||
- **PostgreSQL**: `xpeditis:xpeditis_dev_password@localhost:5432/xpeditis_dev`
|
|
||||||
- **Redis**: password `xpeditis_redis_password`, port 6379
|
|
||||||
- **MinIO** (S3-compatible storage): `minioadmin:minioadmin`, API port 9000, console port 9001
|
|
||||||
|
|
||||||
Frontend env var: `NEXT_PUBLIC_API_URL` (defaults to `http://localhost:4000`) — configured in `next.config.js`.
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
### Hexagonal Architecture (Backend)
|
|
||||||
|
|
||||||
```
|
|
||||||
apps/backend/src/
|
|
||||||
├── domain/ # CORE - Pure TypeScript, NO framework imports
|
|
||||||
│ ├── entities/ # Booking, RateQuote, Carrier, Port, Container, Notification, Webhook,
|
|
||||||
│ │ # AuditLog, User, Organization, Subscription, License, CsvBooking,
|
|
||||||
│ │ # CsvRate, InvitationToken
|
|
||||||
│ ├── value-objects/ # Money, Email, BookingNumber, BookingStatus, PortCode, ContainerType,
|
|
||||||
│ │ # Volume, DateRange, Surcharge
|
|
||||||
│ ├── services/ # Pure domain services (csv-rate-price-calculator)
|
|
||||||
│ ├── ports/
|
|
||||||
│ │ ├── in/ # Use case interfaces with execute() method
|
|
||||||
│ │ └── out/ # Repository/SPI interfaces (token constants like BOOKING_REPOSITORY = 'BookingRepository')
|
|
||||||
│ └── exceptions/ # Domain-specific exceptions
|
|
||||||
├── application/ # Controllers, DTOs (class-validator), Guards, Decorators, Mappers
|
|
||||||
│ ├── [feature]/ # Feature modules: auth/, bookings/, csv-bookings, rates/, ports/,
|
|
||||||
│ │ # organizations/, users/, dashboard/, audit/, notifications/, webhooks/,
|
|
||||||
│ │ # gdpr/, admin/, subscriptions/
|
|
||||||
│ ├── controllers/ # REST controllers (also nested under feature folders)
|
|
||||||
│ ├── services/ # Application services: audit, notification, webhook,
|
|
||||||
│ │ # booking-automation, export, fuzzy-search, brute-force-protection
|
|
||||||
│ ├── gateways/ # WebSocket gateways (notifications.gateway.ts via Socket.IO)
|
|
||||||
│ ├── guards/ # JwtAuthGuard, RolesGuard, CustomThrottlerGuard
|
|
||||||
│ ├── decorators/ # @Public(), @Roles(), @CurrentUser()
|
|
||||||
│ ├── dto/ # Request/response DTOs with class-validator
|
|
||||||
│ ├── mappers/ # Domain ↔ DTO mappers
|
|
||||||
│ └── interceptors/ # PerformanceMonitoringInterceptor
|
|
||||||
└── infrastructure/ # TypeORM entities/repos/mappers, Redis cache, carrier APIs,
|
|
||||||
# MinIO/S3, email (MJML+Nodemailer), Stripe, Sentry,
|
|
||||||
# Pappers (French SIRET registry), PDF generation
|
|
||||||
```
|
|
||||||
|
|
||||||
**Critical dependency rules**:
|
|
||||||
- Domain layer: zero imports from NestJS, TypeORM, Redis, or any framework
|
|
||||||
- Dependencies flow inward only: Infrastructure → Application → Domain
|
|
||||||
- Path aliases: `@domain/*`, `@application/*`, `@infrastructure/*` (defined in `apps/backend/tsconfig.json`)
|
|
||||||
- Domain tests run without NestJS TestingModule
|
|
||||||
- Backend has strict TypeScript: `strict: true`, `strictNullChecks: true` (but `strictPropertyInitialization: false`)
|
|
||||||
- Env vars validated at startup via Joi schema in `app.module.ts` — required vars include DATABASE_*, REDIS_*, JWT_SECRET, SMTP_*
|
|
||||||
|
|
||||||
### NestJS Modules (app.module.ts)
|
|
||||||
|
|
||||||
Global guards: JwtAuthGuard (all routes protected by default), CustomThrottlerGuard.
|
|
||||||
|
|
||||||
Feature modules: Auth, Rates, Ports, Bookings, CsvBookings, Organizations, Users, Dashboard, Audit, Notifications, Webhooks, GDPR, Admin, Subscriptions.
|
|
||||||
|
|
||||||
Infrastructure modules: CacheModule, CarrierModule, SecurityModule, CsvRateModule, StripeModule, PdfModule, StorageModule, EmailModule.
|
|
||||||
|
|
||||||
Swagger plugin enabled in `nest-cli.json` — DTOs auto-documented. Logging via `nestjs-pino` (pino-pretty in dev).
|
|
||||||
|
|
||||||
### Frontend (Next.js 14 App Router)
|
|
||||||
|
|
||||||
```
|
|
||||||
apps/frontend/
|
|
||||||
├── app/ # App Router pages (root-level)
|
|
||||||
│ ├── dashboard/ # Protected routes (bookings, admin, settings, wiki, search)
|
|
||||||
│ ├── carrier/ # Carrier portal (magic link auth — accept/reject/documents)
|
|
||||||
│ ├── booking/ # Booking confirmation/rejection flows
|
|
||||||
│ └── [auth pages] # login, register, forgot-password, verify-email
|
|
||||||
└── src/
|
|
||||||
├── app/ # Additional app pages (e.g. rates/csv-search)
|
|
||||||
├── components/ # React components (ui/, layout/, bookings/, admin/, rate-search/, organization/)
|
|
||||||
├── hooks/ # useBookings, useNotifications, useCsvRateSearch, useCompanies, useFilterOptions
|
|
||||||
├── lib/
|
|
||||||
│ ├── api/ # Fetch-based API client with auto token refresh (client.ts + per-module files)
|
|
||||||
│ ├── context/ # Auth context, cookie context
|
|
||||||
│ ├── providers/ # QueryProvider (TanStack Query / React Query)
|
|
||||||
│ └── fonts.ts # Manrope (headings) + Montserrat (body)
|
|
||||||
├── types/ # TypeScript type definitions
|
|
||||||
├── utils/ # Export utilities (Excel, PDF)
|
|
||||||
└── legacy-pages/ # Archived page components (BookingsManagement, CarrierManagement, CarrierMonitoring)
|
|
||||||
```
|
|
||||||
|
|
||||||
Path aliases: `@/*` → `./src/*`, `@/components/*`, `@/lib/*`, `@/app/*` → `./app/*`, `@/types/*`, `@/hooks/*`, `@/utils/*`
|
|
||||||
|
|
||||||
**Note**: Frontend tsconfig has `strict: false`, `noImplicitAny: false`, `strictNullChecks: false` (unlike backend which is strict). Uses TanStack Query (React Query) for server state — wrap new data fetching in hooks, not bare `fetch` calls.
|
|
||||||
|
|
||||||
### Brand Design
|
|
||||||
|
|
||||||
Colors: Navy `#10183A` (primary), Turquoise `#34CCCD` (accent), Green `#067224` (success), Gray `#F2F2F2`.
|
|
||||||
Fonts: Manrope (headings), Montserrat (body).
|
|
||||||
Landing page is in French.
|
|
||||||
|
|
||||||
## Key Patterns
|
|
||||||
|
|
||||||
### Entity Pattern (Domain)
|
|
||||||
Private constructor + static `create()` factory. Immutable — mutation methods return new instances. Some entities also have `fromPersistence()` for reconstitution and `toObject()` for serialization.
|
|
||||||
```typescript
|
|
||||||
export class Booking {
|
|
||||||
private readonly props: BookingProps;
|
|
||||||
static create(props: Omit<BookingProps, 'bookingNumber' | 'status'>): Booking { ... }
|
|
||||||
updateStatus(newStatus: BookingStatus): Booking { // Returns new instance
|
|
||||||
return new Booking({ ...this.props, status: newStatus });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Value Object Pattern
|
|
||||||
Immutable, self-validating via static `create()`. E.g. `Money` supports USD, EUR, GBP, CNY, JPY with arithmetic and formatting methods.
|
|
||||||
|
|
||||||
### Repository Pattern
|
|
||||||
- Interface in `domain/ports/out/` with token constant (e.g. `BOOKING_REPOSITORY = 'BookingRepository'`)
|
|
||||||
- Implementation in `infrastructure/persistence/typeorm/repositories/`
|
|
||||||
- ORM entities: `infrastructure/persistence/typeorm/entities/*.orm-entity.ts`
|
|
||||||
- Separate mapper classes (`infrastructure/persistence/typeorm/mappers/`) with static `toOrm()`, `toDomain()`, `toDomainMany()` methods
|
|
||||||
|
|
||||||
### Frontend API Client
|
|
||||||
Custom Fetch wrapper in `src/lib/api/client.ts` — exports `get()`, `post()`, `patch()`, `del()`, `upload()`, `download()`. Auto-refreshes JWT on 401. Tokens stored in localStorage **and synced to cookies** (`accessToken` cookie) so Next.js middleware can read them server-side. Per-module files (auth.ts, bookings.ts, rates.ts, etc.) import from client.
|
|
||||||
|
|
||||||
### Route Protection (Middleware)
|
|
||||||
`apps/frontend/middleware.ts` checks the `accessToken` cookie to protect routes. Public paths are defined in two lists:
|
|
||||||
- `exactPublicPaths`: exact matches (e.g. `/`)
|
|
||||||
- `prefixPublicPaths`: prefix matches including sub-paths (e.g. `/login`, `/carrier`, `/about`, etc.)
|
|
||||||
|
|
||||||
All other routes redirect to `/login?redirect=<pathname>` when the cookie is absent.
|
|
||||||
|
|
||||||
### Application Decorators
|
|
||||||
- `@Public()` — skip JWT auth
|
|
||||||
- `@Roles()` — role-based access control
|
|
||||||
- `@CurrentUser()` — inject authenticated user
|
|
||||||
|
|
||||||
### API Key Authentication
|
|
||||||
A second auth mechanism alongside JWT. `ApiKey` domain entity (`domain/entities/api-key.entity.ts`) — keys are hashed with Argon2. `ApiKeyGuard` in `application/guards/` checks the `x-api-key` header. Routes can accept either JWT or API key; see `admin.controller.ts` for examples.
|
|
||||||
|
|
||||||
### WebSocket (Real-time Notifications)
|
|
||||||
Socket.IO gateway at `application/gateways/notifications.gateway.ts`. Clients connect to `/` namespace with a JWT bearer token in the handshake auth. Server emits `notification` events. The frontend `useNotifications` hook handles subscriptions.
|
|
||||||
|
|
||||||
### Carrier Connectors
|
|
||||||
Five carrier connectors (Maersk, MSC, CMA CGM, Hapag-Lloyd, ONE) extending `base-carrier.connector.ts`, each with request/response mappers. Circuit breaker via `opossum` (5s timeout).
|
|
||||||
|
|
||||||
### Caching
|
|
||||||
Redis with 15-min TTL for rate quotes. Key format: `rate:{origin}:{destination}:{containerType}`.
|
|
||||||
|
|
||||||
## Business Rules
|
|
||||||
|
|
||||||
- Booking number format: `WCM-YYYY-XXXXXX`
|
|
||||||
- Booking status flow: draft → confirmed → shipped → delivered
|
|
||||||
- Rate quotes expire after 15 minutes
|
|
||||||
- Multi-currency: USD, EUR, GBP, CNY, JPY
|
|
||||||
- RBAC Roles: ADMIN, MANAGER, USER, VIEWER, CARRIER
|
|
||||||
- JWT: access token 15min, refresh token 7d
|
|
||||||
- Password hashing: Argon2
|
|
||||||
- OAuth providers: Google, Microsoft (configured via passport strategies)
|
|
||||||
- Organizations can be validated via Pappers API (French SIRET/company registry) at `infrastructure/external/pappers-siret.adapter.ts`
|
|
||||||
|
|
||||||
### Carrier Portal Workflow
|
|
||||||
1. Admin creates CSV booking → assigns carrier
|
|
||||||
2. Email with magic link sent (1-hour expiry)
|
|
||||||
3. Carrier auto-login → accept/reject booking
|
|
||||||
4. Activity logged in `carrier_activities` table (via `CarrierProfile` + `CarrierActivity` ORM entities)
|
|
||||||
|
|
||||||
## Common Pitfalls
|
|
||||||
|
|
||||||
- Never import NestJS/TypeORM in domain layer
|
|
||||||
- Never use `any` type in backend (strict mode enabled)
|
|
||||||
- Never modify applied migrations — create new ones
|
|
||||||
- Always validate DTOs with `class-validator` decorators
|
|
||||||
- Always create separate mappers for Domain ↔ ORM conversions
|
|
||||||
- ORM entity files must match pattern `*.orm-entity.{ts,js}` (auto-discovered by data-source)
|
|
||||||
- Migration files must be in `infrastructure/persistence/typeorm/migrations/`
|
|
||||||
- Database synchronize is hard-coded to `false` — always use migrations
|
|
||||||
|
|
||||||
## Adding a New Feature
|
|
||||||
|
|
||||||
1. **Domain Entity** → `domain/entities/*.entity.ts` (pure TS, unit tests)
|
|
||||||
2. **Value Objects** → `domain/value-objects/*.vo.ts` (immutable)
|
|
||||||
3. **In Port (Use Case)** → `domain/ports/in/*.use-case.ts` (interface with `execute()`)
|
|
||||||
4. **Out Port (Repository)** → `domain/ports/out/*.repository.ts` (with token constant)
|
|
||||||
5. **ORM Entity** → `infrastructure/persistence/typeorm/entities/*.orm-entity.ts`
|
|
||||||
6. **Migration** → `npm run migration:generate -- src/infrastructure/persistence/typeorm/migrations/MigrationName`
|
|
||||||
7. **Repository Impl** → `infrastructure/persistence/typeorm/repositories/`
|
|
||||||
8. **Mapper** → `infrastructure/persistence/typeorm/mappers/` (static toOrm/toDomain/toDomainMany)
|
|
||||||
9. **DTOs** → `application/dto/` (with class-validator decorators)
|
|
||||||
10. **Controller** → `application/controllers/` (with Swagger decorators)
|
|
||||||
11. **Module** → Register repository + use-case providers, import in `app.module.ts`
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
- API Docs: http://localhost:4000/api/docs (Swagger, when running)
|
|
||||||
- Setup guide: `docs/installation/START-HERE.md`
|
|
||||||
- Carrier Portal API: `apps/backend/docs/CARRIER_PORTAL_API.md`
|
|
||||||
- Full docs index: `docs/README.md`
|
|
||||||
- Development roadmap: `TODO.md`
|
|
||||||
- Infrastructure configs (CI/CD, Docker): `infra/`
|
|
||||||
723
CLAUDE.md
723
CLAUDE.md
@ -4,274 +4,609 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
**Xpeditis** is a B2B SaaS maritime freight booking platform. Freight forwarders search and compare real-time shipping rates, book containers, and manage shipments. Monorepo with NestJS 10 backend (Hexagonal Architecture) and Next.js 14 frontend.
|
**Xpeditis** is a B2B SaaS maritime freight booking and management platform (maritime equivalent of WebCargo). The platform allows freight forwarders to search and compare real-time shipping rates, book containers online, and manage shipments from a centralized dashboard.
|
||||||
|
|
||||||
|
**Current Status**: Phase 4 - Production-ready with security hardening, monitoring, and comprehensive testing infrastructure.
|
||||||
|
|
||||||
## Development Commands
|
## Development Commands
|
||||||
|
|
||||||
All commands run from repo root unless noted otherwise.
|
### Local Development Setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Infrastructure (PostgreSQL 15 + Redis 7 + MinIO)
|
# Install all dependencies (monorepo)
|
||||||
|
npm install
|
||||||
|
cd apps/backend && npm install
|
||||||
|
cd ../frontend && npm install
|
||||||
|
|
||||||
|
# Start infrastructure (PostgreSQL + Redis + MinIO)
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
|
||||||
# Install all dependencies
|
# Verify all services are running
|
||||||
npm run install:all
|
docker-compose ps
|
||||||
|
# Expected: xpeditis-postgres, xpeditis-redis, xpeditis-minio
|
||||||
|
|
||||||
# Environment setup (required on first run)
|
# Run database migrations
|
||||||
cp apps/backend/.env.example apps/backend/.env
|
cd apps/backend
|
||||||
cp apps/frontend/.env.example apps/frontend/.env
|
npm run migration:run
|
||||||
|
|
||||||
# Database migrations (from apps/backend/)
|
# Start backend development server (with hot reload)
|
||||||
cd apps/backend && npm run migration:run
|
npm run backend:dev # From root, or:
|
||||||
|
cd apps/backend && npm run dev
|
||||||
|
|
||||||
# Development servers
|
# Start frontend development server
|
||||||
npm run backend:dev # http://localhost:4000, Swagger: /api/docs
|
npm run frontend:dev # From root, or:
|
||||||
npm run frontend:dev # http://localhost:3000
|
cd apps/frontend && npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### Testing
|
**Access Points**:
|
||||||
|
- Frontend: http://localhost:3000
|
||||||
|
- Backend API: http://localhost:4000
|
||||||
|
- API Docs (Swagger): http://localhost:4000/api/docs
|
||||||
|
- MinIO Console (local S3): http://localhost:9001 (minioadmin/minioadmin)
|
||||||
|
|
||||||
|
### Monorepo Scripts (from root)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Backend (from apps/backend/)
|
# Development
|
||||||
npm test # Unit tests (Jest)
|
npm run backend:dev # Start backend dev server
|
||||||
npm test -- booking.entity.spec.ts # Single file
|
npm run frontend:dev # Start frontend dev server
|
||||||
npm test -- --testNamePattern="should create" # Filter by test name
|
|
||||||
npm run test:cov # With coverage
|
|
||||||
npm run test:integration # Integration tests (needs DB/Redis, 30s timeout)
|
|
||||||
npm run test:e2e # E2E tests
|
|
||||||
|
|
||||||
# Frontend (from apps/frontend/)
|
# Testing
|
||||||
npm test
|
npm run backend:test # Run backend unit tests
|
||||||
npm run test:e2e # Playwright (chromium, firefox, webkit + mobile)
|
npm run frontend:test # Run frontend tests
|
||||||
|
npm run backend:lint # Lint backend code
|
||||||
|
npm run frontend:lint # Lint frontend code
|
||||||
|
|
||||||
# From root
|
# Code Quality
|
||||||
npm run backend:test
|
npm run format # Format all code (Prettier)
|
||||||
npm run frontend:test
|
npm run format:check # Check formatting
|
||||||
|
|
||||||
|
# Build
|
||||||
|
npm run backend:build # Build backend for production
|
||||||
|
npm run frontend:build # Build frontend for production
|
||||||
|
|
||||||
|
# Utilities
|
||||||
|
npm run install:all # Install deps for all workspaces
|
||||||
|
npm run clean # Clean all node_modules and build artifacts
|
||||||
```
|
```
|
||||||
|
|
||||||
Backend test config is in `apps/backend/package.json` (Jest). Integration test config: `apps/backend/jest-integration.json` (covers infrastructure layer, setup in `test/setup-integration.ts`). Frontend E2E config: `apps/frontend/playwright.config.ts`.
|
### Testing Commands
|
||||||
|
|
||||||
### Linting, Formatting & Type Checking
|
#### Backend Tests
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run backend:lint # ESLint backend
|
cd apps/backend
|
||||||
npm run frontend:lint # ESLint frontend
|
|
||||||
npm run format # Prettier (all files)
|
# Unit tests (domain layer - no external dependencies)
|
||||||
npm run format:check # Check formatting
|
npm test # Run all unit tests
|
||||||
# From apps/frontend/
|
npm run test:watch # Run in watch mode
|
||||||
npm run type-check # TypeScript checking (frontend only)
|
npm run test:cov # With coverage report
|
||||||
|
|
||||||
|
# Integration tests (infrastructure layer with real DB/Redis)
|
||||||
|
npm run test:integration # Run all integration tests
|
||||||
|
npm run test:integration:watch # Run in watch mode
|
||||||
|
npm run test:integration:cov # With coverage report
|
||||||
|
|
||||||
|
# E2E tests (full API workflow)
|
||||||
|
npm run test:e2e # Run end-to-end tests
|
||||||
|
|
||||||
|
# Run a single test file
|
||||||
|
npm test -- booking.service.spec.ts
|
||||||
|
npm run test:integration -- redis-cache.adapter.spec.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Load Testing (K6)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd apps/backend
|
||||||
|
|
||||||
|
# Install k6 (macOS)
|
||||||
|
brew install k6
|
||||||
|
|
||||||
|
# Run rate search load test (100 virtual users)
|
||||||
|
k6 run load-tests/rate-search.test.js
|
||||||
|
|
||||||
|
# Run with custom parameters
|
||||||
|
k6 run --vus 50 --duration 60s load-tests/rate-search.test.js
|
||||||
|
```
|
||||||
|
|
||||||
|
#### E2E Testing (Playwright)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd apps/frontend
|
||||||
|
|
||||||
|
# Install Playwright
|
||||||
|
npx playwright install
|
||||||
|
|
||||||
|
# Run E2E tests (booking workflow)
|
||||||
|
npx playwright test e2e/booking-workflow.spec.ts
|
||||||
|
|
||||||
|
# Run with UI mode
|
||||||
|
npx playwright test --ui
|
||||||
|
|
||||||
|
# Run specific browser
|
||||||
|
npx playwright test --project=chromium
|
||||||
|
```
|
||||||
|
|
||||||
|
#### API Testing (Postman/Newman)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Newman globally
|
||||||
|
npm install -g newman
|
||||||
|
|
||||||
|
# Run Postman collection
|
||||||
|
newman run postman/Xpeditis_API.postman_collection.json
|
||||||
```
|
```
|
||||||
|
|
||||||
### Database Migrations
|
### Database Migrations
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd apps/backend
|
cd apps/backend
|
||||||
|
|
||||||
|
# Generate new migration (after changing ORM entities)
|
||||||
npm run migration:generate -- src/infrastructure/persistence/typeorm/migrations/MigrationName
|
npm run migration:generate -- src/infrastructure/persistence/typeorm/migrations/MigrationName
|
||||||
|
|
||||||
|
# Run pending migrations
|
||||||
npm run migration:run
|
npm run migration:run
|
||||||
|
|
||||||
|
# Revert last migration
|
||||||
npm run migration:revert
|
npm run migration:revert
|
||||||
```
|
```
|
||||||
|
|
||||||
### Build
|
### Build & Production
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run backend:build # NestJS build with tsc-alias for path resolution
|
# Backend build
|
||||||
npm run frontend:build # Next.js production build (standalone output)
|
cd apps/backend
|
||||||
npm run clean # Remove all node_modules, dist, .next directories
|
npm run build
|
||||||
|
npm run start:prod
|
||||||
|
|
||||||
|
# Frontend build
|
||||||
|
cd apps/frontend
|
||||||
|
npm run build
|
||||||
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
## Local Infrastructure
|
|
||||||
|
|
||||||
Docker-compose defaults (no `.env` changes needed for local dev):
|
|
||||||
- **PostgreSQL**: `xpeditis:xpeditis_dev_password@localhost:5432/xpeditis_dev`
|
|
||||||
- **Redis**: password `xpeditis_redis_password`, port 6379
|
|
||||||
- **MinIO** (S3-compatible storage): `minioadmin:minioadmin`, API port 9000, console port 9001
|
|
||||||
|
|
||||||
Frontend env var: `NEXT_PUBLIC_API_URL` (defaults to `http://localhost:4000`) — configured in `next.config.js`.
|
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
### Hexagonal Architecture (Backend)
|
### Hexagonal Architecture (Ports & Adapters)
|
||||||
|
|
||||||
|
The backend follows strict hexagonal architecture with three isolated layers:
|
||||||
|
|
||||||
```
|
```
|
||||||
apps/backend/src/
|
apps/backend/src/
|
||||||
├── domain/ # CORE - Pure TypeScript, NO framework imports
|
├── domain/ # 🎯 Pure business logic (ZERO external dependencies)
|
||||||
│ ├── entities/ # Booking, RateQuote, Carrier, Port, Container, Notification, Webhook,
|
│ ├── entities/ # Booking, RateQuote, User, Organization, Carrier
|
||||||
│ │ # AuditLog, User, Organization, Subscription, License, CsvBooking,
|
│ ├── value-objects/ # Email, Money, BookingNumber, PortCode
|
||||||
│ │ # CsvRate, InvitationToken
|
│ ├── services/ # Domain services (rate-search, booking, availability)
|
||||||
│ ├── value-objects/ # Money, Email, BookingNumber, BookingStatus, PortCode, ContainerType,
|
|
||||||
│ │ # Volume, DateRange, Surcharge
|
|
||||||
│ ├── services/ # Pure domain services (csv-rate-price-calculator)
|
|
||||||
│ ├── ports/
|
│ ├── ports/
|
||||||
│ │ ├── in/ # Use case interfaces with execute() method
|
│ │ ├── in/ # Use cases (search-rates, create-booking)
|
||||||
│ │ └── out/ # Repository/SPI interfaces (token constants like BOOKING_REPOSITORY = 'BookingRepository')
|
│ │ └── out/ # Repository interfaces, connector ports
|
||||||
│ └── exceptions/ # Domain-specific exceptions
|
│ └── exceptions/ # Business exceptions
|
||||||
├── application/ # Controllers, DTOs (class-validator), Guards, Decorators, Mappers
|
│
|
||||||
│ ├── [feature]/ # Feature modules: auth/, bookings/, csv-bookings, rates/, ports/,
|
├── application/ # 🔌 Controllers & DTOs (depends ONLY on domain)
|
||||||
│ │ # organizations/, users/, dashboard/, audit/, notifications/, webhooks/,
|
│ ├── controllers/ # REST endpoints
|
||||||
│ │ # gdpr/, admin/, subscriptions/
|
│ ├── dto/ # Data transfer objects with validation
|
||||||
│ ├── controllers/ # REST controllers (also nested under feature folders)
|
│ ├── guards/ # Auth guards, rate limiting, RBAC
|
||||||
│ ├── services/ # Application services: audit, notification, webhook,
|
│ ├── services/ # Brute-force protection, file validation
|
||||||
│ │ # booking-automation, export, fuzzy-search, brute-force-protection
|
│ └── mappers/ # DTO ↔ Domain entity mapping
|
||||||
│ ├── gateways/ # WebSocket gateways (notifications.gateway.ts via Socket.IO)
|
│
|
||||||
│ ├── guards/ # JwtAuthGuard, RolesGuard, CustomThrottlerGuard
|
└── infrastructure/ # 🏗️ External integrations (depends ONLY on domain)
|
||||||
│ ├── decorators/ # @Public(), @Roles(), @CurrentUser()
|
├── persistence/typeorm/ # PostgreSQL repositories
|
||||||
│ ├── dto/ # Request/response DTOs with class-validator
|
├── cache/ # Redis adapter
|
||||||
│ ├── mappers/ # Domain ↔ DTO mappers
|
├── carriers/ # Maersk, MSC, CMA CGM connectors
|
||||||
│ └── interceptors/ # PerformanceMonitoringInterceptor
|
├── email/ # MJML email service
|
||||||
└── infrastructure/ # TypeORM entities/repos/mappers, Redis cache, carrier APIs,
|
├── storage/ # S3 storage adapter
|
||||||
# MinIO/S3, email (MJML+Nodemailer), Stripe, Sentry,
|
├── websocket/ # Real-time carrier updates
|
||||||
# Pappers (French SIRET registry), PDF generation
|
└── security/ # Helmet.js, rate limiting, CORS
|
||||||
```
|
```
|
||||||
|
|
||||||
**Critical dependency rules**:
|
**Critical Rules**:
|
||||||
- Domain layer: zero imports from NestJS, TypeORM, Redis, or any framework
|
1. **Domain layer**: No imports of NestJS, TypeORM, Redis, or any framework
|
||||||
- Dependencies flow inward only: Infrastructure → Application → Domain
|
2. **Dependencies flow inward**: Infrastructure → Application → Domain
|
||||||
- Path aliases: `@domain/*`, `@application/*`, `@infrastructure/*` (defined in `apps/backend/tsconfig.json`)
|
3. **TypeScript path aliases**: Use `@domain/*`, `@application/*`, `@infrastructure/*`
|
||||||
- Domain tests run without NestJS TestingModule
|
4. **Testing**: Domain tests must run without NestJS TestingModule
|
||||||
- Backend has strict TypeScript: `strict: true`, `strictNullChecks: true` (but `strictPropertyInitialization: false`)
|
|
||||||
- Env vars validated at startup via Joi schema in `app.module.ts` — required vars include DATABASE_*, REDIS_*, JWT_SECRET, SMTP_*
|
|
||||||
|
|
||||||
### NestJS Modules (app.module.ts)
|
### Frontend Architecture (Next.js 14 App Router)
|
||||||
|
|
||||||
Global guards: JwtAuthGuard (all routes protected by default), CustomThrottlerGuard.
|
|
||||||
|
|
||||||
Feature modules: Auth, Rates, Ports, Bookings, CsvBookings, Organizations, Users, Dashboard, Audit, Notifications, Webhooks, GDPR, Admin, Subscriptions.
|
|
||||||
|
|
||||||
Infrastructure modules: CacheModule, CarrierModule, SecurityModule, CsvRateModule, StripeModule, PdfModule, StorageModule, EmailModule.
|
|
||||||
|
|
||||||
Swagger plugin enabled in `nest-cli.json` — DTOs auto-documented. Logging via `nestjs-pino` (pino-pretty in dev).
|
|
||||||
|
|
||||||
### Frontend (Next.js 14 App Router)
|
|
||||||
|
|
||||||
```
|
```
|
||||||
apps/frontend/
|
apps/frontend/
|
||||||
├── app/ # App Router pages (root-level)
|
├── app/ # Next.js 14 App Router (routing)
|
||||||
│ ├── dashboard/ # Protected routes (bookings, admin, settings, wiki, search)
|
│ ├── page.tsx # Landing page
|
||||||
│ ├── carrier/ # Carrier portal (magic link auth — accept/reject/documents)
|
│ ├── layout.tsx # Root layout
|
||||||
│ ├── booking/ # Booking confirmation/rejection flows
|
│ ├── login/ # Auth pages
|
||||||
│ └── [auth pages] # login, register, forgot-password, verify-email
|
│ ├── register/
|
||||||
└── src/
|
│ └── dashboard/ # Protected dashboard routes
|
||||||
├── app/ # Additional app pages (e.g. rates/csv-search)
|
├── src/
|
||||||
├── components/ # React components (ui/, layout/, bookings/, admin/, rate-search/, organization/)
|
│ ├── components/ # React components
|
||||||
├── hooks/ # useBookings, useNotifications, useCsvRateSearch, useCompanies, useFilterOptions
|
│ │ ├── ui/ # shadcn/ui components (Button, Dialog, etc.)
|
||||||
├── lib/
|
│ │ └── features/ # Feature-specific components
|
||||||
│ ├── api/ # Fetch-based API client with auto token refresh (client.ts + per-module files)
|
│ ├── hooks/ # Custom React hooks
|
||||||
│ ├── context/ # Auth context, cookie context
|
│ ├── lib/ # Utilities and API client
|
||||||
│ ├── providers/ # QueryProvider (TanStack Query / React Query)
|
│ ├── types/ # TypeScript type definitions
|
||||||
│ └── fonts.ts # Manrope (headings) + Montserrat (body)
|
│ ├── utils/ # Helper functions
|
||||||
├── types/ # TypeScript type definitions
|
│ └── pages/ # Legacy page components
|
||||||
├── utils/ # Export utilities (Excel, PDF)
|
└── public/ # Static assets (logos, images)
|
||||||
└── legacy-pages/ # Archived page components (BookingsManagement, CarrierManagement, CarrierMonitoring)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Path aliases: `@/*` → `./src/*`, `@/components/*`, `@/lib/*`, `@/app/*` → `./app/*`, `@/types/*`, `@/hooks/*`, `@/utils/*`
|
**Frontend Patterns**:
|
||||||
|
- Server Components by default, Client Components when needed (`"use client"`)
|
||||||
|
- React Hook Form + Zod for form validation
|
||||||
|
- TanStack Query for server state management
|
||||||
|
- Zustand for client state management
|
||||||
|
- shadcn/ui for accessible UI components
|
||||||
|
|
||||||
**Note**: Frontend tsconfig has `strict: false`, `noImplicitAny: false`, `strictNullChecks: false` (unlike backend which is strict). Uses TanStack Query (React Query) for server state — wrap new data fetching in hooks, not bare `fetch` calls.
|
**TypeScript Path Aliases** (Frontend):
|
||||||
|
- `@/*` - Maps to `./src/*`
|
||||||
|
- `@/components/*` - Maps to `./src/components/*`
|
||||||
|
- `@/lib/*` - Maps to `./src/lib/*`
|
||||||
|
- `@/app/*` - Maps to `./app/*`
|
||||||
|
- `@/types/*` - Maps to `./src/types/*`
|
||||||
|
- `@/hooks/*` - Maps to `./src/hooks/*`
|
||||||
|
- `@/utils/*` - Maps to `./src/utils/*`
|
||||||
|
- `@/pages/*` - Maps to `./src/pages/*`
|
||||||
|
|
||||||
### Brand Design
|
### Tech Stack
|
||||||
|
|
||||||
Colors: Navy `#10183A` (primary), Turquoise `#34CCCD` (accent), Green `#067224` (success), Gray `#F2F2F2`.
|
**Backend**:
|
||||||
Fonts: Manrope (headings), Montserrat (body).
|
- NestJS 10+ (framework)
|
||||||
Landing page is in French.
|
- TypeScript 5+ (strict mode)
|
||||||
|
- PostgreSQL 15+ (database)
|
||||||
|
- TypeORM 0.3+ (ORM)
|
||||||
|
- Redis 7+ (cache, 15min TTL for rates)
|
||||||
|
- Passport + JWT (authentication)
|
||||||
|
- Argon2 (password hashing)
|
||||||
|
- Helmet.js (security headers)
|
||||||
|
- Pino (structured logging)
|
||||||
|
- Sentry (error tracking + APM)
|
||||||
|
|
||||||
## Key Patterns
|
**Frontend**:
|
||||||
|
- Next.js 14+ App Router
|
||||||
|
- TypeScript 5+
|
||||||
|
- React 18+
|
||||||
|
- TanStack Table (data grids)
|
||||||
|
- TanStack Query (server state)
|
||||||
|
- React Hook Form + Zod (forms)
|
||||||
|
- Socket.IO (real-time updates)
|
||||||
|
- Tailwind CSS + shadcn/ui
|
||||||
|
- Framer Motion (animations)
|
||||||
|
|
||||||
### Entity Pattern (Domain)
|
**Infrastructure**:
|
||||||
Private constructor + static `create()` factory. Immutable — mutation methods return new instances. Some entities also have `fromPersistence()` for reconstitution and `toObject()` for serialization.
|
- Docker + Docker Compose
|
||||||
```typescript
|
- GitHub Actions (CI/CD)
|
||||||
export class Booking {
|
- AWS RDS (PostgreSQL)
|
||||||
private readonly props: BookingProps;
|
- AWS ElastiCache (Redis)
|
||||||
static create(props: Omit<BookingProps, 'bookingNumber' | 'status'>): Booking { ... }
|
- AWS S3 (document storage)
|
||||||
updateStatus(newStatus: BookingStatus): Booking { // Returns new instance
|
- MinIO (local S3-compatible storage for development)
|
||||||
return new Booking({ ...this.props, status: newStatus });
|
|
||||||
}
|
## Testing Strategy
|
||||||
}
|
|
||||||
|
### Test Coverage Targets
|
||||||
|
- **Domain layer**: 90%+ (currently ~100% for value objects and entities)
|
||||||
|
- **Application layer**: 80%+
|
||||||
|
- **Infrastructure layer**: 70%+ (currently ~82% for Phase 3 services)
|
||||||
|
|
||||||
|
### Test File Locations
|
||||||
|
|
||||||
|
```
|
||||||
|
apps/backend/
|
||||||
|
├── src/
|
||||||
|
│ └── domain/
|
||||||
|
│ ├── entities/
|
||||||
|
│ │ └── rate-quote.entity.spec.ts # Unit test example
|
||||||
|
│ └── value-objects/
|
||||||
|
│ ├── email.vo.spec.ts
|
||||||
|
│ └── money.vo.spec.ts
|
||||||
|
├── test/
|
||||||
|
│ ├── integration/ # Infrastructure tests
|
||||||
|
│ │ ├── booking.repository.spec.ts
|
||||||
|
│ │ ├── redis-cache.adapter.spec.ts
|
||||||
|
│ │ └── maersk.connector.spec.ts
|
||||||
|
│ ├── app.e2e-spec.ts # E2E API tests
|
||||||
|
│ ├── jest-integration.json # Integration test config
|
||||||
|
│ └── setup-integration.ts # Test setup
|
||||||
|
└── load-tests/
|
||||||
|
└── rate-search.test.js # K6 load tests
|
||||||
|
|
||||||
|
apps/frontend/
|
||||||
|
└── e2e/
|
||||||
|
└── booking-workflow.spec.ts # Playwright E2E tests
|
||||||
```
|
```
|
||||||
|
|
||||||
### Value Object Pattern
|
### Running Tests in CI
|
||||||
Immutable, self-validating via static `create()`. E.g. `Money` supports USD, EUR, GBP, CNY, JPY with arithmetic and formatting methods.
|
|
||||||
|
|
||||||
### Repository Pattern
|
Tests run automatically on GitHub Actions for all PRs:
|
||||||
- Interface in `domain/ports/out/` with token constant (e.g. `BOOKING_REPOSITORY = 'BookingRepository'`)
|
- Linting & formatting check
|
||||||
- Implementation in `infrastructure/persistence/typeorm/repositories/`
|
- Backend unit tests
|
||||||
- ORM entities: `infrastructure/persistence/typeorm/entities/*.orm-entity.ts`
|
- Backend integration tests (with PostgreSQL + Redis services)
|
||||||
- Separate mapper classes (`infrastructure/persistence/typeorm/mappers/`) with static `toOrm()`, `toDomain()`, `toDomainMany()` methods
|
- Backend E2E tests
|
||||||
|
- Frontend tests
|
||||||
|
- Security scans
|
||||||
|
|
||||||
### Frontend API Client
|
See [.github/workflows/ci.yml](.github/workflows/ci.yml) for full pipeline.
|
||||||
Custom Fetch wrapper in `src/lib/api/client.ts` — exports `get()`, `post()`, `patch()`, `del()`, `upload()`, `download()`. Auto-refreshes JWT on 401. Tokens stored in localStorage **and synced to cookies** (`accessToken` cookie) so Next.js middleware can read them server-side. Per-module files (auth.ts, bookings.ts, rates.ts, etc.) import from client.
|
|
||||||
|
|
||||||
### Route Protection (Middleware)
|
## Security Features (Phase 4)
|
||||||
`apps/frontend/middleware.ts` checks the `accessToken` cookie to protect routes. Public paths are defined in two lists:
|
|
||||||
- `exactPublicPaths`: exact matches (e.g. `/`)
|
|
||||||
- `prefixPublicPaths`: prefix matches including sub-paths (e.g. `/login`, `/carrier`, `/about`, etc.)
|
|
||||||
|
|
||||||
All other routes redirect to `/login?redirect=<pathname>` when the cookie is absent.
|
**OWASP Top 10 Compliance**:
|
||||||
|
- ✅ Helmet.js security headers (CSP, HSTS, X-Frame-Options)
|
||||||
|
- ✅ Rate limiting (global: 100/min, auth: 5/min, search: 30/min)
|
||||||
|
- ✅ Brute-force protection (exponential backoff after 3 failed attempts)
|
||||||
|
- ✅ File upload validation (MIME, magic number, size limits)
|
||||||
|
- ✅ Password policy (12+ chars, complexity requirements, Argon2 hashing)
|
||||||
|
- ✅ CORS with strict origin validation
|
||||||
|
- ✅ SQL injection prevention (TypeORM parameterized queries)
|
||||||
|
- ✅ XSS protection (CSP headers + input sanitization)
|
||||||
|
|
||||||
### Application Decorators
|
**Monitoring & Observability**:
|
||||||
- `@Public()` — skip JWT auth
|
- Sentry error tracking + APM (10% trace sampling)
|
||||||
- `@Roles()` — role-based access control
|
- Performance monitoring interceptor (slow request alerts)
|
||||||
- `@CurrentUser()` — inject authenticated user
|
- Structured JSON logging with Pino
|
||||||
|
- WebSocket real-time notifications (NotificationsGateway)
|
||||||
|
- WebSocket carrier status updates
|
||||||
|
|
||||||
### API Key Authentication
|
## Database Schema
|
||||||
A second auth mechanism alongside JWT. `ApiKey` domain entity (`domain/entities/api-key.entity.ts`) — keys are hashed with Argon2. `ApiKeyGuard` in `application/guards/` checks the `x-api-key` header. Routes can accept either JWT or API key; see `admin.controller.ts` for examples.
|
|
||||||
|
|
||||||
### WebSocket (Real-time Notifications)
|
**Key Tables**:
|
||||||
Socket.IO gateway at `application/gateways/notifications.gateway.ts`. Clients connect to `/` namespace with a JWT bearer token in the handshake auth. Server emits `notification` events. The frontend `useNotifications` hook handles subscriptions.
|
- `organizations` - Freight forwarders and carriers
|
||||||
|
- `users` - User accounts with RBAC roles (Argon2 password hashing)
|
||||||
|
- `carriers` - Shipping line integrations (Maersk, MSC, CMA CGM, etc.)
|
||||||
|
- `ports` - 10k+ global ports (UN LOCODE)
|
||||||
|
- `rate_quotes` - Cached shipping rates (15min TTL)
|
||||||
|
- `bookings` - Container bookings (status workflow)
|
||||||
|
- `containers` - Container details (type, VGM, seal numbers)
|
||||||
|
- `shipments` - Real-time shipment tracking
|
||||||
|
- `audit_logs` - Compliance audit trail
|
||||||
|
- `csv_rates` - CSV-based rate data for offline/bulk rate loading
|
||||||
|
- `csv_bookings` - CSV-based booking imports
|
||||||
|
- `notifications` - User notifications (email, in-app)
|
||||||
|
- `webhooks` - Webhook configurations for external integrations
|
||||||
|
|
||||||
### Carrier Connectors
|
**Migrations**: Located in `apps/backend/src/infrastructure/persistence/typeorm/migrations/`
|
||||||
Five carrier connectors (Maersk, MSC, CMA CGM, Hapag-Lloyd, ONE) extending `base-carrier.connector.ts`, each with request/response mappers. Circuit breaker via `opossum` (5s timeout).
|
|
||||||
|
|
||||||
### Caching
|
See [apps/backend/DATABASE-SCHEMA.md](apps/backend/DATABASE-SCHEMA.md) for complete schema documentation.
|
||||||
Redis with 15-min TTL for rate quotes. Key format: `rate:{origin}:{destination}:{containerType}`.
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
### Required Variables
|
||||||
|
|
||||||
|
**Backend** (`apps/backend/.env`):
|
||||||
|
```bash
|
||||||
|
NODE_ENV=development
|
||||||
|
PORT=4000
|
||||||
|
DATABASE_HOST=localhost
|
||||||
|
DATABASE_PORT=5432
|
||||||
|
DATABASE_USER=xpeditis
|
||||||
|
DATABASE_PASSWORD=xpeditis_dev_password
|
||||||
|
DATABASE_NAME=xpeditis_dev
|
||||||
|
REDIS_HOST=localhost
|
||||||
|
REDIS_PORT=6379
|
||||||
|
REDIS_PASSWORD=xpeditis_redis_password
|
||||||
|
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
|
||||||
|
JWT_ACCESS_EXPIRATION=15m
|
||||||
|
JWT_REFRESH_EXPIRATION=7d
|
||||||
|
```
|
||||||
|
|
||||||
|
**Frontend** (`apps/frontend/.env.local`):
|
||||||
|
```bash
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost:4000
|
||||||
|
NEXT_PUBLIC_WS_URL=ws://localhost:4000
|
||||||
|
```
|
||||||
|
|
||||||
|
See `apps/backend/.env.example` and `apps/frontend/.env.example` for all available variables.
|
||||||
|
|
||||||
|
## API Documentation
|
||||||
|
|
||||||
|
**OpenAPI/Swagger**: http://localhost:4000/api/docs (when backend running)
|
||||||
|
|
||||||
|
**Key Endpoints**:
|
||||||
|
- `POST /api/v1/auth/login` - JWT authentication
|
||||||
|
- `POST /api/v1/auth/register` - User registration
|
||||||
|
- `POST /api/v1/rates/search` - Search shipping rates (cached 15min)
|
||||||
|
- `POST /api/v1/bookings` - Create booking
|
||||||
|
- `GET /api/v1/bookings` - List bookings (paginated)
|
||||||
|
- `GET /api/v1/bookings/:id` - Get booking details
|
||||||
|
- `GET /api/v1/carriers/:id/status` - Real-time carrier status
|
||||||
|
- `POST /api/v1/rates/csv-search` - Search rates from CSV data
|
||||||
|
- `POST /api/v1/bookings/csv-import` - Bulk import bookings from CSV
|
||||||
|
- `GET /api/v1/notifications` - Get user notifications
|
||||||
|
- `WS /notifications` - WebSocket for real-time notifications
|
||||||
|
- `WS /carrier-status` - WebSocket for carrier status updates
|
||||||
|
|
||||||
## Business Rules
|
## Business Rules
|
||||||
|
|
||||||
- Booking number format: `WCM-YYYY-XXXXXX`
|
**Critical Constraints**:
|
||||||
- Booking status flow: draft → confirmed → shipped → delivered
|
- Rate quotes expire after 15 minutes (Redis TTL)
|
||||||
- Rate quotes expire after 15 minutes
|
- Carrier API timeout: 5 seconds per carrier
|
||||||
- Multi-currency: USD, EUR, GBP, CNY, JPY
|
- Booking workflow: Maximum 4 steps
|
||||||
- RBAC Roles: ADMIN, MANAGER, USER, VIEWER, CARRIER
|
- Session timeout: 2 hours inactivity
|
||||||
- JWT: access token 15min, refresh token 7d
|
- Rate search: <2s response time (90% with cache)
|
||||||
- Password hashing: Argon2
|
- Booking number format: `WCM-YYYY-XXXXXX` (6 alphanumeric chars)
|
||||||
- OAuth providers: Google, Microsoft (configured via passport strategies)
|
- Cache hit target: >90% for common routes
|
||||||
- Organizations can be validated via Pappers API (French SIRET/company registry) at `infrastructure/external/pappers-siret.adapter.ts`
|
- Multi-currency support: USD, EUR
|
||||||
|
|
||||||
### Carrier Portal Workflow
|
**RBAC Roles**:
|
||||||
1. Admin creates CSV booking → assigns carrier
|
- `ADMIN` - Full system access
|
||||||
2. Email with magic link sent (1-hour expiry)
|
- `MANAGER` - Manage organization bookings + users
|
||||||
3. Carrier auto-login → accept/reject booking
|
- `USER` - Create and view own bookings
|
||||||
4. Activity logged in `carrier_activities` table (via `CarrierProfile` + `CarrierActivity` ORM entities)
|
- `VIEWER` - Read-only access
|
||||||
|
|
||||||
## Common Pitfalls
|
## Real-Time Features (WebSocket)
|
||||||
|
|
||||||
- Never import NestJS/TypeORM in domain layer
|
The platform uses WebSocket connections for real-time updates:
|
||||||
- Never use `any` type in backend (strict mode enabled)
|
|
||||||
- Never modify applied migrations — create new ones
|
|
||||||
- Always validate DTOs with `class-validator` decorators
|
|
||||||
- Always create separate mappers for Domain ↔ ORM conversions
|
|
||||||
- ORM entity files must match pattern `*.orm-entity.{ts,js}` (auto-discovered by data-source)
|
|
||||||
- Migration files must be in `infrastructure/persistence/typeorm/migrations/`
|
|
||||||
- Database synchronize is hard-coded to `false` — always use migrations
|
|
||||||
|
|
||||||
## Adding a New Feature
|
**Notifications Gateway** (`application/gateways/notifications.gateway.ts`):
|
||||||
|
- Real-time user notifications (booking updates, system alerts)
|
||||||
|
- JWT-authenticated WebSocket connections
|
||||||
|
- Auto-reconnect with exponential backoff
|
||||||
|
- Connect to `ws://localhost:4000/notifications`
|
||||||
|
|
||||||
1. **Domain Entity** → `domain/entities/*.entity.ts` (pure TS, unit tests)
|
**Carrier Status Updates**:
|
||||||
2. **Value Objects** → `domain/value-objects/*.vo.ts` (immutable)
|
- Real-time carrier API status monitoring
|
||||||
3. **In Port (Use Case)** → `domain/ports/in/*.use-case.ts` (interface with `execute()`)
|
- Live shipment tracking updates
|
||||||
4. **Out Port (Repository)** → `domain/ports/out/*.repository.ts` (with token constant)
|
- Connection status: online/offline/degraded
|
||||||
5. **ORM Entity** → `infrastructure/persistence/typeorm/entities/*.orm-entity.ts`
|
- Connect to `ws://localhost:4000/carrier-status`
|
||||||
6. **Migration** → `npm run migration:generate -- src/infrastructure/persistence/typeorm/migrations/MigrationName`
|
|
||||||
7. **Repository Impl** → `infrastructure/persistence/typeorm/repositories/`
|
**Frontend Integration**:
|
||||||
8. **Mapper** → `infrastructure/persistence/typeorm/mappers/` (static toOrm/toDomain/toDomainMany)
|
- Socket.IO client for WebSocket connections
|
||||||
9. **DTOs** → `application/dto/` (with class-validator decorators)
|
- Context providers in `lib/providers/`
|
||||||
10. **Controller** → `application/controllers/` (with Swagger decorators)
|
- Real-time notification dropdown component
|
||||||
11. **Module** → Register repository + use-case providers, import in `app.module.ts`
|
- Auto-refresh on status changes
|
||||||
|
|
||||||
|
## CSV Import/Export Features
|
||||||
|
|
||||||
|
The platform supports CSV-based operations for bulk data management:
|
||||||
|
|
||||||
|
**CSV Rate Search**:
|
||||||
|
- Upload CSV files with rate data for offline/bulk rate loading
|
||||||
|
- CSV-based carrier connectors in `infrastructure/carriers/csv-loader/`
|
||||||
|
- Stored in `csv_rates` table
|
||||||
|
- Accessible via admin dashboard at `/admin/csv-rates`
|
||||||
|
|
||||||
|
**CSV Booking Import**:
|
||||||
|
- Bulk import bookings from CSV files
|
||||||
|
- Validation and mapping to domain entities
|
||||||
|
- Stored in `csv_bookings` table
|
||||||
|
- CSV parsing with `csv-parse` library
|
||||||
|
|
||||||
|
**Export Features**:
|
||||||
|
- Export bookings to Excel (`.xlsx`) using `exceljs`
|
||||||
|
- Export to CSV format
|
||||||
|
- Export to PDF documents using `pdfkit`
|
||||||
|
- File downloads using `file-saver` on frontend
|
||||||
|
|
||||||
|
## Admin User Management
|
||||||
|
|
||||||
|
The platform includes a dedicated admin interface for user management:
|
||||||
|
|
||||||
|
**Admin Features** (Branch: `users_admin`):
|
||||||
|
- User CRUD operations (Create, Read, Update, Delete)
|
||||||
|
- Organization management
|
||||||
|
- Role assignment and permissions
|
||||||
|
- Argon2 password hash generation for new users
|
||||||
|
- Accessible at `/admin/users` (ADMIN role required)
|
||||||
|
|
||||||
|
**Password Hashing Utility**:
|
||||||
|
- Use `apps/backend/generate-hash.js` to generate Argon2 password hashes
|
||||||
|
- Example: `node apps/backend/generate-hash.js mypassword`
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
### Docker Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build backend image
|
||||||
|
docker build -t xpeditis-backend:latest -f apps/backend/Dockerfile .
|
||||||
|
|
||||||
|
# Build frontend image
|
||||||
|
docker build -t xpeditis-frontend:latest -f apps/frontend/Dockerfile .
|
||||||
|
|
||||||
|
# Run with Docker Compose (development)
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Deployment (Portainer)
|
||||||
|
|
||||||
|
See [docker/PORTAINER_DEPLOYMENT_GUIDE.md](docker/PORTAINER_DEPLOYMENT_GUIDE.md) for complete instructions:
|
||||||
|
- Scaleway Container Registry (rg.fr-par.scw.cloud/weworkstudio)
|
||||||
|
- Docker Swarm stack deployment
|
||||||
|
- Traefik reverse proxy configuration
|
||||||
|
- Environment-specific configs (staging/production)
|
||||||
|
|
||||||
|
**CI/CD**: Automated via GitHub Actions
|
||||||
|
- Build and push Docker images to Scaleway Registry
|
||||||
|
- Deploy to staging/production via Portainer
|
||||||
|
- Run smoke tests post-deployment
|
||||||
|
|
||||||
|
**Deployment Scripts**:
|
||||||
|
- `docker/build-images.sh` - Build and tag Docker images
|
||||||
|
- `deploy-to-portainer.sh` - Automated deployment script
|
||||||
|
- `docker/portainer-stack.yml` - Production stack configuration
|
||||||
|
|
||||||
|
## Performance Targets
|
||||||
|
|
||||||
|
- Rate search: <2s for 90% of requests (with cache)
|
||||||
|
- Rate search: <5s for 90% of requests (cache miss)
|
||||||
|
- Dashboard load: <1s for up to 5k bookings
|
||||||
|
- Email confirmation: Send within 3s of booking
|
||||||
|
- Cache hit ratio: >90% for top 100 trade lanes
|
||||||
|
- Carrier API timeout: 5s (with circuit breaker)
|
||||||
|
|
||||||
|
## Naming Conventions
|
||||||
|
|
||||||
|
**TypeScript**:
|
||||||
|
- Entities: `Booking`, `RateQuote` (PascalCase)
|
||||||
|
- Value Objects: `Email`, `Money`, `BookingNumber`
|
||||||
|
- Services: `BookingService`, `RateSearchService`
|
||||||
|
- Repositories: `BookingRepository` (interface in domain)
|
||||||
|
- Repository Implementations: `TypeOrmBookingRepository`
|
||||||
|
- DTOs: `CreateBookingDto`, `RateSearchRequestDto`
|
||||||
|
- Ports: `SearchRatesPort`, `CarrierConnectorPort`
|
||||||
|
|
||||||
|
**Files**:
|
||||||
|
- Entities: `booking.entity.ts`
|
||||||
|
- Value Objects: `email.vo.ts`
|
||||||
|
- Services: `booking.service.ts`
|
||||||
|
- Tests: `booking.service.spec.ts`
|
||||||
|
- ORM Entities: `booking.orm-entity.ts`
|
||||||
|
- Migrations: `1730000000001-CreateBookings.ts`
|
||||||
|
|
||||||
|
## Common Pitfalls to Avoid
|
||||||
|
|
||||||
|
❌ **DO NOT**:
|
||||||
|
- Import NestJS/TypeORM in domain layer
|
||||||
|
- Put business logic in controllers or repositories
|
||||||
|
- Use `any` type (strict mode enabled)
|
||||||
|
- Skip writing tests (coverage targets enforced)
|
||||||
|
- Use `DATABASE_SYNC=true` in production
|
||||||
|
- Commit `.env` files
|
||||||
|
- Expose sensitive data in API responses
|
||||||
|
- Skip rate limiting on public endpoints
|
||||||
|
- Use circular imports (leverage barrel exports)
|
||||||
|
|
||||||
|
✅ **DO**:
|
||||||
|
- Follow hexagonal architecture strictly
|
||||||
|
- Write tests for all new features (domain 90%+)
|
||||||
|
- Use TypeScript path aliases (`@domain/*`)
|
||||||
|
- Validate all DTOs with `class-validator`
|
||||||
|
- Implement circuit breakers for external APIs
|
||||||
|
- Cache frequently accessed data (Redis)
|
||||||
|
- Use structured logging (Pino)
|
||||||
|
- Document APIs with Swagger decorators
|
||||||
|
- Run migrations before deployment
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
- API Docs: http://localhost:4000/api/docs (Swagger, when running)
|
**Architecture & Planning**:
|
||||||
- Setup guide: `docs/installation/START-HERE.md`
|
- [ARCHITECTURE.md](ARCHITECTURE.md) - System architecture (5,800 words)
|
||||||
- Carrier Portal API: `apps/backend/docs/CARRIER_PORTAL_API.md`
|
- [DEPLOYMENT.md](DEPLOYMENT.md) - Deployment guide (4,500 words)
|
||||||
- Full docs index: `docs/README.md`
|
- [PRD.md](PRD.md) - Product requirements
|
||||||
- Development roadmap: `TODO.md`
|
- [TODO.md](TODO.md) - 30-week development roadmap
|
||||||
- Infrastructure configs (CI/CD, Docker): `infra/`
|
|
||||||
|
**Implementation Summaries**:
|
||||||
|
- [PHASE4_SUMMARY.md](PHASE4_SUMMARY.md) - Security, monitoring, testing
|
||||||
|
- [PHASE3_COMPLETE.md](PHASE3_COMPLETE.md) - Booking workflow, exports
|
||||||
|
- [PHASE2_COMPLETE.md](PHASE2_COMPLETE.md) - Authentication, RBAC
|
||||||
|
- [PHASE-1-WEEK5-COMPLETE.md](PHASE-1-WEEK5-COMPLETE.md) - Rate search, cache
|
||||||
|
|
||||||
|
**Testing**:
|
||||||
|
- [TEST_EXECUTION_GUIDE.md](TEST_EXECUTION_GUIDE.md) - How to run all tests
|
||||||
|
- [TEST_COVERAGE_REPORT.md](TEST_COVERAGE_REPORT.md) - Coverage metrics
|
||||||
|
- [GUIDE_TESTS_POSTMAN.md](GUIDE_TESTS_POSTMAN.md) - Postman API tests
|
||||||
|
|
||||||
|
**Deployment**:
|
||||||
|
- [docker/PORTAINER_DEPLOYMENT_GUIDE.md](docker/PORTAINER_DEPLOYMENT_GUIDE.md) - Portainer setup
|
||||||
|
- [docker/DOCKER_BUILD_GUIDE.md](docker/DOCKER_BUILD_GUIDE.md) - Docker build instructions
|
||||||
|
- [DEPLOYMENT_CHECKLIST.md](DEPLOYMENT_CHECKLIST.md) - Pre-deployment checklist
|
||||||
|
|
||||||
|
## Code Review Checklist
|
||||||
|
|
||||||
|
1. Hexagonal architecture principles followed
|
||||||
|
2. Domain layer has zero external dependencies
|
||||||
|
3. Unit tests written (90%+ coverage for domain)
|
||||||
|
4. Integration tests for infrastructure adapters
|
||||||
|
5. DTOs validated with class-validator
|
||||||
|
6. Swagger documentation updated
|
||||||
|
7. No secrets committed
|
||||||
|
8. TypeScript strict mode passes
|
||||||
|
9. Prettier formatting applied
|
||||||
|
10. ESLint passes with no warnings
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
### 4. Nettoyage des fichiers CSV
|
### 4. Nettoyage des fichiers CSV
|
||||||
- ✅ Suppression de la colonne `companyEmail` des fichiers CSV (elle n'est plus nécessaire)
|
- ✅ Suppression de la colonne `companyEmail` des fichiers CSV (elle n'est plus nécessaire)
|
||||||
- ✅ Script Python créé pour automatiser l'ajout/suppression: `scripts/add-email-to-csv.py`
|
- ✅ Script Python créé pour automatiser l'ajout/suppression: `add-email-to-csv.py`
|
||||||
|
|
||||||
## ✅ Ce qui a été complété (SUITE)
|
## ✅ Ce qui a été complété (SUITE)
|
||||||
|
|
||||||
393
INDEX.md
393
INDEX.md
@ -1,81 +1,348 @@
|
|||||||
# Index de documentation — Xpeditis
|
# 📑 Xpeditis Documentation Index
|
||||||
|
|
||||||
|
Complete guide to all documentation files in the Xpeditis project.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Démarrage
|
## 🚀 Getting Started (Read First)
|
||||||
|
|
||||||
| Fichier | Description |
|
Start here if you're new to the project:
|
||||||
|---------|-------------|
|
|
||||||
| [README.md](README.md) | Vue d'ensemble du projet |
|
1. **[README.md](README.md)** - Project overview and quick start
|
||||||
| [QUICK-START.md](QUICK-START.md) | Démarrage en 5 minutes |
|
2. **[QUICK-START.md](QUICK-START.md)** ⚡ - Get running in 5 minutes
|
||||||
| [CLAUDE.md](CLAUDE.md) | Architecture hexagonale, conventions, règles |
|
3. **[INSTALLATION-STEPS.md](INSTALLATION-STEPS.md)** - Detailed installation guide
|
||||||
| [docs/README.md](docs/README.md) | Index complet de la documentation |
|
4. **[NEXT-STEPS.md](NEXT-STEPS.md)** - What to do after setup
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Documentation complète
|
## 📊 Project Status & Planning
|
||||||
|
|
||||||
Toute la documentation est organisée dans [docs/](docs/) :
|
### Sprint 0 (Complete ✅)
|
||||||
|
|
||||||
```
|
- **[SPRINT-0-FINAL.md](SPRINT-0-FINAL.md)** - Complete Sprint 0 report
|
||||||
docs/
|
- All deliverables
|
||||||
├── README.md # Index principal
|
- Architecture details
|
||||||
├── getting-started/ # Installation et démarrage
|
- How to use
|
||||||
│ ├── quick-start.md # Guide rapide mis à jour
|
- Success criteria
|
||||||
│ ├── installation.md # Installation détaillée
|
|
||||||
│ └── windows.md # Spécifique Windows
|
- **[SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md)** - Executive summary
|
||||||
│
|
- Objectives achieved
|
||||||
├── architecture/ # Documentation technique
|
- Metrics
|
||||||
│ ├── overview.md # Vue d'ensemble système
|
- Key features
|
||||||
│ ├── database.md # Schéma BDD complet (21 tables)
|
- Next steps
|
||||||
│ ├── backend.md # NestJS hexagonal, patterns
|
|
||||||
│ └── frontend.md # Next.js 14, App Router, i18n
|
- **[SPRINT-0-COMPLETE.md](SPRINT-0-COMPLETE.md)** - Technical completion checklist
|
||||||
│
|
- Week-by-week breakdown
|
||||||
├── features/ # Documentation par fonctionnalité
|
- Files created
|
||||||
│ ├── auth.md # Auth JWT/OAuth/API Keys + RBAC
|
- Remaining tasks
|
||||||
│ ├── bookings.md # Réservations standard
|
|
||||||
│ ├── csv-bookings.md # CSV bookings + portail carrier
|
### Project Roadmap
|
||||||
│ ├── rate-search.md # Recherche tarifs FCL + CSV
|
|
||||||
│ ├── subscriptions.md # Stripe + abonnements
|
- **[TODO.md](TODO.md)** 📅 - 30-week MVP development roadmap
|
||||||
│ ├── notifications.md # WebSocket + webhooks
|
- Sprint-by-sprint breakdown
|
||||||
│ └── api-access.md # Clés API
|
- Detailed tasks with checkboxes
|
||||||
│
|
- Phase 1-4 planning
|
||||||
├── deployment/ # Déploiement
|
- Go-to-market strategy
|
||||||
│ ├── portainer.md # Portainer / Docker Swarm (consolidé)
|
|
||||||
│ ├── hetzner/ # Kubernetes Hetzner (15 fichiers numérotés)
|
- **[PRD.md](PRD.md)** 📋 - Product Requirements Document
|
||||||
│ └── STRIPE_SETUP.md # Configuration Stripe
|
- Business context
|
||||||
│
|
- Functional specifications
|
||||||
├── testing/ # Tests
|
- Technical requirements
|
||||||
├── csv-system/ # Système CSV (format, calcul prix)
|
- Success metrics
|
||||||
├── carrier-portal/ # Portail carrier (recherche API)
|
|
||||||
├── api-access/ # Documentation accès API
|
|
||||||
├── backend/ # Notes backend (cleanup, MinIO)
|
|
||||||
└── archive/ # Rapports de sprint archivés
|
|
||||||
├── phases/ # Historique phases 1-4
|
|
||||||
└── debug/ # Notes de debug résolues
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Commandes essentielles
|
## 🏗️ Architecture & Development Guidelines
|
||||||
|
|
||||||
```bash
|
### Core Architecture
|
||||||
# Démarrer
|
|
||||||
docker-compose up -d
|
|
||||||
npm run install:all
|
|
||||||
cd apps/backend && npm run migration:run && cd ../..
|
|
||||||
npm run backend:dev # http://localhost:4000
|
|
||||||
npm run frontend:dev # http://localhost:3000
|
|
||||||
|
|
||||||
# Tests
|
- **[CLAUDE.md](CLAUDE.md)** 🏗️ - **START HERE FOR ARCHITECTURE**
|
||||||
npm run backend:test
|
- Complete hexagonal architecture guide
|
||||||
npm run frontend:test
|
- Domain/Application/Infrastructure layers
|
||||||
|
- Ports & Adapters pattern
|
||||||
|
- Naming conventions
|
||||||
|
- Testing strategy
|
||||||
|
- Common pitfalls
|
||||||
|
- Complete examples (476 lines)
|
||||||
|
|
||||||
# Qualité
|
### Component-Specific Documentation
|
||||||
npm run format
|
|
||||||
npm run backend:lint && npm run frontend:lint
|
- **[apps/backend/README.md](apps/backend/README.md)** - Backend (NestJS + Hexagonal)
|
||||||
```
|
- Architecture details
|
||||||
|
- Available scripts
|
||||||
|
- API endpoints
|
||||||
|
- Testing guide
|
||||||
|
- Hexagonal architecture DOs and DON'Ts
|
||||||
|
|
||||||
|
- **[apps/frontend/README.md](apps/frontend/README.md)** - Frontend (Next.js 14)
|
||||||
|
- Tech stack
|
||||||
|
- Project structure
|
||||||
|
- API integration
|
||||||
|
- Forms & validation
|
||||||
|
- Testing guide
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
*Dernière mise à jour : Mai 2026*
|
## 🛠️ Technical Documentation
|
||||||
|
|
||||||
|
### Configuration Files
|
||||||
|
|
||||||
|
**Root Level**:
|
||||||
|
- `package.json` - Workspace configuration
|
||||||
|
- `.gitignore` - Git ignore rules
|
||||||
|
- `.prettierrc` - Code formatting
|
||||||
|
- `docker-compose.yml` - PostgreSQL + Redis
|
||||||
|
- `tsconfig.json` - TypeScript configuration (per app)
|
||||||
|
|
||||||
|
**Backend** (`apps/backend/`):
|
||||||
|
- `package.json` - Backend dependencies
|
||||||
|
- `tsconfig.json` - TypeScript strict mode + path aliases
|
||||||
|
- `nest-cli.json` - NestJS CLI configuration
|
||||||
|
- `.eslintrc.js` - ESLint rules
|
||||||
|
- `.env.example` - Environment variables template
|
||||||
|
|
||||||
|
**Frontend** (`apps/frontend/`):
|
||||||
|
- `package.json` - Frontend dependencies
|
||||||
|
- `tsconfig.json` - TypeScript configuration
|
||||||
|
- `next.config.js` - Next.js configuration
|
||||||
|
- `tailwind.config.ts` - Tailwind CSS theme
|
||||||
|
- `postcss.config.js` - PostCSS configuration
|
||||||
|
- `.env.example` - Environment variables template
|
||||||
|
|
||||||
|
### CI/CD
|
||||||
|
|
||||||
|
**GitHub Actions** (`.github/workflows/`):
|
||||||
|
- `ci.yml` - Continuous Integration
|
||||||
|
- Lint & format check
|
||||||
|
- Unit tests (backend + frontend)
|
||||||
|
- E2E tests
|
||||||
|
- Build verification
|
||||||
|
|
||||||
|
- `security.yml` - Security Audit
|
||||||
|
- npm audit
|
||||||
|
- Dependency review
|
||||||
|
|
||||||
|
**Templates**:
|
||||||
|
- `.github/pull_request_template.md` - PR template with hexagonal architecture checklist
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 Documentation by Use Case
|
||||||
|
|
||||||
|
### I want to...
|
||||||
|
|
||||||
|
**...get started quickly**
|
||||||
|
1. [QUICK-START.md](QUICK-START.md) - 5-minute setup
|
||||||
|
2. [INSTALLATION-STEPS.md](INSTALLATION-STEPS.md) - Detailed steps
|
||||||
|
3. [NEXT-STEPS.md](NEXT-STEPS.md) - Begin development
|
||||||
|
|
||||||
|
**...understand the architecture**
|
||||||
|
1. [CLAUDE.md](CLAUDE.md) - Complete hexagonal architecture guide
|
||||||
|
2. [apps/backend/README.md](apps/backend/README.md) - Backend specifics
|
||||||
|
3. [SPRINT-0-FINAL.md](SPRINT-0-FINAL.md) - See what's implemented
|
||||||
|
|
||||||
|
**...know what to build next**
|
||||||
|
1. [TODO.md](TODO.md) - Full roadmap
|
||||||
|
2. [NEXT-STEPS.md](NEXT-STEPS.md) - Immediate next tasks
|
||||||
|
3. [PRD.md](PRD.md) - Business requirements
|
||||||
|
|
||||||
|
**...understand the business context**
|
||||||
|
1. [PRD.md](PRD.md) - Product requirements
|
||||||
|
2. [README.md](README.md) - Project overview
|
||||||
|
3. [SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md) - Executive summary
|
||||||
|
|
||||||
|
**...fix an installation issue**
|
||||||
|
1. [INSTALLATION-STEPS.md](INSTALLATION-STEPS.md) - Troubleshooting section
|
||||||
|
2. [QUICK-START.md](QUICK-START.md) - Common issues
|
||||||
|
3. [README.md](README.md) - Basic setup
|
||||||
|
|
||||||
|
**...write code following best practices**
|
||||||
|
1. [CLAUDE.md](CLAUDE.md) - Architecture guidelines (READ THIS FIRST)
|
||||||
|
2. [apps/backend/README.md](apps/backend/README.md) - Backend DOs and DON'Ts
|
||||||
|
3. [TODO.md](TODO.md) - Task specifications and acceptance criteria
|
||||||
|
|
||||||
|
**...run tests**
|
||||||
|
1. [apps/backend/README.md](apps/backend/README.md) - Testing section
|
||||||
|
2. [apps/frontend/README.md](apps/frontend/README.md) - Testing section
|
||||||
|
3. [CLAUDE.md](CLAUDE.md) - Testing strategy
|
||||||
|
|
||||||
|
**...deploy to production**
|
||||||
|
1. [SPRINT-0-FINAL.md](SPRINT-0-FINAL.md) - Security checklist
|
||||||
|
2. [apps/backend/.env.example](apps/backend/.env.example) - All required variables
|
||||||
|
3. `.github/workflows/ci.yml` - CI/CD pipeline
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📖 Documentation by Role
|
||||||
|
|
||||||
|
### For Developers
|
||||||
|
|
||||||
|
**Must Read**:
|
||||||
|
1. [CLAUDE.md](CLAUDE.md) - Architecture principles
|
||||||
|
2. [apps/backend/README.md](apps/backend/README.md) OR [apps/frontend/README.md](apps/frontend/README.md)
|
||||||
|
3. [TODO.md](TODO.md) - Current sprint tasks
|
||||||
|
|
||||||
|
**Reference**:
|
||||||
|
- [INSTALLATION-STEPS.md](INSTALLATION-STEPS.md) - Setup issues
|
||||||
|
- [PRD.md](PRD.md) - Business context
|
||||||
|
|
||||||
|
### For Architects
|
||||||
|
|
||||||
|
**Must Read**:
|
||||||
|
1. [CLAUDE.md](CLAUDE.md) - Complete architecture
|
||||||
|
2. [SPRINT-0-FINAL.md](SPRINT-0-FINAL.md) - Implementation details
|
||||||
|
3. [PRD.md](PRD.md) - Technical requirements
|
||||||
|
|
||||||
|
**Reference**:
|
||||||
|
- [TODO.md](TODO.md) - Technical roadmap
|
||||||
|
- [apps/backend/README.md](apps/backend/README.md) - Backend architecture
|
||||||
|
|
||||||
|
### For Project Managers
|
||||||
|
|
||||||
|
**Must Read**:
|
||||||
|
1. [SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md) - Status overview
|
||||||
|
2. [TODO.md](TODO.md) - Complete roadmap
|
||||||
|
3. [PRD.md](PRD.md) - Requirements & KPIs
|
||||||
|
|
||||||
|
**Reference**:
|
||||||
|
- [SPRINT-0-FINAL.md](SPRINT-0-FINAL.md) - Detailed completion report
|
||||||
|
- [README.md](README.md) - Project overview
|
||||||
|
|
||||||
|
### For DevOps
|
||||||
|
|
||||||
|
**Must Read**:
|
||||||
|
1. [INSTALLATION-STEPS.md](INSTALLATION-STEPS.md) - Setup guide
|
||||||
|
2. [docker-compose.yml](docker-compose.yml) - Infrastructure
|
||||||
|
3. `.github/workflows/` - CI/CD pipelines
|
||||||
|
|
||||||
|
**Reference**:
|
||||||
|
- [apps/backend/.env.example](apps/backend/.env.example) - Environment variables
|
||||||
|
- [SPRINT-0-FINAL.md](SPRINT-0-FINAL.md) - Security checklist
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🗂️ Complete File List
|
||||||
|
|
||||||
|
### Documentation (11 files)
|
||||||
|
|
||||||
|
| File | Purpose | Length |
|
||||||
|
|------|---------|--------|
|
||||||
|
| [README.md](README.md) | Project overview | Medium |
|
||||||
|
| [CLAUDE.md](CLAUDE.md) | Architecture guide | Long (476 lines) |
|
||||||
|
| [PRD.md](PRD.md) | Product requirements | Long (352 lines) |
|
||||||
|
| [TODO.md](TODO.md) | 30-week roadmap | Very Long (1000+ lines) |
|
||||||
|
| [QUICK-START.md](QUICK-START.md) | 5-minute setup | Short |
|
||||||
|
| [INSTALLATION-STEPS.md](INSTALLATION-STEPS.md) | Detailed setup | Medium |
|
||||||
|
| [NEXT-STEPS.md](NEXT-STEPS.md) | What's next | Medium |
|
||||||
|
| [SPRINT-0-FINAL.md](SPRINT-0-FINAL.md) | Sprint 0 report | Long |
|
||||||
|
| [SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md) | Executive summary | Medium |
|
||||||
|
| [SPRINT-0-COMPLETE.md](SPRINT-0-COMPLETE.md) | Technical checklist | Short |
|
||||||
|
| [INDEX.md](INDEX.md) | This file | Medium |
|
||||||
|
|
||||||
|
### App-Specific (2 files)
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| [apps/backend/README.md](apps/backend/README.md) | Backend guide |
|
||||||
|
| [apps/frontend/README.md](apps/frontend/README.md) | Frontend guide |
|
||||||
|
|
||||||
|
### Configuration (10+ files)
|
||||||
|
|
||||||
|
Root, backend, and frontend configuration files (package.json, tsconfig.json, etc.)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📊 Documentation Statistics
|
||||||
|
|
||||||
|
- **Total Documentation Files**: 13
|
||||||
|
- **Total Lines**: ~4,000+
|
||||||
|
- **Coverage**: Setup, Architecture, Development, Testing, Deployment
|
||||||
|
- **Last Updated**: October 7, 2025
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎯 Recommended Reading Path
|
||||||
|
|
||||||
|
### For New Team Members (Day 1)
|
||||||
|
|
||||||
|
**Morning** (2 hours):
|
||||||
|
1. [README.md](README.md) - 10 min
|
||||||
|
2. [QUICK-START.md](QUICK-START.md) - 30 min (includes setup)
|
||||||
|
3. [CLAUDE.md](CLAUDE.md) - 60 min (comprehensive architecture)
|
||||||
|
4. [PRD.md](PRD.md) - 20 min (business context)
|
||||||
|
|
||||||
|
**Afternoon** (2 hours):
|
||||||
|
5. [apps/backend/README.md](apps/backend/README.md) OR [apps/frontend/README.md](apps/frontend/README.md) - 30 min
|
||||||
|
6. [TODO.md](TODO.md) - Current sprint section - 30 min
|
||||||
|
7. [NEXT-STEPS.md](NEXT-STEPS.md) - 30 min
|
||||||
|
8. Start coding! 🚀
|
||||||
|
|
||||||
|
### For Code Review (30 minutes)
|
||||||
|
|
||||||
|
1. [CLAUDE.md](CLAUDE.md) - Hexagonal architecture section
|
||||||
|
2. [apps/backend/README.md](apps/backend/README.md) - DOs and DON'Ts
|
||||||
|
3. [TODO.md](TODO.md) - Acceptance criteria for the feature
|
||||||
|
|
||||||
|
### For Sprint Planning (1 hour)
|
||||||
|
|
||||||
|
1. [TODO.md](TODO.md) - Next sprint tasks
|
||||||
|
2. [PRD.md](PRD.md) - Requirements for the module
|
||||||
|
3. [SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md) - Current status
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔍 Quick Reference
|
||||||
|
|
||||||
|
### Common Questions
|
||||||
|
|
||||||
|
**Q: How do I get started?**
|
||||||
|
A: [QUICK-START.md](QUICK-START.md)
|
||||||
|
|
||||||
|
**Q: What is hexagonal architecture?**
|
||||||
|
A: [CLAUDE.md](CLAUDE.md) - Complete guide with examples
|
||||||
|
|
||||||
|
**Q: What should I build next?**
|
||||||
|
A: [NEXT-STEPS.md](NEXT-STEPS.md) then [TODO.md](TODO.md)
|
||||||
|
|
||||||
|
**Q: How do I run tests?**
|
||||||
|
A: [apps/backend/README.md](apps/backend/README.md) or [apps/frontend/README.md](apps/frontend/README.md)
|
||||||
|
|
||||||
|
**Q: Where are the business requirements?**
|
||||||
|
A: [PRD.md](PRD.md)
|
||||||
|
|
||||||
|
**Q: What's the project status?**
|
||||||
|
A: [SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md)
|
||||||
|
|
||||||
|
**Q: Installation failed, what do I do?**
|
||||||
|
A: [INSTALLATION-STEPS.md](INSTALLATION-STEPS.md) - Troubleshooting section
|
||||||
|
|
||||||
|
**Q: Can I change the database/framework?**
|
||||||
|
A: Yes! That's the point of hexagonal architecture. See [CLAUDE.md](CLAUDE.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📞 Getting Help
|
||||||
|
|
||||||
|
If you can't find what you need:
|
||||||
|
|
||||||
|
1. **Check this index** - Use Ctrl+F to search
|
||||||
|
2. **Read CLAUDE.md** - Covers 90% of architecture questions
|
||||||
|
3. **Check TODO.md** - Has detailed task specifications
|
||||||
|
4. **Open an issue** - If documentation is unclear or missing
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎉 Happy Reading!
|
||||||
|
|
||||||
|
All documentation is up-to-date as of Sprint 0 completion.
|
||||||
|
|
||||||
|
**Quick Links**:
|
||||||
|
- 🚀 [Get Started](QUICK-START.md)
|
||||||
|
- 🏗️ [Architecture](CLAUDE.md)
|
||||||
|
- 📅 [Roadmap](TODO.md)
|
||||||
|
- 📋 [Requirements](PRD.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Xpeditis MVP - Maritime Freight Booking Platform*
|
||||||
|
*Documentation Index - October 7, 2025*
|
||||||
|
|||||||
285
README.md
285
README.md
@ -1,151 +1,206 @@
|
|||||||
# Xpeditis — Maritime Freight Booking Platform
|
# Xpeditis - Maritime Freight Booking Platform
|
||||||
|
|
||||||
Plateforme B2B SaaS permettant aux transitaires de rechercher, comparer et réserver du fret maritime en temps réel.
|
**Xpeditis** is a B2B SaaS platform for freight forwarders to search, compare, and book maritime freight in real-time.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Démarrage rapide
|
## ⭐ **[START HERE](START-HERE.md)** ⭐
|
||||||
|
|
||||||
|
**New to the project?** Read **[START-HERE.md](START-HERE.md)** - Get running in 10 minutes!
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- Node.js >= 20.0.0
|
||||||
|
- npm >= 10.0.0
|
||||||
|
- Docker & Docker Compose
|
||||||
|
- PostgreSQL 15+
|
||||||
|
- Redis 7+
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1. Installer les dépendances
|
# Install dependencies
|
||||||
npm run install:all
|
npm install
|
||||||
|
|
||||||
# 2. Démarrer l'infrastructure (PostgreSQL + Redis + MinIO)
|
# Start infrastructure (PostgreSQL + Redis)
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
|
||||||
# 3. Configurer l'environnement
|
# Setup environment variables
|
||||||
cp apps/backend/.env.example apps/backend/.env
|
cp apps/backend/.env.example apps/backend/.env
|
||||||
cp apps/frontend/.env.example apps/frontend/.env.local
|
cp apps/frontend/.env.example apps/frontend/.env
|
||||||
|
|
||||||
# 4. Exécuter les migrations
|
# Run database migrations
|
||||||
cd apps/backend && npm run migration:run && cd ../..
|
npm run backend:migrate
|
||||||
|
|
||||||
# 5. Démarrer les serveurs
|
# Start backend (development)
|
||||||
npm run backend:dev # http://localhost:4000 · Swagger: /api/docs
|
npm run backend:dev
|
||||||
npm run frontend:dev # http://localhost:3000
|
|
||||||
|
# Start frontend (development)
|
||||||
|
npm run frontend:dev
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
### Access Points
|
||||||
|
|
||||||
## Structure du projet
|
- **Frontend**: http://localhost:3000
|
||||||
|
- **Backend API**: http://localhost:4000
|
||||||
|
- **API Documentation**: http://localhost:4000/api/docs
|
||||||
|
|
||||||
|
## 📁 Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
xpeditis/
|
xpeditis/
|
||||||
├── apps/
|
├── apps/
|
||||||
│ ├── backend/ # NestJS 10 — Architecture hexagonale
|
│ ├── backend/ # NestJS API (Hexagonal Architecture)
|
||||||
│ │ └── src/
|
│ │ └── src/
|
||||||
│ │ ├── domain/ # Logique métier pure (TypeScript)
|
│ │ ├── domain/ # Pure business logic
|
||||||
│ │ ├── application/ # Controllers, DTOs, Guards
|
│ │ ├── application/ # Controllers & DTOs
|
||||||
│ │ └── infrastructure/ # TypeORM, Redis, S3, Email, Stripe
|
│ │ └── infrastructure/ # External adapters
|
||||||
│ └── frontend/ # Next.js 14 App Router
|
│ └── frontend/ # Next.js 14 App Router
|
||||||
│ ├── app/[locale]/ # Routing i18n (fr, en)
|
├── packages/
|
||||||
│ └── src/ # Components, hooks, lib/api
|
│ ├── shared-types/ # Shared TypeScript types
|
||||||
├── docker-compose.yml # PostgreSQL 15 + Redis 7 + MinIO
|
│ └── domain/ # Shared domain logic
|
||||||
└── docs/ # Documentation complète
|
└── infra/ # Infrastructure configs
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
## 🏗️ Architecture
|
||||||
|
|
||||||
## Documentation
|
This project follows **Hexagonal Architecture** (Ports & Adapters) principles:
|
||||||
|
|
||||||
| Sujet | Fichier |
|
- **Domain Layer**: Pure business logic, no external dependencies
|
||||||
|-------|---------|
|
- **Application Layer**: Use cases, controllers, DTOs
|
||||||
| Index complet | [docs/README.md](docs/README.md) |
|
- **Infrastructure Layer**: Database, external APIs, cache, email, storage
|
||||||
| Architecture hexagonale + conventions | [CLAUDE.md](CLAUDE.md) |
|
|
||||||
| Vue d'ensemble système | [docs/architecture/overview.md](docs/architecture/overview.md) |
|
|
||||||
| Schéma BDD (21 tables) | [docs/architecture/database.md](docs/architecture/database.md) |
|
|
||||||
| Démarrage rapide | [docs/getting-started/quick-start.md](docs/getting-started/quick-start.md) |
|
|
||||||
|
|
||||||
---
|
See [CLAUDE.md](CLAUDE.md) for detailed architecture guidelines.
|
||||||
|
|
||||||
## Commandes de développement
|
## 🛠️ Development
|
||||||
|
|
||||||
```bash
|
|
||||||
# Backend
|
|
||||||
npm run backend:dev # Serveur avec hot-reload
|
|
||||||
npm run backend:test # Tests unitaires Jest
|
|
||||||
npm run backend:lint # ESLint
|
|
||||||
npm run backend:build # Build production
|
|
||||||
|
|
||||||
# Frontend
|
|
||||||
npm run frontend:dev # Serveur avec hot-reload
|
|
||||||
npm run frontend:test # Tests unitaires Jest
|
|
||||||
npm run frontend:lint # ESLint
|
|
||||||
cd apps/frontend && npm run test:e2e # Playwright E2E
|
|
||||||
|
|
||||||
# Qualité
|
|
||||||
npm run format # Prettier (tous les fichiers)
|
|
||||||
|
|
||||||
# Base de données
|
|
||||||
cd apps/backend
|
|
||||||
npm run migration:generate -- src/infrastructure/persistence/typeorm/migrations/NomMigration
|
|
||||||
npm run migration:run
|
|
||||||
npm run migration:revert
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Stack technique
|
|
||||||
|
|
||||||
### Backend
|
### Backend
|
||||||
|
|
||||||
| Composant | Technologie |
|
```bash
|
||||||
|-----------|-------------|
|
npm run backend:dev # Start dev server
|
||||||
| Framework | NestJS 10 + TypeScript 5 (strict) |
|
npm run backend:test # Run tests
|
||||||
| Base de données | PostgreSQL 15 + TypeORM |
|
npm run backend:test:watch # Run tests in watch mode
|
||||||
| Cache | Redis 7 (ioredis) |
|
npm run backend:test:cov # Generate coverage report
|
||||||
| Auth | JWT (15min) + Refresh + OAuth2 + API Keys (Argon2) |
|
npm run backend:lint # Lint code
|
||||||
| Temps réel | Socket.IO |
|
npm run backend:build # Build for production
|
||||||
| Email | Nodemailer + MJML |
|
```
|
||||||
| Paiements | Stripe |
|
|
||||||
| Stockage | S3/MinIO |
|
|
||||||
| Logging | nestjs-pino |
|
|
||||||
| Monitoring | Sentry |
|
|
||||||
|
|
||||||
### Frontend
|
### Frontend
|
||||||
|
|
||||||
| Composant | Technologie |
|
```bash
|
||||||
|-----------|-------------|
|
npm run frontend:dev # Start dev server
|
||||||
| Framework | Next.js 14 App Router + TypeScript |
|
npm run frontend:build # Build for production
|
||||||
| Styling | Tailwind CSS + shadcn/ui (Radix UI) |
|
npm run frontend:test # Run tests
|
||||||
| State serveur | TanStack Query v5 |
|
npm run frontend:lint # Lint code
|
||||||
| Tables | TanStack Table v8 + Virtual |
|
```
|
||||||
| Formulaires | react-hook-form + zod |
|
|
||||||
| Temps réel | Socket.IO client |
|
## 📚 Documentation
|
||||||
| i18n | next-intl (fr, en) |
|
|
||||||
| Graphiques | recharts |
|
### Getting Started
|
||||||
|
- **[QUICK-START.md](QUICK-START.md)** ⚡ - Get running in 5 minutes
|
||||||
|
- **[INSTALLATION-STEPS.md](INSTALLATION-STEPS.md)** 📦 - Detailed installation guide
|
||||||
|
- **[NEXT-STEPS.md](NEXT-STEPS.md)** 🚀 - What to do after setup
|
||||||
|
|
||||||
|
### Architecture & Guidelines
|
||||||
|
- **[CLAUDE.md](CLAUDE.md)** 🏗️ - Hexagonal architecture guidelines (complete)
|
||||||
|
- **[apps/backend/README.md](apps/backend/README.md)** - Backend documentation
|
||||||
|
- **[apps/frontend/README.md](apps/frontend/README.md)** - Frontend documentation
|
||||||
|
|
||||||
|
### Project Planning
|
||||||
|
- **[PRD.md](PRD.md)** 📋 - Product Requirements Document
|
||||||
|
- **[TODO.md](TODO.md)** 📅 - 30-week development roadmap
|
||||||
|
- **[SPRINT-0-FINAL.md](SPRINT-0-FINAL.md)** ✅ - Sprint 0 completion report
|
||||||
|
- **[SPRINT-0-SUMMARY.md](SPRINT-0-SUMMARY.md)** 📊 - Executive summary
|
||||||
|
|
||||||
|
### API Documentation
|
||||||
|
- **[API Docs](http://localhost:4000/api/docs)** 📖 - OpenAPI/Swagger (when running)
|
||||||
|
|
||||||
|
## 🧪 Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run all tests
|
||||||
|
npm run test:all
|
||||||
|
|
||||||
|
# Run backend tests
|
||||||
|
npm run backend:test
|
||||||
|
|
||||||
|
# Run frontend tests
|
||||||
|
npm run frontend:test
|
||||||
|
|
||||||
|
# E2E tests (after implementation)
|
||||||
|
npm run test:e2e
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔒 Security
|
||||||
|
|
||||||
|
- All passwords hashed with bcrypt (12 rounds minimum)
|
||||||
|
- JWT tokens (access: 15min, refresh: 7 days)
|
||||||
|
- HTTPS/TLS 1.2+ enforced
|
||||||
|
- OWASP Top 10 protection
|
||||||
|
- Rate limiting on all endpoints
|
||||||
|
- CSRF protection
|
||||||
|
|
||||||
|
## 📊 Tech Stack
|
||||||
|
|
||||||
|
### Backend
|
||||||
|
- **Framework**: NestJS 10+
|
||||||
|
- **Language**: TypeScript 5+
|
||||||
|
- **Database**: PostgreSQL 15+
|
||||||
|
- **Cache**: Redis 7+
|
||||||
|
- **ORM**: TypeORM
|
||||||
|
- **Testing**: Jest, Supertest
|
||||||
|
- **API Docs**: Swagger/OpenAPI
|
||||||
|
|
||||||
|
### Frontend
|
||||||
|
- **Framework**: Next.js 14+ (App Router)
|
||||||
|
- **Language**: TypeScript 5+
|
||||||
|
- **Styling**: Tailwind CSS
|
||||||
|
- **UI Components**: shadcn/ui
|
||||||
|
- **State**: React Query (TanStack Query)
|
||||||
|
- **Forms**: React Hook Form + Zod
|
||||||
|
- **Testing**: Jest, React Testing Library, Playwright
|
||||||
|
|
||||||
|
## 🚢 Carrier Integrations
|
||||||
|
|
||||||
|
MVP supports the following maritime carriers:
|
||||||
|
|
||||||
|
- ✅ Maersk
|
||||||
|
- ✅ MSC
|
||||||
|
- ✅ CMA CGM
|
||||||
|
- ✅ Hapag-Lloyd
|
||||||
|
- ✅ ONE (Ocean Network Express)
|
||||||
|
|
||||||
|
## 📈 Monitoring & Logging
|
||||||
|
|
||||||
|
- **Logging**: Winston / Pino
|
||||||
|
- **Error Tracking**: Sentry
|
||||||
|
- **APM**: Application Performance Monitoring
|
||||||
|
- **Metrics**: Prometheus (planned)
|
||||||
|
|
||||||
|
## 🔧 Environment Variables
|
||||||
|
|
||||||
|
See `.env.example` files in each app for required environment variables.
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
|
||||||
|
1. Create a feature branch
|
||||||
|
2. Make your changes
|
||||||
|
3. Write tests
|
||||||
|
4. Run linting and formatting
|
||||||
|
5. Submit a pull request
|
||||||
|
|
||||||
|
## 📝 License
|
||||||
|
|
||||||
|
Proprietary - All rights reserved
|
||||||
|
|
||||||
|
## 👥 Team
|
||||||
|
|
||||||
|
Built with ❤️ by the Xpeditis team
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Carriers intégrés
|
For detailed implementation guidelines, see [CLAUDE.md](CLAUDE.md).
|
||||||
|
|
||||||
| Carrier | Code | Statut |
|
|
||||||
|---------|------|--------|
|
|
||||||
| Maersk | MAEU | Connecteur API |
|
|
||||||
| MSC | MSCU | Connecteur API |
|
|
||||||
| CMA CGM | CMDU | Connecteur API |
|
|
||||||
| Hapag-Lloyd | HLCU | Connecteur API |
|
|
||||||
| ONE | ONEY | Connecteur API |
|
|
||||||
| SSC Consolidation | — | CSV |
|
|
||||||
| ECU Worldwide | — | CSV + API |
|
|
||||||
| TCC Logistics | — | CSV |
|
|
||||||
| NVO Consolidation | — | CSV |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Fonctionnalités principales
|
|
||||||
|
|
||||||
- **Recherche tarifs** : FCL (carriers API + cache Redis 15min) + LCL CSV
|
|
||||||
- **Réservation standard** : workflow 4 étapes, numéro WCM-YYYY-XXXXXX
|
|
||||||
- **Réservation CSV + Portail Carrier** : magic link, accept/reject
|
|
||||||
- **Dashboard** : KPI, graphiques, table interactive virtuelle
|
|
||||||
- **Auth** : JWT, OAuth2 (Google/Microsoft), API Keys, RBAC (5 rôles)
|
|
||||||
- **Abonnements** : Stripe (FREE/BRONZE/SILVER/GOLD/PLATINIUM)
|
|
||||||
- **Notifications** : WebSocket temps réel + webhooks tiers
|
|
||||||
- **GDPR** : export/suppression des données utilisateur
|
|
||||||
- **Blog** : gestion de contenu bilingue (fr/en)
|
|
||||||
- **Audit** : journal d'audit de toutes les actions
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*Architecture hexagonale — NestJS 10 + Next.js 14 — PostgreSQL 15 + Redis 7*
|
|
||||||
|
|||||||
@ -130,16 +130,16 @@ docker push rg.fr-par.scw.cloud/weworkstudio/xpeditis-frontend:preprod
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Rendre le script exécutable
|
# Rendre le script exécutable
|
||||||
chmod +x docker/deploy-to-portainer.sh
|
chmod +x deploy-to-portainer.sh
|
||||||
|
|
||||||
# Option 1 : Build et push tout
|
# Option 1 : Build et push tout
|
||||||
./docker/deploy-to-portainer.sh all
|
./deploy-to-portainer.sh all
|
||||||
|
|
||||||
# Option 2 : Backend seulement
|
# Option 2 : Backend seulement
|
||||||
./docker/deploy-to-portainer.sh backend
|
./deploy-to-portainer.sh backend
|
||||||
|
|
||||||
# Option 3 : Frontend seulement
|
# Option 3 : Frontend seulement
|
||||||
./docker/deploy-to-portainer.sh frontend
|
./deploy-to-portainer.sh frontend
|
||||||
```
|
```
|
||||||
|
|
||||||
Le script fait automatiquement :
|
Le script fait automatiquement :
|
||||||
@ -271,8 +271,8 @@ docker images | grep rg.fr-par.scw.cloud
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Plus simple et recommandé
|
# Plus simple et recommandé
|
||||||
chmod +x docker/deploy-to-portainer.sh
|
chmod +x deploy-to-portainer.sh
|
||||||
./docker/deploy-to-portainer.sh all
|
./deploy-to-portainer.sh all
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -2,6 +2,7 @@
|
|||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
package-lock.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
|
||||||
@ -24,7 +25,6 @@ e2e
|
|||||||
|
|
||||||
# Environment files
|
# Environment files
|
||||||
.env
|
.env
|
||||||
.env.*
|
|
||||||
.env.local
|
.env.local
|
||||||
.env.development
|
.env.development
|
||||||
.env.test
|
.env.test
|
||||||
|
|||||||
@ -18,19 +18,11 @@ REDIS_PORT=6379
|
|||||||
REDIS_PASSWORD=xpeditis_redis_password
|
REDIS_PASSWORD=xpeditis_redis_password
|
||||||
REDIS_DB=0
|
REDIS_DB=0
|
||||||
|
|
||||||
# JWT (JWT_SECRET must be at least 32 characters)
|
# JWT
|
||||||
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
|
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
|
||||||
JWT_ACCESS_EXPIRATION=15m
|
JWT_ACCESS_EXPIRATION=15m
|
||||||
JWT_REFRESH_EXPIRATION=7d
|
JWT_REFRESH_EXPIRATION=7d
|
||||||
|
|
||||||
# Auth cookies — domain shared between frontend and API in production
|
|
||||||
# (e.g. .xpeditis.com). Leave unset for localhost development.
|
|
||||||
# COOKIE_DOMAIN=.xpeditis.com
|
|
||||||
|
|
||||||
# Secret used to derive carrier document passwords (min 16 chars).
|
|
||||||
# Falls back to JWT_SECRET when unset.
|
|
||||||
# DOCUMENT_PASSWORD_SECRET=your-document-password-secret
|
|
||||||
|
|
||||||
# OAuth2 - Google
|
# OAuth2 - Google
|
||||||
GOOGLE_CLIENT_ID=your-google-client-id
|
GOOGLE_CLIENT_ID=your-google-client-id
|
||||||
GOOGLE_CLIENT_SECRET=your-google-client-secret
|
GOOGLE_CLIENT_SECRET=your-google-client-secret
|
||||||
@ -43,27 +35,44 @@ MICROSOFT_CALLBACK_URL=http://localhost:4000/api/v1/auth/microsoft/callback
|
|||||||
|
|
||||||
# Application URL
|
# Application URL
|
||||||
APP_URL=http://localhost:3000
|
APP_URL=http://localhost:3000
|
||||||
FRONTEND_URL=http://localhost:3000
|
|
||||||
|
|
||||||
# Email (SMTP)
|
# Email (SMTP)
|
||||||
SMTP_HOST=smtp-relay.brevo.com
|
SMTP_HOST=smtp.sendgrid.net
|
||||||
SMTP_PORT=587
|
SMTP_PORT=587
|
||||||
SMTP_USER=
|
|
||||||
SMTP_PASS=
|
|
||||||
SMTP_SECURE=false
|
SMTP_SECURE=false
|
||||||
|
SMTP_USER=apikey
|
||||||
|
SMTP_PASS=your-sendgrid-api-key
|
||||||
SMTP_FROM=noreply@xpeditis.com
|
SMTP_FROM=noreply@xpeditis.com
|
||||||
|
|
||||||
# AWS S3 / Storage (or MinIO for development)
|
# AWS S3 / Storage (or MinIO for development)
|
||||||
AWS_ACCESS_KEY_ID=minioadmin
|
AWS_ACCESS_KEY_ID=your-aws-access-key
|
||||||
AWS_SECRET_ACCESS_KEY=minioadmin
|
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
|
||||||
AWS_REGION=us-east-1
|
AWS_REGION=us-east-1
|
||||||
AWS_S3_ENDPOINT=http://localhost:9000
|
AWS_S3_ENDPOINT=http://localhost:9000
|
||||||
# AWS_S3_ENDPOINT= # Leave empty for AWS S3
|
# AWS_S3_ENDPOINT= # Leave empty for AWS S3
|
||||||
|
|
||||||
|
# Carrier APIs
|
||||||
|
# Maersk
|
||||||
|
MAERSK_API_KEY=your-maersk-api-key
|
||||||
|
MAERSK_API_URL=https://api.maersk.com/v1
|
||||||
|
|
||||||
# Swagger Documentation Access (HTTP Basic Auth — only you can access /api/docs)
|
# MSC
|
||||||
SWAGGER_USERNAME=
|
MSC_API_KEY=your-msc-api-key
|
||||||
SWAGGER_PASSWORD=
|
MSC_API_URL=https://api.msc.com/v1
|
||||||
|
|
||||||
|
# CMA CGM
|
||||||
|
CMACGM_API_URL=https://api.cma-cgm.com/v1
|
||||||
|
CMACGM_CLIENT_ID=your-cmacgm-client-id
|
||||||
|
CMACGM_CLIENT_SECRET=your-cmacgm-client-secret
|
||||||
|
|
||||||
|
# Hapag-Lloyd
|
||||||
|
HAPAG_API_URL=https://api.hapag-lloyd.com/v1
|
||||||
|
HAPAG_API_KEY=your-hapag-api-key
|
||||||
|
|
||||||
|
# ONE (Ocean Network Express)
|
||||||
|
ONE_API_URL=https://api.one-line.com/v1
|
||||||
|
ONE_USERNAME=your-one-username
|
||||||
|
ONE_PASSWORD=your-one-password
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
BCRYPT_ROUNDS=12
|
BCRYPT_ROUNDS=12
|
||||||
@ -75,43 +84,3 @@ RATE_LIMIT_MAX=100
|
|||||||
|
|
||||||
# Monitoring
|
# Monitoring
|
||||||
SENTRY_DSN=your-sentry-dsn
|
SENTRY_DSN=your-sentry-dsn
|
||||||
|
|
||||||
|
|
||||||
# Frontend URL (for redirects)
|
|
||||||
FRONTEND_URL=http://localhost:3000
|
|
||||||
|
|
||||||
# Stripe (Subscriptions & Payments)
|
|
||||||
STRIPE_SECRET_KEY=
|
|
||||||
STRIPE_WEBHOOK_SECRET=
|
|
||||||
|
|
||||||
# Stripe Price IDs (from Stripe Dashboard)
|
|
||||||
STRIPE_SILVER_MONTHLY_PRICE_ID=
|
|
||||||
STRIPE_SILVER_YEARLY_PRICE_ID=
|
|
||||||
STRIPE_GOLD_MONTHLY_PRICE_ID=
|
|
||||||
STRIPE_GOLD_YEARLY_PRICE_ID=
|
|
||||||
STRIPE_PLATINIUM_MONTHLY_PRICE_ID=
|
|
||||||
STRIPE_PLATINIUM_YEARLY_PRICE_ID=
|
|
||||||
|
|
||||||
# Premier administrateur (amorcage) - migration BootstrapAdminFromEnv
|
|
||||||
# En developpement, laissez vide : SeedTestUsers cree deja admin@xpeditis.com.
|
|
||||||
# En production, renseignez une adresse RELEVABLE : le compte est cree sans
|
|
||||||
# mot de passe utilisable et vous definissez le votre via "mot de passe oublie".
|
|
||||||
# BOOTSTRAP_ADMIN_EMAIL=
|
|
||||||
# BOOTSTRAP_ADMIN_FIRST_NAME=Admin
|
|
||||||
# BOOTSTRAP_ADMIN_LAST_NAME=Xpeditis
|
|
||||||
# BOOTSTRAP_ADMIN_ORG_NAME=Xpeditis
|
|
||||||
# BOOTSTRAP_ADMIN_ORG_STREET=A completer
|
|
||||||
# BOOTSTRAP_ADMIN_ORG_CITY=A completer
|
|
||||||
# BOOTSTRAP_ADMIN_ORG_POSTAL_CODE=00000
|
|
||||||
# BOOTSTRAP_ADMIN_ORG_COUNTRY=FR
|
|
||||||
# Facultatif : hash Argon2id, si SMTP n'est pas encore operationnel.
|
|
||||||
# Generer avec : node scripts/setup/generate-admin-hash.js
|
|
||||||
# Jamais un mot de passe en clair - la migration le refuse.
|
|
||||||
# BOOTSTRAP_ADMIN_PASSWORD_HASH=
|
|
||||||
|
|
||||||
# Force la neutralisation des comptes de demonstration hors production.
|
|
||||||
# FORCE_NEUTRALIZE_SEED_ACCOUNTS=true
|
|
||||||
|
|
||||||
# Trade assistant — server only. Empty key enables guided help only.
|
|
||||||
OPENAI_API_KEY=
|
|
||||||
OPENAI_MODEL=gpt-4.1-mini
|
|
||||||
|
|||||||
@ -5,22 +5,20 @@ module.exports = {
|
|||||||
tsconfigRootDir: __dirname,
|
tsconfigRootDir: __dirname,
|
||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
},
|
},
|
||||||
plugins: ['@typescript-eslint/eslint-plugin', 'unused-imports'],
|
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||||
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
|
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
|
||||||
root: true,
|
root: true,
|
||||||
env: {
|
env: {
|
||||||
node: true,
|
node: true,
|
||||||
jest: true,
|
jest: true,
|
||||||
},
|
},
|
||||||
ignorePatterns: ['.eslintrc.js', 'dist/**', 'node_modules/**', 'apps/**'],
|
ignorePatterns: ['.eslintrc.js', 'dist/**', 'node_modules/**'],
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/interface-name-prefix': 'off',
|
'@typescript-eslint/interface-name-prefix': 'off',
|
||||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||||
'@typescript-eslint/no-explicit-any': 'off', // Désactivé pour projet existant en production
|
'@typescript-eslint/no-explicit-any': 'warn',
|
||||||
'@typescript-eslint/no-unused-vars': 'off', // Désactivé car remplacé par unused-imports
|
'@typescript-eslint/no-unused-vars': [
|
||||||
'unused-imports/no-unused-imports': 'error',
|
|
||||||
'unused-imports/no-unused-vars': [
|
|
||||||
'warn',
|
'warn',
|
||||||
{
|
{
|
||||||
argsIgnorePattern: '^_',
|
argsIgnorePattern: '^_',
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
# ===============================================
|
# ===============================================
|
||||||
# Stage 1: Dependencies Installation
|
# Stage 1: Dependencies Installation
|
||||||
# ===============================================
|
# ===============================================
|
||||||
FROM node:22-alpine AS dependencies
|
FROM node:20-alpine AS dependencies
|
||||||
|
|
||||||
# Install build dependencies
|
# Install build dependencies
|
||||||
RUN apk add --no-cache python3 make g++ libc6-compat
|
RUN apk add --no-cache python3 make g++ libc6-compat
|
||||||
@ -14,12 +14,12 @@ COPY package*.json ./
|
|||||||
COPY tsconfig*.json ./
|
COPY tsconfig*.json ./
|
||||||
|
|
||||||
# Install all dependencies (including dev for build)
|
# Install all dependencies (including dev for build)
|
||||||
RUN npm ci --legacy-peer-deps
|
RUN npm install --legacy-peer-deps
|
||||||
|
|
||||||
# ===============================================
|
# ===============================================
|
||||||
# Stage 2: Build Application
|
# Stage 2: Build Application
|
||||||
# ===============================================
|
# ===============================================
|
||||||
FROM node:22-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@ -38,11 +38,7 @@ RUN npm prune --production --legacy-peer-deps
|
|||||||
# ===============================================
|
# ===============================================
|
||||||
# Stage 3: Production Image
|
# Stage 3: Production Image
|
||||||
# ===============================================
|
# ===============================================
|
||||||
FROM node:22-alpine AS production
|
FROM node:20-alpine AS production
|
||||||
|
|
||||||
# Runtime starts with node; remove the base image package manager and its dependencies.
|
|
||||||
# npm remains available in the dependency and build stages.
|
|
||||||
RUN npm uninstall --global npm
|
|
||||||
|
|
||||||
# Install dumb-init for proper signal handling
|
# Install dumb-init for proper signal handling
|
||||||
RUN apk add --no-cache dumb-init
|
RUN apk add --no-cache dumb-init
|
||||||
@ -63,11 +59,7 @@ COPY --from=builder --chown=nestjs:nodejs /app/package*.json ./
|
|||||||
COPY --from=builder --chown=nestjs:nodejs /app/src ./src
|
COPY --from=builder --chown=nestjs:nodejs /app/src ./src
|
||||||
|
|
||||||
# Copy startup script (includes migrations)
|
# Copy startup script (includes migrations)
|
||||||
COPY --chown=nestjs:nodejs scripts/setup/startup.js ./startup.js
|
COPY --chown=nestjs:nodejs startup.js ./startup.js
|
||||||
|
|
||||||
# Recovery command: set an admin password without SMTP
|
|
||||||
# docker exec -it <backend-container> node admin-password.js <email>
|
|
||||||
COPY --chown=nestjs:nodejs scripts/setup/admin-password.js ./admin-password.js
|
|
||||||
|
|
||||||
# Create logs and uploads directories
|
# Create logs and uploads directories
|
||||||
RUN mkdir -p /app/logs && \
|
RUN mkdir -p /app/logs && \
|
||||||
@ -82,7 +74,7 @@ EXPOSE 4000
|
|||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||||
CMD node -e "require('http').get('http://localhost:4000/api/v1/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"
|
CMD node -e "require('http').get('http://localhost:4000/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV NODE_ENV=production \
|
ENV NODE_ENV=production \
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user