# abhiifour/panchayat architecture

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

- Interactive diagram: https://gitdiagram.com/abhiifour/panchayat
- Repository: https://github.com/abhiifour/panchayat

## Overview

##### Project Type and Purpose
- This is a full-stack real-time chat application.
- Frontend: Next.js 13 (app router), React, Tailwind CSS, Zustand for state management.
- Backend: Node.js + TypeScript, Prisma ORM managing a relational database (e.g., PostgreSQL).
- Purpose: Render chat UI in the browser, fetch and send messages via REST or WebSocket APIs, persist chat data to the database, and support dynamic chat rooms.

##### File Structure
- Top-level “frontend” and “backend” directories clearly separate presentation from business/data layers.
- Frontend/app: Next.js pages and components (dynamic routes under /chats/[room]).
- Frontend/store: client-side state (roomStore.ts, userStore.ts).
- Frontend/style: global CSS and Tailwind config.
- Backend/src/index.ts: main server entrypoint (likely Express/Fastify + API routes or WebSocket server).
- Backend/prisma: schema.prisma and migration SQL files → data model and migrations.
- Backend/dist: compiled JS bundle for production.

a. Client Layer
– Web Browser running React/Next.js pages and components.
– Zustand stores for user and room state.
b. Frontend Layer
– Next.js server (SSR/SSG/Client-side).
– Static asset server (public/assets).
c. API Layer
– REST or WebSocket endpoints exposed by the backend.
d. Backend Layer
– Node.js + TypeScript service (business logic for chat, auth, etc.).
– Prisma ORM translating queries to SQL.
e. Database Layer
– PostgreSQL (or another RDBMS) hosting chat messages, users, rooms.

##### Architectural Patterns and Design Principles
- Layered Architecture:
– Presentation (React/Next.js)
– API Gateway (Next.js API routes or direct to backend)
– Business Logic (Node.js service)
– Data Access (Prisma ORM)
– Storage (Relational DB)
- Separation of Concerns: UI vs. state management vs. data persistence.
- Dynamic Routing: Next.js app router supporting parameterized pages under /chats/[room].
- State Store: Zustand for client-side caching of user and room contexts.
- Migrations: Prisma migrations under backend/prisma/migrations ensure schema versioning.

##### Detailed Checklist
[ ] Frontend: Next.js app router, dynamic chat rooms, Tailwind CSS, Zustand store
[ ] Backend: Express/Fastify entrypoint (src/index.ts), Prisma ORM layer, Node.js runtime
[ ] Database: represent migrations and schema (schema.prisma) connecting to PostgreSQL
[ ] Data flows: page render requests, API fetches, real-time message streams
[ ] Configuration: note Next.js (next.config.ts), Tailwind (tailwind.config.ts), Prisma schema

## Diagram (Mermaid)

```mermaid
graph TB
  %% Client Layer
  subgraph "Client Layer"
    Browser["Web Browser (React/Next.js UI)"]:::ui
    subgraph "Zustand Stores"
      roomStore["roomStore.ts"]:::state
      userStore["userStore.ts"]:::state
    end
  end

  %% Frontend Layer
  subgraph "Frontend Layer"
    NextServer["Next.js Server (SSR/SSG + Routing)"]:::server
    assets["Static Assets Server"]:::assets
    subgraph "Next.js App Files"
      chatPage["/chats/[room]/page.tsx"]:::frontend
      chatOverview["/chats/page.tsx"]:::frontend
      landing["landing.tsx"]:::frontend
      layout["layout.tsx"]:::frontend
      rootPage["page.tsx"]:::frontend
    end
    subgraph "Tailwind & Config"
      tailwindCfg["tailwind.config.ts"]:::config
      gradientCSS["gradient.css"]:::config
      globalsCSS["globals.css"]:::config
      postcssCFG["postcss.config.mjs"]:::config
      nextCfg["next.config.ts"]:::config
    end
  end

  %% API Layer
  subgraph "API Layer"
    API["API Endpoints (REST / WebSocket)"]:::api
  end

  %% Backend Layer
  subgraph "Backend Layer"
    NodeService["Node.js Service (TypeScript + WebSocket)"]:::server
    subgraph "Prisma ORM Layer"
      schemaPrisma["schema.prisma"]:::orm
      migrations["migration.sql files"]:::orm
    end
    distIndex["Compiled Bundle (dist/index.js)"]:::server
    pkgCfg["package.json & tsconfig.json"]:::config
  end

  %% Database Layer
  Database["PostgreSQL Database"]:::db

  %% Connections
  Browser -->|"HTTP GET/POST"| NextServer
  Browser -->|"Assets"| assets
  roomStore --> Browser
  userStore --> Browser
  NextServer -->|"API calls (HTTP/WS)"| API
  API -->|"Forwards requests"| NodeService
  NodeService -->|"Prisma queries"| schemaPrisma
  schemaPrisma -->|"SQL / migrations"| migrations
  NodeService -->|"Read/Write"| Database
  Database -->|"Data responses"| NodeService
  NodeService -->|"Real-time events"| API
  API -->|"Push to frontend"| NextServer
  NextServer -->|"Updates UI"| Browser

  %% Click Events
  click Browser "https://github.com/abhiifour/panchayat/tree/main/frontend/app"
  click roomStore "https://github.com/abhiifour/panchayat/blob/main/frontend/store/roomStore.ts"
  click userStore "https://github.com/abhiifour/panchayat/blob/main/frontend/store/userStore.ts"
  click NextServer "https://github.com/abhiifour/panchayat/tree/main/frontend/app"
  click assets "https://github.com/abhiifour/panchayat/tree/main/frontend/public/assets"
  click chatPage "https://github.com/abhiifour/panchayat/blob/main/frontend/app/chats/[room]/page.tsx"
  click chatOverview "https://github.com/abhiifour/panchayat/blob/main/frontend/app/chats/page.tsx"
  click landing "https://github.com/abhiifour/panchayat/blob/main/frontend/app/landing.tsx"
  click layout "https://github.com/abhiifour/panchayat/blob/main/frontend/app/layout.tsx"
  click rootPage "https://github.com/abhiifour/panchayat/blob/main/frontend/app/page.tsx"
  click tailwindCfg "https://github.com/abhiifour/panchayat/blob/main/frontend/tailwind.config.ts"
  click gradientCSS "https://github.com/abhiifour/panchayat/blob/main/frontend/style/gradient.css"
  click globalsCSS "https://github.com/abhiifour/panchayat/blob/main/frontend/app/globals.css"
  click postcssCFG "https://github.com/abhiifour/panchayat/blob/main/frontend/postcss.config.mjs"
  click nextCfg "https://github.com/abhiifour/panchayat/blob/main/frontend/next.config.ts"
  click NodeService "https://github.com/abhiifour/panchayat/blob/main/backend/src/index.ts"
  click schemaPrisma "https://github.com/abhiifour/panchayat/blob/main/backend/prisma/schema.prisma"
  click migrations "https://github.com/abhiifour/panchayat/blob/main/backend/prisma/migrations/**/migration.sql"
  click distIndex "https://github.com/abhiifour/panchayat/blob/main/backend/dist/index.js"
  click pkgCfg "https://github.com/abhiifour/panchayat/blob/main/backend/package.json"
  
  %% Styles
  classDef ui fill:#d0e7ff,stroke:#1e78c7
  classDef state fill:#e0f7fa,stroke:#00796b
  classDef server fill:#ffe0b2,stroke:#e65100
  classDef assets fill:#f1f8e9,stroke:#33691e
  classDef config fill:#e8eaf6,stroke:#283593
  classDef api fill:#fff3e0,stroke:#ff6f00
  classDef orm fill:#fff8e1,stroke:#ff8f00
  classDef db fill:#c8e6c9,stroke:#2e7d32
```
