Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
davidleonmayor avatar

Backend Context

  • 1 installs
  • 3 repo stars
  • Updated June 17, 2026
  • davidleonmayor/proyecto-grado-unimayor

Manages backend architecture context and API design for university capstone project.

About

Academic skill documenting backend patterns and API structure for graduation project. Educational reference.

  • API design patterns
  • Backend documentation

Backend Context by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #3,836 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/davidleonmayor/proyecto-grado-unimayor --skill backend-context

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars3
Last updatedJune 17, 2026
Repositorydavidleonmayor/proyecto-grado-unimayor

What it does

Manages backend architecture context and API design for university capstone project.

Files

SKILL.mdMarkdownGitHub ↗

Stack

TechnologyVersionPurpose
Express.js5HTTP framework
TypeScript5Language
Prisma6ORM
MySQL-Database
Zod4Env validation
express-validator7Request validation
JWT (jsonwebtoken)9Authentication
Winston3Logging
Morgan1HTTP request logging
Multer2File uploads
Brevo3Transactional emails
Nodemailer7Email (fallback)
Jest + ts-jest-Testing
Supertest7HTTP testing

File Naming Example:

  • sendAuthEmail.test.ts (all tests with .test extencion)
  • createToken.ts (common files use camel case)
  • auth.controller.ts | auth.route.ts auth.schema.ts auth.service.ts (for each repositori spesification)
  • AuthMiddleware.ts (Uper camel case for classes)
  • create-token.ts (WRONG - do no separate be -)
  • sign-up-validation.spec.ts | sing-up-validation.ts(WRONG )

Scope Detection (ASK IF AMBIGUOUS)

User SaysAction
"a test", "one test", "new test", "add test"Create ONE test() in existing spec
"comprehensive tests", "all tests", "test suite", "generate tests"Create full suite
"create route", "create router"Trigger backend-router skill and add it
"create schema", "add validation"Trigger backend-schema skill and add it

Examples:

  • "Create a test for user sign-up" → ONE test only
  • "Generate E2E tests for login page" → Full suite
  • "Add a test to verify form validation" → ONE test to existing spec
  • "create POST /login route” → ONE route

Directory Structure

backend/
├── prisma/                   # Database schema, migrations, seeds
│   ├── schema.prisma         # MySQL schema definition
│   ├── migrations/           # Prisma migration history
│   ├── seed.ts               # Database seeder
│   └── clear.ts              # Database cleanup script
├── src/
│   ├── index.ts              # Entry point — instantiates Server
│   ├── server.ts             # Server class (middlewares, routes, shutdown)
│   ├── config/               # App configuration (envs, prisma, logger, cors, email clients)
│   ├── routes/               # Route class definitions — mounted under /api/
│   ├── controllers/          # Request handlers for each domain
│   ├── auth/                 # Self-contained auth module (routes, controller, service, schema, tests)
│   ├── common/               # Shared code
│   │   ├── middleware/       # Auth, Role, validation, error handling, timeout
│   │   ├── schema/           # Global validation schemas
│   │   └── utils/            # Helpers (asyncHandler, createToken)
│   ├── email/                # Email templates (Brevo / Nodemailer)
│   ├── example/              # Reference module for new features
│   └── __test__/             # Integration / unit tests
├── logs/                     # Winston log output (gitignored)
├── docs/                     # Additional documentation
└── jest.config.js            # Jest + ts-jest config

Architecture

The backend uses two architectural patterns:

Repository pattern — Self-contained modules under src/ with own routes, controller, service, schema, and tests. Each repository owns its full vertical slice.

RepositoryPathDescription
authsrc/auth/Authentication, JWT, password flows — details

Layered pattern — Domains that share src/routes/, src/controllers/ and src/common/. Currently used by the remaining modules while migrating to repository pattern.

DomainRoutesController
projectssrc/routes/project.routes.tssrc/controllers/project.controller.ts
eventssrc/routes/event.routes.tssrc/controllers/event.controller.ts
personssrc/routes/person.routes.tssrc/controllers/person.controller.ts

Request flow:

Request → Middleware Chain → Route Class → Controller → Service → Prisma → MySQL
                                              ↓
                                         schema (express-validator)

Layered responsibilities:

LayerResponsibilityLocation
ServerBootstrap, middleware chain, graceful shutdownsrc/server.ts
RoutesHTTP method + path + middleware stack per endpointsrc/routes/, src/auth/auth.routes.ts
ControllerParse request, call service/prisma, format responsesrc/controllers/, src/auth/auth.controller.ts
ServiceBusiness logic, reusable operationssrc/auth/auth.service.ts
SchemaRequest validation rules (express-validator)src/auth/auth.schema.ts, src/common/schema/
MiddlewareCross-cutting: auth, roles, timeout, errors, loggingsrc/common/middleware/
ConfigSingletons and env-validated settingssrc/config/

Request lifecycle:

1. requestTimeout(30s) wraps the request 2. Body parsers (json, urlencoded) with 10mb limit 3. CORS via corsConfig 4. Morgan HTTP logging 5. Routes.init(app) matches the endpoint 6. Route-level middleware chain (e.g. authLimitervalidateSchemaauthMiddleware → controller) 7. Controller handles logic, returns response 8. Unmatched routes → notFound (404) 9. Errors → errorHandler (global catch-all)

Critical Patterns

Server Class

server.ts is a class-based Express setup. Middleware order matters:

1. requestTimeout(30000) — 30s global timeout 2. express.json({ limit: '10mb' }) — body parser 3. cors(corsConfig) — CORS 4. morganMiddleware — HTTP logging 5. Routes via Routes.init(app) 6. notFound — 404 handler 7. errorHandler — global error handler (always last)

Route Registration

Routes are class-based and mounted in src/routes/index.ts:

export class Routes {
    public static init(app: Application) {
        app.use("/api/auth", authRoutes.router);
        app.use("/api/projects", projectRoutes.router);
        app.use("/api/events", eventRoutes.router);
        app.use("/api/persons", personRoutes.router);
    }
}

All API endpoints live under /api/.

Route Class Pattern

export class MyRoutes {
    public router: Router;
    private controller: MyController;
    private authMiddleware: AuthMiddleware;

    constructor() {
        this.router = Router();
        this.controller = new MyController();
        this.authMiddleware = new AuthMiddleware();
        this.initRoutes();
    }

    public initRoutes() {
        this.router.get("/",
            this.authMiddleware.isAuthenticatedUser,
            this.controller.getItems
        );
    }
}

Authentication

  • JWT via Bearer token in Authorization header
  • AuthMiddleware.isAuthenticatedUser verifies token and attaches req.user (type Partial<persona>)
  • Token created with jsonwebtoken, secret from JWT_SECRET env var

Authorization (Roles)

Roles are determined by actores table (many-to-many between persona and trabajo_grado with tipo_rol):

MiddlewareAllows
isPrivilegedUserDirector, Jurado, Coordinador de Carrera, Decano
isAdminadmin, Administrador, Admin
isCoordinatorCoordinador de Carrera, Coordinador
isDirectorOrProfessorDirector

Prisma (Database)

  • Singleton in config/prisma.ts via PrismaService.getInstance()
  • Import: import { prisma } from "../config"
  • MySQL database, models use Spanish names with @@map("TABLE_NAME")
  • Key models: persona, trabajo_grado, actores, seguimiento_tg, evento

Environment Variables

Validated with Zod in config/envs.ts. Required vars:

NODE_ENV, PORT, DATABASE_URL, JWT_SECRET,
FRONTEND_URL, NODEMAILER_*, BREVO_*

Access: import { envs } from "./config"

Validation

Two approaches coexist:

  • express-validator via validateSchema() middleware — wraps checkSchema()
  • zod — used for env validation, available for request schemas

Error Handling

Global error handler in common/middleware/errorHandler.ts handles:

  • Prisma errors (P2002 conflict, P2025 not found, P2003 FK violation)
  • JWT errors (invalid, expired)
  • JSON syntax errors
  • Generic errors with statusCode

Logging

Winston logger with levels: error, warn, info, http, debug.

  • Console + file transports (logs/error.log, logs/combined.log)
  • Development: debug level. Production: warn level.
  • Import: import { logger } from "../config"

File Uploads

Multer handles file uploads. Two configs in project.controller.ts:

  • upload — general file uploads (PDF, images)
  • excelUpload — Excel bulk upload (.xlsx, .xls)

Commands

pnpm dev                 # Dev server with nodemon (port 4000)
pnpm db:generate         # Generate Prisma client
pnpm db:migrate          # Run migrations
pnpm db:studio           # Open Prisma Studio
pnpm db:seed             # Seed database
pnpm db:clear            # Clear database
pnpm test                # Run tests (uses .env.test)

Resources

  • Repositories: See references/ for detailed context on each repository module
  • auth-context.md — Auth repository: endpoints, schemas, JWT, password flows

Related AI Skills

  • `backend-schema`: Guidelines for creating express-validator schemas.
  • `backend-router`: Guidelines for writing class-based Express routers.

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.