# danishaft/photo-ai architecture

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

- Interactive diagram: https://gitdiagram.com/danishaft/photo-ai
- Repository: https://github.com/danishaft/photo-ai

## Overview

##### Main Components
- Frontend (apps/web): Built with Next.js 14 and integrated with Clerk for authentication. This component contains multiple pages, UI elements (many lie in apps/web/components) and leverages shared UI packages.
- Backend (apps/backend): A Node.js (TypeScript) service, handling routes (like payment and webhook endpoints), middleware, models, and service logic for payments and likely AI-related functionality.
- Shared Packages (packages/): Includes:
– Shared UI library (@repo/ui) that provides reusable React components.
– TypeScript and ESLint configurations which enforce style and coding conventions across the monorepo.
– A database package (packages/db) that likely encapsulates database interactions using Prisma with migration scripts.
- Docker Configuration (docker/): Contains Dockerfiles for both frontend and backend — these are used for containerizing the two major applications.
- Infrastructure & CI/CD (GitHub workflows in .github/workflows): Automates deployment and other operations.
- External Services: Authentication is handled via Clerk. Payment processing is part of both the backend services (payment routes and service) and the frontend (payment components and related pages). There could be additional integrations through external APIs for image generation or model training.

##### Relationships and Interactions
- The Frontend interacts with the Backend via API calls (using NEXT_PUBLIC_BACKEND_URL) to trigger processes like image generation, payment processing, model training, etc.
- Authentication flows (with Clerk) begin at the Frontend and the Backend validates based on the passed information.
- The Backend communicates with the database (from packages/db) and leverages ORM via Prisma to manage models and migrations.
- Shared packages are used by both apps to maintain consistency in UI, linting, and TypeScript setups.
- Containerization ties together infrastructure aspects with Docker commands, ensuring both services run within their own container environments.

##### Architectural Patterns and Design Principles
- Monorepo structure managed with Turborepo, ensuring modularity and reusability of packages.
- Separation of concerns with distinct frontend and backend modules.
- Component-based design in the frontend (using Next.js pages, React components, hooks, etc.).
- Microservice-like separation (even if within one repository): the backend service handles API routing and business logic separately from UI concerns.
- CI/CD pipelines (GitHub workflows) automate deployments for both frontend and backend.

##### Relevant Technologies & Frameworks
- Next.js 14 with App Router, Tailwind CSS, and Shadcn/UI for the frontend.
- Node.js and TypeScript for the backend.
- Prisma (inside the packages/db folder) for database migrations and data modeling.
- Docker for containerization and deployment.
- Clerk for authentication management.
- Bun as the package manager for local development.
- Turborepo for monorepo orchestration.

- Notes on deployment (e.g., container orchestration with Docker, automated deployments via GitHub workflows).
- On the monorepo structure by showcasing both the Apps (frontend and backend) and the shared Packages to emphasize the reusability and centralized configuration.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External User
    User["User"]:::external

    %% External Services
    AUTH["Authentication (Clerk)"]:::external
    PAYMENT["Payment Processor"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["Web Frontend (Next.js)"]:::frontend
        FE2["UI Components & Pages"]:::frontend
        FE1 -->|"contains"| FE2
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE1["Backend Service (Node.js/TypeScript)"]:::backend
        BE2["API Routes & Business Logic"]:::backend
        BE1 -->|"handles"| BE2
    end

    %% Shared Packages
    subgraph "Shared Packages"
        UI["Shared UI Library (@repo/ui)"]:::shared
        ESLINT["ESLint Config"]:::shared
        TS["TypeScript Config"]:::shared
        DB["Database (Prisma ORM/Migrations)"]:::shared
    end

    %% Infrastructure & DevOps
    subgraph "Infrastructure & DevOps"
        DOCKER["Docker Configuration"]:::infra
        CICD["CI/CD (GitHub Actions)"]:::infra
    end

    %% Relationships
    User -->|"interacts"| FE1
    FE1 -->|"HTTP/API Calls"| BE1
    FE1 -->|"uses"| UI
    FE1 -->|"auth flows"| AUTH
    BE1 -->|"validates auth"| AUTH
    BE1 -->|"ORM Calls"| DB
    FE1 -->|"payment UI"| PAYMENT
    BE1 -->|"processes payments"| PAYMENT
    FE1 -->|"lint/config"| ESLINT
    FE1 -->|"ts config"| TS
    BE1 -->|"lint/config"| ESLINT
    BE1 -->|"ts config"| TS

    %% Deployment relationships
    FE1 -->|"containerized via"| DOCKER
    BE1 -->|"containerized via"| DOCKER
    FE1 -->|"deployed via"| CICD
    BE1 -->|"deployed via"| CICD

    %% Styling Classes
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef shared fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef infra fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px;

    %% Click Events
    click FE1 "https://github.com/danishaft/photo-ai/tree/main/apps/web"
    click BE1 "https://github.com/danishaft/photo-ai/tree/main/apps/backend"
    click UI "https://github.com/danishaft/photo-ai/tree/main/packages/ui"
    click ESLINT "https://github.com/danishaft/photo-ai/tree/main/packages/eslint-config"
    click TS "https://github.com/danishaft/photo-ai/tree/main/packages/typescript-config"
    click DB "https://github.com/danishaft/photo-ai/tree/main/packages/db"
    click DOCKER "https://github.com/danishaft/photo-ai/tree/main/docker"
    click CICD "https://github.com/danishaft/photo-ai/tree/main/.github/workflows"
```
