r-agency-mesh
v1.435.0
Published
My owen mesh graphql server
Downloads
3,251
Readme
Mesh Server
Overview
Mesh Server is a powerful, modular GraphQL server framework built with TypeScript. It provides a flexible architecture for building scalable backend applications with support for GraphQL, REST APIs, WebSockets, and more.
Features
- GraphQL API: Built-in GraphQL server with schema generation
- Plugin System: Extensible architecture with plugin support
- Multiple Communication Protocols: HTTP, GraphQL, WebSockets
- Database Integration: Support for PostgreSQL and MySQL through TypeORM
- Authentication: Built-in authentication and authorization
- Caching: Integrated caching mechanisms
- Task Scheduling: Cron job support for scheduled tasks
- Event System: Comprehensive event management
- Media Handling: Tools for managing media files
- Performance Monitoring: Built-in performance tracking
Installation
Prerequisites
- Node.js (v16 or higher)
- npm or yarn
- PostgreSQL or MySQL (depending on your configuration)
Steps
Clone the repository:
git clone <repository-url> cd mesh/serverInstall dependencies:
npm installConfigure environment variables:
- Create a
.envfile in the root directory - Add required environment variables (see Configuration section)
- Create a
Build the project:
npm run build-devStart the development server:
npm run dev
Configuration
Mesh Server uses a combination of environment variables and configuration files:
Environment Variables
Create a .env file in the root directory with the following variables:
# Server Configuration
HTTP_PORT=3000
GRAPHQL_PORT=4000
WEBSOCKET_PORT=5000
GRAPHQL_PATH=/graphql
# Database Configuration
DB_TYPE=postgres # or mysql
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=username
DB_PASSWORD=password
DB_DATABASE=mesh
# Other Configuration
NODE_ENV=developmentConfiguration Files
The mesh.config.yml file contains additional configuration options:
server:
http-port: 3000
graphql-port: 4000
websocket-port: 5000
graphql-path: /graphql
http-request-limit: 50mb
graphql-request-limit: 50mbUsage
Starting the Server
Development mode:
npm run devProduction mode:
npm run start-prodUsing Forever (for production):
npm run startCreating a GraphQL API
- Define your GraphQL schema in the appropriate directory
- Create resolvers for your schema
- The server will automatically generate the necessary code
Architecture
Mesh Server follows a modular, plugin-based architecture:
Core Components
- Bootstrap: Initializes and starts the server
- MeshConfig: Manages configuration
- PluginManager: Handles plugin registration and execution
- EventManager: Manages event emission and handling
- GraphQlSchemaBuilder: Generates GraphQL schema
Key Directories
- src/core: Core framework components
- async-worker: Asynchronous task processing
- auth: Authentication and authorization
- boot: System initialization
- database: Database access and management
- graphql: GraphQL implementation
- plugin: Plugin system
- websocket: WebSocket implementation
- rest-api: REST API implementation
- event-manager: Event handling
- helper: Utility functions
API Documentation
GraphQL API
The GraphQL API is available at the configured endpoint (default: /graphql). You can use tools like GraphQL Playground or Apollo Studio to explore the API.
WebSocket API
WebSocket connections are available on the configured port (default: 5000).
Development
Available Scripts
npm run build-dev: Build for developmentnpm run build-prod: Build for productionnpm run dev: Start development server with hot reloadingnpm run lint: Run ESLintnpm run lint:fix: Fix ESLint issuesnpm run format: Format code with Prettiernpm run test: Run tests
Adding Plugins
Plugins can be added to extend the functionality of the server:
import { startServer } from './index';
import { MyCustomPlugin } from './plugins/my-custom-plugin';
startServer({
rootDir: __dirname,
loadGlobalEnv: true,
plugins: [new MyCustomPlugin()],
});Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit your changes:
git commit -am 'Add my feature' - Push to the branch:
git push origin feature/my-feature - Submit a pull request
License
ISC License
