This repository houses the Short Link Service, a tool for creating and managing short links (URLs). Whether you need concise URLs for marketing campaigns or improved user experience, this service simplifies the process of generating and handling short links.
- Short Link Generation:
- Create short links for long URLs effortlessly.
- Customization:
- Optionally customize short link aliases for branding or meaningful links.
- Analytics:
- Track and analyze short link usage with built-in analytics.
- Expiration:
- Set expiration dates for short links to control their validity.
- Create Short Link:
- POST /shorten
- Payload: { "url": "your-long-url", "short_link": "custom-short-link" (OPTIONAL), "expired": "your-set-expired" }
- Redirect by Short link:
- GET /:shortCode
- Node.js v14
- Mongoose (MongoDB ODM)
- Sequelize (SQL ORM)
- TypeScript
- Docker
- Express (HTTP framework)
The project follows the principles of Clean Architecture, emphasizing separation of concerns into distinct layers:
- Entities: Representing the core business entities.
- Use Cases: Defining application-specific business rules.
- Interface Adapters: Implementing details for external frameworks and tools.
- Frameworks & Drivers: Implementing details for external frameworks and tools (Express, databases, etc.).
-
Clone the repository:
git clone https://github.com/jabardigitalservice/shortlink-service.git
-
Navigate to the project directory:
cd shortlink-service
-
Install dependencies:
npm install
-
Copy the appropriate environment file:
-
For SQL (choose MySQL, PostgreSQL, or SQLite), use
.env.example.sql
:cp .env.example.sql .env
Customize the
.env
file according to your configuration. -
npm run start:dev
npm run build
npm start
Build Docker image:
docker -f docker/Dockerfile build -t your-image-name .
Run Docker container:
docker run -p 3000:3000 -d your-image-name
-
Linting:
- Check code formatting:
npm run lint
- Fix code formatting:
npm run lint:fix
- Check code formatting:
-
Database Migration:
- Run migrations:
npm run migrate:up
- Rollback migrations:
npm run migrate:down
- Run migrations:
-
Local Database Migration (development):
- Generate migration file:
npm run migration:generate --name=your-migration-name
- Run migrations:
npm run migrate:up:local
- Rollback migrations:
npm run migrate:down:local
- Generate migration file:
-
Seed:
- Run Seed:
npm run seed:run --name=your-seed-filename
- Run Seed:
-
Cron:
- Run Cron:
npm run seed:run --name=your-cron-filename
- Run Cron:
-
Testing:
- Run tests:
npm test
- Run tests:
modules/
└── name module/
├── delivery/
│ ├── http/
│ │ └── handler.ts
│ ├── grpc/
│ │ └── handler.ts
│ └── graphQL/
│ └── handler.ts
├── entity/
│ ├── interface.ts // for the core business entities
│ └── schema.ts // for the schema validation
├── repository/
│ ├── mongo/
│ │ └── repository.ts
│ ├── mySQL/
│ │ └── repository.ts
│ └── postgreSQL/
│ └── repository.ts
├── usecase/
│ └── usecase.ts
└── name module.ts // for init the module to load in the main
We welcome contributions! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details. Support:
Feel free to customize this README to reflect your specific Short Link Service implementation.