- Node.js 22+
- Docker (optional, for database)
- PostgreSQL (can be via Docker)
git clone https://github.com/medinavs/webinar-api.git
cd webinar-api
npm install-
Configure the
.envfile with theDATABASE_URLvariable for PostgreSQL. -
To run the database using Docker:
docker-compose up
-
Run Prisma migrations:
npm run prisma:migrate
-
Create entities from the Prisma schema:
npm run prisma:push
-
Populate Database:
npm run db:populate
npm run buildnpm run start:dev- The API will be available at
http://localhost:8080 - Swagger documentation at
http://localhost:8080/docs
- Fastify as the main HTTP framework for high performance.
- Prisma as ORM for PostgreSQL integration.
- Better Auth for authentication and session management.
- Modular structure: clear separation between infrastructure, domain modules (e.g., webinars, categories), and shared utilities. The project follows SOLID principles to ensure maintainability, scalability, and clear responsibility separation.
- Validation: Zod for data and schema validation.
- Swagger: automatic route documentation via Fastify plugins (implemented, but routes are not yet documented).
- Access control: Middleware for authentication.
- Environment variables: Validated at runtime with Zod.
.
├── prisma/ # Prisma schema and migrations
├── src/
│ ├── infrastructure/ # Auth, config, database, HTTP plugins/middlewares
│ ├── modules/
│ │ └── content/*
│ │ ├── http/ # Controllers and routes
│ │ ├── repositories/ # repositories contracts and concrete implementation
│ │ └── use-cases/ # Business logic for domains
│ ├── shared/
│ │ ├── constants/ # Shared constants
│ │ ├── exceptions/ # Custom error classes
│ │ ├── models/ # Shared models/interfaces
│ │ └── utils/ # Utility functions
│ └── app.ts # Fastify app setup
│ └── server.ts # Server entrypoint
├── .env # Environment variables (not in repo)
├── .eslintrc.json # Lint config
├── .example.env # Example environment variables
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker build configuration
├── package.json # NPM scripts and dependencies
├── tsconfig.json # TypeScript config
└── vite.config.js # Vite config for path alias ("@")
The API uses decorator-based routing with controllers for each domain. Main endpoints:
-
Webinars
GET /webinars: List webinars (with filters)GET /webinars/populars: List of most popular webinarsGET /webinars/recents: List of recents webinarsGET /webinars/:id: Get webinar detailsGET /webinars/registered/:userId: List webinars a user is registered forPOST /webinars/:webinarId/registrations: Register authenticated user for a webinar
-
Categories
GET /categories: List all categories
-
Auth
- "*" all auth endpoints from BetterAuth (admin plugin too)
POST /api/auth/sign-up: Create user accountPOST /api/auth/sign-in: LoginPOST /api/auth/sign-out: LogoutGET /api/auth/session: Get current session
- Implement automated tests (unit and integration).
- Add caching for frequent queries (e.g., categories, webinars).
- Implement more detailed roles and permissions for users.
- Enhanced monitoring and logging for production.
- Add documentation to endpoints and example payloads.