# david12-ops/project_m architecture

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

- Interactive diagram: https://gitdiagram.com/david12-ops/project_m
- Repository: https://github.com/david12-ops/project_m

## Overview

##### Project type and purpose
- From the file tree and minimal README, we see a Next.js-based full-stack web application (“Project_M”)
- It uses React/Next.js for the frontend, Apollo Client for GraphQL queries, Next.js API routes as a GraphQL server, and Firebase (Auth + Firestore) as its backend/data store

##### File structure
- Top-level:
- next.config.js, pages/ – Next.js entry points
- copmonents/ – reusable React UI components (cards, forms, modals, navbar, etc.)
- pages/api/ – API routes: graphql.ts (Apollo Server), verify-token.ts, hello.ts
- firebase/ – client and admin Firebase config + auth utilities
- utility/ – Apollo Client setup, Emotion cache, shared helpers
- queris/ – .graphql files with queries/mutations grouped by domain (Package, Supplier, History)
- generated/ – codegen’d GraphQL types
- Patterns:
- Full-stack SSR/SSG via Next.js
- API layer: GraphQL endpoint built on Apollo Server (Next API route)
- Data layer: Firebase Auth (client + admin) and Firestore
- Typesafety via codegen

##### README (scant info)
- No architecture section, so we infer from dependencies & folder names

a. Main components
- Client (Next.js/React in the browser)
- Apollo Client (in the browser)
- Next.js server / API routes
- Apollo Server (GraphQL resolvers)
- Firebase Auth (client & admin SDK)
- Firestore (data persistence)
- Codegen process (offline build step)
b. Relationships & interactions
1. Browser → Next.js (SSR) / React pages
2. React UI uses Apollo Client to send GraphQL operations (defined in queris/) to /api/graphql
3. Next.js API route runs Apollo Server, invokes resolvers
4. Resolvers use firebase-admin SDK to read/write Firestore & verify tokens
5. Responses returned via GraphQL to Apollo Client → UI
6. Firebase Auth on client handles login/register flows (via firebase/auth-utils.tsx)
c. Architectural patterns/design principles
- Three-tier architecture (UI / API / Data)
- API Gateway via Next.js API routes
- Code-first or schema-first GraphQL approach with codegen
- Authentication + Authorization via JWTs in GraphQL context
d. Key technologies/frameworks
- Next.js (SSR, routing, API routes)
- React & Emotion (UI, styling)
- Apollo Client & Apollo Server (GraphQL)
- Firebase Auth & Firestore (backend)
- GraphQL Code Generator (type safety)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client (Next.js/React)"
        direction TB
        pages["pages/"]:::client
        components["components/"]:::client
        public["public/"]:::client
        styles["styles/"]:::client
    end

    ApolloClient["Apollo Client\n(utility/apollo-client.ts)"]:::client

    subgraph "Server/API (Next.js)"
        direction TB
        GraphQLAPI["/api/graphql\nApollo Server"]:::server
        VerifyToken["/api/verify-token.ts"]:::server
        Hello["/api/hello.ts"]:::server
    end

    subgraph "Firebase Auth (Client SDK)"
        direction TB
        AuthUtils["auth-utils.tsx"]:::client
        Config["config.ts"]:::client
    end

    subgraph "Firebase Admin & Firestore"
        direction TB
        AdminConfig["firebase-admin-config.ts"]:::data
        Firestore["Firestore"]:::data
    end

    subgraph "GraphQL Queries & Mutations"
        direction TB
        Queries["queris/"]:::server
    end

    subgraph "GraphQL Codegen (Build time)"
        direction TB
        CodegenYML["codegen.yml"]:::codegen
        Generated["generated/graphql.tsx"]:::codegen
        GenTSX["generaze-graph.tsx"]:::codegen
    end

    pages -->|uses| ApolloClient
    components -->|uses| ApolloClient
    public -->|serves| ApolloClient
    styles -->|styles for UI| ApolloClient

    ApolloClient -->|sends GraphQL ops| GraphQLAPI

    AuthUtils <-->|login/register| pages
    AuthUtils -->|provides token to| GraphQLAPI

    GraphQLAPI -->|invokes resolvers via| AdminConfig
    AdminConfig -->|reads/writes| Firestore

    CodegenYML -->|generates types| Generated
    CodegenYML -->|generates code| GenTSX

    classDef client fill:#cce5ff,stroke:#0066cc,color:#003366
    classDef server fill:#ccffcc,stroke:#339933,color:#003300
    classDef data fill:#ffe0b2,stroke:#ff9800,color:#e65100
    classDef codegen fill:#f3e5f5,stroke:#9c27b0,color:#4a148c

    click pages "https://github.com/david12-ops/project_m/tree/main/pages/"
    click components "https://github.com/david12-ops/project_m/tree/main/copmonents/"
    click public "https://github.com/david12-ops/project_m/tree/main/public/"
    click styles "https://github.com/david12-ops/project_m/tree/main/styles/"
    click ApolloClient "https://github.com/david12-ops/project_m/blob/main/utility/apollo-client.ts"
    click GraphQLAPI "https://github.com/david12-ops/project_m/blob/main/pages/api/graphql.ts"
    click VerifyToken "https://github.com/david12-ops/project_m/blob/main/pages/api/verify-token.ts"
    click Hello "https://github.com/david12-ops/project_m/blob/main/pages/api/hello.ts"
    click AuthUtils "https://github.com/david12-ops/project_m/blob/main/firebase/auth-utils.tsx"
    click Config "https://github.com/david12-ops/project_m/blob/main/firebase/config.ts"
    click AdminConfig "https://github.com/david12-ops/project_m/blob/main/firebase/firebase-admin-config.ts"
    click Queries "https://github.com/david12-ops/project_m/tree/main/queris/"
    click CodegenYML "https://github.com/david12-ops/project_m/blob/main/codegen.yml"
    click Generated "https://github.com/david12-ops/project_m/blob/main/generated/graphql.tsx"
    click GenTSX "https://github.com/david12-ops/project_m/blob/main/generaze-graph.tsx"
```
