# kudith/notario architecture

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

- Interactive diagram: https://gitdiagram.com/kudith/notario
- Repository: https://github.com/kudith/notario

## Overview

##### Project type and purpose
- This is a full-stack Next.js application that provides a document signing and verification platform. Users can register, authenticate, upload documents, add QR codes, sign documents, verify signatures, and download completed files. The backend is implemented as Next.js App-Router API routes (serverless functions), and the frontend uses React components under the `app/` directory.

##### File structure
- Top-level “app” directory holds both UI pages (`app/page.js`, `app/register`, `app/sign`, etc.) and the API routes under `app/api/`.
- API routes are organized by domain:
- `auth` (NextAuth adapter)
- `register`, `verify-email`, `resend-verification`
- `user` (profile, avatar, documents, settings)
- `documents` (upload, analyze, sign, verify, download, QR-code)
- Shared business logic lives in `lib/` (e.g. `lib/document-service.js`, `lib/auth-adapter.js`, `lib/google-drive.js`, `lib/cloudinary.js`, `lib/prisma.js`).
- `components/` holds all UI building blocks.
- `prisma/schema.prisma` defines the database model.
- `middleware.js` enforces auth on protected routes.

##### Essential architectural elements
– Do not list every single file; instead, represent each domain (auth, user, documents) as a single API cluster.
– Capture the service layer abstraction and the flow to both database and external services.
– Highlight that this is a serverless Next.js architecture with React front-end.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser)"
        client["Browser"]:::frontend
        appPage["app/page.js"]:::frontend
        layout["app/layout.js"]:::frontend
        loginPage["app/login/page.jsx"]:::frontend
        registerPage["app/register/page.jsx"]:::frontend
        dashboardPage["app/dashboard/page.jsx"]:::frontend
        profilePage["app/profile/page.jsx"]:::frontend
        signPage["app/sign/page.js"]:::frontend
        verifyPage["app/verify/page.js"]:::frontend
        verifyIdPage["app/verify/[certificateId]/page.js"]:::frontend
        verifyEmailPage["app/verify-email/page.js"]:::frontend
        componentsDir["components/"]:::frontend
    end

    %% Serverless Functions Layer
    subgraph "Serverless Functions (app/api)"    
        subgraph "Auth API"    
            authNextAuth["[...nextauth]"]:::api
            registerAPI["register"]:::api
            verifyEmailAPI["verify-email"]:::api
            resendVerAPI["resend-verification"]:::api
        end
        subgraph "User API"
            userMe["user/me"]:::api
            userById["user/[id]"]:::api
            avatarAPI["user/avatar"]:::api
            changeAlg["user/change-algorithm"]:::api
            updateKeys["user/updateKeys"]:::api
            userDocs["user/documents"]:::api
        end
        subgraph "Documents API"
            docsAPI["documents"]:::api
            addQR["documents/add-qrcode"]:::api
            analyze["documents/analyze"]:::api
            check["documents/check"]:::api
            diagnose["documents/diagnose-signature"]:::api
            sign["documents/sign"]:::api
            verifyDoc["documents/verify"]:::api
            download["documents/download"]:::api
        end
        uploadAPI["upload"]:::api
    end

    middleware["middleware.js"]:::service

    %% Service Layer
    subgraph "Service Layer (lib)"
        docService["document-service.js"]:::service
        authAdapter["auth-adapter.js"]:::service
        cloudinary["cloudinary.js"]:::service
        googleDrive["google-drive.js"]:::service
        prismaLib["prisma.js"]:::service
        utils["utils.js"]:::service
    end

    %% Database
    prismaSchema["prisma/schema.prisma"]:::database
    database["Database (PostgreSQL/MySQL)"]:::database

    %% External Services
    cloudStorage["Cloudinary Storage"]:::external
    driveStorage["Google Drive"]:::external
    emailSvc["Email Service"]:::external

    %% Connections
    client -->|"requests"| authNextAuth
    client --> registerAPI
    client --> userMe
    client --> docsAPI
    client --> uploadAPI

    authNextAuth --> middleware
    registerAPI --> middleware
    userMe --> middleware
    docsAPI --> middleware
    uploadAPI --> middleware

    middleware --> authAdapter
    middleware --> docService

    authAdapter --> prismaLib
    authAdapter --> emailSvc

    docService --> prismaLib
    docService --> cloudinary
    docService --> googleDrive

    prismaLib --> prismaSchema
    prismaSchema --> database

    cloudinary --> cloudStorage
    googleDrive --> driveStorage

    %% Click Events
    click appPage "https://github.com/kudith/notario/blob/main/app/page.js"
    click layout "https://github.com/kudith/notario/blob/main/app/layout.js"
    click loginPage "https://github.com/kudith/notario/blob/main/app/login/page.jsx"
    click registerPage "https://github.com/kudith/notario/blob/main/app/register/page.jsx"
    click dashboardPage "https://github.com/kudith/notario/blob/main/app/dashboard/page.jsx"
    click profilePage "https://github.com/kudith/notario/blob/main/app/profile/page.jsx"
    click signPage "https://github.com/kudith/notario/blob/main/app/sign/page.js"
    click verifyPage "https://github.com/kudith/notario/blob/main/app/verify/page.js"
    click verifyIdPage "https://github.com/kudith/notario/blob/main/app/verify/[certificateId]/page.js"
    click verifyEmailPage "https://github.com/kudith/notario/blob/main/app/verify-email/page.js"
    click componentsDir "https://github.com/kudith/notario/tree/main/components/"

    click authNextAuth "https://github.com/kudith/notario/blob/main/app/api/auth/[...nextauth]/route.js"
    click registerAPI "https://github.com/kudith/notario/blob/main/app/api/register/route.js"
    click verifyEmailAPI "https://github.com/kudith/notario/blob/main/app/api/verify-email/route.js"
    click resendVerAPI "https://github.com/kudith/notario/blob/main/app/api/resend-verification/route.js"

    click userMe "https://github.com/kudith/notario/blob/main/app/api/user/me/route.js"
    click userById "https://github.com/kudith/notario/blob/main/app/api/user/[id].js"
    click avatarAPI "https://github.com/kudith/notario/blob/main/app/api/user/avatar/route.js"
    click changeAlg "https://github.com/kudith/notario/blob/main/app/api/user/change-algorithm/route.js"
    click updateKeys "https://github.com/kudith/notario/blob/main/app/api/user/updateKeys/route.js"
    click userDocs "https://github.com/kudith/notario/blob/main/app/api/user/documents/route.js"

    click docsAPI "https://github.com/kudith/notario/blob/main/app/api/documents/route.js"
    click addQR "https://github.com/kudith/notario/blob/main/app/api/documents/add-qrcode/route.js"
    click analyze "https://github.com/kudith/notario/blob/main/app/api/documents/analyze/route.js"
    click check "https://github.com/kudith/notario/blob/main/app/api/documents/check/route.js"
    click diagnose "https://github.com/kudith/notario/blob/main/app/api/documents/diagnose-signature/route.js"
    click sign "https://github.com/kudith/notario/blob/main/app/api/documents/sign/route.js"
    click verifyDoc "https://github.com/kudith/notario/blob/main/app/api/documents/verify/route.js"
    click download "https://github.com/kudith/notario/blob/main/app/api/documents/download/route.js"

    click uploadAPI "https://github.com/kudith/notario/blob/main/app/api/upload/route.js"

    click middleware "https://github.com/kudith/notario/blob/main/middleware.js"

    click docService "https://github.com/kudith/notario/blob/main/lib/document-service.js"
    click authAdapter "https://github.com/kudith/notario/blob/main/lib/auth-adapter.js"
    click cloudinary "https://github.com/kudith/notario/blob/main/lib/cloudinary.js"
    click googleDrive "https://github.com/kudith/notario/blob/main/lib/google-drive.js"
    click prismaLib "https://github.com/kudith/notario/blob/main/lib/prisma.js"
    click utils "https://github.com/kudith/notario/blob/main/lib/utils.js"

    click prismaSchema "https://github.com/kudith/notario/blob/main/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085
    classDef api fill:#d4edda,stroke:#155724
    classDef service fill:#fff3cd,stroke:#856404
    classDef database fill:#ffeeba,stroke:#665c00
    classDef external fill:#e2e3e5,stroke:#6c757d
```
