# uzibytes/knitkraft architecture

> Architecture diagram of the GitHub repository uzibytes/knitkraft, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uzibytes/knitkraft
- Repository: https://github.com/uzibytes/knitkraft

## Overview

#### Purpose and runtime
KnitKraft is a role-based wool-industry platform spanning farm production, services, storage/transport, trading, education, and market information. It is a server-rendered Node.js/Express application using EJS, backed by MongoDB, with deployment intended for Render. Primary startup chain: `package.json` → `bin/www` → `app.js`.

#### HTTP application boundary
Express application setup, middleware, static asset hosting, view rendering, and route mounting are centralized in `app.js`. Browser requests enter page routes and API/auth routes through `routes/index.js`, `routes/users.js`, and `routes/api.js`; responses are predominantly rendered EJS pages rather than a separate SPA/API client.

#### Authentication and role access
Account registration/login and user-facing identity operations are handled by `src/controllers/auth.controller.js` and `src/controllers/user.controller.js`. JWT authentication and signup validation form the primary access-control boundary in `src/middleware/authJwt.js`, `src/middleware/verifySignUp.js`, and `src/middleware/index.js`. Role-specific interfaces are represented by separate views, including farmer, teacher, transport, warehouse, seller, and service areas.

#### Persistence model
MongoDB connection ownership is isolated in `src/db/db.js`. Mongoose-style domain entities cover users plus core operational records: `models/userregister.js`, `models/Transport.js`, `models/Warehouse.js`, `models/Service.js`, and `models/Meeting.js`. These models are the persistence boundary for identities, logistics/storage requests, service workflows, and learning sessions.

#### Wool supply-chain operations
The product’s operational flow starts with farmer actions, then crosses service, transport, and warehousing functions before marketplace-oriented buying/selling. Relevant workflow screens include `views/farmer/index.ejs`, `views/input/Transportation.ejs`, `views/input/Warehouse.ejs`, `views/table/Farmer-Transportation.ejs`, and `views/table/Farmer-Warehouse.ejs`. Transport and warehouse partners have dedicated landing interfaces at `views/transport/index.ejs` and `views/warehouse/index.ejs`.

#### Marketplace and service catalog
Trading and service discovery are delivered as server-rendered modules. Wool marketplace screens reside in `views/Woolkart/index.ejs` and `views/Woolkart/buynow.ejs`; negotiation has `views/Pages/negotiate.ejs`. Service offerings—such as transport, warehousing, grading, insurance, processing, and veterinary support—are organized under `views/Services/index.ejs` and service-specific EJS pages, with service records represented by `models/Service.js`.

#### Education, analytics, and localization
Training/live or recorded learning experiences are grouped in `views/Learning/index.ejs`, `views/Learning/meetPage.ejs`, and `views/Learning/video.ejs`, with meetings persisted in `models/Meeting.js`. Market/statistics presentation is represented by `views/Statistics/index.ejs`. English and Hindi translation resources are supplied via `lang/eng.json` and `lang/hin.json`.

#### Presentation and client delivery
EJS templates compose shared navigation and layout through `views/partials/header.ejs`, `views/partials/AppSidebar.ejs`, and `views/partials/footer.ejs`. Mobile-oriented static frontend assets, including service-worker artifacts, are served from `public/__manifest.json`, `public/__service-worker.js`, and `public/assets/`; Bootstrap/SASS-based styling and JavaScript enhancements remain client-side presentation concerns.

Main entry points: [`routes/index.js`](https://github.com/uzibytes/knitkraft/blob/master/routes/index.js) (Page and API routes), [`models/userregister.js`](https://github.com/uzibytes/knitkraft/blob/master/models/userregister.js) (Operational models), [`app.js`](https://github.com/uzibytes/knitkraft/blob/master/app.js) (Express application), [`views/input/Transportation.ejs`](https://github.com/uzibytes/knitkraft/blob/master/views/input/Transportation.ejs) (Transport and warehouse)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_package["Package startup<br/>Node package<br/>[package.json]"]
  node_www["HTTP launcher<br/>Node entrypoint"]
end

subgraph group_server["Server &amp; Access"]
  node_app["Express application<br/>Express host<br/>[app.js]"]
  node_routes["Page and API routes<br/>Express routes<br/>[index.js]"]
  node_auth["Auth controllers<br/>identity controllers<br/>[auth.controller.js]"]
  node_user["User controller<br/>identity controller<br/>[user.controller.js]"]
  node_access["JWT and signup guards<br/>access middleware<br/>[index.js]"]
  node_mongo[("MongoDB connection<br/>database connection<br/>[db.js]")]
end

subgraph group_operations["Supply Chain"]
  node_records[("Operational models<br/>Mongoose models<br/>[userregister.js]")]
  node_farmer["Farmer workflow<br/>EJS module<br/>[index.ejs]"]
  node_logistics["Transport and warehouse<br/>EJS workflows<br/>[Transportation.ejs]"]
  node_services["Service catalog<br/>EJS module<br/>[index.ejs]"]
  node_marketplace["Wool marketplace<br/>EJS module<br/>[index.ejs]"]
end

subgraph group_experience["Rendered Experience"]
  node_learning["Learning sessions<br/>EJS module<br/>[index.ejs]"]
  node_statistics["Market statistics<br/>EJS module<br/>[index.ejs]"]
  node_layout["Shared EJS layout<br/>template partials<br/>[header.ejs]"]
  node_i18n["English and Hindi<br/>translation resources<br/>[eng.json]"]
  node_static["Mobile static assets<br/>public assets<br/>[__manifest.json]"]
end

node_package -->|"starts"| node_www
node_www -->|"loads"| node_app
node_app -->|"mounts"| node_routes
node_app -->|"applies"| node_access
node_app -->|"renders"| node_layout
node_app -->|"serves"| node_static
node_routes -->|"identity requests"| node_auth
node_routes -->|"user requests"| node_user
node_access -.->|"protects"| node_auth
node_auth -->|"accounts"| node_records
node_user -->|"users"| node_records
node_records -->|"persists through"| node_mongo
node_routes -->|"renders"| node_farmer
node_farmer -->|"initiates requests"| node_logistics
node_logistics -->|"uses offerings"| node_services
node_logistics -->|"stores workflows"| node_records
node_services -->|"uses service records"| node_records
node_marketplace -.->|"uses operational data"| node_records
node_learning -->|"stores meetings"| node_records
node_routes -->|"renders"| node_marketplace
node_routes -->|"renders"| node_learning
node_routes -->|"renders"| node_statistics
node_layout -.->|"localizes"| node_i18n

click node_package "https://github.com/uzibytes/knitkraft/blob/master/package.json"
click node_www "https://github.com/uzibytes/knitkraft/blob/master/bin/www"
click node_app "https://github.com/uzibytes/knitkraft/blob/master/app.js"
click node_routes "https://github.com/uzibytes/knitkraft/blob/master/routes/index.js"
click node_auth "https://github.com/uzibytes/knitkraft/blob/master/src/controllers/auth.controller.js"
click node_user "https://github.com/uzibytes/knitkraft/blob/master/src/controllers/user.controller.js"
click node_access "https://github.com/uzibytes/knitkraft/blob/master/src/middleware/index.js"
click node_mongo "https://github.com/uzibytes/knitkraft/blob/master/src/db/db.js"
click node_records "https://github.com/uzibytes/knitkraft/blob/master/models/userregister.js"
click node_farmer "https://github.com/uzibytes/knitkraft/blob/master/views/farmer/index.ejs"
click node_logistics "https://github.com/uzibytes/knitkraft/blob/master/views/input/Transportation.ejs"
click node_services "https://github.com/uzibytes/knitkraft/blob/master/views/Services/index.ejs"
click node_marketplace "https://github.com/uzibytes/knitkraft/blob/master/views/Woolkart/index.ejs"
click node_learning "https://github.com/uzibytes/knitkraft/blob/master/views/Learning/index.ejs"
click node_statistics "https://github.com/uzibytes/knitkraft/blob/master/views/Statistics/index.ejs"
click node_layout "https://github.com/uzibytes/knitkraft/blob/master/views/partials/header.ejs"
click node_i18n "https://github.com/uzibytes/knitkraft/blob/master/lang/eng.json"
click node_static "https://github.com/uzibytes/knitkraft/blob/master/public/__manifest.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package,node_www toneBlue
class node_app,node_routes,node_auth,node_user,node_access,node_mongo toneAmber
class node_records,node_farmer,node_logistics,node_services,node_marketplace toneMint
class node_learning,node_statistics,node_layout,node_i18n,node_static toneRose
```

## Components

### Runtime

- [Package startup](https://github.com/uzibytes/knitkraft/blob/master/package.json): Node package · Starts the Express runtime chain. · `package.json`
- [HTTP launcher](https://github.com/uzibytes/knitkraft/blob/master/bin/www): Node entrypoint · `bin/www`

### Server & Access

- [Express application](https://github.com/uzibytes/knitkraft/blob/master/app.js): Express host · Owns middleware, static delivery, views, and route mounting. · `app.js`
- [Page and API routes](https://github.com/uzibytes/knitkraft/blob/master/routes/index.js): Express routes · `routes/index.js`
- [Auth controllers](https://github.com/uzibytes/knitkraft/blob/master/src/controllers/auth.controller.js): identity controllers · `src/controllers/auth.controller.js`
- [User controller](https://github.com/uzibytes/knitkraft/blob/master/src/controllers/user.controller.js): identity controller · `src/controllers/user.controller.js`
- [JWT and signup guards](https://github.com/uzibytes/knitkraft/blob/master/src/middleware/index.js): access middleware · `src/middleware/index.js`
- [MongoDB connection](https://github.com/uzibytes/knitkraft/blob/master/src/db/db.js): database connection · `src/db/db.js`

### Supply Chain

- [Operational models](https://github.com/uzibytes/knitkraft/blob/master/models/userregister.js): Mongoose models · Users, transport, warehouse, service, and meeting records. · `models/userregister.js`
- [Farmer workflow](https://github.com/uzibytes/knitkraft/blob/master/views/farmer/index.ejs): EJS module · `views/farmer/index.ejs`
- [Transport and warehouse](https://github.com/uzibytes/knitkraft/blob/master/views/input/Transportation.ejs): EJS workflows · Captures logistics and storage requests and partner work. · `views/input/Transportation.ejs`
- [Service catalog](https://github.com/uzibytes/knitkraft/blob/master/views/Services/index.ejs): EJS module · Discover transport, storage, grading, insurance, processing, and veterinary services. · `views/Services/index.ejs`
- [Wool marketplace](https://github.com/uzibytes/knitkraft/blob/master/views/Woolkart/index.ejs): EJS module · Buying, selling, and negotiation screens. · `views/Woolkart/index.ejs`

### Rendered Experience

- [Learning sessions](https://github.com/uzibytes/knitkraft/blob/master/views/Learning/index.ejs): EJS module · Live and recorded learning experiences. · `views/Learning/index.ejs`
- [Market statistics](https://github.com/uzibytes/knitkraft/blob/master/views/Statistics/index.ejs): EJS module · `views/Statistics/index.ejs`
- [Shared EJS layout](https://github.com/uzibytes/knitkraft/blob/master/views/partials/header.ejs): template partials · Navigation, sidebar, and footer compose rendered pages. · `views/partials/header.ejs`
- [English and Hindi](https://github.com/uzibytes/knitkraft/blob/master/lang/eng.json): translation resources · `lang/eng.json`
- [Mobile static assets](https://github.com/uzibytes/knitkraft/blob/master/public/__manifest.json): public assets · Manifest, service worker, and client assets. · `public/__manifest.json`

## Connections

- Package startup → HTTP launcher: starts
- HTTP launcher → Express application: loads
- Express application → Page and API routes: mounts
- Express application → JWT and signup guards: applies
- Express application → Shared EJS layout: renders
- Express application → Mobile static assets: serves
- Page and API routes → Auth controllers: identity requests
- Page and API routes → User controller: user requests
- JWT and signup guards → Auth controllers: protects
- Auth controllers → Operational models: accounts
- User controller → Operational models: users
- Operational models → MongoDB connection: persists through
- Page and API routes → Farmer workflow: renders
- Farmer workflow → Transport and warehouse: initiates requests
- Transport and warehouse → Service catalog: uses offerings
- Transport and warehouse → Operational models: stores workflows
- Service catalog → Operational models: uses service records
- Wool marketplace → Operational models: uses operational data
- Learning sessions → Operational models: stores meetings
- Page and API routes → Wool marketplace: renders
- Page and API routes → Learning sessions: renders
- Page and API routes → Market statistics: renders
- Shared EJS layout → English and Hindi: localizes
