# duydev/api.cleancode.typescript.boilerplate architecture

> Architecture diagram of the GitHub repository duydev/api.cleancode.typescript.boilerplate, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duydev/api.cleancode.typescript.boilerplate
- Repository: https://github.com/duydev/api.cleancode.typescript.boilerplate

## Overview

##### Main Architectural Pattern
This project follows the Clean Architecture pattern (also known as Hexagonal Architecture or Ports and Adapters), which is evident from the directory structure. Here's how to represent the core layers:

##### Key Components

a. Core Layers (represent as concentric circles or hexagons):
- Domain Layer (innermost) - Contains business entities
- Application Layer - Contains business logic
- Interface Layer - Contains HTTP adapters
- Infrastructure Layer - Contains technical implementations

b. Important Components to Highlight:
- HTTP Server (Interface Layer)
- Logger System (Infrastructure Layer)
- Dependency Container
- Configuration Management

##### Core Structure (from inside out)
- [Domain Core]
- → Business Entities (user.ts, post.ts, category.ts)

- [Application Layer]
- → Application Services (application.ts)

- [Interface Layer]
- → HTTP Router and Server

- [Infrastructure Layer]
- → Logger
- → Configuration

##### Component Relationships
- How the HTTP server depends on the router
- Logger integration across layers
- Demonstrate how the dependency container manages instances
- Configuration flow

##### Specific Elements

a. Domain Layer:
- User Entity
- Post Entity
- Category Entity

b. Application Layer:
- Application Service
- Use Cases (implied by structure)

c. Interface Layer:
- HTTP Router
- Server Configuration

d. Infrastructure Layer:
- Logger Registry
- Debugger
- Environment Configuration

##### Cross-Cutting Concerns
- How the logger spans across all layers
- How configuration affects different components
- Demonstrate dependency injection flow

##### Technical Details to Note
- TypeScript implementation
- Environment-based configuration
- Dependency injection container
- Clean Architecture principles

Remember to:
- Use consistent styling
- Notes for important architectural decisions
- Clear boundaries between layers
- Direction of dependencies (always pointing inward)

This will provide a clear visualization of how the boilerplate can be extended while maintaining clean architecture principles and how new features can be added without violating the dependency rule.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Domain Layer]:::domain
        L2[Application Layer]:::application
        L3[Interface Layer]:::interface
        L4[Infrastructure Layer]:::infra
        L5[System Components]:::system
    end

    subgraph Domain
        User[User Entity]:::domain
        Post[Post Entity]:::domain
        Category[Category Entity]:::domain
    end

    subgraph Application
        AppService[Application Service]:::application
        UseCases[Use Cases]:::application
    end

    subgraph Interface
        HTTPServer[HTTP Server]:::interface
        Router[Router]:::interface
    end

    subgraph Infrastructure
        Logger[Logger Registry]:::infra
        Debugger[Debugger]:::infra
        Config[Configuration]:::infra
    end

    subgraph System
        Container[Dependency Container]:::system
        Entry[Application Entry]:::system
        ModuleLoader[Module Loader]:::system
        Types[Type Definitions]:::system
        Interfaces[Interfaces]:::system
        Constants[Constants]:::system
    end

    Entry --> Container
    Container --> AppService
    Container --> Logger
    Container --> Config
    
    HTTPServer --> Router
    Router --> AppService
    
    AppService --> User
    AppService --> Post
    AppService --> Category
    
    Logger --> Debugger
    Config --> Logger
    
    ModuleLoader --> Container
    Types --> Container
    Interfaces --> Container
    Constants --> Container

    %% Click events for component mapping
    click User "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/domain/user.ts"
    click Post "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/domain/post.ts"
    click Category "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/domain/category.ts"
    click AppService "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/app/application.ts"
    click HTTPServer "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/interface/http/server.ts"
    click Router "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/interface/http/router.ts"
    click Logger "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/infra/logger/logger-registry.ts"
    click Debugger "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/infra/logger/debugger.ts"
    click Config "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/config/index.ts"
    click Container "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/container.ts"
    click Entry "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/index.ts"
    click ModuleLoader "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/loader.ts"
    click Types "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/types.ts"
    click Interfaces "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/interfaces.ts"
    click Constants "https://github.com/duydev/api.cleancode.typescript.boilerplate/blob/develop/src/constants.ts"

    classDef domain fill:#2196F3,stroke:#1565C0,color:white
    classDef application fill:#4CAF50,stroke:#2E7D32,color:white
    classDef interface fill:#FF9800,stroke:#EF6C00,color:white
    classDef infra fill:#9E9E9E,stroke:#616161,color:white
    classDef system fill:#673AB7,stroke:#4527A0,color:white
```
