# hide-adachi/backend_sample architecture

> Architecture diagram of the GitHub repository hide-adachi/backend_sample, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hide-adachi/backend_sample
- Repository: https://github.com/hide-adachi/backend_sample

## Overview

##### Project type and purpose
- This is a TypeScript-based Node.js backend sample application exposing a REST API under `/api/v1/samples`.
- It follows a Domain-Driven Design (DDD) / layered architecture (Presentation, Application, Domain, Infrastructure).
- It is designed to run inside a VS Code devcontainer or Docker, with tests driven by Jest.

##### File structure
- Top-level:
- `.devcontainer` / `docker` / `compose.yaml` → local development & containerization
- `src/` → core code, subdivided into:
– `Presentation` (HTTP layer, controllers, server)
– `Application` (service orchestration, use-cases)
– `Domain` (business entities, rules)
– `Infrastructure` (concrete repository implementing persistence)
- `test/` → Medium-level integration tests targeting the controller layer
- Config files: `jest.config.js`, `nodemon.json`, `tsconfig.json`, `package.json`, `dprint.json`

##### README for additional insights
- Confirms devcontainer workflow (VS Code)
- Mentions running the API at `http://localhost:3000/api/v1/samples`
- Intentionally omits DB, CI/CD, auth, caching for you to experiment

##### Detail is key
- Interfaces vs. implementations (e.g. `ISampleRepository` interface in Domain vs. `SampleRepository` in Infrastructure)
- Test harness as a separate flow that targets the Presentation layer
- Devcontainer/Docker Compose as the outermost environment boundary

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Dev & Environment"
        DC["VSCode Devcontainer"]:::dev
        DC2["Docker Compose"]:::dev
        DC3["Dockerfile (local)"]:::dev
    end

    subgraph "Sample Service Container"
        subgraph "Presentation Layer"
            Entry["Entry Point (src/index.ts)"]:::api
            Server["HTTP Listener (src/Presentation/Server.ts)"]:::api
            Router["Main Router (src/Presentation/Controller/api.ts)"]:::api
            Controller["Samples Controller v1 (src/Presentation/Controller/v1/samples.ts)"]:::api
        end

        subgraph "Application Layer"
            Service["Sample Service (src/Application/SampleService.ts)"]:::application
        end

        subgraph "Domain Layer"
            Entity["Sample Entity (src/Domain/Sample.ts)"]:::domain
        end

        subgraph "Infrastructure Layer"
            Repo["Sample Repository (src/Infrastructure/Repository/SampleRepository.ts)"]:::infrastructure
            DB["Data Store"]:::infra
        end
    end

    Client["External Client"]:::client
    Test["Test Harness (Jest) (test/Medium/Infrastructure/Controller/api/v1/Samples.test.ts)"]:::test

    Client -->|HTTP Request| Entry
    Entry --> Server
    Server --> Router
    Router --> Controller
    Controller -->|invokes| Service
    Service -->|applies rules| Entity
    Service -->|calls repository| Repo
    Repo -->|persists/fetches| DB

    Test -->|HTTP Test| Controller

    click Entry "https://github.com/hide-adachi/backend_sample/blob/main/src/index.ts"
    click Server "https://github.com/hide-adachi/backend_sample/blob/main/src/Presentation/Server.ts"
    click Router "https://github.com/hide-adachi/backend_sample/blob/main/src/Presentation/Controller/api.ts"
    click Controller "https://github.com/hide-adachi/backend_sample/blob/main/src/Presentation/Controller/v1/samples.ts"
    click Service "https://github.com/hide-adachi/backend_sample/blob/main/src/Application/SampleService.ts"
    click Entity "https://github.com/hide-adachi/backend_sample/blob/main/src/Domain/Sample.ts"
    click Repo "https://github.com/hide-adachi/backend_sample/blob/main/src/Infrastructure/Repository/SampleRepository.ts"
    click DC "https://github.com/hide-adachi/backend_sample/blob/main/.devcontainer/devcontainer.json"
    click DC2 "https://github.com/hide-adachi/backend_sample/blob/main/compose.yaml"
    click DC3 "https://github.com/hide-adachi/backend_sample/blob/main/docker/Dockerfile.local"
    click Test "https://github.com/hide-adachi/backend_sample/blob/main/test/Medium/Infrastructure/Controller/api/v1/Samples.test.ts"

    classDef dev fill:#FDE68A,stroke:#92400E,color:#92400E;
    classDef client fill:#A5B4FC,stroke:#4338CA,color:#4338CA;
    classDef api fill:#BFDBFE,stroke:#1E40AF,color:#1E40AF;
    classDef application fill:#D1FAE5,stroke:#065F46,color:#065F46;
    classDef domain fill:#FECACA,stroke:#991B1B,color:#991B1B;
    classDef infrastructure fill:#FDBA74,stroke:#C2410C,color:#C2410C;
    classDef infra fill:#E0E7FF,stroke:#4338CA,color:#4338CA;
    classDef test fill:#FEF08A,stroke:#854D0E,color:#854D0E;
```
