# trap-jp/trao-judge-backend architecture

> Architecture diagram of the GitHub repository trap-jp/trao-judge-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/trap-jp/trao-judge-backend
- Repository: https://github.com/trap-jp/trao-judge-backend

## Overview

##### Project type and purpose
- This is the “traO-Judge-backend”, a Rust-based backend service for an online judge system (traP Online Judge). It exposes HTTP endpoints for authentication, user management, problem and submission handling, and integrates with a relational database plus external services (Mail, Object Storage).

##### File structure
- Top-level:
- Cargo.toml: Rust project manifest
- docker-compose.yaml, .env.dev: local orchestration
- Taskfile.yaml: build/test tasks
- migrations/: SQL scripts for schema
- docs/architecture.md: additional architecture notes
- src/: clearly follows a layered, DDD-inspired design:
- di.rs: Dependency injection / wiring
- domain/: core entities, repository interfaces, external-service interfaces
- infrastructure/: concrete implementations of repository + external interfaces
- usecase/: application/service layer that orchestrates domain logic
- presentation/: HTTP handlers and transport-level models
- bin/main.rs: application entry point
- tests/: integration tests covering HTTP and database interactions

##### README
- Minimal: project title and Japanese description (“traP Online Judge バックエンド”).
- Refer to docs/architecture.md for more detailed component descriptions.

##### Elements
– Internal layers (Presentation, Usecase, Domain)
– Adapters (Infrastructure)
– External systems (Database, Mail, Object Storage)
- Annotations for folder or module names (e.g., src/domain, src/infrastructure).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers and components
    Client["Client / Frontend"]:::external
    subgraph "Presentation Layer" 
        Presentation["HTTP Handlers\n(src/presentation)"]:::presentation
    end
    subgraph "Usecase Layer"
        Usecase["Service Orchestrators\n(src/usecase)"]:::usecase
    end
    subgraph "Domain Layer"
        Domain["Domain Entities & Traits\n(src/domain)"]:::domain
    end
    subgraph "Infrastructure Layer"
        Infra["Adapters\n(src/infrastructure)"]:::infra
    end
    Database[(PostgreSQL)]:::external
    MailService[(Mail Service)]:::external
    ObjectStorage[(Object Storage)]:::external
    DI["Dependency Injection\n(src/di.rs)"]:::misc
    Main["Application Entry\n(src/bin/main.rs)"]:::misc
    Migrations[(DB Migrations)]:::misc
    Docs["Architecture Docs\n(docs/architecture.md)"]:::misc
    DockerCompose["Docker Compose\n(docker-compose.yaml)"]:::misc
    TaskRunner["Task Runner\n(Taskfile.yaml)"]:::misc
    Tests["Integration Tests\n(tests/)"]:::misc

    %% Flow
    Client -->|"HTTP Request"| Presentation
    Presentation -->|"call service"| Usecase
    Usecase -->|"invoke trait"| Domain
    Domain -->|"bound to impl"| Infra
    Infra -->|"SQL Query"| Database
    Infra -->|"SMTP/API"| MailService
    Infra -->|"S3 API"| ObjectStorage
    Infra -->|"returns data"| Usecase
    Usecase -->|"response"| Presentation
    Presentation -->|"HTTP Response"| Client

    %% Orchestration
    Main -->|starts| DI
    DI -->|wires| Presentation
    DI -->|wires| Usecase
    DI -->|wires| Domain
    DI -->|wires| Infra

    DockerCompose -->|orchestrates| Presentation
    DockerCompose -->|orchestrates| Database
    TaskRunner -->|runs tasks| Main
    Migrations -->|schema| Database
    Docs -->|reference| DI
    Tests -->|test| Presentation
    Tests -->|test| Database

    %% Click Events
    click Presentation "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/presentation.rs"
    click Usecase "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/usecase.rs"
    click Domain "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/domain.rs"
    click Infra "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/infrastructure.rs"
    click DI "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/di.rs"
    click Main "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/bin/main.rs"
    click Migrations "https://github.com/trap-jp/trao-judge-backend/blob/develop/migrations/0_create-table.sql"
    click Docs "https://github.com/trap-jp/trao-judge-backend/blob/develop/docs/architecture.md"
    click DockerCompose "https://github.com/trap-jp/trao-judge-backend/blob/develop/docker-compose.yaml"
    click TaskRunner "https://github.com/trap-jp/trao-judge-backend/blob/develop/Taskfile.yaml"
    click Tests "https://github.com/trap-jp/trao-judge-backend/blob/develop/tests/test.rs"
    click MailService "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/infrastructure/external/mail.rs"
    click ObjectStorage "https://github.com/trap-jp/trao-judge-backend/blob/develop/src/infrastructure/external/object_strage.rs"

    %% Styles
    classDef presentation fill:#CCE5FF,stroke:#3399FF,color:#003366;
    classDef usecase fill:#D5E8D4,stroke:#82B366,color:#274E13;
    classDef domain fill:#FFF2CC,stroke:#D6B656,color:#665C00;
    classDef infra fill:#F8CECC,stroke:#B85450,color:#660000;
    classDef external fill:#E1D5E7,stroke:#9673A6,color:#3F3151,stroke-dasharray: 5 5;
    classDef misc fill:#F2F2F2,stroke:#999999,color:#333333,stroke-dasharray: 2 2;
```
