# proyecto26/projectx architecture

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

- Interactive diagram: https://gitdiagram.com/proyecto26/projectx
- Repository: https://github.com/proyecto26/projectx

## Overview

##### Main Components
- Frontend:
- apps/web: The web application built using React (via Remix) that handles user interactions.
- libs/frontend/ui: The UI component library providing reusable components, themes, and Storybook configurations.
- Backend Services:
- apps/auth, apps/order, apps/product: Each dedicated to specific domains (authentication, order processing, and product catalog/inventory). They expose REST APIs and integrate business logic.
- Shared Backend Libraries:
- libs/backend/core: Contains shared business logic, utilities, and common NestJS modules.
- libs/backend/db: Manages database access with Prisma, schema definitions, and the Repository pattern.
- libs/backend/email: Handles email template generation (using MJML) and email sending logic.
- libs/backend/payment: Provides payment integration (e.g., Stripe) and related workflows.
- libs/backend/workflows: Integrates Temporal workflows and orchestration, handling long-running business processes.
- Domain Models and DTO Definitions:
- libs/models: Contains common data transfer objects (DTOs) and types ensuring consistency between services.
- Infrastructure Components:
- Temporal Server and UI: Orchestrates durable executions and coordinated workflows.
- Database Layer: PostgreSQL with PostGIS SQL schemas (initialized via docker-entrypoint scripts).
- Docker & Deployment: docker-compose file, Dockerfile, and deployment scripts, which define the containerization and orchestration of services.

##### Out Interactions and Relationships
- Frontend (apps/web) communicates with backend services (auth, order, product) through HTTP/REST API endpoints.
- Backend services share common functionalities (authentication, logging, configuration) via libs/backend/core.
- The Temporal orchestration layer (via libs/backend/workflows) interacts with backend services to manage long-lived business processes, handle asynchronous signals, and execute retries as necessary.
- The DB layer (libs/backend/db) is uniformly accessed by the backend services for data persistence.
- Payment workflows in libs/backend/payment manage integration with external payment providers (Stripe) and use webhooks to communicate results.
- Email notifications (via libs/backend/email) are triggered based on events from workflow progression or external inputs.
- The shared data models in libs/models ensure type safety and consistency across all layers.

##### Architectural Patterns and Principles
- Monorepo architecture managed via Nx, enabling code share, centralized configuration, and consistent tooling.
- Separation of Concerns: Distinct apps for different domains (auth, order, product, web) and libraries for shared business logic.
- Microservices-like design within the monorepo: Even if deployed together, each app is kept modularly separated.
- Workflow Orchestration: Temporal is used to manage long-running, distributed operations with durability and compensation.
- Domain Driven Design (DDD): Each domain (auth, order, product) has its domain models and business logic implemented via DTOs and service modules.

##### Additional Detailed Suggestions
- Present the overall monorepo as a container, with internal subdivisions for apps and libs.
- Adding a layer or annotation representing “Deployment & DevOps” indicating the Dockerfiles, docker-compose setup, and CI pipelines (as seen in the .github/workflows/ci.yml file).
- Use labels such as “Configuration Files” for global settings (nx.json, tsconfig.base.json) to indicate how consistency is maintained across the project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Monorepo Container
    subgraph "ProjectX Monorepo"
        %% Frontend Layer
        subgraph "Frontend"
            FE1("apps/web (React/Remix)"):::frontend
            FE2("libs/frontend/ui (UI Components, TailwindCSS, Storybook)"):::frontend
        end

        %% Backend Services Layer
        subgraph "Backend Services"
            BA1("apps/auth (REST API)"):::backend
            BA2("apps/order (REST API)"):::backend
            BA3("apps/product (REST API)"):::backend
        end

        %% Shared Libraries/Utilities
        subgraph "Shared Libraries/Utilities"
            SL1("libs/backend/core (Common Modules & Business Logic)"):::shared
            SL2("libs/backend/db (Database Access, Prisma)"):::shared
            SL3("libs/backend/email (Email Templates & Sending)"):::shared
            SL4("libs/backend/payment (Stripe Integration & Payment Workflows)"):::shared
            SL5("libs/backend/workflows (Temporal Workflows)"):::shared
            SL6("libs/models (Domain Models & DTOs)"):::shared
        end

        %% Infrastructure Components
        subgraph "Infrastructure"
            INF1("Temporal Server (Workflow Orchestration)"):::infra
            INF2["PostgreSQL\nwith PostGIS (Database)"]:::infra
            INF3("Docker & Deployment"):::infra
        end
    end

    %% Frontend to Backend interactions
    FE1 -->|"HTTP API"| BA1
    FE1 -->|"HTTP API"| BA2
    FE1 -->|"HTTP API"| BA3

    %% Backend Services using Shared Libraries
    BA1 -->|"uses"| SL1
    BA1 -->|"queries"| SL2
    BA1 -->|"DTOs"| SL6
    BA2 -->|"uses"| SL1
    BA2 -->|"queries"| SL2
    BA2 -->|"DTOs"| SL6
    BA3 -->|"uses"| SL1
    BA3 -->|"queries"| SL2
    BA3 -->|"DTOs"| SL6

    %% Email and Payment integrations
    BA1 -->|"triggers"| SL3
    BA2 -->|"initiates"| SL4
    BA3 -->|"triggers"| SL3

    %% Temporal Workflows interactions with Backend Services
    SL5 -->|"workflow signal"| BA1
    SL5 -->|"workflow signal"| BA2
    SL5 -->|"workflow signal"| BA3
    INF1 -->|"orchestrates"| SL5

    %% Database interaction from Backend Services directly
    BA1 -->|"database query"| INF2
    BA2 -->|"database query"| INF2
    BA3 -->|"database query"| INF2

    %% Deployment touches all services (conceptual)
    INF3 ---|"containerized"| FE1
    INF3 ---|"containerized"| FE2
    INF3 ---|"containerized"| BA1
    INF3 ---|"containerized"| BA2
    INF3 ---|"containerized"| BA3
    INF3 ---|"containerized"| SL1
    INF3 ---|"containerized"| SL2
    INF3 ---|"containerized"| SL3
    INF3 ---|"containerized"| SL4
    INF3 ---|"containerized"| SL5
    INF3 ---|"containerized"| SL6
    INF3 ---|"containerized"| INF1
    INF3 ---|"containerized"| INF2

    %% External Integrations
    SP("Stripe"):::external
    EM("Email Provider"):::external
    SL4 -->|"payment integration"| SP
    SL3 -->|"email notifications"| EM

    %% Click Events for Component Mapping
    click FE1 "https://github.com/proyecto26/projectx/tree/develop/apps/web"
    click FE2 "https://github.com/proyecto26/projectx/tree/develop/libs/frontend/ui"
    click BA1 "https://github.com/proyecto26/projectx/tree/develop/apps/auth"
    click BA2 "https://github.com/proyecto26/projectx/tree/develop/apps/order"
    click BA3 "https://github.com/proyecto26/projectx/tree/develop/apps/product"
    click SL1 "https://github.com/proyecto26/projectx/tree/develop/libs/backend/core"
    click SL2 "https://github.com/proyecto26/projectx/tree/develop/libs/backend/db"
    click SL3 "https://github.com/proyecto26/projectx/tree/develop/libs/backend/email"
    click SL4 "https://github.com/proyecto26/projectx/tree/develop/libs/backend/payment"
    click SL5 "https://github.com/proyecto26/projectx/tree/develop/libs/backend/workflows"
    click SL6 "https://github.com/proyecto26/projectx/tree/develop/libs/models"
    click INF3 "https://github.com/proyecto26/projectx/blob/develop/docker-compose.yml"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#e67e22,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#3498db,stroke-width:2px;
    classDef shared fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef infra fill:#f5b7b1,stroke:#e74c3c,stroke-width:2px;
    classDef external fill:#d2b4de,stroke:#8e44ad,stroke-width:2px;
```
