# hungtrungthinh/simple-nextjs-file-server architecture

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

- Interactive diagram: https://gitdiagram.com/hungtrungthinh/simple-nextjs-file-server
- Repository: https://github.com/hungtrungthinh/simple-nextjs-file-server

## Overview

##### Project Type and Purpose
- This is a monolithic, server-rendered Next.js 13 application whose sole responsibility is to serve static files from the `public` directory and show a 403 “Forbidden” page for any invalid paths.
- No database or external APIs are involved. Deployment is typically on Vercel or Dokploy.

##### File Structure
- Top-level files: `next.config.ts`, `tsconfig.json`, ESLint/PostCSS configs, and `package.json` scripts.
- `public/`: your “file store” – any files or subfolders here are exposed over HTTP.
- `src/app/`: Next 13 App Router
- `page.tsx`, `layout.tsx`, `globals.css` – main UI and layout
- `access-forbidden/page.tsx` – 403 UI
- `not-found.tsx` – 404 UI
- `src/middleware.ts`: intercepts all incoming requests and enforces “only serve what’s in public, otherwise 403”.

##### Extract Insights from the README
- Static-only file server
- Manual file upload to `public/`
- 403 on invalid or dynamic routes
- Deployment: Vercel or Dokploy (auto-detect Next.js)

##### Main Components
a. Clients (Browsers or HTTP clients)
b. Next.js Server (Node.js runtime)
– App Router (the routing layer in `src/app`)
– Middleware logic (`src/middleware.ts`)
– React/SSR renderers for 403, 404, homepage
c. File System Storage (`public/` directory)
d. Deployment Platform (Vercel / Dokploy – optional)

##### Relationships & Data Flows
1. Client → HTTP request to Next.js Server
2. Server.middleware inspects the path
- If file exists in `public/` → static asset served directly
- Else → render and return 403 page (or 404 where appropriate)
3. Server → HTTP response back to Client

##### Architectural Patterns & Technologies
- File-based routing (Next.js App Router)
- Middleware for access control
- Static asset hosting
- React / SSR for error pages
- Deployment via Vercel / Dokploy

## Diagram (Mermaid)

```mermaid
graph TB
    classDef client fill:#FFA500,stroke:#333,stroke-width:1px
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef storage fill:#90EE90,stroke:#333,stroke-width:1px
    classDef deploy fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef config fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef page fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef error fill:#ADD8E6,stroke:#333,stroke-width:1px

    Client["Client\n(Browser/HTTP Client)"]:::client
    FileStore["Static File Store\n(public/)"]:::storage
    Deployment["Deployment Platform\n(Vercel / Dokploy)"]:::deploy

    subgraph "Next.js Server" 
        direction TB
        Config["next.config.ts"]:::config
        Package["package.json"]:::config
        Middleware["Middleware Logic\n(src/middleware.ts)"]:::server
        AppRouter["App Router\n(src/app/)"]:::server

        subgraph "App Router Components"
            direction TB
            Homepage["Homepage UI\npage.tsx"]:::page
            Layout["Global Layout\nlayout.tsx"]:::page
            Globals["Global Styles\nglobals.css"]:::page
            ForbiddenPage["403 Forbidden Page\naccess-forbidden/page.tsx"]:::error
            NotFoundPage["404 Not Found Page\nnot-found.tsx"]:::error
        end
    end

    Client -->|HTTP request| Middleware
    Config --> Middleware
    Package --> Middleware
    Middleware -->|check path| FileStore
    FileStore -->|static-file response| Client
    Middleware -->|invalid path| AppRouter
    AppRouter -->|serve homepage| Homepage
    AppRouter -->|render layout| Layout
    AppRouter -->|apply styles| Globals
    AppRouter -->|403 render| ForbiddenPage
    AppRouter -->|404 render| NotFoundPage
    Homepage -->|HTTP response| Client
    ForbiddenPage -->|HTTP response| Client
    NotFoundPage -->|HTTP response| Client
    Deployment -.-> Middleware

    click Config "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/next.config.ts"
    click Package "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/package.json"
    click Middleware "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/src/middleware.ts"
    click AppRouter "https://github.com/hungtrungthinh/simple-nextjs-file-server/tree/main/src/app/"
    click Homepage "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/src/app/page.tsx"
    click Layout "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/src/app/layout.tsx"
    click Globals "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/src/app/globals.css"
    click ForbiddenPage "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/src/app/access-forbidden/page.tsx"
    click NotFoundPage "https://github.com/hungtrungthinh/simple-nextjs-file-server/blob/main/src/app/not-found.tsx"
    click FileStore "https://github.com/hungtrungthinh/simple-nextjs-file-server/tree/main/public/"
```
