# isaacinsoll/picr architecture

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

- Interactive diagram: https://gitdiagram.com/isaacinsoll/picr
- Repository: https://github.com/isaacinsoll/picr

## Overview

##### Main Components
- Frontend: A React-based client application (in the frontend directory) built using TypeScript. It includes components, pages, hooks, and GraphQL querying mechanisms (using URQL). This part of the system manages the user interface, client-side routing, and interactions such as viewing folders, files, and commenting.
- Backend: A Node.js server (in the backend directory) that handles:
- HTTP routing via Express (see backend/express)
- Authentication (backend/auth)
- GraphQL API server with queries, mutations, enums, and types (backend/graphql)
- Database interactions via models (backend/db)
- File and media management (backend/filesystem and backend/media) which include monitoring, file hashing, and thumbnail generation
- Helper modules for business logic (backend/helpers), configuration (backend/config), and logging (backend/logger)
- Database: A Postgres database as indicated in the README and Docker instructions (typically deployed as a separate container via docker-compose).
- External services: The system may integrate with external services and libraries (e.g., Docker for deployment, ffmpeg for media processing, JWT-based authentication, and potentially image processing tools).

##### Relationships and Interactions
- Within the backend, show separate submodules:
- An Express server module which listens for HTTP requests. From Express, a flow goes into the GraphQL server for API calls.
- Authentication components (JWT management, user lookup) handle the security aspects before allowing access to backend functionality.
- File system and media processing modules run background processes for file management (watchers, queues) and generating thumbnails for images and videos. Indicate interactions between these modules and the GraphQL server for triggering tasks like thumbnail generation or zip file creation.
- Configuration and bootstrapping modules (backend/boot and backend/config) that initialize environment variables, run migrations, etc.

##### Architectural Patterns and Design Principles
- Clearly distinguish between presentation (frontend) and business logic (backend), following a layered architecture.
- Microservice-like separation within the backend (e.g., dedicated modules for authentication, file system events, and GraphQL API).
- Clear separation of concerns: authentication is isolated, database models are in one location, and UI components are well-structured.
- That containerization (using Docker) ensures that services (for example, web server and Postgres DB) are managed and deployed in isolated environments.

##### Final Composition
- Point from the frontend to the backend which is further divided into several functional layers (API server, auth, file management, media processing).
- Finally, connect the backend to the database component.
- Incorporate Docker to illustrate that both the web server and the DB run as containers—this can be depicted as a larger “infrastructure” boundary that contains both Picr and Postgres.

## Diagram (Mermaid)

```mermaid
graph TD
    A["User"]:::external
    A -->|"starts"| B["Frontend (React + URQL)"]:::frontend
    B -->|"GraphQLAPICall"| C["Backend (Node.js)"]:::backend

    subgraph "Backend (Node.js)"
        D["Configuration"]:::module
        E["Bootstrapping/Migrations"]:::module
        D --> E

        F["HTTP Routing (Express)"]:::module
        G["Authentication Module"]:::module
        G --> F

        H["GraphQL API Server"]:::module
        F --> H

        I["Database Models"]:::module
        H --> I

        J["Filesystem Operations"]:::module
        H --> J

        K["Media Processing"]:::module
        J --> K

        L["Helper Modules"]:::module
        L --- H

        M["Logging"]:::module
        M --- H
    end

    C -->|"routes to"| F
    C -->|"handles"| H
    I -->|"Query/Mutation"| N["Database (Postgres)"]:::db
    C --> O["Docker Containerization"]:::infra
    N --> O

    click B "https://github.com/isaacinsoll/picr/tree/master/frontend/"
    click C "https://github.com/isaacinsoll/picr/tree/master/backend/"
    click F "https://github.com/isaacinsoll/picr/tree/master/backend/express/"
    click G "https://github.com/isaacinsoll/picr/tree/master/backend/auth/"
    click H "https://github.com/isaacinsoll/picr/tree/master/backend/graphql/"
    click I "https://github.com/isaacinsoll/picr/tree/master/backend/db/"
    click J "https://github.com/isaacinsoll/picr/tree/master/backend/filesystem/"
    click K "https://github.com/isaacinsoll/picr/tree/master/backend/media/"
    click L "https://github.com/isaacinsoll/picr/tree/master/backend/helpers/"
    click D "https://github.com/isaacinsoll/picr/tree/master/backend/config/"
    click E "https://github.com/isaacinsoll/picr/tree/master/backend/boot/"
    click M "https://github.com/isaacinsoll/picr/blob/master/backend/logger.ts"
    click O "https://github.com/isaacinsoll/picr/tree/master/Dockerfile"

    classDef external fill:#FFFACD,stroke:#B8860B,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef db fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef infra fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef module fill:#e2e3e5,stroke:#d6d8db,stroke-width:2px;
```
