# amanbairagi30/merged-n-share architecture

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

- Interactive diagram: https://gitdiagram.com/amanbairagi30/merged-n-share
- Repository: https://github.com/amanbairagi30/merged-n-share

## Overview

##### Main Components
- Frontend Client: Represented by the Next.js “app” directory. This includes pages, UI components (from the “src/components” directory), hooks, and utilities. It is responsible for rendering the user interface, handling routing, and initiating API calls.
- API Endpoints: Located under “src/app/api/…” (for analytics, authentication, leaderboard, PR, organisation, etc.). These endpoints encapsulate business logic and process client requests.
- Authentication Module: A specialized API route for NextAuth (found in “src/app/api/auth/[...nextauth]”) which handles user sign-in, session management, and integration with GitHub OAuth.
- Database Layer: PostgreSQL as the database, interfaced using Prisma ORM. The “prisma” directory contains migrations and the “schema.prisma” file, signifying data models and relationships.
- External Services: GitHub – as users’ merged pull requests are fetched from public GitHub repositories; and possibly analytics services (as indicated by the “analytics” API component).
- State Management & UI Frameworks: Zustand for state management; Tailwind CSS and Shadcn-UI for design components; and TypeScript defining types and project-wide contracts.
- Docker Configuration: A Dockerfile is provided to containerize the application for deployment.

##### Relationships and Interactions
- User interaction begins at the Frontend Client (UI and page components) that communicates with the internal API endpoints.
- The Authentication module (handled by NextAuth.js) secures API routes and manages user sessions.
- API endpoints handle the core functionalities such as fetching merged PRs, analytics data, and leaderboard information. They interact with the Database via the Prisma ORM.
- External calls: Some endpoints are likely interfacing with GitHub’s API to fetch pull request data.
- Third-party libraries (e.g., Zustand, Shadcn-UI) integrate on the client side to manage state and UI interactions.
- The Dockerfile ties everything together for deployment, ensuring that the environment is consistently reproduced.

##### Important Architectural Patterns and Design Principles
- Separation of Concerns: The project distinctly separates client-side UI from server-side API logic.
- API-First Interaction: Using Next.js API routes to encapsulate backend services.
- Modular Component Design: The “src/components” directory contains reusable UI elements, supporting modularity and reusability.
- ORM-based Data Access: Database interactions are abstracted through Prisma, which enforces schema migrations and consistency.
- Secure Authentication: Integration of NextAuth.js ensures standardized security via OAuth with GitHub.
- Containerization for Deployment: Docker support signals an environment that is prepared for scaling and consistent production environments.

##### Relevant Technologies
- Next.js (React framework for full-stack development)
- TypeScript (for type-safety across front and back ends)
- PostgreSQL (as the database)
- Prisma (ORM for database interactions)
- Tailwind CSS (for styling)
- NextAuth.js (for authentication)
- Zustand (state management)
- Docker (containerization)

- Optionally, include a Docker container boundary outlining the production/service deployment boundary.
- Optionally, annotate parts of the architecture that allow for future expansion (e.g., possibility to integrate additional third-party services or expand API endpoints).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U["User"]:::userStyle

    subgraph "Frontend Layer"
        F1["Next.js Pages"]:::frontend
        F2["UI Components"]:::frontend
        F3["Zustand Store"]:::frontend
        F4["Tailwind CSS"]:::frontend
        F5["Shadcn-UI Components"]:::frontend
    end

    subgraph "API Layer"
        A1["API Endpoints"]:::api
        A2["Authentication Module"]:::api
    end

    subgraph "Data Layer"
        D1["Prisma ORM"]:::db
        D2["PostgreSQL Database"]:::db
    end

    subgraph "External Services"
        E1["GitHub API"]:::external
        E2["Analytics Service"]:::external
    end

    subgraph "Deployment"
        DEP["Docker Container"]:::deployment
    end

    %% Connections
    U -->|"Access"| F1
    F1 -->|"renders"| F2
    F1 -->|"utilizes"| F3
    F1 -->|"styled_with"| F4
    F1 -->|"styled_with"| F5
    F1 -->|"calls_API"| A1
    A1 -->|"authenticates"| A2
    A1 -->|"db_operations"| D1
    D1 -->|"manages"| D2
    A1 -->|"fetches_PRs"| E1
    A1 -->|"sends_analytics"| E2
    DEP -->|"deploys"| F1
    DEP -->|"deploys"| A1
    DEP -->|"hosts"| D2

    %% Click Events
    click F1 "https://github.com/amanbairagi30/merged-n-share/tree/master/src/app"
    click F2 "https://github.com/amanbairagi30/merged-n-share/tree/master/src/components"
    click F3 "https://github.com/amanbairagi30/merged-n-share/tree/master/src/store"
    click F4 "https://github.com/amanbairagi30/merged-n-share/blob/master/tailwind.config.ts"
    click F5 "https://github.com/amanbairagi30/merged-n-share/tree/master/src/components/ui"
    click A1 "https://github.com/amanbairagi30/merged-n-share/tree/master/src/app/api"
    click A2 "https://github.com/amanbairagi30/merged-n-share/blob/master/src/app/api/auth/[...nextauth]/route.ts"
    click D1 "https://github.com/amanbairagi30/merged-n-share/tree/master/prisma"
    click DEP "https://github.com/amanbairagi30/merged-n-share/tree/master/Dockerfile"

    %% Styles
    classDef frontend fill:#D1E8FF,stroke:#1D4ED8,stroke-width:2px;
    classDef api fill:#FDE68A,stroke:#F59E0B,stroke-width:2px;
    classDef db fill:#C6F6D5,stroke:#2F855A,stroke-width:2px;
    classDef external fill:#FEE2E2,stroke:#C53030,stroke-width:2px;
    classDef deployment fill:#E2E8F0,stroke:#718096,stroke-width:2px;
    classDef userStyle fill:#FFF7ED,stroke:#D97706,stroke-width:2px;
```
