# valerakoz/photographer-service architecture

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

- Interactive diagram: https://gitdiagram.com/valerakoz/photographer-service
- Repository: https://github.com/valerakoz/photographer-service

## Overview

##### Main Components
- Frontend/UI Layer:
– Represented by the Next.js pages and components under src/app (e.g., dashboard, photo gallery, modal dialogs, etc.) and UI components under src/components and src/ui.
– This is responsible for rendering pages, interacting with users, and presenting the dashboard and photo management interfaces.

- API / Backend Layer:
– Next.js API routes under src/app/api handle backend functions such as authentication (with Yandex), photo management, and project/folder operations.
– These routes encapsulate RESTful endpoints (or possibly edge functions) that serve data to the UI.

- Database Layer:
– The prisma directory, containing a Prisma schema (prisma/schema.prisma), database migrations, and the generated Prisma client (prisma/prisma-client.ts) indicates that the persistent data (projects, folders, user data, photos, etc.) is managed via a relational database through Prisma ORM.

- External Services:
– Authentication via Yandex is clearly integrated (files under src/app/api/auth/ and utils/auth/yandex).
– There is an S3 integration for file uploads (src/service/S3Client and src/service/file-upload), which represents a connection to an external object storage service.

- Utility & State Management:
– State management and helper functions are in src/lib/store and src/lib/helpers.
– Global query management is hinted by src/lib/queryClient which might be using a client like React Query.

##### Relationships and Data Flow
- The UI (frontend) makes requests (using RESTful API or possibly GraphQL endpoints) to the API endpoints provided by Next.js under src/app/api for various functions:
– Authentication endpoints handle sign-in/up via Yandex.
– Photo and project endpoints handle file and project management.
- The API layer interacts with the Database via Prisma to persist and query data.
- For file upload and storage, the API layer or dedicated service calls the S3Client service to upload files to the external S3 storage.
- Utility functions and middleware (e.g., src/middleware.ts) facilitate session management, authentication, and possibly error handling.

##### Architectural Patterns and Design Principles
- Modular, Component-Based Architecture:
– Separation between UI components (React components) and API routes.
– Code is logically organized: dashboard files, form components, and modal management help maintain a clean separation of concerns.
- Server-Side Rendering (SSR) and API integration:
- Data Access Layer via Prisma ORM:
– All database interactions go through Prisma, emphasizing abstraction between the raw database and business logic.
- External Service Integration:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend/UI Layer
    subgraph "Frontend (Next.js Pages & Components)"
        FE1["src/app/dashboard"]:::frontend
        FE2["src/app/page.tsx"]:::frontend
        FE3["src/app/layout.tsx"]:::frontend
        FE4["src/components/dashboard-content"]:::frontend
        FE5["src/ui/form"]:::frontend
    end

    %% API/Backend Layer
    subgraph "API Endpoints (Next.js API Routes)"
        API1["src/app/api/auth"]:::backend
        API2["src/app/api/photos"]:::backend
        API3["src/app/api/project"]:::backend
    end

    %% Database Layer
    subgraph "Database (Prisma ORM & DB)"
        DB1["prisma/schema.prisma"]:::database
        DB2["prisma/migrations"]:::database
        DB3["prisma/prisma-client.ts"]:::database
    end

    %% External Services
    subgraph "External Services"
        subgraph "Yandex OAuth"
            YD1["src/app/api/auth/callback/yandex"]:::external
            YD2["utils/auth/yandex/getYandexAccessToken.ts"]:::external
        end
        subgraph "S3 Storage"
            S3A["src/service/S3Client"]:::external
            S3B["src/service/file-upload/useFileUpload.tsx"]:::external
        end
    end

    %% Utility & State Management
    subgraph "Utility & State Management"
        UT1["src/lib/store"]:::utility
        UT2["src/lib/helpers"]:::utility
        UT3["src/lib/queryClient/query-client.ts"]:::utility
        UT4["src/providers/ModalController.tsx"]:::utility
        UT5["src/providers/StoreProvider.tsx"]:::utility
    end

    %% Middleware
    M["src/middleware.ts"]:::middleware

    %% Connections between layers
    FE1 -->|"APIcall"| API1
    FE2 -->|"APIcall"| API2
    FE3 -->|"APIcall"| API3

    API1 -->|"PrismaQuery"| DB1
    API2 -->|"PrismaQuery"| DB2
    API3 -->|"PrismaQuery"| DB3

    API2 -->|"FileUpload"| S3A
    API2 -->|"FileUpload"| S3B

    FE1 -->|"OAuth"| YD1
    FE1 -->|"OAuth"| YD2

    M -->|"Middleware"| API1
    M -->|"Middleware"| API2
    M -->|"Middleware"| API3

    UT1 -->|"State/Helpers"| FE1
    UT2 -->|"Helpers"| API1
    UT3 -->|"QueryClient"| API2
    UT4 -->|"ProvidesModal"| FE4
    UT5 -->|"ProvidesStore"| FE5

    %% Click Events for Frontend/UI Layer
    click FE1 "https://github.com/valerakoz/photographer-service/tree/main/src/app/dashboard"
    click FE2 "https://github.com/valerakoz/photographer-service/blob/main/src/app/page.tsx"
    click FE3 "https://github.com/valerakoz/photographer-service/blob/main/src/app/layout.tsx"
    click FE4 "https://github.com/valerakoz/photographer-service/tree/main/src/components/dashboard-content"
    click FE5 "https://github.com/valerakoz/photographer-service/tree/main/src/ui/form"

    %% Click Events for API/Backend Layer
    click API1 "https://github.com/valerakoz/photographer-service/tree/main/src/app/api/auth"
    click API2 "https://github.com/valerakoz/photographer-service/tree/main/src/app/api/photos"
    click API3 "https://github.com/valerakoz/photographer-service/tree/main/src/app/api/project"

    %% Click Events for Database Layer
    click DB1 "https://github.com/valerakoz/photographer-service/blob/main/prisma/schema.prisma"
    click DB2 "https://github.com/valerakoz/photographer-service/tree/main/prisma/migrations"
    click DB3 "https://github.com/valerakoz/photographer-service/blob/main/prisma/prisma-client.ts"

    %% Click Events for External Services – Yandex OAuth
    click YD1 "https://github.com/valerakoz/photographer-service/tree/main/src/app/api/auth/callback/yandex"
    click YD2 "https://github.com/valerakoz/photographer-service/blob/main/utils/auth/yandex/getYandexAccessToken.ts"

    %% Click Events for External Services – S3 Storage
    click S3A "https://github.com/valerakoz/photographer-service/tree/main/src/service/S3Client"
    click S3B "https://github.com/valerakoz/photographer-service/blob/main/src/service/file-upload/useFileUpload.tsx"

    %% Click Events for Utility & State Management
    click UT1 "https://github.com/valerakoz/photographer-service/tree/main/src/lib/store"
    click UT2 "https://github.com/valerakoz/photographer-service/tree/main/src/lib/helpers"
    click UT3 "https://github.com/valerakoz/photographer-service/blob/main/src/lib/queryClient/query-client.ts"
    click UT4 "https://github.com/valerakoz/photographer-service/blob/main/src/providers/ModalController.tsx"
    click UT5 "https://github.com/valerakoz/photographer-service/blob/main/src/providers/StoreProvider.tsx"

    %% Click Event for Middleware
    click M "https://github.com/valerakoz/photographer-service/blob/main/src/middleware.ts"

    %% Styles
    classDef frontend fill:#ffebcc,stroke:#e69500,stroke-width:2px;
    classDef backend fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef database fill:#ffd6cc,stroke:#cc3300,stroke-width:2px;
    classDef external fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef utility fill:#e8f8f5,stroke:#1abc9c,stroke-width:2px;
    classDef middleware fill:#fdebd0,stroke:#d35400,stroke-width:2px;
```
