{"id":24056292,"url":"https://github.com/mohsen104/crud","last_synced_at":"2025-04-22T23:45:18.198Z","repository":{"id":269158121,"uuid":"905787704","full_name":"mohsen104/CRUD","owner":"mohsen104","description":"🔥 CRUD operations are fundamental building blocks for many applications, allowing for the management of persistent data.","archived":false,"fork":false,"pushed_at":"2025-02-08T13:29:24.000Z","size":264,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T20:04:23.526Z","etag":null,"topics":["backend","inversify","mongodb","mongoose","node-js","pino","reflect-metadata","swagger","typegoose","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohsen104.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-19T14:20:39.000Z","updated_at":"2025-03-13T12:54:48.000Z","dependencies_parsed_at":"2025-01-08T20:38:46.336Z","dependency_job_id":"a7af9c6d-486e-4270-b90a-f4dd73f4acb8","html_url":"https://github.com/mohsen104/CRUD","commit_stats":null,"previous_names":["mohsen104/crud"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen104%2FCRUD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen104%2FCRUD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen104%2FCRUD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohsen104%2FCRUD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohsen104","download_url":"https://codeload.github.com/mohsen104/CRUD/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250343865,"owners_count":21415035,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","inversify","mongodb","mongoose","node-js","pino","reflect-metadata","swagger","typegoose","typescript"],"created_at":"2025-01-09T05:00:28.966Z","updated_at":"2025-04-22T23:45:18.191Z","avatar_url":"https://github.com/mohsen104.png","language":"TypeScript","readme":"# Backend Project\n\nThis project is a backend service built using modern technologies and powerful Node.js libraries. It employs modern architectures such as Dependency Injection and Decorators to ensure clean, maintainable, and scalable code.\n\n## Table of Contents\n\n- [Technologies Used](#technologies-used)\n- [Project Structure](#project-structure)\n- [Setup and Installation](#setup-and-installation)\n- [API Documentation](#api-documentation)\n- [Logging](#logging)\n- [Dependency Injection](#dependency-injection)\n- [Routing](#routing)\n- [Decorators](#decorators)\n- [Running the Project](#running-the-project)\n\n---\n\n## Technologies Used\n\n### Core Dependencies\n- **Express.js**: A fast and minimalist web framework for Node.js, used to handle HTTP requests and routing.\n- **Mongoose**: An ODM (Object Data Modeling) library for MongoDB, used to interact with the database.\n- **Typegoose**: A wrapper for Mongoose that allows defining models using TypeScript classes and decorators.\n- **Inversify**: A powerful dependency injection (DI) container for TypeScript and JavaScript, used to manage dependencies and promote modularity.\n- **Zod**: A TypeScript-first schema validation library, used for validating input data.\n- **Pino**: A fast and low-overhead logging library, used for structured logging.\n- **Swagger UI Express**: A middleware to serve Swagger API documentation.\n\n### Development Dependencies\n- **@types/express**: TypeScript definitions for Express.\n- **@types/mongoose**: TypeScript definitions for Mongoose.\n- **pino-pretty**: A prettifier for Pino logs to make them more readable during development.\n- **pino-mongodb**: A transport for Pino to store logs in MongoDB.\n\n---\n\n## Project Structure\n\nThe project is organized into modules, with each module containing its own controllers, services, and models. The main components include:\n\n- **`src/index.routes.ts`**: Handles route setup and registration.\n- **`src/modules/`**: Contains application modules (e.g., `user` module).\n- **`src/common/`**: Shared utilities, configurations, and types.\n- **`src/exceptions/`**: Custom exception handlers.\n- **`src/configs/`**: Configuration files for MongoDB, logging, etc.\n- **`openapi.json`**: OpenAPI specification for API documentation.\n\n---\n\n## Setup and Installation\n\n1. Clone the repository:\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd \u003cproject-folder\u003e\n   ```\n\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n3. Set up environment variables:\n   Create a `.env` file in the root directory and add the following variables:\n   ```\n   PORT=3000\n   MONGODB_URI=\u003cyour-mongodb-uri\u003e\n   MONGODB_DATABASE=\u003cyour-database-name\u003e\n   ```\n\n4. Start the server:\n   ```bash\n   npm start\n   ```\n\n---\n\n## API Documentation\n\nThe API documentation is generated using Swagger and is available at `/api-docs`. The OpenAPI specification is defined in the `openapi.json` file.\n\nTo access the documentation:\n1. Start the server.\n2. Navigate to `http://localhost:\u003cPORT\u003e/api-docs`.\n\n---\n\n## Logging\n\nThe project uses **Pino** for structured logging. Logs are output in JSON format and can be prettified during development using `pino-pretty`. Additionally, logs can be stored in MongoDB using `pino-mongodb`.\n\nExample log output:\n```json\n{\n  \"level\": \"info\",\n  \"time\": 1633024800000,\n  \"msg\": \"Request received: GET /api/v1/users\"\n}\n```\n\n---\n\n## Dependency Injection\n\nDependency Injection (DI) is implemented using **Inversify**. This allows for better modularity and testability by decoupling dependencies.\n\nExample of DI setup:\n```typescript\nimport { Container } from 'inversify';\nimport { UserService } from '@modules/user/user.service';\nimport { UserController } from '@modules/user/user.controller';\n\nconst container = new Container();\ncontainer.bind\u003cUserService\u003e(UserService).toSelf();\ncontainer.bind\u003cUserController\u003e(UserController).toSelf();\n\nexport default container;\n```\n\n---\n\n## Routing\n\nRoutes are dynamically registered using decorators and metadata reflection. The `setupRoutes` function scans controllers and registers routes based on the metadata.\n\nExample route registration:\n```typescript\n@Controller('/users')\nclass UserController {\n  @Get('/')\n  getUsers() {\n    // Handle GET /api/v1/users\n  }\n\n  @Post('/')\n  createUser() {\n    // Handle POST /api/v1/users\n  }\n}\n```\n\n---\n\n## Decorators\n\nCustom decorators are used to define routes and metadata for controllers and methods. These decorators simplify route registration and make the code more declarative.\n\nExample decorators:\n```typescript\n@Controller('/users')\nclass UserController {\n  @Get('/')\n  getUsers() {\n    // Handle GET /api/v1/users\n  }\n\n  @Post('/')\n  @Middleware(someMiddleware)\n  createUser() {\n    // Handle POST /api/v1/users\n  }\n}\n```\n\n---\n\n## Running the Project\n\n1. Ensure MongoDB is running and accessible.\n2. Start the server:\n   ```bash\n   npm start\n   ```\n3. The server will be available at `http://localhost:\u003cPORT\u003e`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohsen104%2Fcrud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohsen104%2Fcrud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohsen104%2Fcrud/lists"}