# betagouv/signalement-api architecture

> Architecture diagram of the GitHub repository betagouv/signalement-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/betagouv/signalement-api
- Repository: https://github.com/betagouv/signalement-api

## Overview

##### Main Components

a. Client Layer:
- Consumer Web Interface
- Professional Dashboard
- DGCCRF (Administrative) Dashboard
- Mobile App Interface

b. API Layer (Core Application):
- Authentication Service (with Cookie-based auth)
- Controllers Layer (RESTful endpoints)
- Orchestrators Layer (Business logic)
- Repository Layer (Data access)
- Task Scheduler (Background jobs)

c. External Services:
- Email Service
- S3 Storage
- Antivirus Service
- Company Data API (ETABLISSEMENT_API)
- GS1 Barcode Service
- New Relic (Logging)

d. Data Storage:
- PostgreSQL Database
- File Storage (S3)

##### Key Relationships to Highlight

a. Authentication Flow:
- Cookie-based authentication flow
- Different auth paths (API Key, Cookie)
- Demonstrate user role separation (Consumer, Professional, Admin)

b. Data Flow:
- Report submission path
- File upload and virus scanning process
- Email notification system
- Company data synchronization
- Background task execution

##### Specific Implementation Details

- Blue rectangles for core services
- Green diamonds for external APIs
- Red hexagons for security components
- Purple rectangles for scheduled tasks

##### Important Architectural Patterns to Highlight

- MVC pattern in the core application
- Repository pattern for data access
- Actor system for async operations
- Task scheduling system
- Event-driven architecture for notifications

##### The background task architecture

This system design should reflect the application's focus on security, scalability, and maintainability, as evidenced by the extensive configuration options and modular architecture shown in the codebase.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#e1f5fe,stroke:#01579b
    classDef auth fill:#ffcdd2,stroke:#b71c1c
    classDef api fill:#c8e6c9,stroke:#1b5e20
    classDef service fill:#e8eaf6,stroke:#1a237e
    classDef database fill:#fff3e0,stroke:#e65100
    classDef external fill:#f3e5f5,stroke:#4a148c
    classDef task fill:#fff9c4,stroke:#f57f17

    %% Client Layer
    subgraph Clients
        CW[Consumer Web Interface]:::client
        PD[Professional Dashboard]:::client
        AD[DGCCRF Dashboard]:::client
        MA[Mobile App Interface]:::client
    end

    %% Authentication Layer
    subgraph Authentication
        CA[Cookie Authenticator]:::auth
        AK[API Key Authenticator]:::auth
    end
    click CA "https://github.com/betagouv/signalement-api/blob/master/app/authentication/CookieAuthenticator.scala"
    click AK "https://github.com/betagouv/signalement-api/blob/master/app/authentication/APIKeyAuthenticator.scala"

    %% Controllers Layer
    subgraph Controllers
        AC[Auth Controller]:::api
        RC[Report Controller]:::api
        CC[Company Controller]:::api
    end
    click AC "https://github.com/betagouv/signalement-api/blob/master/app/controllers/AuthController.scala"
    click RC "https://github.com/betagouv/signalement-api/blob/master/app/controllers/ReportController.scala"
    click CC "https://github.com/betagouv/signalement-api/blob/master/app/controllers/CompanyController.scala"

    %% Orchestrators Layer
    subgraph Orchestrators
        AO[Auth Orchestrator]:::service
        RO[Report Orchestrator]:::service
        CO[Company Orchestrator]:::service
    end
    click AO "https://github.com/betagouv/signalement-api/blob/master/app/orchestrators/AuthOrchestrator.scala"
    click RO "https://github.com/betagouv/signalement-api/blob/master/app/orchestrators/ReportOrchestrator.scala"
    click CO "https://github.com/betagouv/signalement-api/blob/master/app/orchestrators/CompanyOrchestrator.scala"

    %% Repositories Layer
    subgraph Repositories
        PP[Postgres Profile]:::service
        RR[Report Repository]:::service
        CR[Company Repository]:::service
    end
    click PP "https://github.com/betagouv/signalement-api/blob/master/app/repositories/PostgresProfile.scala"
    click RR "https://github.com/betagouv/signalement-api/blob/master/app/repositories/report/ReportRepository.scala"
    click CR "https://github.com/betagouv/signalement-api/blob/master/app/repositories/company/CompanyRepository.scala"

    %% Services Layer
    subgraph Services
        EM[Email Service]:::service
        S3[S3 Storage]:::service
        AV[Antivirus Service]:::service
        GS[GS1 Barcode Service]:::service
    end
    click EM "https://github.com/betagouv/signalement-api/blob/master/app/services/emails/MailService.scala"
    click S3 "https://github.com/betagouv/signalement-api/blob/master/app/services/S3Service.scala"
    click AV "https://github.com/betagouv/signalement-api/blob/master/app/services/antivirus/AntivirusService.scala"
    click GS "https://github.com/betagouv/signalement-api/blob/master/app/services/GS1Service.scala"

    %% Task Scheduler
    subgraph Tasks
        ST[Scheduled Task]:::task
        RN[Report Notification Task]:::task
    end
    click ST "https://github.com/betagouv/signalement-api/blob/master/app/tasks/ScheduledTask.scala"
    click RN "https://github.com/betagouv/signalement-api/blob/master/app/tasks/report/ReportNotificationTask.scala"

    %% Data Storage
    subgraph Storage
        DB[(PostgreSQL)]:::database
        S3S[(S3 Files)]:::database
    end
    click DB "https://github.com/betagouv/signalement-api/blob/master/conf/common/database.conf"

    %% External Services
    subgraph External
        EA[ETABLISSEMENT API]:::external
        NR[New Relic]:::external
    end

    %% Relationships
    Clients --> Authentication
    Authentication --> Controllers
    Controllers --> Orchestrators
    Orchestrators --> Repositories
    Repositories --> Storage
    Orchestrators --> Services
    Services --> External
    Tasks --> Orchestrators
    Tasks --> Services

    %% Legend
    subgraph Legend
        L1[Client Components]:::client
        L2[Authentication Components]:::auth
        L3[API Components]:::api
        L4[Service Components]:::service
        L5[Database Components]:::database
        L6[External Services]:::external
        L7[Scheduled Tasks]:::task
    end
```
