# waterrmalann/bit-warriors-nextjs architecture

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

- Interactive diagram: https://gitdiagram.com/waterrmalann/bit-warriors-nextjs
- Repository: https://github.com/waterrmalann/bit-warriors-nextjs

## Overview

##### Project type and purpose
- This is the **frontend** microservice of **BitWarriors**, a MERN-based, Next.js/React SSR application that serves as the UI layer in a larger **microservices** architecture. It handles user authentication flows, problem browsing/submission pages, dashboards, and landing pages. All backend operations (auth, problems, submissions, leaderboards, etc.) are exposed via a separate API Gateway and microservices (not in this repo).

##### File structure
- **src/app/** (Next.js “app router”): server-rendered routes for
- /(landing): public landing, terms, privacy, guidelines
- /(auth): login, register, MFA, OAuth callbacks (GitHub/Google), email verification
- /(dashboard): home, problems, submissions, top, profile, user profiles
- **src/components/**: reusable UI components, top-level (Logo, CodeEditor, Terminal, etc.)
- **src/components/ui/**: design-system primitives (buttons, cards, forms, tables, toast, etc.)
- **src/hooks/**: data-fetch hooks that call the backend API via Axios
- **src/lib/**: Axios configuration, route constants, utility functions
- **public/**: static assets
- Config files: next.config.js, tailwind.config.js, tsconfig.json, ESLint, etc.

##### README for additional insights
- It’s part of a **microservices** ecosystem: this repo only contains the Next.js UI; the backend API Gateway + individual services (Auth, Problem, User, Leaderboard, etc.) live in a separate repo.
- Tech stack: Next.js (SSR/SSG), React, TypeScript, TailwindCSS, PNPM, Axios, Node/Express, MongoDB (backend).

##### Final advice
- Be **granular**: break down the frontend service into SSR, routing, UI layer, data-fetching layer, and static assets.
- **all integration points**: OAuth flows, API Gateway, microservices, DB.
- Critical configuration (e.g., next.config.js for redirects, tailwind.config for theming).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Browser
    Browser["User Browser"]:::external

    %% Frontend Microservice
    subgraph "Frontend Microservice (BitWarriors UI)" 
        direction TB

        subgraph "Next.js Server (SSR & App Router)" 
            direction TB
            NextSSR["Next.js SSR & App Router"]:::frontend
            NextConfig["Next.js Config"]:::config
        end

        %% Routes
        subgraph "Routes"
            direction TB
            Landing["Landing Pages"]:::frontend
            AuthRoutes["Auth & OAuth Callbacks"]:::frontend
            DashboardRoutes["Dashboard Pages"]:::frontend
        end

        %% Client UI
        subgraph "React UI Layer"
            direction TB
            UIComponents["UI Components"]:::frontend
            UIPLibrary["Design System Primitives"]:::frontend
        end

        %% Data Fetch
        subgraph "Data-Fetch Layer"
            direction TB
            Hooks["Custom Hooks"]:::frontend
            Lib["Axios Config & Routes"]:::frontend
        end

        Assets["Static Assets"]:::assets

        %% Internal flows
        Browser -->|"Initial SSR"| NextSSR
        NextSSR -->|"renders routes"| Landing
        NextSSR -->|"renders routes"| AuthRoutes
        NextSSR -->|"renders routes"| DashboardRoutes
        NextSSR -->|"serves assets"| Assets
        Landing --> LinkClient
        AuthRoutes --> LinkClient
        DashboardRoutes --> LinkClient

        %% Hydration
        LinkClient["React Hydration"]:::frontend
        NextSSR --> LinkClient
        LinkClient --> UIComponents
        UIComponents --> UIPLibrary
        UIComponents --> Hooks
        Hooks --> Lib
        Lib -->|"HTTP Calls"| APIGateway
        LinkClient -->|"API Calls"| APIGateway
        APIGateway --> AuthService
        APIGateway --> UserService
        APIGateway --> ProblemsService
        APIGateway --> SubmissionsService
        APIGateway --> LeaderboardService

        %% OAuth
        OAuthGitHub["GitHub OAuth"]:::external
        OAuthGoogle["Google OAuth"]:::external
        Browser -->|Redirect| OAuthGitHub
        Browser -->|Redirect| OAuthGoogle
        OAuthGitHub -->|Callback| AuthRoutes
        OAuthGoogle -->|Callback| AuthRoutes
    end

    %% Backend Microservices & DB
    subgraph "API Gateway & Microservices"
        direction TB
        APIGateway["API Gateway"]:::service
        AuthService["Auth Service"]:::service
        UserService["User Service"]:::service
        ProblemsService["Problems Service"]:::service
        SubmissionsService["Submissions Service"]:::service
        LeaderboardService["Leaderboard Service"]:::service
    end

    subgraph "Datastore"
        direction TB
        MongoDB["MongoDB Cluster"]:::db
    end

    %% Service to DB
    AuthService --> MongoDB
    UserService --> MongoDB
    ProblemsService --> MongoDB
    SubmissionsService --> MongoDB
    LeaderboardService --> MongoDB

    %% Click Events
    click NextSSR "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/app/"
    click NextConfig "https://github.com/waterrmalann/bit-warriors-nextjs/blob/main/next.config.js"
    click Landing "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/app/(landing)/"
    click AuthRoutes "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/app/(auth)/"
    click DashboardRoutes "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/app/(dashboard)/"
    click UIComponents "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/components/"
    click UIPLibrary "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/components/ui/"
    click Hooks "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/hooks/"
    click Lib "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/src/lib/"
    click Assets "https://github.com/waterrmalann/bit-warriors-nextjs/tree/main/public/"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef service fill:#FFF3E0,stroke:#E65100,color:#E65100;
    classDef db fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20;
    classDef external stroke-dasharray: 5 5,fill:#F5F5F5,stroke:#9E9E9E,color:#616161;
    classDef config fill:#EDE7F6,stroke:#5E35B1,color:#5E35B1;
    classDef assets fill:#FFFDE7,stroke:#F9A825,color:#F9A825;
```
