# ljcl79/api-nodejs-express-typeorm-mysql architecture

> Architecture diagram of the GitHub repository ljcl79/api-nodejs-express-typeorm-mysql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ljcl79/api-nodejs-express-typeorm-mysql
- Repository: https://github.com/ljcl79/api-nodejs-express-typeorm-mysql

## Overview

##### Project type and purpose
- This is a backend-only REST API built with Node.js, Express.js and TypeScript, using TypeORM to talk to a PostgreSQL database.
- It exposes CRUD operations for three primary resources: Estudiantes (students), Profesores (professors) and Cursos (courses).

##### File structure
- src/index.ts: application entry point that loads the Express server.
- src/app.ts: configures Express (JSON parsing, middleware).
- src/routes/*.ts: defines HTTP routes for each resource.
- src/controllers/*.ts: houses the request handlers (create, read, update, delete).
- src/models/*.ts: TypeORM entity definitions for each table.
- src/db/conexion.ts: initializes and exports the TypeORM connection.
- build/index.js: compiled output for production.
- tsconfig.json / package.json: build & dependency config.

##### README for additional insights
- Uses TypeORM for entity-relationship mapping (1-N, N-M).
- PostgreSQL is the production datastore.
- Architecture follows a standard MVC pattern:
- Model = TypeORM entities
- Controller = business logic + ORM queries
- View = not applicable (API only)
- Routes = HTTP interface

##### Detailed capture of essential elements
- Don’t just show “API” and “DB” – break the API into Router → Controller → ORM.
- Types of entity relationships (1-N between Profesor→Cursos, N-M between Estudiante↔Curso).
- Call out the TypeORM connection module (src/db/conexion.ts) as the bridge to PostgreSQL.

## Diagram (Mermaid)

```mermaid
flowchart TB
    client["Client"]:::external

    subgraph "Express API Server"
        entry["src/index.ts"]:::code
        config["src/app.ts"]:::code

        subgraph "Router Layer"
            cursosRoute["src/routes/cursosRoutes.ts"]:::code
            estudiantesRoute["src/routes/estudiantesRoutes.ts"]:::code
            profesoresRoute["src/routes/profesoresRoutes.ts"]:::code
        end

        subgraph "Controller Layer"
            cursosCtrl["src/controllers/cursosController.ts"]:::code
            estudiantesCtrl["src/controllers/estudiantesController.ts"]:::code
            profesoresCtrl["src/controllers/profesoresController.ts"]:::code
        end

        subgraph "ORM/Model Layer"
            conexion["src/db/conexion.ts"]:::code
            cursoModel["src/models/cursoModel.ts"]:::model
            estudianteModel["src/models/estudianteModel.ts"]:::model
            profesorModel["src/models/profesoresModel.ts"]:::model
        end
    end

    db["PostgreSQL Database"]:::db

    pkg["package.json"]:::config
    tscfg["tsconfig.json"]:::config
    build["build/index.js"]:::build

    client -->|"HTTP Request"| entry
    entry --> config
    config --> cursosRoute
    config --> estudiantesRoute
    config --> profesoresRoute

    cursosRoute -->|"handles routes"| cursosCtrl
    estudiantesRoute -->|"handles routes"| estudiantesCtrl
    profesoresRoute -->|"handles routes"| profesoresCtrl

    cursosCtrl -->|"uses ORM"| conexion
    estudiantesCtrl -->|"uses ORM"| conexion
    profesoresCtrl -->|"uses ORM"| conexion

    conexion -->|"executes queries"| db
    db -->|"returns data"| conexion

    pkg --> build
    tscfg --> build

    classDef external fill:#E7F0FD,stroke:#0366d6
    classDef code fill:#D0E8FF,stroke:#0366d6
    classDef model fill:#DFFFE0,stroke:#2D6A0F
    classDef db fill:#FFEFD0,stroke:#D97706,stroke-dasharray:5 5
    classDef build fill:#F0F0F0,stroke:#999
    classDef config fill:#FFF0F5,stroke:#C71585

    click entry "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/index.ts"
    click config "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/app.ts"
    click cursosRoute "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/routes/cursosRoutes.ts"
    click estudiantesRoute "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/routes/estudiantesRoutes.ts"
    click profesoresRoute "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/routes/profesoresRoutes.ts"
    click cursosCtrl "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/controllers/cursosController.ts"
    click estudiantesCtrl "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/controllers/estudiantesController.ts"
    click profesoresCtrl "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/controllers/profesoresController.ts"
    click conexion "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/db/conexion.ts"
    click cursoModel "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/models/cursoModel.ts"
    click estudianteModel "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/models/estudianteModel.ts"
    click profesorModel "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/src/models/profesoresModel.ts"
    click build "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/build/index.js"
    click tscfg "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/tsconfig.json"
    click pkg "https://github.com/ljcl79/api-nodejs-express-typeorm-mysql/blob/main/package.json"
```
