# borjapazr/express-typescript-skeleton architecture

> Architecture diagram of the GitHub repository borjapazr/express-typescript-skeleton, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/borjapazr/express-typescript-skeleton
- Repository: https://github.com/borjapazr/express-typescript-skeleton

## Overview

##### Main Components

a. Presentation Layer (REST API):
- Controllers (Authentication, Health, Users)
- Middleware (Authentication, Error Handling, Logging)
- API Documentation (Swagger/OpenAPI)

b. Application Layer:
- Use Cases (Sessions, Users, Health)
- Request/Response DTOs

c. Domain Layer:
- Entities (User, Session)
- Value Objects
- Domain Services
- Repository Interfaces

d. Infrastructure Layer:
- Database Implementations (Prisma - PostgreSQL)
- Caching (Redis)
- Authentication (JWT)
- Logging (Pino)

e. External Services:
- PostgreSQL Database
- Redis Cache

**[Client Applications]**
- ↓
**[Presentation Layer (REST API)]**
- ↓
**[Application Layer (Use Cases)]**
- ↓
**[Domain Layer (Business Logic)]**
- ↓
**[Infrastructure Layer]**
- ↓
**[External Services]**

##### Specific Implementation Details

Key architectural elements:

a. REST API Layer:
- Main endpoints (/api/health, /api/users, /api/auth)
- Middleware chain
- OpenAPI/Swagger documentation

b. Authentication Flow:
- JWT token generation and validation
- Session management
- User authentication process

c. Data Flow:
- Repository pattern implementation
- Prisma ORM integration
- Redis caching strategy

d. Cross-Cutting Concerns:
- Error handling
- Logging
- Configuration management

##### Technical Stack Callouts

Technologies:
- Node.js & Express
- TypeScript
- Prisma ORM
- Redis
- PostgreSQL
- JWT
- Pino Logger

##### Deployment View

A separate section showing:
- Docker containers
- Database connections
- Cache connections
- API endpoints

- Clean Architecture principles
- Dependency flow (always inward)
- Clear separation of concerns
- Infrastructure independence
- Domain-driven design elements

Remember to emphasize the modular nature of the application and how the different layers interact while maintaining loose coupling through dependency injection and interfaces.

This system design should help developers understand both the high-level architecture and the specific implementation details of this Express TypeScript application.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        C[Client Applications]
    end

    subgraph PresentationLayer
        API[REST API Endpoints]:::api
        click API "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/presentation/rest"
        
        subgraph Controllers
            AuthC[Authentication Controller]:::controller
            click AuthC "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/presentation/rest/controllers/authentication/authentication.controller.ts"
            HealthC[Health Controller]:::controller
            click HealthC "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/presentation/rest/controllers/health/health.controller.ts"
            UserC[User Controller]:::controller
            click UserC "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/presentation/rest/controllers/users/user.controller.ts"
        end

        subgraph Middleware
            AuthM[Auth Middleware]:::middleware
            click AuthM "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/presentation/rest/middlewares/authentication.middleware.ts"
            ErrorM[Error Handler]:::middleware
            click ErrorM "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/presentation/rest/middlewares/error-handler.middleware.ts"
            LogM[Logger Middleware]:::middleware
            click LogM "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/presentation/rest/middlewares/logger.middleware.ts"
        end
    end

    subgraph ApplicationLayer
        subgraph UseCases
            HealthUC[Health Use Cases]:::usecase
            click HealthUC "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/application/health"
            SessionUC[Session Use Cases]:::usecase
            click SessionUC "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/application/sessions"
            UserUC[User Use Cases]:::usecase
            click UserUC "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/application/users"
        end
    end

    subgraph DomainLayer
        subgraph Entities
            UserE[User Entity]:::entity
            click UserE "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/users/user.ts"
            SessionE[Session Entity]:::entity
            click SessionE "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/sessions/session.ts"
            HealthE[Health Status Entity]:::entity
            click HealthE "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/health/health-status.ts"
        end

        subgraph DomainServices
            HasherS[Hasher Service]:::service
            click HasherS "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/shared/services/hasher.domain-service.ts"
            LoggerS[Logger Service]:::service
            click LoggerS "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/shared/services/logger.domain-service.ts"
            TokenS[Token Provider]:::service
            click TokenS "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/sessions/tokens/token-provider.domain-service.ts"
        end

        subgraph Repositories
            UserR[User Repository]:::repository
            click UserR "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/users/user.repository.ts"
            SessionR[Session Repository]:::repository
            click SessionR "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/domain/sessions/session.repository.ts"
        end
    end

    subgraph InfrastructureLayer
        subgraph Persistence
            PrismaDB[Prisma ORM]:::infrastructure
            click PrismaDB "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/infrastructure/shared/persistence/prisma"
            RedisCache[Redis Cache]:::infrastructure
            click RedisCache "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/infrastructure/shared/persistence/redis"
        end

        subgraph Infrastructure
            Auth[JWT Auth]:::infrastructure
            click Auth "https://github.com/borjapazr/express-typescript-skeleton/tree/main/src/infrastructure/shared/authentication"
            Logger[Pino Logger]:::infrastructure
            click Logger "https://github.com/borjapazr/express-typescript-skeleton/blob/main/src/infrastructure/shared/logger/pino-logger.ts"
        end
    end

    subgraph ExternalServices
        PostgreSQL[(PostgreSQL)]:::external
        Redis[(Redis)]:::external
    end

    %% Relationships
    C --> API
    API --> AuthC & HealthC & UserC
    AuthC & HealthC & UserC --> AuthM & ErrorM & LogM
    AuthC --> SessionUC
    HealthC --> HealthUC
    UserC --> UserUC
    SessionUC & UserUC --> UserR & SessionR
    HealthUC --> HealthE
    UserR --> UserE
    SessionR --> SessionE
    UserR & SessionR --> PrismaDB
    PrismaDB --> PostgreSQL
    RedisCache --> Redis
    Auth --> TokenS
    Logger --> LoggerS

    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef controller fill:#42A5F5,stroke:#1E88E5,color:white
    classDef middleware fill:#64B5F6,stroke:#42A5F5,color:white
    classDef usecase fill:#81C784,stroke:#66BB6A,color:white
    classDef entity fill:#FFD54F,stroke:#FFC107,color:black
    classDef service fill:#FFB74D,stroke:#FFA726,color:black
    classDef repository fill:#FFA726,stroke:#FB8C00,color:black
    classDef infrastructure fill:#9575CD,stroke:#7E57C2,color:white
    classDef external fill:#90A4AE,stroke:#78909C,color:white
```
