# y1lion/kinetix architecture

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

- Interactive diagram: https://gitdiagram.com/y1lion/kinetix
- Repository: https://github.com/y1lion/kinetix

## Overview

#### Purpose and entry points
Kinetix is a containerized sports-product e-commerce system: a Next.js browser UI calls an Express REST API, which persists data and sessions in MongoDB Atlas, indexes/searches products through Meilisearch, and uses Azure AI for enrichment. Runtime entry points are `frontend/app/page.tsx`, `backend/server.js`, and `docker-compose.yml`.

#### Frontend application
The Next.js/React TypeScript frontend provides catalogue browsing, authentication, basket, and administration views. The root UI and shared application shell are in `frontend/app/page.tsx` and `frontend/app/layout.tsx`; dedicated user flows are `frontend/app/login/page.tsx`, `frontend/app/basket/page.tsx`, and `frontend/app/admin/page.tsx`. It runs on port 3000 and must send credentialed API requests for session continuity.

#### HTTP API and route boundary
Express bootstrapping, database/session setup, CORS, and API documentation are centralized in `backend/server.js`. Routes partition the API by domain: authentication in `backend/routes/auth.js`, catalogue/search in `backend/routes/products.js` and `backend/routes/search.js`, basket operations in `backend/routes/basket.js`, and privileged operations in `backend/routes/admin.js`. Health is separately exposed through `backend/routes/health.js`.

#### Identity, sessions, and authorization
Registration/login logic belongs to `backend/controllers/authController.js`; user management is in `backend/controllers/userController.js`. Passwords are bcrypt-hashed, while `express-session` with Mongo-backed persistence makes the browser cookie the authentication boundary. `backend/middleware/requireAuth.js` gates authenticated operations, and `backend/middleware/requireAdmin.js` adds role-based protection for administration.

#### Domain persistence and commerce flow
Mongoose models define the durable core entities: users, products, and user-linked baskets in `backend/models/user.js`, `backend/models/product.js`, and `backend/models/basket.js`. `backend/controllers/productController.js` implements catalogue/product management; `backend/controllers/basketController.js` applies basket changes for the authenticated user. Seeded catalogue content enters through `backend/data/productsDataset.js` and `backend/scripts/seedProducts.js`.

#### Search and AI enrichment pipeline
Product discovery is separated from MongoDB persistence. `backend/config/meilisearch.js` and `backend/services/meiliService.js` connect and synchronize the Meilisearch index; `backend/scripts/initMeili.js` initializes it. Search quality is composed in `backend/services/hybridEngine.js`, with intent interpretation, product matching, and AI scoring split across `backend/services/intentService.js`, `backend/services/matchService.js`, and `backend/services/aiScoreService.js`. Azure AI Language and Vision are external dependencies, with image-oriented processing in `backend/services/imageService.js`.

#### Deployment and operational boundaries
Docker Compose coordinates frontend, backend, and local Meilisearch in `docker-compose.yml`; service images are defined by `frontend/Dockerfile` and `backend/Dockerfile`. MongoDB Atlas remains external and requires network access plus `MONGO_URI`; Meilisearch is addressed internally as `http://meilisearch:7700`. GitHub Actions in `.github/workflows/ci.yml` builds the stack, temporarily permits the runner in Atlas, verifies health/UI/Swagger, and runs database validation.

Main entry points: [`backend/server.js`](https://github.com/y1lion/kinetix/blob/master/backend/server.js) (Express server), [`docker-compose.yml`](https://github.com/y1lion/kinetix/blob/master/docker-compose.yml) (Docker Compose), [`frontend/app/page.tsx`](https://github.com/y1lion/kinetix/blob/master/frontend/app/page.tsx) (Next.js application), [`backend/controllers/basketController.js`](https://github.com/y1lion/kinetix/blob/master/backend/controllers/basketController.js) (Product & basket logic)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_browser(("Browser client<br/>user runtime"))
  node_next_app["Next.js application<br/>React UI<br/>[page.tsx]"]
  node_app_shell["Shared app shell<br/>Next layout<br/>[layout.tsx]"]
end

subgraph group_api["Express API"]
  node_express["Express server<br/>REST API bootstrap<br/>[server.js]"]
  node_auth_routes["Auth routes<br/>route boundary<br/>[auth.js]"]
  node_commerce_routes["Catalogue &amp; basket routes<br/>route boundary<br/>[products.js]"]
  node_admin_routes["Admin routes<br/>privileged route boundary<br/>[admin.js]"]
  node_auth_logic["Identity &amp; session logic<br/>controllers<br/>[authController.js]"]
  node_access_control["Auth and role guards<br/>middleware<br/>[requireAuth.js]"]
  node_commerce_logic["Product &amp; basket logic<br/>controllers"]
  node_models["Commerce models<br/>Mongoose models<br/>[basket.js]"]
  node_seed_catalogue["Catalogue seed<br/>data initialization<br/>[seedProducts.js]"]
end

subgraph group_search["Search &amp; enrichment"]
  node_search_routes["Search routes<br/>route boundary<br/>[search.js]"]
  node_hybrid_search["Hybrid search engine<br/>search orchestration<br/>[hybridEngine.js]"]
  node_meili_sync["Meilisearch sync<br/>index service<br/>[meiliService.js]"]
  node_azure_ai{{"Azure AI Language &amp; Vision<br/>external AI services"}}
end

subgraph group_runtime["Runtime &amp; operations"]
  node_mongo[("MongoDB Atlas<br/>external database")]
  node_meilisearch[("Meilisearch<br/>search index")]
  node_compose["Docker Compose<br/>container orchestration<br/>[docker-compose.yml]"]
  node_ci["GitHub Actions CI<br/>deployment validation<br/>[ci.yml]"]
end

node_browser -->|"renders"| node_next_app
node_next_app -->|"uses"| node_app_shell
node_next_app -->|"credentialed REST requests"| node_express
node_express -->|"mounts"| node_auth_routes
node_express -->|"mounts"| node_commerce_routes
node_express -->|"mounts"| node_admin_routes
node_express -->|"mounts"| node_search_routes
node_express -->|"stores sessions"| node_mongo
node_auth_routes -->|"delegates"| node_auth_logic
node_auth_logic -->|"reads and writes users"| node_mongo
node_commerce_routes -->|"requires authentication"| node_access_control
node_admin_routes -->|"requires admin role"| node_access_control
node_access_control -->|"permits requests"| node_commerce_logic
node_commerce_logic -->|"uses"| node_models
node_models -->|"persists"| node_mongo
node_seed_catalogue -->|"loads products"| node_models
node_search_routes -->|"queries"| node_hybrid_search
node_hybrid_search -->|"retrieves candidates"| node_meilisearch
node_hybrid_search -->|"scores and enriches"| node_azure_ai
node_commerce_logic -->|"synchronizes products"| node_meili_sync
node_meili_sync -->|"indexes"| node_meilisearch
node_compose -->|"runs"| node_next_app
node_compose -->|"runs"| node_express
node_compose -->|"runs"| node_meilisearch
node_ci -->|"builds and verifies"| node_compose
node_ci -.->|"temporarily authorizes runner"| node_mongo

click node_next_app "https://github.com/y1lion/kinetix/blob/master/frontend/app/page.tsx"
click node_app_shell "https://github.com/y1lion/kinetix/blob/master/frontend/app/layout.tsx"
click node_express "https://github.com/y1lion/kinetix/blob/master/backend/server.js"
click node_auth_routes "https://github.com/y1lion/kinetix/blob/master/backend/routes/auth.js"
click node_commerce_routes "https://github.com/y1lion/kinetix/blob/master/backend/routes/products.js"
click node_admin_routes "https://github.com/y1lion/kinetix/blob/master/backend/routes/admin.js"
click node_auth_logic "https://github.com/y1lion/kinetix/blob/master/backend/controllers/authController.js"
click node_access_control "https://github.com/y1lion/kinetix/blob/master/backend/middleware/requireAuth.js"
click node_commerce_logic "https://github.com/y1lion/kinetix/blob/master/backend/controllers/basketController.js"
click node_models "https://github.com/y1lion/kinetix/blob/master/backend/models/basket.js"
click node_seed_catalogue "https://github.com/y1lion/kinetix/blob/master/backend/scripts/seedProducts.js"
click node_search_routes "https://github.com/y1lion/kinetix/blob/master/backend/routes/search.js"
click node_hybrid_search "https://github.com/y1lion/kinetix/blob/master/backend/services/hybridEngine.js"
click node_meili_sync "https://github.com/y1lion/kinetix/blob/master/backend/services/meiliService.js"
click node_compose "https://github.com/y1lion/kinetix/blob/master/docker-compose.yml"
click node_ci "https://github.com/y1lion/kinetix/blob/master/.github/workflows/ci.yml"

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_browser,node_next_app,node_app_shell toneBlue
class node_express,node_auth_routes,node_commerce_routes,node_admin_routes,node_auth_logic,node_access_control,node_commerce_logic,node_models,node_seed_catalogue toneAmber
class node_search_routes,node_hybrid_search,node_meili_sync,node_azure_ai toneMint
class node_mongo,node_meilisearch,node_compose,node_ci toneRose
```

## Components

### Frontend

- **Browser client**: user runtime · Uses credentialed requests to preserve sessions.
- [Next.js application](https://github.com/y1lion/kinetix/blob/master/frontend/app/page.tsx): React UI · Catalogue, login, basket, and administration flows. · `frontend/app/page.tsx`
- [Shared app shell](https://github.com/y1lion/kinetix/blob/master/frontend/app/layout.tsx): Next layout · `frontend/app/layout.tsx`

### Express API

- [Express server](https://github.com/y1lion/kinetix/blob/master/backend/server.js): REST API bootstrap · Configures CORS, sessions, database access, and API documentation. · `backend/server.js`
- [Auth routes](https://github.com/y1lion/kinetix/blob/master/backend/routes/auth.js): route boundary · `backend/routes/auth.js`
- [Catalogue & basket routes](https://github.com/y1lion/kinetix/blob/master/backend/routes/products.js): route boundary · Product, search, and basket API domains. · `backend/routes/products.js`
- [Admin routes](https://github.com/y1lion/kinetix/blob/master/backend/routes/admin.js): privileged route boundary · `backend/routes/admin.js`
- [Identity & session logic](https://github.com/y1lion/kinetix/blob/master/backend/controllers/authController.js): controllers · Bcrypt credentials and Mongo-backed browser sessions. · `backend/controllers/authController.js`
- [Auth and role guards](https://github.com/y1lion/kinetix/blob/master/backend/middleware/requireAuth.js): middleware · Requires an authenticated user and, where needed, an admin role. · `backend/middleware/requireAuth.js`
- [Product & basket logic](https://github.com/y1lion/kinetix/blob/master/backend/controllers/basketController.js): controllers · Manages catalogue data and authenticated user baskets. · `backend/controllers/basketController.js`
- [Commerce models](https://github.com/y1lion/kinetix/blob/master/backend/models/basket.js): Mongoose models · User, product, and user-linked basket entities. · `backend/models/basket.js`
- [Catalogue seed](https://github.com/y1lion/kinetix/blob/master/backend/scripts/seedProducts.js): data initialization · Loads the product dataset into persistence. · `backend/scripts/seedProducts.js`

### Search & enrichment

- [Search routes](https://github.com/y1lion/kinetix/blob/master/backend/routes/search.js): route boundary · `backend/routes/search.js`
- [Hybrid search engine](https://github.com/y1lion/kinetix/blob/master/backend/services/hybridEngine.js): search orchestration · Combines intent interpretation, matching, and AI scoring. · `backend/services/hybridEngine.js`
- [Meilisearch sync](https://github.com/y1lion/kinetix/blob/master/backend/services/meiliService.js): index service · Synchronizes product records to the search index. · `backend/services/meiliService.js`
- **Azure AI Language & Vision**: external AI services · Supports scoring and image-oriented enrichment.

### Runtime & operations

- **MongoDB Atlas**: external database · Durable users, products, baskets, and sessions.
- **Meilisearch**: search index · Local Compose service addressed internally on port 7700.
- [Docker Compose](https://github.com/y1lion/kinetix/blob/master/docker-compose.yml): container orchestration · Coordinates frontend, backend, and local Meilisearch. · `docker-compose.yml`
- [GitHub Actions CI](https://github.com/y1lion/kinetix/blob/master/.github/workflows/ci.yml): deployment validation · Builds the stack and verifies health, UI, Swagger, and database validation. · `.github/workflows/ci.yml`

## Connections

- Browser client → Next.js application: renders
- Next.js application → Shared app shell: uses
- Next.js application → Express server: credentialed REST requests
- Express server → Auth routes: mounts
- Express server → Catalogue & basket routes: mounts
- Express server → Admin routes: mounts
- Express server → Search routes: mounts
- Express server → MongoDB Atlas: stores sessions
- Auth routes → Identity & session logic: delegates
- Identity & session logic → MongoDB Atlas: reads and writes users
- Catalogue & basket routes → Auth and role guards: requires authentication
- Admin routes → Auth and role guards: requires admin role
- Auth and role guards → Product & basket logic: permits requests
- Product & basket logic → Commerce models: uses
- Commerce models → MongoDB Atlas: persists
- Catalogue seed → Commerce models: loads products
- Search routes → Hybrid search engine: queries
- Hybrid search engine → Meilisearch: retrieves candidates
- Hybrid search engine → Azure AI Language & Vision: scores and enriches
- Product & basket logic → Meilisearch sync: synchronizes products
- Meilisearch sync → Meilisearch: indexes
- Docker Compose → Next.js application: runs
- Docker Compose → Express server: runs
- Docker Compose → Meilisearch: runs
- GitHub Actions CI → Docker Compose: builds and verifies
- GitHub Actions CI → MongoDB Atlas: temporarily authorizes runner
