# Megh > A TypeScript-first web framework built on Fastify. Decorator routing, dependency injection, validation, OpenAPI, MeghORM, queues, mail and a CLI, for building REST APIs in TypeScript. Each link is the page as markdown; drop `.md` for the HTML page. Every page in one file: https://meghjs.github.io/llms-full.txt. For version-matched docs and project tools inside an editor, use the Megh MCP server: `npx -y @meghjs/mcp`. ## Getting Started - [Introduction](https://meghjs.github.io/getting-started/introduction.md): What Megh is, who it's for, what it includes and how it compares. - [Installation](https://meghjs.github.io/getting-started/installation.md): Creating a Megh project with the CLI, or setting one up by hand. - [Quick Start](https://meghjs.github.io/getting-started/usage.md): Writing your first routes, with a controller or inline, returning responses and running the app. - [Application](https://meghjs.github.io/getting-started/application.md): Creating the app, its options, the use* methods, what run() does, lifecycle hooks and shutdown. ## The Basics - [Controllers](https://meghjs.github.io/core-concept/controller.md): Defining routes with controllers, reading route parameters, building REST controllers and returning errors. - [Middleware](https://meghjs.github.io/core-concept/middleware.md): Creating and applying Megh middleware. - [Validation](https://meghjs.github.io/core-concept/validation.md): Validating request bodies and query strings with DTOs, custom and async validators, and shaping responses with Expose and Exclude. - [Error Handling](https://meghjs.github.io/core-concept/error-handling.md): HTTP exceptions, the default error response, and custom exception filters. - [Configuration and Environment](https://meghjs.github.io/core-concept/configuration.md): Reading environment variables, loading .env, and typed config classes with @AppConfig and GetConfig. - [Dependency Injection](https://meghjs.github.io/core-concept/dependency-injection.md): Registering services and injecting them with constructors, inject() and tokens. - [Request Context](https://meghjs.github.io/core-concept/request-context.md): Per-request values (the user, a tenant, a transaction) readable anywhere in the request, without passing them through every call. ## Security - [Authentication](https://meghjs.github.io/core-concept/authentication.md): Identifying callers and protecting routes. - [Sessions](https://meghjs.github.io/advanced/sessions.md): Cookie sessions, flash messages and login state for server-rendered apps. - [Hashing](https://meghjs.github.io/core-concept/hashing.md): Hash and check passwords with scrypt, bcrypt or argon2id, and upgrade old hashes at sign-in. - [Security Hardening](https://meghjs.github.io/production/security.md): What Megh protects by default, and the checklist for running an app in production. ## Database - [MeghORM](https://meghjs.github.io/advanced/orm.md): Megh's built-in, type-safe ORM on Kysely. Installing a driver, connecting, and where to find models, queries, relations, migrations and seeding. - [Models](https://meghjs.github.io/advanced/orm/models.md): Defining MeghORM models with decorators: columns, keys, column names, timestamps, soft deletes and casts. - [Queries](https://meghjs.github.io/advanced/orm/queries.md): Reading and writing rows with MeghORM models: where clauses, joins, aggregates, scopes, pagination, large results, locks, upserts, writes and transactions. - [Relations](https://meghjs.github.io/advanced/orm/relations.md): MeghORM relations: hasMany, hasOne, belongsTo, belongsToMany, has-many-through and polymorphic relations, eager loading, relation queries and aggregates. - [Query Builder](https://meghjs.github.io/advanced/orm/query-builder.md): The DB query builder and raw SQL in MeghORM, for queries that don't map to a model. - [Migrations](https://meghjs.github.io/advanced/orm/migrations.md): Creating and changing tables with MeghORM migrations and the schema builder. - [Seeding and Factories](https://meghjs.github.io/advanced/orm/seeding.md): Filling the database with seeders, and building fake rows with model factories and Faker. - [TypeORM and Knex](https://meghjs.github.io/advanced/database.md): Using TypeORM or Knex through @meghjs/data, as an alternative to MeghORM. ## Frontend - [Views](https://meghjs.github.io/advanced/views.md): Server-rendered HTML with Blade-style templates. - [Vite](https://meghjs.github.io/advanced/vite.md): Browser code in frontend/, built by Vite and loaded in views with @vite. - [Inertia.js](https://meghjs.github.io/advanced/inertia.md): Build a single-page app with Vue, React or Svelte pages and Megh controllers, using the Inertia.js protocol. ## Files and Storage - [File Uploads](https://meghjs.github.io/advanced/file-uploads.md): Receiving and storing uploaded files safely. - [Storage](https://meghjs.github.io/advanced/storage.md): Read and write files on named disks, local or in the cloud (S3 and S3-compatible services, Azure Blob Storage, Google Cloud Storage), with presigned URLs and an in-memory fake for tests. ## Messaging and Background Work - [Messaging](https://meghjs.github.io/advanced/messaging.md): Events between processes and replicas over Redis Streams or RabbitMQ, with retries, dead letters, dedupe and a transactional outbox. - [Events](https://meghjs.github.io/advanced/events.md): Dispatching and handling events in a Megh application. - [Queue](https://meghjs.github.io/advanced/queue.md): Background jobs in memory, on Redis or on RabbitMQ. - [Scheduler](https://meghjs.github.io/advanced/scheduler.md): Running methods on a cron schedule, a fixed interval, or once after startup. - [Mail](https://meghjs.github.io/advanced/mail.md): Send email with mailable classes, over SMTP or a provider's API, now or from a queue. - [Notifications](https://meghjs.github.io/advanced/notifications.md): Send one message to users over mail and Socket.IO. ## APIs and Realtime - [OpenAPI](https://meghjs.github.io/microservices/openapi.md): Generating API documentation from your controllers: typed options, request bodies and responses from DTOs and models, and secured routes. - [WebSocket](https://meghjs.github.io/microservices/websocket.md): Realtime communication with Socket.IO. - [Caching](https://meghjs.github.io/advanced/caching.md): In-memory and Redis caching with tags. ## AI - [LLM Tools](https://meghjs.github.io/ai/tools.md): Turn Megh routes into LLM tools with @Tool() from @meghjs/ai. Every call runs through authentication, authorization and validation. - [Agents](https://meghjs.github.io/ai/agents.md): Run LLM agents on Megh queues with @Agent from @meghjs/ai. Each step is a queue job, saved as it goes, with hard limits and tools that run as the user who started the run. - [MCP Server](https://meghjs.github.io/ai/mcp.md): Connect AI assistants to your Megh app with @meghjs/mcp, the Megh Model Context Protocol server. ## Testing and Operations - [Testing](https://meghjs.github.io/advanced/testing.md): Unit testing controllers and services, and sending requests to your routes with MeghTest. - [Logging](https://meghjs.github.io/advanced/logging.md): Structured logging with LoggerService. - [Tracing](https://meghjs.github.io/advanced/tracing.md): Trace requests with OpenTelemetry. - [Monitoring](https://meghjs.github.io/advanced/monitoring.md): A live dashboard for a running app with megh monit. - [Health Checks](https://meghjs.github.io/advanced/health.md): Liveness and readiness endpoints for load balancers and orchestrators. - [Deployment](https://meghjs.github.io/production/deployment.md): Building a Megh app, running it in production, containers, process managers and migrations. ## CLI - [CLI](https://meghjs.github.io/cli/basic.md): The megh command: create, run and build apps, generate code and manage the database. - [Generators](https://meghjs.github.io/cli/generators.md): Generating resources, controllers, services, models, classes, middleware, config classes and their unit tests with the Megh CLI. - [Database Commands](https://meghjs.github.io/cli/database.md): Running migrations, seeders and factories with the Megh CLI. - [Scaffold](https://meghjs.github.io/cli/scaffold/index.md): Generate tables, models and whole features from templates with the Megh CLI. - [Templates and Fields](https://meghjs.github.io/cli/scaffold/templates.md): Create tables and models from templates and field specs with make:model --template and --fields. - [Domains](https://meghjs.github.io/cli/scaffold/domains.md): Scaffold the tables of a business domain, such as e-commerce, POS or medical, with scaffold:domain. - [Auth](https://meghjs.github.io/cli/scaffold/auth.md): Scaffold sign-up and sign-in with JWTs, API keys or both, and optionally roles and permissions, with scaffold:auth. - [RBAC](https://meghjs.github.io/cli/scaffold/rbac.md): Add roles and permissions to an app's users with scaffold:rbac, and check them with @Authorized. ## Extending - [Plugins](https://meghjs.github.io/advanced/plugins.md): Add features to a Megh app with plugins, write your own, and publish them as packages. With worked examples for maintenance mode, a Redis client and an audit log. ## Reference - [API Reference](https://meghjs.github.io/reference/api.md): Every public export of @meghjs/core, grouped by area, with signatures for the application methods and decorators. - [Versioning Policy](https://meghjs.github.io/reference/versioning.md): How Megh versions its packages, what counts as a breaking change, and how to upgrade. - [FAQ and Troubleshooting](https://meghjs.github.io/reference/faq.md): Answers to common questions and fixes for the problems people hit most often. ## Upgrade Guides - [Upcoming changes](https://meghjs.github.io/getting-started/upgrading-next.md): Changes on main since 0.8.0 that will ship in the next release: megh serve compiles into .megh/build instead of dist/, internal exports removed from @meghjs/core, renamed exports (ValidateOptions, ArrayNotEmpty, Injectable, generateSwaggerSchema, EventDispatchOptions, SocketDispatchOptions), and new HttpExceptions shortcuts. - [Upgrading to 0.8](https://meghjs.github.io/getting-started/upgrading-0.8.md): What changes in Megh 0.8.0: messaging, notifications, OpenTelemetry tracing, the megh monit dashboard, hashing, storage disks, agents and megh upgrade; @ApiController renamed to @Controller, messaging over Redis Streams or RabbitMQ, queues on transports instead of drivers, Megh-owned job types, Redis connection options instead of ioredis clients, and scheduler jobs that run once across replicas. - [Upgrading to 0.7](https://meghjs.github.io/getting-started/upgrading-0.7.md): What changes in Megh 0.7.3, 0.7.2, 0.7.1 and 0.7.0: sessions, gates and @auth/@can view directives, editor support for templates, LLM tools and an MCP server for your app (@meghjs/ai), AGENTS.md and llms.txt for coding agents, optional class-validator and class-transformer, a fuller ORM (constrained eager loading, upserts, model events, hidden columns, polymorphic relations), server-rendered views, the @meghjs/mcp server, deny-by-default authorization and the request context API. - [Upgrading to 0.6](https://meghjs.github.io/getting-started/upgrading-0.6.md): What changes in Megh 0.6: removed no-op APIs, run() reading PORT, framework logs through the logger and a safer scaffolded .env in 0.6.0; mail, security headers and rate limiting in 0.6.1; module-first generators, event, queue and task generators and change review in 0.6.3; generated tests, make:test, make:class, make:model --orm/--typeorm, compression, versioning and env schemas in 0.6.5. - [Upgrading to 0.5.5](https://meghjs.github.io/getting-started/upgrading-0.5.md): What changes in Megh 0.5.1 to 0.5.5: Megh's own validation decorators, exception filters, health checks and request IDs, one pipeline order, scaffolding from templates, auth and RBAC, seeders and factories, typed OpenAPI responses, SQL Server fixes, useMeghORM and Megh's own DI container. - [Moving from Avleon to Megh](https://meghjs.github.io/getting-started/upgrading-megh.md): Avleon is now Megh. How to move an Avleon project to the @meghjs packages. - [Upgrading to 0.4](https://meghjs.github.io/getting-started/upgrading-0.4.md): Breaking changes from 0.3 and what is new in 0.4. - [Upgrading to 0.3](https://meghjs.github.io/getting-started/upgrading.md): Breaking changes from 0.2 and known issues in 0.3.0.