# code100x/photo-ai architecture

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

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

## Overview

Based on our analysis of the file tree and README, here’s an approach tailored to the 100xPhoto project—a full-stack AI image generation platform with a clear separation between a Next.js-based frontend and a Node.js backend, plus shared packages and Docker containerization.

##### Main Components
- Frontend (apps/web): This is the Next.js application using TypeScript, Tailwind CSS, and Shadcn/UI for the UI. It handles user interaction, displays AI-generated images, and integrates with authentication (Clerk) and payment flows.
- Backend (apps/backend): A Node.js/TypeScript service that provides APIs for image generation, payment processing (routes like payment.routes.ts and webhook.routes.ts), and model training. It likely communicates with a database.
- Shared Packages:
- UI Components (packages/ui) – a shared React component library for both frontend consistency.
- Configuration and Linting (packages/typescript-config, packages/eslint-config) – to ensure consistency across the monorepo.
- Database (packages/db) – contains Prisma schemas and migrations; it represents the data layer.
- Docker Containerization: Dockerfiles for both frontend and backend (in the docker directory) allow deployment of services in isolated containers.
- CI/CD Workflows: Found in the .github/workflows directory handling deployment for both backend and frontend.

##### Relationships and Interactions
- The Frontend communicates with the Backend primarily via REST or potentially other API mechanisms. It relies on environment (`NEXT_PUBLIC_BACKEND_URL`) to point to the backend service.
- The Backend interacts with the Database layer (via Prisma configurations found in packages/db) to store and retrieve image data, subscription details, transactions, etc.
- Shared UI components are used in the frontend to provide a consistent user interface.
- The authentication mechanism using Clerk is integrated within the frontend (and possibly backend) components.
- CI/CD workflows, managed with GitHub Actions, trigger deployments for the dockerized images.

##### Architectural Patterns and Technologies
- Separation of Concerns: Clear separation between frontend and backend.
- Monorepo Management: Managed via Turborepo (as indicated in the README) which coordinates the builds across apps and packages.
- Containerization: Docker is used to build and run isolated environments for the frontend and backend.
- Shared Libraries: Reusing components and configurations across applications.
- API-Driven Interaction: The frontend uses API calls to drive business logic while the backend provides endpoints for operations like payment and image generation.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Monorepo Level
    subgraph "Monorepo (Turborepo)"
        MONO["Monorepo (Turborepo)"]:::monorepo
    end

    %% Applications Layer
    subgraph "Applications"
        F["Frontend (Next.js, TypeScript, Tailwind, Clerk)"]:::frontend
        B["Backend (Node.js, API Services)"]:::backend
    end

    %% Shared Packages Layer
    subgraph "Shared Packages"
        UI["UI Components (React)"]:::shared
        DB["Database (Prisma)"]:::database
        TS["TypeScript Config"]:::config
        ESLINT["ESLint Config"]:::config
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        D["Docker Containerization"]:::docker
        DF["Dockerfile (Frontend)"]:::dockerfile
        DBF["Dockerfile (Backend)"]:::dockerfile
        CICD["CI/CD Pipeline (GitHub Actions)"]:::ci
    end

    %% Relationships among components
    F -->|"API_calls"| B
    B -->|"CRUD"| DB
    F -->|"Uses"| UI
    F -->|"Configured_by"| TS
    F -->|"Configured_by"| ESLINT
    B -->|"Configured_by"| TS
    B -->|"Configured_by"| ESLINT
    D --> DF
    D --> DBF
    CICD -->|"Deploys"| D

    %% Monorepo connectivity for shared context
    MONO --> F
    MONO --> B
    MONO --> UI
    MONO --> DB
    MONO --> TS
    MONO --> ESLINT

    %% Click Events
    click F "https://github.com/code100x/photo-ai/tree/main/apps/web"
    click B "https://github.com/code100x/photo-ai/tree/main/apps/backend"
    click UI "https://github.com/code100x/photo-ai/tree/main/packages/ui"
    click DB "https://github.com/code100x/photo-ai/tree/main/packages/db"
    click TS "https://github.com/code100x/photo-ai/tree/main/packages/typescript-config"
    click ESLINT "https://github.com/code100x/photo-ai/tree/main/packages/eslint-config"
    click D "https://github.com/code100x/photo-ai/tree/main/docker"
    click DF "https://github.com/code100x/photo-ai/blob/main/docker/Dockerfile.frontend"
    click DBF "https://github.com/code100x/photo-ai/blob/main/docker/Dockerfile.backend"
    click CICD "https://github.com/code100x/photo-ai/tree/main/.github/workflows"

    %% Style Definitions
    classDef frontend fill:#FFEBEE,stroke:#B71C1C,stroke-width:2px;
    classDef backend fill:#E3F2FD,stroke:#0D47A1,stroke-width:2px;
    classDef shared fill:#E8F5E9,stroke:#1B5E20,stroke-width:2px;
    classDef database fill:#FFF3E0,stroke:#E65100,stroke-width:2px;
    classDef config fill:#E0F7FA,stroke:#006064,stroke-width:2px;
    classDef docker fill:#F3E5F5,stroke:#4A148C,stroke-width:2px;
    classDef dockerfile fill:#F3E5F5,stroke:#4A148C,stroke-width:2px;
    classDef ci fill:#FCE4EC,stroke:#880E4F,stroke-width:2px;
    classDef monorepo fill:#FFFDE7,stroke:#F57F17,stroke-width:2px;
```
