Skip to content

Commit 6390f8e

Browse files
committed
added redis provider and queueService
1 parent 4055dcb commit 6390f8e

File tree

9 files changed

+182
-25
lines changed

9 files changed

+182
-25
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ If you forked this repository before May 27th, you'll want to view commit `653e2
66

77
## ❔ What
88

9-
A scalable, testable, extensible, template for Sveltekit.
9+
A scalable, testable, extensible, template for Sveltekit.
1010

1111
Sveltekit is awesome, but sometimes you need a bit more capability in the backend than what frameworks like
1212
NextJS & Sveltekit can deliver.
@@ -25,25 +25,35 @@ export const DELETE: RequestHandler = ({ request }) => app.fetch(request);
2525
export const POST: RequestHandler = ({ request }) => app.fetch(request);
2626
```
2727

28+
## Local Setup
29+
30+
1. Make sure Docker is running
31+
2. Copy the `.env.example` file and rename to `.env`
32+
3. `pnpm install`
33+
4. `pnpm initialize`(this will start the docker-compose and run the initial database migration.)
34+
5. `pnpm dev`
35+
36+
No additional setup is required, zero api keys, zero services to signup for, zero cost.
37+
2838
## How to Use
2939

30-
This is **not** supposed to serve as an all batteries included ["production boilerplate"](https://github.com/ixartz/Next-js-Boilerplate) with 200 useless sponsored features that get in your way. Templates that do this are ANYTHING but "production" and "quick start".
40+
This is **not** supposed to serve as an all batteries included ["production boilerplate"](https://github.com/ixartz/Next-js-Boilerplate) with 200 useless sponsored features that get in your way. Templates that do this are ANYTHING but "production" and "quick start".
3141

3242
This is stack is designed to be library agnostic. The philosophy here is to boostrap the concrete, repetitive, and time consuming tasks that every application will need reguardless of what you're building.
3343

34-
**So - fork this repo, add your favorite libraries, and build out your own "more opinionated" personal template tailored to you**!
44+
**So - fork this repo, add your favorite libraries, and build out your own "more opinionated" personal template tailored to you**!
3545

3646
## Features
3747

3848
- 🟢 Full E2E typesafety
3949
- 🟢 RPC Client for API Requests
4050
- 🟢 Custom Fetch Wrapper
41-
- 🔴 Deployment Template
51+
- 🟢 Deployment Template
4252
- 🟠 Authentication
4353
- 🟢 Email/Passkey
4454
- 🔴 OAuth
4555
- 🟢 Email Update/Verifiaction
46-
- 🔴 Rate limiter
56+
- 🟢 Rate limiter
4757

4858
## Technologies
4959

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@typescript-eslint/parser": "^7.13.1",
3737
"arctic": "^1.9.1",
3838
"autoprefixer": "^10.4.19",
39+
"bullmq": "^5.8.3",
3940
"dayjs": "^1.11.11",
4041
"dotenv-cli": "^7.4.2",
4142
"drizzle-kit": "^0.21.4",

pnpm-lock.yaml

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/dtos/update-email.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ ensure that the correct data is being passed around.
1919
/* -------------------------------------------------------------------------- */
2020

2121
export const updateEmailDto = z.object({
22-
email: z.string()
22+
email: z.string().email()
2323
});
2424
export type UpdateEmailDto = z.infer<typeof updateEmailDto>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './database.provider';
22
export * from './lucia.provider';
3+
export * from './redis.provider';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { container } from 'tsyringe';
2+
import RedisClient from 'ioredis'
3+
import { config } from '../common/config';
4+
5+
// Symbol
6+
export const RedisProvider = Symbol('REDIS_TOKEN');
7+
8+
// Type
9+
export type RedisProvider = RedisClient;
10+
11+
// Register
12+
container.register<RedisProvider>(RedisProvider, {
13+
useValue: new RedisClient(config.REDIS_URL)
14+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { injectable } from "tsyringe";
2+
import RedisClient from 'ioredis'
3+
import { config } from "../common/config";
4+
import { Queue, Worker, type Processor } from 'bullmq';
5+
6+
@injectable()
7+
export class QueuesServices {
8+
connection = new RedisClient(config.REDIS_URL);
9+
10+
constructor() { }
11+
12+
createQueue(name: string) {
13+
return new Queue(name, { connection: this.connection })
14+
}
15+
16+
createWorker(name: string, prcoessor: Processor) {
17+
return new Worker(name, prcoessor, { connection: this.connection })
18+
}
19+
}

src/lib/server/api/services/tokens.service.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,6 @@ import { generateRandomString } from "oslo/crypto";
33
import { TimeSpan, createDate, type TimeSpanUnit } from 'oslo';
44
import { HashingService } from './hashing.service';
55

6-
/* -------------------------------------------------------------------------- */
7-
/* Service */
8-
/* -------------------------------------------------------------------------- */
9-
/* -------------------------------------------------------------------------- */
10-
/* ---------------------------------- About --------------------------------- */
11-
/*
12-
Services are responsible for handling business logic and data manipulation.
13-
They genreally call on repositories or other services to complete a use-case.
14-
*/
15-
/* ---------------------------------- Notes --------------------------------- */
16-
/*
17-
Services should be kept as clean and simple as possible.
18-
19-
Create private functions to handle complex logic and keep the public methods as
20-
simple as possible. This makes the service easier to read, test and understand.
21-
*/
22-
/* -------------------------------------------------------------------------- */
23-
246
@injectable()
257
export class TokensService {
268
constructor(@inject(HashingService) private readonly hashingService: HashingService) { }

src/lib/server/api/tests/login-requests.service.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'reflect-metadata';
22
import { LoginRequestsService } from '../services/login-requests.service';
3-
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
3+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
44
import { TokensService } from '../services/tokens.service';
55
import { MailerService } from '../services/mailer.service';
66
import { UsersRepository } from '../repositories/users.repository';

0 commit comments

Comments
 (0)