# gokruzk/photo_manager architecture

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

- Interactive diagram: https://gitdiagram.com/gokruzk/photo_manager
- Repository: https://github.com/gokruzk/photo_manager

## Overview

##### Project type and purpose
- This is a full-stack web application (“Photo Album Manager”) composed of:
- Frontend: Next.js (React + TypeScript + Tailwind)
- Backend: FastAPI (Python) with a modular routes/controllers structure
- Persistence: PostgreSQL via Prisma ORM

##### File structure
- Top-level directories:
- Backend/ – Python service, organized into config, controller, routes, model, utils, prisma schema, database artifacts
- Frontend/ – Next.js 13+ “app” directory, API‐caller modules, shared components, styles, middleware
- Patterns:
- Backend follows a layered (routes → controllers → models) / MVC‐style pattern
- Frontend uses React server + client components under “app/” and a thin API layer in api/*.tsx
- Config & deployment artifacts:
- Backend/config/db.py, .env for DB_URL & JWT SECRET_KEY
- Frontend/next.config.mjs, tsconfig.json, tailwind.config.ts

##### Key README insights
- Backend stack: FastAPI + PrismaORM + PostgreSQL, JWT‐based auth, email service variable (API_EMAIL)
- Frontend: create-next-app bootstrapped, uses next/font, Tailwind for styling

a. Main components
1) Client/browser (Web UI)
2) Next.js Server / App Layer
3) FastAPI Backend
– Route handlers (routes/*.py)
– Business logic (controller/*.py)
– Models & ORM (prisma/schema.prisma + model/models.py)
– Utilities (auth, hashing, session)
4) PostgreSQL Database
5) External services
– Email provider (for notifications)
– (Optional) Object store or CDN for images, if applicable
b. Relationships & interactions
- User interacts with Next.js UI → issues HTTP(S) calls to FastAPI endpoints (e.g. /users, /images, /countries)
- FastAPI routes forward to controller logic → use Prisma client to query/update PostgreSQL
- Auth utility issues/verifies JWTs; controllers validate tokens on protected routes
- On successful upload, images are persisted (either in DB or file store) and metadata recorded
- If configured, backend invokes external email API (API_EMAIL) for password resets or notifications
c. Architectural patterns & design principles
- Layered architecture (Presentation → Application/API → Domain logic → Data access)
- RESTful API design in FastAPI
- Modularization by domain (auth, user, image, country)
- Type safety and code sharing in Frontend (TypeScript types)
d. Key technologies/frameworks
- Frontend: Next.js 13 app router, React, Tailwind CSS, TypeScript
- Backend: FastAPI, Python 3.x, Prisma ORM, PostgreSQL, JWT for authentication
- DevOps/tools: prisma CLI, pydantic models, node/npm or pnpm for FE

##### Detail without over-complication
- Prisma schema and database scripts as part of the Data Access layer
- Notes on environment configuration (.env variables for DB_URL, SECRET_KEY, API_EMAIL)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client/UI Layer
    subgraph "Client/UI Layer"
        LAYOUT["layout.tsx"]:::frontend
        PAGE_MAIN["page.tsx"]:::frontend
        PAGE_LOGIN["login/page.tsx"]:::frontend
        PAGE_REGISTER["register/page.tsx"]:::frontend
        PAGE_ALBUM["album/page.tsx"]:::frontend
        PAGE_UPLOAD["upload/page.tsx"]:::frontend
        PAGE_PROFILE["profile/page.tsx"]:::frontend
        ROUTE_ME["me/route.tsx"]:::frontend
        PAGE_ABOUTME["aboutme/page.tsx"]:::frontend
        PAGE_EDITPROFILE["editprofile/page.tsx"]:::frontend
        COMPONENT_DELETE["DeleteButton.tsx"]:::frontend
        COMPONENT_LINK["LinkButton.tsx"]:::frontend
        STYLE_GLOBAL["globals.css"]:::frontend
        CONFIG_TAILWIND["tailwind.config.ts"]:::frontend
        CONFIG_NEXT["next.config.mjs"]:::frontend
        TS_CONFIG["tsconfig.json"]:::frontend
        POSTCSS["postcss.config.mjs"]:::frontend
    end

    %% Frontend API Layer
    subgraph "Frontend API Layer"
        API_COUNTRY["countryAPI.tsx"]:::frontend
        API_IMAGE["imageAPI.tsx"]:::frontend
        API_USER["userAPI.tsx"]:::frontend
    end

    %% Frontend Utilities & Middleware
    subgraph "Frontend Utils & Middleware"
        UTIL_SESSION["userSession.ts"]:::frontend
        TYPES["types/index.ts"]:::frontend
        MIDDLEWARE["middleware.tsx"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend - FastAPI"
        ENTRY["main.py"]:::backend
        subgraph "Configuration"
            CONF_DB["db.py"]:::backend
            ENV[".env"]:::backend
        end
        subgraph "FastAPI Routes"
            ROUTE_COUNTRY["country.py"]:::backend
            ROUTE_IMAGE["image.py"]:::backend
            ROUTE_USER["user.py"]:::backend
        end
        subgraph "Controllers"
            CTRL_AUTH["auth.py"]:::backend
            CTRL_COUNTRY["country.py"]:::backend
            CTRL_IMAGE["image.py"]:::backend
            CTRL_USER["user.py"]:::backend
        end
        subgraph "Models & ORM"
            MODEL_PY["models.py"]:::backend
            PRISMA_SCHEMA["schema.prisma"]:::backend
        end
        UTIL_AUTH["auth.py"]:::backend
        REQ_TXT["requirements.txt"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        DB["PostgreSQL Database"]:::database
        subgraph "Database Artifacts"
            SQL_CAL["calendario.sql"]:::database
            SQL_PHOTO["photo_manager.sql"]:::database
            DIAGRAM["db_diagram.drawio"]:::database
            LDB_FILES["photo_album.*"]:::database
        end
    end

    %% External Services
    subgraph "External Services"
        EMAIL["Email Service"]:::external
        OBJECT_STORE["CDN/Object Store"]:::external
    end

    %% Frontend dependencies
    PKG_JSON["package.json"]:::frontend
    PKG_LOCK["package-lock.json"]:::frontend

    %% Connections
    %% User flow
    BROWSER["User's Browser"]:::external
    BROWSER --> PAGE_MAIN
    BROWSER --> PAGE_LOGIN
    BROWSER --> PAGE_REGISTER
    BROWSER --> PAGE_ALBUM
    BROWSER --> PAGE_UPLOAD
    BROWSER --> PAGE_PROFILE
    BROWSER --> PAGE_ABOUTME
    BROWSER --> PAGE_EDITPROFILE

    %% UI calling APIs
    PAGE_LOGIN --> API_USER
    PAGE_REGISTER --> API_USER
    PAGE_PROFILE --> API_USER
    ROUTE_ME --> API_USER
    PAGE_ABOUTME --> API_USER
    PAGE_EDITPROFILE --> API_USER
    PAGE_ALBUM --> API_IMAGE
    PAGE_UPLOAD --> API_IMAGE

    %% Middleware & Utils
    MIDDLEWARE -.-> PAGE_MAIN
    UTIL_SESSION -.-> PAGE_MAIN
    TYPES -.-> PAGE_MAIN

    %% API to Backend Routes
    API_COUNTRY --> ROUTE_COUNTRY
    API_IMAGE --> ROUTE_IMAGE
    API_USER --> ROUTE_USER

    %% Entry to Routes
    ENTRY --> ROUTE_COUNTRY
    ENTRY --> ROUTE_IMAGE
    ENTRY --> ROUTE_USER

    %% Routes to Controllers
    ROUTE_COUNTRY --> CTRL_COUNTRY
    ROUTE_IMAGE --> CTRL_IMAGE
    ROUTE_USER --> CTRL_USER

    %% Controllers to models and utils
    CTRL_AUTH --> UTIL_AUTH
    CTRL_USER --> UTIL_AUTH
    CTRL_COUNTRY --> MODEL_PY
    CTRL_IMAGE --> MODEL_PY
    CTRL_USER --> MODEL_PY
    CTRL_AUTH --> MODEL_PY
    MODEL_PY --> PRISMA_SCHEMA

    %% Data Access
    PRISMA_SCHEMA --> DB
    MODEL_PY --> DB

    %% Email notifications
    CTRL_AUTH --> EMAIL

    %% Optional object storage
    CTRL_IMAGE --> OBJECT_STORE

    %% Dependencies
    ENTRY --> REQ_TXT
    PAGE_MAIN --> PKG_JSON
    PAGE_MAIN --> PKG_LOCK

    %% Click Events
    click LAYOUT "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/layout.tsx"
    click PAGE_MAIN "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/page.tsx"
    click PAGE_LOGIN "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/login/page.tsx"
    click PAGE_REGISTER "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/register/page.tsx"
    click PAGE_ALBUM "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/album/page.tsx"
    click PAGE_UPLOAD "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/upload/page.tsx"
    click PAGE_PROFILE "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/profile/page.tsx"
    click ROUTE_ME "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/me/route.tsx"
    click PAGE_ABOUTME "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/aboutme/page.tsx"
    click PAGE_EDITPROFILE "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/editprofile/page.tsx"
    click COMPONENT_DELETE "https://github.com/gokruzk/photo_manager/blob/main/Frontend/components/DeleteButton.tsx"
    click COMPONENT_LINK "https://github.com/gokruzk/photo_manager/blob/main/Frontend/components/LinkButton.tsx"
    click STYLE_GLOBAL "https://github.com/gokruzk/photo_manager/blob/main/Frontend/app/globals.css"
    click CONFIG_TAILWIND "https://github.com/gokruzk/photo_manager/blob/main/Frontend/tailwind.config.ts"
    click CONFIG_NEXT "https://github.com/gokruzk/photo_manager/blob/main/Frontend/next.config.mjs"
    click TS_CONFIG "https://github.com/gokruzk/photo_manager/blob/main/Frontend/tsconfig.json"
    click POSTCSS "https://github.com/gokruzk/photo_manager/blob/main/Frontend/postcss.config.mjs"
    click API_COUNTRY "https://github.com/gokruzk/photo_manager/blob/main/Frontend/api/countryAPI.tsx"
    click API_IMAGE "https://github.com/gokruzk/photo_manager/blob/main/Frontend/api/imageAPI.tsx"
    click API_USER "https://github.com/gokruzk/photo_manager/blob/main/Frontend/api/userAPI.tsx"
    click UTIL_SESSION "https://github.com/gokruzk/photo_manager/blob/main/Frontend/utils/userSession.ts"
    click TYPES "https://github.com/gokruzk/photo_manager/blob/main/Frontend/types/index.ts"
    click MIDDLEWARE "https://github.com/gokruzk/photo_manager/blob/main/Frontend/middleware.tsx"
    click ENTRY "https://github.com/gokruzk/photo_manager/blob/main/Backend/main.py"
    click CONF_DB "https://github.com/gokruzk/photo_manager/blob/main/Backend/config/db.py"
    click ROUTE_COUNTRY "https://github.com/gokruzk/photo_manager/blob/main/Backend/routes/country.py"
    click ROUTE_IMAGE "https://github.com/gokruzk/photo_manager/blob/main/Backend/routes/image.py"
    click ROUTE_USER "https://github.com/gokruzk/photo_manager/blob/main/Backend/routes/user.py"
    click CTRL_AUTH "https://github.com/gokruzk/photo_manager/blob/main/Backend/controller/auth.py"
    click CTRL_COUNTRY "https://github.com/gokruzk/photo_manager/blob/main/Backend/controller/country.py"
    click CTRL_IMAGE "https://github.com/gokruzk/photo_manager/blob/main/Backend/controller/image.py"
    click CTRL_USER "https://github.com/gokruzk/photo_manager/blob/main/Backend/controller/user.py"
    click MODEL_PY "https://github.com/gokruzk/photo_manager/blob/main/Backend/model/models.py"
    click PRISMA_SCHEMA "https://github.com/gokruzk/photo_manager/blob/main/Backend/prisma/schema.prisma"
    click SQL_CAL "https://github.com/gokruzk/photo_manager/blob/main/Backend/database/calendario.sql"
    click SQL_PHOTO "https://github.com/gokruzk/photo_manager/blob/main/Backend/database/photo_manager.sql"
    click DIAGRAM "https://github.com/gokruzk/photo_manager/blob/main/Backend/database/db_diagram.drawio"
    click LDB_FILES "https://github.com/gokruzk/photo_manager/blob/main/Backend/database/photo_album.ldb/.ldm/.pdb/.pdm"
    click UTIL_AUTH "https://github.com/gokruzk/photo_manager/blob/main/Backend/utils/auth.py"
    click REQ_TXT "https://github.com/gokruzk/photo_manager/blob/main/Backend/requirements.txt"
    click PKG_JSON "https://github.com/gokruzk/photo_manager/blob/main/Frontend/package.json"
    click PKG_LOCK "https://github.com/gokruzk/photo_manager/blob/main/Frontend/package-lock.json"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#000,stroke-width:1px
    classDef backend fill:#d4edda,stroke:#000,stroke-width:1px
    classDef database fill:#ffe5b4,stroke:#000,stroke-width:1px
    classDef external fill:#fff,stroke:#333,stroke-dasharray:5 5,stroke-width:1px
```
