# wjsoj/phybench-website architecture

> Architecture diagram of the GitHub repository wjsoj/phybench-website, 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/wjsoj/phybench-website
- Repository: https://github.com/wjsoj/phybench-website

## Overview

##### Main Components
- User Interface (UI) / Frontend:
- Represented by the Next.js “app” directory (src/app), which includes pages for various functions such as admin actions (e.g., calculate score, download problem, examine control), chat, problem views, submissions, and profiles.
- The “components” directory (src/components) houses reusable UI components (cards, buttons, modals) and feature-specific components (e.g., chat components, markdown editors, and admin panels).
- Server/API Layer:
- The API routes are under src/app/api. They cover authentication (using NextAuth, as indicated by the auth folder), chat (completions and standard routes), and various data retrieval endpoints (like getproblem, getexamineproblems, getuser, and others).
- This layer is responsible for handling business logic, authentication, and interfacing between the frontend and the database.
- Database:
- The Prisma folder contains the schema file (prisma/schema.prisma) and numerous migration directories that detail changes to the database over time.
- The connection is likely managed through a Prisma client (see src/prisma.ts).
- Supporting Infrastructure:
- Containerization: Dockerfile and docker-compose.yml indicate that the app can be containerized for consistent deployments.
- CI/CD: The .github/workflows directory contains build, test, and deploy configuration files.
- Testing: The __tests__ directory and Vitest configuration files (vitest.config.ts, vitest.setup.ts) show that unit and integration tests are in place.
- Configuration & Tooling: Files like next.config.ts, tailwind.config.mjs, eslint.config.mjs, and various TypeScript config files set up the development environment.

- Database connectivity:
- Integration with CI/CD and Deployment:

##### Architectural Patterns and Design Principles
- Next.js approach that merges frontend and backend logic (co-located API routes and page components).
- Design patterns such as:
- Component-based UI (React components).
- API Gateway-like behavior for handling various routes (authentication, chat, data).
- Modularization in the codebase (distinct directories for app pages, components, lib functions, and mocks for testing).
- That the API endpoints are arranged by functionality (e.g., auth, data, chat), making the architecture clear and maintainable.

##### Relevant Technologies and Tools
- Next.js: for both server-side rendering and API route handling.
- React: along with functional components and hooks (visible in src/components and src/lib/hooks.tsx).
- Prisma: for ORM and database migrations.
- Docker & docker-compose: containerization and local environment simulation.
- GitHub Workflows and testing tools (Vitest) for streamlined CI/CD and quality assurance.
- Tailwind CSS (configured via tailwind.config.mjs) for styling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Browser["Browser (User)"]:::external

    %% Next.js Frontend Layer
    subgraph "Next.js Frontend"
        FN1["Pages (UI)"]:::ui
        FN2["Reusable UI Components"]:::ui
    end

    %% Next.js Server / API Layer
    subgraph "Next.js Server / API Layer"
        APIAuth["API Routes - Authentication"]:::api
        APIChat["API Routes - Chat"]:::api
        APIData["API Routes - Data"]:::api
    end

    %% Database Layer
    subgraph "Database Layer"
        DBSchema["Database Schema"]:::db
        DBMigrations["Database Migrations"]:::db
        PrismaClient["Prisma Client Integration"]:::db
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        Dockerfile["Dockerfile"]:::infra
        DockerCompose["docker-compose.yml"]:::infra
        CICD["CI/CD Pipelines"]:::infra
        TestsFolder["__tests__"]:::infra
        VitestConfig["vitest.config.ts"]:::infra
        VitestSetup["vitest.setup.ts"]:::infra
    end

    %% Connections
    Browser -->|"UI_request"| FN1
    FN2 ---|"components"| FN1

    FN1 -->|"auth_request"| APIAuth
    FN1 -->|"chat_request"| APIChat
    FN1 -->|"data_request"| APIData

    APIAuth -->|"db_query"| PrismaClient
    APIChat -->|"db_query"| PrismaClient
    APIData -->|"db_query"| PrismaClient

    PrismaClient -->|"accesses"| DBSchema
    DBMigrations -->|"defines"| DBSchema

    CICD -->|"triggers"| Dockerfile
    CICD -->|"triggers"| DockerCompose

    Dockerfile -->|"hosts"| APIAuth
    Dockerfile -->|"hosts"| APIChat
    Dockerfile -->|"hosts"| APIData

    DockerCompose -->|"hosts"| PrismaClient
    DockerCompose -->|"hosts"| DBSchema

    TestsFolder -->|"tests_UI"| FN1
    VitestConfig -->|"tests_API"| APIAuth
    VitestSetup -->|"tests_API"| APIChat

    %% Styles
    classDef ui fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef db fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
    classDef infra fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events
    click FN1 "https://github.com/wjsoj/phybench-website/tree/main/src/app"
    click FN2 "https://github.com/wjsoj/phybench-website/tree/main/src/components"
    click APIAuth "https://github.com/wjsoj/phybench-website/tree/main/src/app/api/auth"
    click APIChat "https://github.com/wjsoj/phybench-website/tree/main/src/app/api/chat"
    click APIData "https://github.com/wjsoj/phybench-website/tree/main/src/app/api/data"
    click DBSchema "https://github.com/wjsoj/phybench-website/blob/main/prisma/schema.prisma"
    click DBMigrations "https://github.com/wjsoj/phybench-website/tree/main/prisma/migrations"
    click PrismaClient "https://github.com/wjsoj/phybench-website/blob/main/src/prisma.ts"
    click Dockerfile "https://github.com/wjsoj/phybench-website/tree/main/Dockerfile"
    click DockerCompose "https://github.com/wjsoj/phybench-website/blob/main/docker-compose.yml"
    click CICD "https://github.com/wjsoj/phybench-website/tree/main/.github/workflows"
    click TestsFolder "https://github.com/wjsoj/phybench-website/tree/main/__tests__"
    click VitestConfig "https://github.com/wjsoj/phybench-website/blob/main/vitest.config.ts"
    click VitestSetup "https://github.com/wjsoj/phybench-website/blob/main/vitest.setup.ts"
```
