{"id":20159402,"url":"https://github.com/yolgesanchez/typescript_user_api_template","last_synced_at":"2026-02-09T10:33:13.287Z","repository":{"id":257870895,"uuid":"866233198","full_name":"YolgeSanchez/typescript_user_api_template","owner":"YolgeSanchez","description":"Nodejs, JWT, Express, Typescript, Zod, MongoDB, Jest, Supertest","archived":false,"fork":false,"pushed_at":"2024-11-11T17:17:59.000Z","size":141,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T01:25:02.573Z","etag":null,"topics":["expressjs","jest","jwt","mongodb","mongoose","nodejs","supertest","typescript","zod"],"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/YolgeSanchez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-10-01T21:59:29.000Z","updated_at":"2024-11-11T17:18:02.000Z","dependencies_parsed_at":"2024-10-16T20:48:00.468Z","dependency_job_id":null,"html_url":"https://github.com/YolgeSanchez/typescript_user_api_template","commit_stats":null,"previous_names":["yolgesanchez/typescript_user_api_template"],"tags_count":2,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YolgeSanchez%2Ftypescript_user_api_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YolgeSanchez%2Ftypescript_user_api_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YolgeSanchez%2Ftypescript_user_api_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YolgeSanchez%2Ftypescript_user_api_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YolgeSanchez","download_url":"https://codeload.github.com/YolgeSanchez/typescript_user_api_template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248130426,"owners_count":21052742,"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":["expressjs","jest","jwt","mongodb","mongoose","nodejs","supertest","typescript","zod"],"created_at":"2024-11-14T00:07:53.933Z","updated_at":"2026-02-09T10:33:13.226Z","avatar_url":"https://github.com/YolgeSanchez.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript Reusable User API Template\n\nWelcome to the TypeScript Reusable User API Template! This project provides a robust foundation for building user management systems in your Node.js applications. Whether you're starting a new project or looking to integrate user authentication into an existing one, this template has got you covered.\n\n## 🌟 Features\n\n- User registration and login\n- User authentication with email and password\n- User management (CRUD operations)\n- Role-based access control (RBAC) (optional)\n- Logout feature\n- Comprehensive test suite\n\n## 🚀 Quick Start\n\n### Clone the Repository\n\n```\ngit clone https://github.com/YolgeSanchez/typescript_user_api_template.git\ncd typescript_user_api_template\n```\n\n### Install Dependencies\n\n```\nnpm install | npm i\n```\n\n### Configure Environment Variables\n\nCreate a `.env` file in the root directory and add the following:\n\n```\nPORT = \u003cyour_preferred_port_number\u003e\nDB_URI = \"\u003cyour_mongodb_connection_string\u003e\"\nJWT_SECRET = \"\u003cyour_jwt_secret_key\u003e\"\n```\n\n### Run the Application\n\n```\nnpm start\n```\n\nThe server will be running on the port you specified in your .env file.\n\n### Run Tests\n\nThe project includes tests to ensure that the functionality is working correctly. To run the tests:\n\n```\nnpm test src/tests/users.test.ts \u0026\u0026 npm test src/tests/auth.test.ts\n```\n\n## 📚 Usage\n\nThis template provides a solid foundation for user management in your API. You can build upon this base to create your specific product features, tasks, or any other functionality your project requires.\n\n### Role-Based vs. Non-Role-Based Models\n\nBy default, this template includes role-based access control (RBAC). However, if you prefer a simpler model without roles, you can easily switch to the non-role-based version:\n\n```\ngit checkout v1.0-not-role-based-api-model\n```\n\nIn case that you want to return to the role-based access control (RBAC) you can easily return to it with:\n\n```\ngit checkout v2.0-role-based-access-control-model\n```\n\nAlternatively, if you want to start with the non-role-based model from the beginning:\n\n```\ngit clone -b v1.0-not-role-based-api-model https://github.com/YolgeSanchez/typescript_user_api_template.git\n```\n\n## 💻 Getting Started for Development\n\n1. Follow the Quick Start guide to set up the project.\n2. Make sure you have Node.js (version 18 or later) and npm installed.\n3. For development, you can use the following command to run the server with hot-reloading:\n\n```\nnpm run dev\n```\n\n4. To build the project for production:\n\n```\nnpm run build\n```\n\n## 🗂️ Project structure\n\nThis project follows a modular structure, which helps in organizing code for scalability and maintainability. The modular approach allows us to separate different concerns of the application, like user management, authentication, utilities, and middleware, into specific folders. Here's an overview of the structure:\n\n```\n├── src/\n│   ├── config/              # Database configurations\n│   ├── middlewares/         # Custom middleware for authentication, validation, etc.\n│   ├── modules/\n│   │   ├── auth/            # Authentication logic (login, registration)\n│   │   └── users/           # User management (CRUD operations, roles)\n│   ├── tests/               # Test cases for the API\n│   ├── types/               # TypeScript type definitions\n│   └── utils/               # Utility functions (e.g., encryption, admin initialization)\n│   ├── app.ts               # Main app configuration and middleware setup\n│   └── server.ts            # Server entry point, starts the application\n│\n├── .env                     # Environment variables for development\n├── .env.example             # Sample environment file for setup\n├── jest.config.ts           # Jest testing configuration\n├── tsconfig.json            # TypeScript configuration\n├── package.json             # NPM dependencies and scripts\n└── .gitignore               # Ignored files for Git\n```\n\n### Why Modular?\n\nThe modular structure keeps the code organized, making it easier to scale and maintain. Each feature (like users or authentication) is in its own folder, allowing for quick updates or changes without affecting the rest of the app. It also promotes reusability—common functions and middleware can be shared across the project, avoiding duplication. Overall, this structure makes the project cleaner and more efficient to work with as it grows.\n\n## 🌐 API Endpoints\n\nHere's a brief overview of the main API endpoints:\n\n[ only in role model ]\n\n- POST /api/auth/register: Register a new user\n- POST /api/auth/login: Authenticate a user\n- GET /api/users: Get all users (requires authentication) [ admin \u0026 user ]\n- GET /api/users/:id: Get a specific user (requires authentication) [ admin \u0026 user ]\n- POST /api/users/ Create a new user (requires authenticatino) [ admin only ]\n- PUT /api/users/:id: Update a user (requires authentication) [ admin only ]\n- DELETE /api/users/:id: Delete a user (requires authentication) [ admin only ]\n\n## 🛠️ Technologies Used\n\n- Node.js\n- TypeScript\n- Express.js\n- MongoDB\n- Mongoose\n- ZOD (for data validation)\n- JSON Web Tokens (JWT)\n- Jest and Supertest (for testing)\n\n## Customization\n\nFeel free to modify and extend this template to fit your specific needs. The modular structure allows for easy additions and modifications.\n\n## 🤝 Contributing\n\nContributions, issues, and feature requests are welcome! Feel free to check [issues page](https://github.com/YolgeSanchez/typescript_user_api_template/issues).\n\n## 📝 License\n\nThis project is [MIT](https://opensource.org/licenses/MIT) licensed.\n\n---\n\nHappy coding! If you find this template useful, please consider giving it a star on GitHub. For any questions or support, please open an issue on the GitHub repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyolgesanchez%2Ftypescript_user_api_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyolgesanchez%2Ftypescript_user_api_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyolgesanchez%2Ftypescript_user_api_template/lists"}