# amitpallai/notion architecture

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

- Interactive diagram: https://gitdiagram.com/amitpallai/notion
- Repository: https://github.com/amitpallai/notion

## Overview

##### Project type and purpose
- This is a full-stack web application (“Notion Clone”) built with Next.js (App Router) for the frontend and routing, Convex as a real-time database/backend, and Edge Store for file uploads. Its purpose is collaborative, hierarchical document editing with real-time updates, search, file uploads, trash management, theming, and responsive UI.

##### File structure
- Top-level directories and files:
- app/ – Next.js App Router folders, subdivided into (marketing), (public), and (main) route groups.
- components/ – Shared React UI components (modals, toolbar, provider wrappers, UI primitives).
- convex/ – Convex backend functions, schema, auto-generated API types and server modules.
- app/api/edgestore – Next.js API route(s) for file storage interactions (Edge Store).
- hooks/, lib/ – Custom React hooks and utility modules.
- Configuration: next.config.js, tailwind.config.ts, tsconfig.json, .env.example.
- Architectural cues:
- app/(main) hosts the authenticated application routes and UI components.
- app/(marketing) and app/(public) host unauthenticated marketing pages and preview routes.
- API routes under app/api handle file storage.
- Convex folder contains database schema, queries, mutations, and generated types.

##### README for additional insights
- Tech stack highlights: Next.js App Router, Convex for real-time backend and database, Edge Store for file uploads, Tailwind CSS for styling.
- Features emphasize real-time collaboration, hierarchical docs, search, file uploads, authentication, theming, responsive design.

##### Main components and interactions
a. Components
- Client Browser (React UI)
- Next.js Server (App Router)
– Route Groups: marketing, public/preview, main (authenticated)
– API Routes: /api/edgestore (file upload/download)
- Convex Real-Time Backend (queries & mutations, auth)
- Edge Store Service (file storage)
- Database (managed by Convex)
- External Auth Provider (if any; e.g., OAuth via Convex)
b. Relationships & Data Flow
1. Browser ↔ Next.js Server for SSR/SSG and React hydration
2. Browser ↔ Convex Client Library → Convex Backend (real-time DB operations)
3. Browser → Next.js API Route (/api/edgestore) → Edge Store → Next.js API Route → Browser
4. Next.js Server may also read config/env and pass secrets to Convex & Edge Store clients
c. Architectural patterns & principles
- Separation of concerns via App Router route groups
- Real-time event propagation via Convex Pub/Sub
- Serverless, edge-deployed API for file storage
- Component-based UI with providers (theme, modal, Convex)
- API & database schema co-located in convex/ folder
d. Key technologies
- Next.js App Router (app/ directory)
- React & Tailwind CSS for UI
- Convex (convex/ folder, client/server libs)
- Edge Store (app/api/edgestore)
- TypeScript throughout

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Browser" 
        direction TB
        Client["Client Browser\n(React UI, Convex Client)"]:::frontend
    end

    %% Next.js Server Layer
    subgraph "Next.js Server / App Router"
        direction TB
        MarketingRoutes["Marketing Routes\n(app/(marketing))"]:::server
        PublicPreviewRoutes["Public Preview Routes\n(app/(public)/preview)"]:::server
        MainRoutes["Main Authenticated Routes\n(app/(main))"]:::server
        APIEdgestore["API Route: /api/edgestore"]:::server
    end

    %% Edge Store Layer
    subgraph "Edge Store Service"
        direction TB
        EdgeStore["Edge Store Bucket"]:::storage
    end

    %% Convex Backend Layer
    subgraph "Convex Real-Time Backend"
        direction TB
        SchemaResolvers["Schema & Resolvers\n(convex/schema.ts,\nconvex/documents.ts)"]:::backend
        GeneratedAPI["Generated API & Types\n(convex/_generated/)"]:::backend
        AuthConfig["Auth Configuration\n(convex/auth.config.js)"]:::backend
        ConvexDB[(Convex Database)]:::storage
    end

    %% Connections
    Client -->|"HTTP/HTTPS|SSR, SSG"| MarketingRoutes
    Client -->|"HTTP/HTTPS|SSR, SSG"| PublicPreviewRoutes
    Client -->|"HTTP/HTTPS|SSR, SSG"| MainRoutes
    Client -->|"WebSocket/HTTP|Real-time Data"| SchemaResolvers
    Client -->|"WebSocket/HTTP|Real-time Data"| GeneratedAPI

    MainRoutes -->|"REST|File Upload/Download"| APIEdgestore
    APIEdgestore -->|"REST API"| EdgeStore
    EdgeStore -->|"REST API"| APIEdgestore
    APIEdgestore -->|"REST|Response"| Client

    MarketingRoutes --- MainRoutes
    PublicPreviewRoutes --- MainRoutes

    SchemaResolvers -->|"Reads/Writes"| ConvexDB
    GeneratedAPI -->|"Type Definitions"| SchemaResolvers
    AuthConfig -->|"Auth Setup"| GeneratedAPI

    %% Click Events
    click MarketingRoutes "https://github.com/amitpallai/notion/blob/master/app/(marketing)/layout.tsx"
    click PublicPreviewRoutes "https://github.com/amitpallai/notion/blob/master/app/(public)/(routes)/preview/[documentId]/page.tsx"
    click MainRoutes "https://github.com/amitpallai/notion/blob/master/app/(main)/layout.tsx"
    click APIEdgestore "https://github.com/amitpallai/notion/blob/master/app/api/edgestore/[...edgestore]/route.ts"
    click SchemaResolvers "https://github.com/amitpallai/notion/blob/master/convex/schema.ts"
    click GeneratedAPI "https://github.com/amitpallai/notion/blob/master/convex/_generated/api.d.ts"
    click AuthConfig "https://github.com/amitpallai/notion/blob/master/convex/auth.config.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,stroke-width:1px;
    classDef server fill:#ccffcc,stroke:#33cc33,stroke-width:1px;
    classDef backend fill:#fff2cc,stroke:#ffcc33,stroke-width:1px;
    classDef storage fill:#ffe5cc,stroke:#ff9933,stroke-width:1px;
```
