# syedgaian/rest-api-ts-express-prisma architecture

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

- Interactive diagram: https://gitdiagram.com/syedgaian/rest-api-ts-express-prisma
- Repository: https://github.com/syedgaian/rest-api-ts-express-prisma

## Overview

##### High-Level Architecture Components

a) API Layer (Presentation)
- Express.js server and routes
- Middleware components (auth, error handling)

b) Feature Modules (Core Business Logic)
- In the middle layer
- Main features:
- Auth
- Todos
- Assistants
- Assistant Config
- Shared

c) Infrastructure Layer
- At the bottom
- Prisma database connection
- External services integration

##### Detailed Component Breakdown

a) Clean Architecture Layers (from outside to inside):
**Presentation → Infrastructure → Domain**
- ↳ UseCases
- ↳ Entities
- ↳ Repositories (interfaces)
- ↳ DTOs

##### Specific Implementation Details

Key architectural elements:
**┌─────────────────────────────────────┐**
- Express App             │
- ┤
- ┌─────────┐  ┌────────┐  ┌────────┐ │
- Auth   │  │ Todos  │  │Assistant│ │
- ┘  └────────┘  └────────┘ │
- ┤
- Prisma ORM / Database        │
- ┘

##### Technical Details

Highlight:
- TypeScript usage
- Jest testing integration
- ESLint/Prettier configuration
- Environment variable handling
- Prisma schema structure

- Showing the Clean Architecture implementation
- Depicting the actual file structure
- Illustrating runtime behavior
- Representing data flow between components

Remember to:
- Clear boundaries between layers
- Dependency direction (always pointing inward)
- Separation of concerns

- How the application enforces Clean Architecture
- Where to add new features
- How components interact
- The data flow through the system
- Testing boundaries and responsibilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph API_Layer["API Layer - Handles HTTP requests and responses"]
        Server["Express Server - Main application entry point"]:::server
        Routes["Routes - API endpoint definitions"]:::routes
        AuthMiddleware["Auth Middleware - Handles authentication"]:::middleware
        ErrorMiddleware["Error Middleware - Global error handling"]:::middleware
    end

    subgraph Feature_Modules["Feature Modules - Core business logic"]
        subgraph Auth["Authentication Module"]
            AuthPresentation["Presentation - Auth controllers/routes"]:::presentation
            AuthInfra["Infrastructure - Auth implementations"]:::infra
            AuthDomain["Domain - Auth business rules"]:::domain
        end

        subgraph Todos["Todos Module"]
            TodosPresentation["Presentation - Todo controllers/routes"]:::presentation
            TodosInfra["Infrastructure - Todo implementations"]:::infra
            TodosDomain["Domain - Todo business rules"]:::domain
        end

        subgraph Assistants["Assistants Module"]
            AssistantsPresentation["Presentation - Assistant controllers/routes"]:::presentation
            AssistantsInfra["Infrastructure - Assistant implementations"]:::infra
            AssistantsDomain["Domain - Assistant business rules"]:::domain
        end

        subgraph AssistantConfig["Assistant Config Module"]
            ConfigPresentation["Presentation - Config controllers/routes"]:::presentation
            ConfigInfra["Infrastructure - Config implementations"]:::infra
            ConfigDomain["Domain - Config business rules"]:::domain
        end

        subgraph Shared["Shared Module"]
            SharedPresentation["Presentation - Shared controllers/utilities"]:::presentation
            SharedDomain["Domain - Shared business rules"]:::domain
        end
    end

    subgraph Infrastructure_Layer["Infrastructure Layer - External services & tools"]
        subgraph Core["Core Components"]
            Config["Configuration - App settings"]:::core
            ErrorHandling["Error Handling - Custom errors"]:::core
            Types["Types - TypeScript definitions"]:::core
            Constants["Constants - Global constants"]:::core
        end

        subgraph Database["Database Layer"]
            Prisma["Prisma ORM - Database access"]:::database
            Schema["Schema - Database structure"]:::database
            Migrations["Migrations - DB version control"]:::database
        end

        EnvConfig["Environment Config - ENV variables"]:::infra
    end

    %% Connections
    Server --> Routes
    Routes --> AuthMiddleware
    Routes --> ErrorMiddleware

    %% Feature Module Connections
    Routes --> AuthPresentation
    Routes --> TodosPresentation
    Routes --> AssistantsPresentation
    Routes --> ConfigPresentation
    Routes --> SharedPresentation

    AuthPresentation --> AuthInfra
    AuthInfra --> AuthDomain
    TodosPresentation --> TodosInfra
    TodosInfra --> TodosDomain
    AssistantsPresentation --> AssistantsInfra
    AssistantsInfra --> AssistantsDomain
    ConfigPresentation --> ConfigInfra
    ConfigInfra --> ConfigDomain
    SharedPresentation --> SharedDomain

    %% Infrastructure Connections
    AuthInfra --> Prisma
    TodosInfra --> Prisma
    AssistantsInfra --> Prisma
    ConfigInfra --> Prisma
    Prisma --> Schema
    Schema --> Migrations

    %% Core Connections
    AuthDomain --> Types
    TodosDomain --> Types
    AssistantsDomain --> Types
    ConfigDomain --> Types
    SharedDomain --> Types

    ErrorMiddleware --> ErrorHandling
    EnvConfig --> Config

    %% Styling
    classDef server fill:#1E88E5,color:white
    classDef routes fill:#1E88E5,color:white
    classDef middleware fill:#1E88E5,color:white
    classDef presentation fill:#42A5F5,color:white
    classDef infra fill:#FFC107,color:black
    classDef domain fill:#4CAF50,color:white
    classDef core fill:#9C27B0,color:white
    classDef database fill:#FF5722,color:white

    %% Click Events
    click Server "https://github.com/syedgaian/rest-api-ts-express-prisma/blob/dev/src/app.ts"
    click Routes "https://github.com/syedgaian/rest-api-ts-express-prisma/blob/dev/src/routes.ts"
    click AuthMiddleware "https://github.com/syedgaian/rest-api-ts-express-prisma/blob/dev/src/features/auth/presentation/middlewares/auth.middleware.ts"
    click ErrorMiddleware "https://github.com/syedgaian/rest-api-ts-express-prisma/blob/dev/src/features/shared/presentation/middlewares/error.middleware.ts"
    click Auth "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/auth/"
    click AuthDomain "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/auth/domain/"
    click AuthInfra "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/auth/infrastructure/"
    click AuthPresentation "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/auth/presentation/"
    click Todos "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/todos/"
    click TodosDomain "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/todos/domain/"
    click TodosInfra "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/todos/infraestructure/"
    click TodosPresentation "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/todos/presentation/"
    click Assistants "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistants/"
    click AssistantsDomain "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistants/domain/"
    click AssistantsInfra "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistants/infrastructure/"
    click AssistantsPresentation "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistants/presentation/"
    click ConfigDomain "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistant-config/domain/"
    click ConfigInfra "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistant-config/infrastructure/"
    click ConfigPresentation "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/assistant-config/presentation/"
    click SharedDomain "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/shared/domain/"
    click SharedPresentation "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/features/shared/presentation/"
    click Config "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/core/config/"
    click ErrorHandling "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/core/errors/"
    click Types "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/core/types/"
    click Constants "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/src/core/constants/"
    click Schema "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/prisma/schema/"
    click Migrations "https://github.com/syedgaian/rest-api-ts-express-prisma/tree/dev/prisma/migrations/"
    click EnvConfig "https://github.com/syedgaian/rest-api-ts-express-prisma/blob/dev/src/core/config/envs.adapter.ts"
```
