# andypedozz/lightmodel architecture

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

- Interactive diagram: https://gitdiagram.com/andypedozz/lightmodel
- Repository: https://github.com/andypedozz/lightmodel

## Overview

LightModel is a headless CMS with a React management interface and Express API. The main workflow is to define entities and fields, expose slug-based record endpoints, and create or manage content records in SQLite; the UI also presents media and other administration areas. The graph reflects calls and database access visible in sampled code. The media route excerpt is partial, and some frontend features are incomplete or simulated, so uncertain wiring is omitted.

Main entry points: [`backend/src/db/db.js`](https://github.com/andypedozz/lightmodel/blob/master/backend/src/db/db.js) (Knex database), [`backend/src/server.js`](https://github.com/andypedozz/lightmodel/blob/master/backend/src/server.js) (Express server), [`backend/src/entities/entityManagementRoutes.js`](https://github.com/andypedozz/lightmodel/blob/master/backend/src/entities/entityManagementRoutes.js) (Entity management), [`backend/src/media/mediaManagementRoutes.js`](https://github.com/andypedozz/lightmodel/blob/master/backend/src/media/mediaManagementRoutes.js) (Media management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_management["CMS management"]
  node_app["Express server<br/>[server.js]"]
  node_entities["Entity management"]
  node_media["Media management"]
end

subgraph group_content["Content API"]
  node_dynamic["Dynamic record routes<br/>[entityRoutes.js]"]
  node_recordservice["Record service<br/>[recordService.js]"]
  node_validator["Field validation<br/>[fieldValidator.js]"]
end

subgraph group_persistence["Persistence"]
  node_db["Knex database<br/>[db.js]"]
  node_sqlite[("SQLite data<br/>[db.sqlite]")]
  node_filemedia[("Media files")]
end

subgraph group_client["Admin client"]
  node_frontend["CMS interface<br/>[CMSHeadless.jsx]"]
  node_api["API client<br/>[api.js]"]
end

node_admin(("CMS operator"))
node_browser(("Browser user"))
node_externalapi(("API consumers"))

node_browser -->|"uses"| node_frontend
node_frontend -->|"requests"| node_api
node_api -->|"HTTP calls"| node_app
node_externalapi -->|"HTTP calls"| node_app
node_app -->|"registers routes"| node_entities
node_app -->|"registers routes"| node_media
node_app -->|"registers routes"| node_dynamic
node_entities -->|"queries"| node_db
node_entities -->|"registers entity routes"| node_dynamic
node_dynamic -->|"queries"| node_db
node_recordservice -->|"queries"| node_db
node_validator -->|"checks fields"| node_db
node_media -->|"queries"| node_db
node_media -->|"stores files"| node_filemedia
node_db -->|"reads and writes"| node_sqlite

click node_app "https://github.com/andypedozz/lightmodel/blob/master/backend/src/server.js"
click node_entities "https://github.com/andypedozz/lightmodel/blob/master/backend/src/entities/entityManagementRoutes.js"
click node_media "https://github.com/andypedozz/lightmodel/blob/master/backend/src/media/mediaManagementRoutes.js"
click node_dynamic "https://github.com/andypedozz/lightmodel/blob/master/backend/src/entities/entityRoutes.js"
click node_recordservice "https://github.com/andypedozz/lightmodel/blob/master/backend/src/services/recordService.js"
click node_validator "https://github.com/andypedozz/lightmodel/blob/master/backend/src/validation/fieldValidator.js"
click node_db "https://github.com/andypedozz/lightmodel/blob/master/backend/src/db/db.js"
click node_sqlite "https://github.com/andypedozz/lightmodel/blob/master/backend/src/db/db.sqlite"
click node_filemedia "https://github.com/andypedozz/lightmodel/blob/master/backend/src/media/mediaManagementRoutes.js"
click node_frontend "https://github.com/andypedozz/lightmodel/blob/master/frontend/src/components/CMSHeadless.jsx"
click node_api "https://github.com/andypedozz/lightmodel/blob/master/frontend/src/services/api.js"

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_app,node_entities,node_media,node_browser toneBlue
class node_dynamic,node_recordservice,node_validator toneAmber
class node_db,node_sqlite,node_filemedia,node_externalapi toneMint
class node_frontend,node_api toneRose
class node_admin toneIndigo
```

## Components

### CMS management

- [Express server](https://github.com/andypedozz/lightmodel/blob/master/backend/src/server.js): `backend/src/server.js`
- [Entity management](https://github.com/andypedozz/lightmodel/blob/master/backend/src/entities/entityManagementRoutes.js): `backend/src/entities/entityManagementRoutes.js`
- [Media management](https://github.com/andypedozz/lightmodel/blob/master/backend/src/media/mediaManagementRoutes.js): `backend/src/media/mediaManagementRoutes.js`

### Content API

- [Dynamic record routes](https://github.com/andypedozz/lightmodel/blob/master/backend/src/entities/entityRoutes.js): `backend/src/entities/entityRoutes.js`
- [Record service](https://github.com/andypedozz/lightmodel/blob/master/backend/src/services/recordService.js): `backend/src/services/recordService.js`
- [Field validation](https://github.com/andypedozz/lightmodel/blob/master/backend/src/validation/fieldValidator.js): `backend/src/validation/fieldValidator.js`

### Persistence

- [Knex database](https://github.com/andypedozz/lightmodel/blob/master/backend/src/db/db.js): `backend/src/db/db.js`
- [SQLite data](https://github.com/andypedozz/lightmodel/blob/master/backend/src/db/db.sqlite): `backend/src/db/db.sqlite`
- [Media files](https://github.com/andypedozz/lightmodel/blob/master/backend/src/media/mediaManagementRoutes.js): `backend/src/media/mediaManagementRoutes.js`

### Admin client

- [CMS interface](https://github.com/andypedozz/lightmodel/blob/master/frontend/src/components/CMSHeadless.jsx): `frontend/src/components/CMSHeadless.jsx`
- [API client](https://github.com/andypedozz/lightmodel/blob/master/frontend/src/services/api.js): `frontend/src/services/api.js`

### Other components

- **CMS operator**
- **Browser user**
- **API consumers**

## Connections

- Browser user → CMS interface: uses
- CMS interface → API client: requests
- API client → Express server: HTTP calls
- API consumers → Express server: HTTP calls
- Express server → Entity management: registers routes
- Express server → Media management: registers routes
- Express server → Dynamic record routes: registers routes
- Entity management → Knex database: queries
- Entity management → Dynamic record routes: registers entity routes
- Dynamic record routes → Knex database: queries
- Record service → Knex database: queries
- Field validation → Knex database: checks fields
- Media management → Knex database: queries
- Media management → Media files: stores files
- Knex database → SQLite data: reads and writes
