# cozero/engineering-hiring-challenge architecture

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

- Interactive diagram: https://gitdiagram.com/cozero/engineering-hiring-challenge
- Repository: https://github.com/cozero/engineering-hiring-challenge

## Overview

##### Project type and purpose
- This is a full-stack, monorepo-based application composed of three packages:
- `@cozero/client` – a React + Vite SPA that renders a metrics dashboard.
- `@cozero/server` – a NestJS REST API that connects to Postgres via Prisma.
- `@cozero/lib` – a shared TypeScript library supplying common types/utilities to both client and server.
- Its purpose is to display and manage “metrics” data stored in Postgres, with Docker Compose providing local orchestration.

##### File structure
- Top-level artifacts: `docker-compose.yml` (spins up Postgres and server), `initdb.sql` (seed data), workspace `package.json`, TypeScript configs.
- `packages/client`: React entry (`index.html`, `index.tsx`), config (`vite.config.ts`, Tailwind, PostCSS), UI components under `src/components`.
- `packages/server`: Nest CLI config, Prisma folder with schema & migrations, Nest modules under `src/modules` (e.g. `reports`, `ping`), main bootstrap in `main.ts`.
- `packages/lib`: Common code in `src/index.ts` with separate CJS/MJS outputs.
- Tests: Jest unit and e2e setups in both client and server.

##### README for additional insights
- Describes startup (Docker Compose, `db:migrate`, `yarn bootstrap`, separate dev servers).
- Architecture summary: highlights the three libraries and their roles.
- Emphasizes scalability, quality, and potential to add dependencies or improvements.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Orchestration"
    DC["Docker Compose"]:::orchestration
  end

  subgraph "Shared Library (@cozero/lib)"
    SL["src/index.ts"]:::lib
    SL_CJS["tsconfig-cjs.json"]:::lib
    SL_MJS["tsconfig-mjs.json"]:::lib
  end

  subgraph "Client (React + Vite)"
    HTML["index.html"]:::client
    VITE["vite.config.ts"]:::client
    TAIL["tailwind.config.js"]:::client
    ENTRY["src/index.tsx"]:::client
    APP["App.tsx"]:::client
  end

  subgraph "Server (NestJS API)"
    MAIN["src/main.ts"]:::server
    CONF["src/config.ts"]:::server
    PRISMA_SVC["src/prisma.service.ts"]:::server
    API_MODULE["src/modules/api.module.ts"]:::server
    PING["src/modules/ping.controller.ts"]:::server
    subgraph "Reports Module"
      REPORTS_MODULE["reports.module.ts"]:::server
      REPORTS_CTRL["reports.controller.ts"]:::server
      REPORTS_SVC["reports.service.ts"]:::server
    end
    PRISMA_SCHEMA["prisma/schema.prisma"]:::server
    MIG1["migrations/0_init/migration.sql"]:::server
    MIG2["migrations/1_demo_data/migration.sql"]:::server
  end

  subgraph "Database (Postgres)"
    POSTGRES["Postgres Container"]:::db
    INITDB["initdb.sql"]:::db
  end

  subgraph "Testing"
    SVC_TEST["reports.controller.spec.ts"]:::test
    SVC_TEST2["reports.service.spec.ts"]:::test
    E2E["app.e2e-test.ts"]:::test
    JEST_E2E["jest-e2e.json"]:::test
    CLIENT_TYPES["globals.d.ts"]:::test
  end

  DC -->|orchestrates| Server
  DC -->|orchestrates| POSTGRES
  ENTRY -->|imports| SL
  MAIN -->|imports| SL
  ENTRY -->|"HTTP/REST"| API_MODULE
  API_MODULE -->|"includes"| PING
  API_MODULE -->|"includes"| REPORTS_MODULE
  REPORTS_MODULE -->|"invokes"| REPORTS_SVC
  REPORTS_SVC -->|"calls"| PRISMA_SVC
  PRISMA_SVC -->|"executes queries"| POSTGRES
  POSTGRES -->|"initialized by"| INITDB
  SL -->|"shared code"| MAIN
  SL -->|"shared code"| ENTRY

  click DC "https://github.com/cozero/engineering-hiring-challenge/blob/main/docker-compose.yml"
  click INITDB "https://github.com/cozero/engineering-hiring-challenge/blob/main/initdb.sql"
  click HTML "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/client/index.html"
  click ENTRY "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/client/src/index.tsx"
  click APP "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/client/src/components/App/App.tsx"
  click VITE "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/client/vite.config.ts"
  click TAIL "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/client/tailwind.config.js"
  click MAIN "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/main.ts"
  click CONF "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/config.ts"
  click PRISMA_SVC "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/prisma.service.ts"
  click API_MODULE "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/api.module.ts"
  click PING "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/ping.controller.ts"
  click REPORTS_CTRL "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/reports/reports.controller.ts"
  click REPORTS_SVC "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/reports/reports.service.ts"
  click REPORTS_MODULE "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/reports/reports.module.ts"
  click PRISMA_SCHEMA "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/prisma/schema.prisma"
  click MIG1 "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/prisma/migrations/0_init/migration.sql"
  click MIG2 "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/prisma/migrations/1_demo_data/migration.sql"
  click SL "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/lib/src/index.ts"
  click SL_CJS "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/lib/tsconfig-cjs.json"
  click SL_MJS "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/lib/tsconfig-mjs.json"
  click SVC_TEST "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/reports/test/reports.controller.spec.ts"
  click SVC_TEST2 "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/src/modules/reports/test/reports.service.spec.ts"
  click E2E "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/test/app.e2e-test.ts"
  click JEST_E2E "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/server/test/jest-e2e.json"
  click CLIENT_TYPES "https://github.com/cozero/engineering-hiring-challenge/blob/main/packages/client/@types/globals.d.ts"
  click package.json "https://github.com/cozero/engineering-hiring-challenge/blob/main/package.json"
  click tsconfig "https://github.com/cozero/engineering-hiring-challenge/blob/main/tsconfig.json"

  classDef orchestration fill:#f9f,stroke:#333,stroke-width:2px;
  classDef client fill:#bbf,stroke:#333,stroke-width:2px;
  classDef server fill:#bfb,stroke:#333,stroke-width:2px;
  classDef db fill:#fbf,stroke:#333,stroke-width:2px;
  classDef lib fill:#ddd,stroke:#333,stroke-width:2px;
  classDef test fill:#fbd,stroke:#333,stroke-width:2px;
```
