# amfoss/home architecture

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

- Interactive diagram: https://gitdiagram.com/amfoss/home
- Repository: https://github.com/amfoss/home

## Overview

##### Project Type and Purpose
- This is a full-stack React application built with Next.js (App Router).
- It provides authentication (login/logout), a member dashboard with attendance tracking, coding-problem leaderboards, and profile pages.
- It uses Apollo Client for GraphQL queries/mutations and Tailwind CSS for styling.

##### Main Components
a. Client (Browser)
- Renders React pages/components.
- Initiates navigation and GraphQL queries/mutations via Apollo Client.
b. Next.js Server
- Handles server-side rendering (SSR) and routing (src/app).
- Serves static assets (public/) and CSS.
- Hosts API routes or GraphQL proxy if implemented in Next.js.
c. Apollo Client Layer (src/lib/apollo-client.ts + ProviderApollo)
- Wraps the app to provide GraphQL data fetching capabilities.
d. UI Components (src/components/)
- Calendar, Card, LeaderboardTable, Sidebar, etc.
- AttendanceDetails nested under attendance-track.
e. Context Providers (src/context/)
- SelectedButtonContext: manages UI state.
- ProviderApollo: injects Apollo Client into React tree.
f. Services / Data Layer (src/services/)
- attendance-service.ts: GraphQL/REST calls for attendance.
- streak-service.ts: calls to compute streaks.
g. External Systems
- Authentication backend (could be an OAuth/OpenID or custom API).
- GraphQL API Server (hosted separately or as Next.js API routes).
- Vercel (or Netlify) for deployment.

##### Relationships and Data Flow
1. Browser → Next.js Server
- User navigates to /login, /dashboard, etc.
- Next.js SSR returns HTML.
2. React Components → Apollo Client
- On page load or user action, components call Apollo Client.
3. Apollo Client → GraphQL API
- Queries/mutations travel over HTTP to the remote GraphQL endpoint.
4. GraphQL API → Database / Auth Service
- The backend resolves data, applies business logic, and returns responses.
5. Next.js Static Assets
- CSS from tailwind.config.ts, static images under public/, served directly.

##### Architectural Patterns and Principles
- Separation of concerns: UI components, context, data-services, and Apollo setup are modular.
- App Router (file-based routing) for page organization and dynamic routes ([memberId]).
- Context for cross-cutting state; Services for data access.
- Client-side caching and SSR for performance.

- Clear labels for each module and directory (e.g., “UI Components (src/components)”).
- Annotations for dynamic routing, context providers, and styling engine (Tailwind).

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Client Browser"
        direction TB
        Pages["React Pages (src/app/**)"]:::client
        Assets["Static Assets (public/)"]:::client
        Components["UI Components (src/components)"]:::client
        Context["Context Providers (src/context)"]:::client
        ApolloLayer["Apollo Client (src/lib/apollo-client.ts)"]:::client
        Services["Data Services (src/services)"]:::client
        Styling["Styling & Config"]:::client
    end

    subgraph "Next.js Server"
        direction TB
        AppRouter["App Router (src/app/)"]:::server
        APIRoutes["API Routes"]:::server
        StaticServer["Static Assets & CSS Server"]:::server
    end

    subgraph "External Services"
        direction TB
        GraphQL["GraphQL API Server"]:::external
        AuthService["Authentication Backend"]:::external
        DB["Database"]:::external
        Deploy["Vercel/Netlify & CI/CD"]:::external
    end

    Pages -->|"HTTP GET SSR"| AppRouter
    AppRouter -->|"HTML Response"| Pages

    Pages -->|"GraphQL Query/Mutation"| ApolloLayer
    Components -->|"useApolloClient()"| ApolloLayer
    ApolloLayer -->|"HTTP GraphQL"| GraphQL
    GraphQL -->|"auth check"| AuthService
    GraphQL -->|"data read/write"| DB

    Assets -->|"served by"| StaticServer
    Styling -->|"Tailwind CSS, Configs"| StaticServer

    Services -->|"called by UI Components"| Components
    Context -->|"provides state to"| Components

    Deploy -->|"deploys"| AppRouter
    Deploy -->|"deploys static"| StaticServer
    Deploy -->|"ci/cd pipeline"| GraphQL

    click Pages "https://github.com/amfoss/home/tree/main/src/app/"
    click Assets "https://github.com/amfoss/home/tree/main/public/"
    click Components "https://github.com/amfoss/home/tree/main/src/components/"
    click Context "https://github.com/amfoss/home/tree/main/src/context/"
    click ApolloLayer "https://github.com/amfoss/home/blob/main/src/lib/apollo-client.ts"
    click Services "https://github.com/amfoss/home/tree/main/src/services/"
    click Styling "https://github.com/amfoss/home/blob/main/tailwind.config.ts"
    click AppRouter "https://github.com/amfoss/home/blob/main/src/app/page.tsx"
    click APIRoutes "https://github.com/amfoss/home/tree/main/src/app/api/"
    click StaticServer "https://github.com/amfoss/home/blob/main/src/styles/globals.css"
    click GraphQL "https://github.com/amfoss/home/tree/main/src/app/api/graphql/"
    click AuthService "https://github.com/amfoss/home/blob/main/src/context/ProviderApollo.tsx"
    click DB "https://github.com/amfoss/home/blob/main/src/services/attendance-service.ts"
    click Deploy "https://github.com/amfoss/home/blob/main/netlify.toml"

    classDef client fill:#D0E6FF,stroke:#0284C7,color:#0C4A6E
    classDef server fill:#D1FAE5,stroke:#047857,color:#065F46
    classDef external fill:#FFEDD5,stroke:#D97706,color:#92400E
```
