# cour-de-cassation/label architecture

> Architecture diagram of the GitHub repository cour-de-cassation/label, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cour-de-cassation/label
- Repository: https://github.com/cour-de-cassation/label

## Overview

##### Project Identification
- It is designed as a full‑stack application that separates “generic” (reusable components) from “specific” (tailored to the court’s needs, such as connectors and machine learning/NLP components).

##### High-Level Architectural Components
- Frontend Client: Found under packages/generic/client. This layer includes all the user-facing pages, components, and services (such as annotation editing interfaces, admin panels, and document viewers). Tools include TypeScript, React (with .tsx files), and a theming/asset management structure.
- Backend Server: Found mainly under packages/generic/backend and packages/generic/core. This side implements core business logic (e.g., document service, assignation, pre-assignment, user management, caching, and problem reports). It is modular in organization with clear modules for each domain (document, treatment, assignation, etc.), which may be built on Node.js/Express and use additional libraries for handling API requests.
- Domain-Specific Extensions: The packages/courDeCassation directory contains specific annotations and connectors (for instance, for interfacing with the SDER API or NLP annotators) that adapt the core functionality to the requirements of the French Supreme Court and related databases.
- Infrastructure & Deployment: There are multiple Dockerfiles (for backend, client, and local usage), Ansible playbooks and inventories for different environments (dev, preprod, prod), and CI/CD configuration files (from GitHub and GitLab). This indicates the deployment and container orchestration aspects.
- External Services & Data Flow: Likely external APIs for NLP (pre-annotation engine) and database connections (possibly using MongoDB given “mongo” utilities). Tools for logging and caching are also present.
- Scripting and Database Seeding: Scripts in the “scripts” and “seeds” directories manage test databases, local development scripts, and other operational tasks.

##### Relationships and Interactions
- Frontend communicates with the backend via API endpoints. This data flow is bidirectional:
- Users interact with the web interface, triggering API calls (handled in packages/generic/client/src/api).
- The backend processes these requests through various modules (document service, assignation, user management) and returns responses.
- The backend modules further interact with internal libraries (from packages/generic/core) which implement business logic, data transformation, NLP interfacing, anonymization, and other critical utilities.
- External systems (like the NLP service, SDER connectors, or even a database in production) interconnect with the backend.
- Deployment components (via Dockerfiles/ansible) package and orchestrate these components for various environments.

##### Key Architectural Patterns and Principles
- Modular Architecture: The project is separated into “generic” and “specific” packages, with a domain-specific layer (courDeCassation) and core modules (generic/core). There is a clear separation of concerns between client, backend, and shared libraries.
- Containerization & Environment Management: Container images (Dockerfiles) and Ansible roles are used to standardize deployment and configuration across different environments.
- Clean API Design: The backend appears to use Express-like controllers and a layered approach where controllers delegate business logic to dedicated services and repositories.
- Extensibility: LABEL is designed for reuse. The design emphasizes points where developers can hook in new annotation types, connectors, or interfaces without changing the core.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    User("User"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        client["Client (React/TypeScript)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        backend["Backend Server (Node.js/Express)"]:::backend
        core["Shared Core/Utilities"]:::core
        backend -->|"uses"| core
    end

    %% Domain‑Specific Extensions
    subgraph "Domain‑Specific Extensions"
        domain["Cour de cassation Adapters"]:::domain
    end

    %% External Services
    subgraph "External Services"
        extNLP["External NLP Service"]:::external
        db["Database (MongoDB)"]:::external
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        dockerBackend["Docker - Backend"]:::infra
        dockerClient["Docker - Client"]:::infra
        dockerLocal["Docker - Local"]:::infra
        ansible["Ansible & CI/CD"]:::infra
    end

    %% Scripting & Database Seeding
    subgraph "Scripting & Seeding"
        scripting["Scripting"]:::scripting
        seeds["Database Seeding"]:::scripting
    end

    %% Data Flow & Relationships
    User -->|"initiates"| client
    client -->|"API calls"| backend
    backend -->|"integrates"| domain
    backend -->|"calls"| extNLP
    backend -->|"queries"| db
    scripting -->|"populates"| db

    %% Deployment Connections (orchestration)
    dockerBackend --- backend
    dockerClient --- client
    dockerLocal --- client
    ansible --- dockerBackend
    ansible --- dockerClient
    ansible --- dockerLocal

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef core fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef domain fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef infra fill:#e2e3e5,stroke:#343a40,stroke-width:2px;
    classDef scripting fill:#fefefe,stroke:#ced4da,stroke-width:2px;
    classDef external fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;

    %% Click Events
    click client "https://github.com/cour-de-cassation/label/tree/dev/packages/generic/client"
    click backend "https://github.com/cour-de-cassation/label/tree/dev/packages/generic/backend"
    click core "https://github.com/cour-de-cassation/label/tree/dev/packages/generic/core"
    click domain "https://github.com/cour-de-cassation/label/tree/dev/packages/courDeCassation"
    click dockerBackend "https://github.com/cour-de-cassation/label/blob/dev/Dockerfile.label-backend"
    click dockerClient "https://github.com/cour-de-cassation/label/blob/dev/Dockerfile.label-client"
    click dockerLocal "https://github.com/cour-de-cassation/label/blob/dev/Dockerfile.label.local"
    click ansible "https://github.com/cour-de-cassation/label/tree/dev/ansible/"
    click scripting "https://github.com/cour-de-cassation/label/tree/dev/scripts/"
    click seeds "https://github.com/cour-de-cassation/label/tree/dev/seeds/"
```
