{"id":26404213,"url":"https://github.com/gabrielnat1/api-rest-typescript","last_synced_at":"2025-07-12T23:32:03.928Z","repository":{"id":263180993,"uuid":"889598008","full_name":"GabrielNat1/Api-Rest-TypeScript","owner":"GabrielNat1","description":"\"REST API built with Node.js, TypeScript, and Yarn, designed for managing city registrations and user logins, using JSON and SQLite3 for database storage.\"","archived":false,"fork":false,"pushed_at":"2025-01-18T23:57:54.000Z","size":392,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T12:52:16.689Z","etag":null,"topics":["api","api-client","api-rest","api-server","apirest","express","jest-tests","jwt-authentication","sqlite3","typescript","yarn"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GabrielNat1.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-11-16T18:25:01.000Z","updated_at":"2025-02-26T22:21:59.000Z","dependencies_parsed_at":"2025-03-17T22:31:09.474Z","dependency_job_id":null,"html_url":"https://github.com/GabrielNat1/Api-Rest-TypeScript","commit_stats":null,"previous_names":["gabrielnat1/api-rest---typescript","gabrielnat1/api-rest-typescript"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GabrielNat1/Api-Rest-TypeScript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielNat1%2FApi-Rest-TypeScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielNat1%2FApi-Rest-TypeScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielNat1%2FApi-Rest-TypeScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielNat1%2FApi-Rest-TypeScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GabrielNat1","download_url":"https://codeload.github.com/GabrielNat1/Api-Rest-TypeScript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrielNat1%2FApi-Rest-TypeScript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265067391,"owners_count":23706266,"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":["api","api-client","api-rest","api-server","apirest","express","jest-tests","jwt-authentication","sqlite3","typescript","yarn"],"created_at":"2025-03-17T16:29:52.479Z","updated_at":"2025-07-12T23:32:03.894Z","avatar_url":"https://github.com/GabrielNat1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" style=\"font-family: Arial, sans-serif; padding: 20px; background: linear-gradient(135deg, #007acc, #8a2be2); color: #fff; border-radius: 10px; border: 2px solid #fff;\"\u003e\n    \u003ch1\u003eAPI REST TYPESCRIPT\u003c/h1\u003e\n    \u003cbr\u003e\n    \u003cp\u003e\u003cstrong\u003eREST API with Node.js, TypeScript, and Yarn for city registration and user login! 🔐\u003c/strong\u003e\u003c/p\u003e\n    \u003cimg src=\"https://github.com/user-attachments/assets/3cc90132-f83a-44aa-8a6b-c4a1640a530e\" alt=\"API Image\"/\u003e\n    \u003cbr\u003e\n\u003c/div\u003e\n\n---\n\n## 🛠️ Technologies Used\n\n\u003cul\u003e\n    \u003cli\u003e\u003cstrong\u003eNode.js\u003c/strong\u003e 🌐\u003c/li\u003e\n    \u003cli\u003e\u003cstrong\u003eTypeScript\u003c/strong\u003e 🦾\u003c/li\u003e\n    \u003cli\u003e\u003cstrong\u003eYarn\u003c/strong\u003e 📦\u003c/li\u003e\n    \u003cli\u003e\u003cstrong\u003eDatabase:\u003c/strong\u003e JSON \u0026 SQLite3\u003c/li\u003e\n\u003c/ul\u003e\n\n## 🚀 Features\n\n\u003cul\u003e\n    \u003cli\u003eUser authentication (login and password) 🔑\u003c/li\u003e\n    \u003cli\u003eFull CRUD for cities 🏙️\u003c/li\u003e\n    \u003cli\u003eSimple database using JSON 💾\u003c/li\u003e\n\u003c/ul\u003e\n\u003cbr\u003e\n\n---\n\n## 🎯 How to Run the Project Locally\n\n1. **Clone the repository:**\n    ```bash  \n    git clone https://github.com/your-user/CityListAPI.git  \n    ```\n2. **Install dependencies:**\n     ```bash    \n    yarn install  \n     ```\n3. **Run the application:**\n     ```bash    \n    yarn start  \n     ```\n4. **Access the API at:**\n     ```bash   \n    http://localhost:3333  \n     ```\n## 🛡️ Security  \n\n- **Authentication:** Uses JWT (JSON Web Tokens) to ensure that only authenticated users can access protected routes.  \n- **Data Validation:** Input data validation with `class-validator` and `zod` to ensure data integrity.  \n\u003cbr\u003e\n\n---\n\n## 📂 Directory Structure  \n\nThe project directory structure is organized as follows:\n\n ```bash   \napi-rest-typescript/  \n├── src/  \n│   ├── server/  \n│   │   ├── controllers/         # Request and response management  \n│   │   ├── database/            # Database configuration  \n│   │   │   ├── knex/            # Database connection and queries using Knex  \n│   │   │   ├── migrations/      # Files for database versioning  \n│   │   │   ├── models/          # Data entity and schema definitions  \n│   │   │   ├── providers/       # Database related services  \n│   │   │   └── seeds/           # Initial database data  \n│   │   ├── routes/              # API route definitions  \n│   │   └── shared/  \n│   │       ├── middleware/      # Middleware functions (authentication, validation)  \n│   │       └── services/        # Reusable logic and helper services  \n├── tests/  \n│   ├── cities/                 # Tests for city functionalities  \n│   ├── people/                 # Tests for people functionalities  \n│   └── users/                  # Tests for user functionalities  \n├── .env                         # Environment variables file  \n├── README.md                    # Project documentation  \n├── tsconfig.json                # TypeScript configuration  \n├── yarn.lock                    # Yarn dependency lock file  \n├── jest.config.ts               # Jest test configuration  \n└── package.json                 # Project metadata and dependencies  \n ```\n\n\u003cbr\u003e\n\n---\n\n## 📜 Project Scripts  \n\nThe `package.json` file contains the following scripts to automate important tasks in development and running the project:\n\n ```json \n\"scripts\": {  \n  \"start\": \"ts-node-dev ./src/index.ts\",  \n  \"postinstall\": \"tsc\",  \n  \"production\": \"node ./build/index.js\",  \n  \"test\": \"jest\",  \n  \"knex:migrate\": \"knex --knexfile ./src/server/database/knex/Environment.ts migrate:latest\",  \n  \"knex:rollback\": \"knex --knexfile ./src/server/database/knex/Environment.ts migrate:rollback\",  \n  \"knex:rollback-all\": \"knex --knexfile ./src/server/database/knex/Environment.ts migrate:rollback --all\",  \n  \"knex:seed\": \"knex --knexfile ./src/server/database/knex/Environment.ts seed:run\"  \n}  \n ```  \n\n### Explanation of the Scripts  \n\n- **`start`**  \n  Starts the project in development mode using `ts-node-dev`. This allows TypeScript code to be executed directly with automatic reloading when file changes are detected.  \n\n- **`postinstall`**  \n  Generates JavaScript code from TypeScript files after installing dependencies. Useful for preparing the production environment.  \n\n- **`production`**  \n  Runs the project after transpiling, executing the generated JavaScript code in `build/index.js` on Node.js. This script is used to start the server in production.  \n\n- **`test`**  \n  Runs the project tests using Jest, a framework for unit and integration tests.  \n\n- **`knex:migrate`**  \n  Applies database migrations defined in `migrations/` using Knex. This creates or alters tables as needed to keep the database schema updated.  \n\n- **`knex:rollback`**  \n  Rolls back the last applied migration, useful for fixing recent errors.  \n\n- **`knex:rollback-all`**  \n  Rolls back all applied migrations, restoring the database to its initial state.  \n\n- **`knex:seed`**  \n  Executes seed files in `seeds/` to populate the database with initial or test data.  \n\n### Usage Tips  \n\n- During development, use the `start` script to save time with automatic reloading.  \n- Before deploying to production, run `postinstall` and validate everything with `test`.  \n- To keep the database updated, run `knex:migrate`. If needed, use `knex:rollback` or `knex:rollback-all` to fix or reset the state.  \n- Use `knex:seed` to test the system with simulated data or reset the database state in development environments.  \n\u003cbr\u003e\n\n---\n\n## 🧪 Automated Tests!  \n\nTo run automated tests:\n\n1. **Install test dependencies:**  \n     ```bash    \n    yarn add jest @types/jest ts-jest --dev  \n     ```\n2. **Run the tests:**  \n     ```bash    \n    yarn test  \n     ```\n---\n\n## 📚 Test API Endpoints  \n\nYou can directly test the API endpoints.\n\n- Access after opening the server:  \n     ```bash   \n    http://localhost:3333/  \n     ```\n---\n\n## 🌐 CORS Support  \n\nThe API is configured to allow requests from different domains using the `cors` package. This allows the API to be accessed by frontends hosted on different servers.\n\n---\n\n## 🔒 Authorization and Permissions  \n\n- The API uses role-based access control. There are two main types of users:\n  - **Admin:** Full access, including the ability to manage users and cities.\n  - **User:** Limited access to CRUD cities and personal resources.\n\n---\n\n## ⚙️ Configuration and Environment Variables  \n\nThe API requires some environment variables for correct operation. You must rename the `.env.example` file with the following keys:\n\n- `IS_LOCALHOST=true`\n- `NODE_ENV=dev`\n- `PORT=3333`\n- `JWT_SECRET=[key_secret] set a secret key`\n\n---\n\n## 💡 Development  \n\n- **Performance:** Cache for frequently accessed data like city lists.  \n- **Improvements:** Redis caching system to improve response time on routes that perform heavy queries.\n\n---\n\n## 📅 Version Roadmap  \n\n- **Version 1.0:** Initial release with basic CRUD and authentication features.  \n\n\u003cbr\u003e\u003cbr\u003e\n\n---\n\n## 📝 Available Endpoints  \n\n \u003cbr\u003e\n \u003cimg src=\"https://github.com/user-attachments/assets/8d33268b-9507-40b8-9b5f-b6da58b95c0c\" alt=\"API Endpoints\" /\u003e   \n \u003cbr\u003e \n \n \n### Cities \n```bash\n- `GET /cidade` - Listar todas as cidades\n```\n```bash\n- `POST /cidade` - Adicionar uma nova cidade\n```\n```bash\n- `PUT /cidade/:id` - Atualizar uma cidade pelo ID\n```\n```bash\n- `DELETE /cidade/:id` - Remover uma cidade pelo ID\n```\n\n### People  \n```bash\n- `GET /pessoa` - Listar todas as pessoas\n```\n```bash\n- `POST /pessoa` - Adicionar uma nova pessoa\n```\n```bash\n- `PUT /pessoa/:id` - Atualizar uma pessoa pelo ID\n```\n```bash\n- `DELETE /pessoa/:id` - Remover uma pessoa pelo ID\n```\n\n### Login  \n```bash\n- `POST /post/entrar` - Entrar\n```\n```bash \n- `POST /post/cadastrar` - Cadastrar\n```\n\u003cbr\u003e\u003cbr\u003e\n\n\u003cimg src=\"https://github.com/user-attachments/assets/6f3ea7cf-8ffe-4bc4-97e5-28f7f003c40d\" alt=\"API Endpoints Image\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielnat1%2Fapi-rest-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielnat1%2Fapi-rest-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielnat1%2Fapi-rest-typescript/lists"}