# sverdam/retotc2005b architecture

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

- Interactive diagram: https://gitdiagram.com/sverdam/retotc2005b
- Repository: https://github.com/sverdam/retotc2005b

## Overview

1. This repository is split into two deployable parts: a TypeScript backend API in `back-end/` and a Vite/React frontend SPA in `front-end/`. The browser talks to the backend over HTTP; the backend talks to a relational database and the local file system.

2. The backend is the system’s core. `back-end/index.ts` is the entry point, and `src/routes/index.ts` aggregates the feature routes. The README confirms the backend reads a `.env` file for database credentials and a JWT secret, and it initializes the database schema from an empty database on startup.

3. Data access is organized around domain models in `src/models/` and a database connection in `src/connection/connection.ts`. The model set shows the main business entities: `company`, `category`, `contact`, `location`, `filter`, `companyFilter`, `textModule`, `fileModule`, and `user`.

4. The backend API is split by resource, with matching `controllers/` and `routes/` files for companies, categories, contacts, locations, filters, text modules, file modules, and users. `authRoutes.ts` is separate, which indicates authentication is handled as a distinct boundary from the rest of the CRUD/API surface.

5. Security is layered in `src/security/` and `src/middlewares/authMiddleware.ts`. JWT signing/verification lives in `jwt.ts`, password hashing in `hashing.ts`, and the auth middleware likely protects admin or mutation routes. This makes user identity and route authorization a first-class part of the backend architecture.

6. File uploads are a separate subsystem. `src/middlewares/multer.ts` handles multipart uploads, and the `back-end/files/` tree is partitioned into `documents`, `images`, `logos`, and `temp`. `fileModuleController.ts` and `services/fileModuleService.ts` suggest uploaded files are tracked as domain records, not just stored as raw blobs.

7. The backend appears to support a directory/catalog domain centered on companies. Supporting entities like categories, locations, filters, and text modules imply a company profile can be enriched with structured metadata, searchable attributes, and attached content/files.

8. The frontend is a client-side React application with route-based pages defined in `src/routes/index.tsx`. The main screens are `Directory`, `UserAdminPage`, and `ErrorPage`, which suggests a public browsing experience plus an authenticated administration area.

9. UI composition on the frontend is componentized around directory browsing and admin actions: `DirectoryCard`, `FilterModal`, `DeleteConfirmModal`, and `Footer`. This points to a flow where users browse companies, refine results with filters, and admins can confirm destructive actions.

10. The frontend’s API boundary is centralized in `src/api/CompanyAPI.ts` and `src/api/index.ts`, so the UI does not call the backend directly from each component. That separation makes the HTTP contract an explicit layer between presentation and backend services.

11. The main runtime data flow is: user interaction in the React SPA → API calls through the frontend API layer → backend routes/controllers → model/database layer and, when needed, file upload/storage handling. Authenticated flows additionally pass through JWT-based middleware before reaching protected controllers.

12. In architectural terms, this is a modular monolith: one backend service with clear internal boundaries by feature, one frontend SPA, one database, and local filesystem storage for uploaded assets. The most important diagram boundaries are frontend vs backend, API vs persistence, and authenticated vs public routes.

Main entry points: [`back-end/src/routes/index.ts`](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/index.ts) (Route hub), [`back-end/src/models/company.ts`](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/models/company.ts) (Domain models), [`front-end/src/routes/index.tsx`](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/routes/index.tsx) (Page routes), [`back-end/src/routes/textModuleRoutes.ts`](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/textModuleRoutes.ts) (Content API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Front-end SPA"]
  node_fe_entry["App shell<br/>React entry<br/>[main.tsx]"]
  node_fe_routes["Page routes<br/>React router<br/>[index.tsx]"]
  node_fe_directory["Directory<br/>page<br/>[Directory.tsx]"]
  node_fe_admin["Admin page<br/>[UserAdminPage.tsx]"]
  node_fe_error["Error page<br/>[ErrorPage.tsx]"]
  node_fe_cards["Directory UI<br/>components<br/>[DirectoryCard.tsx]"]
  node_fe_api["API layer<br/>HTTP client<br/>[index.ts]"]
  node_fe_company_api["Company API<br/>API module<br/>[CompanyAPI.ts]"]
end

subgraph group_backend["Back-end API"]
  node_be_entry["Server entry<br/>API bootstrap<br/>[index.ts]"]
  node_be_routes["Route hub<br/>HTTP routes<br/>[index.ts]"]
  node_be_auth["Auth routes<br/>auth boundary<br/>[authRoutes.ts]"]
  node_be_company["Company API<br/>feature module<br/>[companyRoutes.ts]"]
  node_be_catalog["Catalog API<br/>feature module<br/>[categoryRoutes.ts]"]
  node_be_content["Content API<br/>feature module"]
  node_be_users["User API<br/>feature module<br/>[userRoutes.ts]"]
  node_be_authmw["Auth middleware<br/>JWT guard<br/>[authMiddleware.ts]"]
  node_be_security["Security utils<br/>crypto<br/>[jwt.ts]"]
  node_be_models[("Domain models<br/>schema layer<br/>[company.ts]")]
  node_be_db[("DB connection<br/>persistence<br/>[connection.ts]")]
end

subgraph group_storage["Storage"]
  node_be_files["File storage<br/>filesystem"]
end

node_fe_entry -->|"mounts"| node_fe_routes
node_fe_routes -->|"renders"| node_fe_directory
node_fe_routes -->|"renders"| node_fe_admin
node_fe_routes -->|"renders"| node_fe_error
node_fe_directory -->|"uses"| node_fe_cards
node_fe_admin -->|"uses"| node_fe_cards
node_fe_cards -->|"calls"| node_fe_api
node_fe_api -->|"exports"| node_fe_company_api
node_fe_company_api -.->|"HTTP"| node_be_routes
node_be_entry -->|"registers"| node_be_routes
node_be_routes -->|"includes"| node_be_auth
node_be_routes -->|"includes"| node_be_company
node_be_routes -->|"includes"| node_be_catalog
node_be_routes -->|"includes"| node_be_content
node_be_routes -->|"includes"| node_be_users
node_be_auth -->|"protects"| node_be_authmw
node_be_company -->|"reads/writes"| node_be_models
node_be_catalog -->|"reads/writes"| node_be_models
node_be_content -->|"reads/writes"| node_be_models
node_be_users -->|"reads/writes"| node_be_models
node_be_models -->|"queries"| node_be_db
node_be_content -->|"stores"| node_be_files
node_be_security -->|"supports"| node_be_auth

click node_fe_entry "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/main.tsx"
click node_fe_routes "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/routes/index.tsx"
click node_fe_directory "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/pages/Directory.tsx"
click node_fe_admin "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/pages/UserAdminPage.tsx"
click node_fe_error "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/pages/ErrorPage.tsx"
click node_fe_cards "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/components/DirectoryCard.tsx"
click node_fe_api "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/api/index.ts"
click node_fe_company_api "https://github.com/sverdam/retotc2005b/blob/main/front-end/src/api/CompanyAPI.ts"
click node_be_entry "https://github.com/sverdam/retotc2005b/blob/main/back-end/index.ts"
click node_be_routes "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/index.ts"
click node_be_auth "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/authRoutes.ts"
click node_be_company "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/companyRoutes.ts"
click node_be_catalog "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/categoryRoutes.ts"
click node_be_content "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/textModuleRoutes.ts"
click node_be_users "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/userRoutes.ts"
click node_be_authmw "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/middlewares/authMiddleware.ts"
click node_be_security "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/security/jwt.ts"
click node_be_models "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/models/company.ts"
click node_be_db "https://github.com/sverdam/retotc2005b/blob/main/back-end/src/connection/connection.ts"
click node_be_files "https://github.com/sverdam/retotc2005b/tree/main/back-end/files"

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_fe_entry,node_fe_routes,node_fe_directory,node_fe_admin,node_fe_error,node_fe_cards,node_fe_api,node_fe_company_api toneBlue
class node_be_entry,node_be_routes,node_be_auth,node_be_company,node_be_catalog,node_be_content,node_be_users,node_be_authmw,node_be_security,node_be_models,node_be_db toneAmber
class node_be_files toneMint
```

## Components

### Front-end SPA

Client-side React application for browsing the directory and administering users.

- [App shell](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/main.tsx): React entry · Bootstraps the SPA and global UI styles. · `front-end/src/main.tsx`
- [Page routes](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/routes/index.tsx): React router · Defines the main client-side screens and navigation. · `front-end/src/routes/index.tsx`
- [Directory](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/pages/Directory.tsx): page · Public browsing experience for companies and filters. · `front-end/src/pages/Directory.tsx`
- [Admin page](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/pages/UserAdminPage.tsx): page · Authenticated administration surface for user or content management. · `front-end/src/pages/UserAdminPage.tsx`
- [Error page](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/pages/ErrorPage.tsx): page · Fallback screen for invalid or failed routes. · `front-end/src/pages/ErrorPage.tsx`
- [Directory UI](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/components/DirectoryCard.tsx): components · Cards, filters, modals, and footer used in the directory flow. · `front-end/src/components/DirectoryCard.tsx`
- [API layer](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/api/index.ts): HTTP client · Centralized browser-to-backend request wrapper. · `front-end/src/api/index.ts`
- [Company API](https://github.com/sverdam/retotc2005b/blob/main/front-end/src/api/CompanyAPI.ts): API module · Frontend contract for directory and company-related calls. · `front-end/src/api/CompanyAPI.ts`

### Back-end API

TypeScript service that exposes the HTTP API, auth, persistence, and file handling.

- [Server entry](https://github.com/sverdam/retotc2005b/blob/main/back-end/index.ts): API bootstrap · Starts the backend service and wires the application runtime. · `back-end/index.ts`
- [Route hub](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/index.ts): HTTP routes · Aggregates feature routes into the API surface. · `back-end/src/routes/index.ts`
- [Auth routes](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/authRoutes.ts): auth boundary · Dedicated authentication endpoints separate from CRUD resources. · `back-end/src/routes/authRoutes.ts`
- [Company API](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/companyRoutes.ts): feature module · Company read/write endpoints and controllers. · `back-end/src/routes/companyRoutes.ts`
- [Catalog API](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/categoryRoutes.ts): feature module · Category, location, filter, and contact endpoints that enrich company data. · `back-end/src/routes/categoryRoutes.ts`
- [Content API](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/textModuleRoutes.ts): feature module · Text and file module endpoints for attached content. · `back-end/src/routes/textModuleRoutes.ts`
- [User API](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/routes/userRoutes.ts): feature module · User administration endpoints. · `back-end/src/routes/userRoutes.ts`
- [Auth middleware](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/middlewares/authMiddleware.ts): JWT guard · Verifies JWTs and protects sensitive routes. · `back-end/src/middlewares/authMiddleware.ts`
- [Security utils](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/security/jwt.ts): crypto · Password hashing and JWT helpers used by auth flows. · `back-end/src/security/jwt.ts`
- [Domain models](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/models/company.ts): schema layer · Company, user, category, location, filter, text, file, and contact entities. · `back-end/src/models/company.ts`
- [DB connection](https://github.com/sverdam/retotc2005b/blob/main/back-end/src/connection/connection.ts): persistence · Database connection used by the model layer. · `back-end/src/connection/connection.ts`

### Storage

Relational database and local filesystem used by the backend.

- [File storage](https://github.com/sverdam/retotc2005b/tree/main/back-end/files): filesystem · Uploaded documents, images, logos, and temp files on disk. · `back-end/files`

## Connections

- App shell → Page routes: mounts · The SPA entry mounts the client-side route tree.
- Page routes → Directory: renders · Route tree serves the directory browsing page.
- Page routes → Admin page: renders · Route tree serves the administration page.
- Page routes → Error page: renders · Route tree serves the fallback error page.
- Directory → Directory UI: uses · Directory page composes cards, filters, and modals.
- Admin page → Directory UI: uses · Admin flow reuses shared UI components.
- Directory UI → API layer: calls · UI components trigger API requests through the shared client.
- API layer → Company API: exports · Central API layer exposes the company contract.
- Company API → Route hub: HTTP · Browser requests travel to the backend route hub.
- Server entry → Route hub: registers · Server bootstrap attaches the aggregate routes.
- Route hub → Auth routes: includes · Main router includes dedicated auth endpoints.
- Route hub → Company API: includes · Main router includes company endpoints.
- Route hub → Catalog API: includes · Main router includes catalog and enrichment endpoints.
- Route hub → Content API: includes · Main router includes content and file module endpoints.
- Route hub → User API: includes · Main router includes user administration endpoints.
- Auth routes → Auth middleware: protects · Authenticated access passes through JWT middleware.
- Company API → Domain models: reads/writes · Company controllers operate through domain models.
- Catalog API → Domain models: reads/writes · Catalog controllers persist structured metadata.
- Content API → Domain models: reads/writes · Content controllers persist text and file module records.
- User API → Domain models: reads/writes · User controllers operate through the user model.
- Domain models → DB connection: queries · Models depend on the database connection.
- Content API → File storage: stores · File module handling moves uploads into local storage.
- Security utils → Auth routes: supports · Hashing and JWT helpers underpin authentication.
