Skip to content

Commit c0eb509

Browse files
committed
Add new files and configurations for the webapp and API components
1 parent 1b70ac8 commit c0eb509

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+8567
-2756
lines changed

Diff for: .github/workflows/api-deploy.yml

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ jobs:
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
16+
- name: Run Migrations
17+
uses: cloudflare/wrangler-action@v3
18+
with:
19+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
20+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
21+
workingDirectory: ./apps/api
22+
command: d1 migrations apply interviews_db
1623
- name: Deploy Worker
1724
uses: cloudflare/wrangler-action@v3
1825
with:

Diff for: .vscode/settings.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
22
"workbench.colorCustomizations": {
3-
"activityBar.activeBackground": "#c06016",
4-
"activityBar.background": "#c06016",
5-
"activityBar.foreground": "#e7e7e7",
6-
"activityBar.inactiveForeground": "#e7e7e799",
7-
"activityBarBadge.background": "#0a562b",
8-
"activityBarBadge.foreground": "#e7e7e7",
9-
"commandCenter.border": "#e7e7e799",
10-
"sash.hoverBorder": "#c06016",
11-
"statusBar.background": "#924911",
12-
"statusBar.foreground": "#e7e7e7",
13-
"statusBarItem.hoverBackground": "#c06016",
14-
"statusBarItem.remoteBackground": "#924911",
15-
"statusBarItem.remoteForeground": "#e7e7e7",
16-
"titleBar.activeBackground": "#924911",
17-
"titleBar.activeForeground": "#e7e7e7",
18-
"titleBar.inactiveBackground": "#92491199",
19-
"titleBar.inactiveForeground": "#e7e7e799"
3+
"activityBar.activeBackground": "#eca101",
4+
"activityBar.background": "#eca101",
5+
"activityBar.foreground": "#15202b",
6+
"activityBar.inactiveForeground": "#15202b99",
7+
"activityBarBadge.background": "#dffff5",
8+
"activityBarBadge.foreground": "#15202b",
9+
"commandCenter.border": "#15202b99",
10+
"sash.hoverBorder": "#eca101",
11+
"statusBar.background": "#b97e01",
12+
"statusBar.foreground": "#15202b",
13+
"statusBarItem.hoverBackground": "#865b01",
14+
"statusBarItem.remoteBackground": "#b97e01",
15+
"statusBarItem.remoteForeground": "#15202b",
16+
"titleBar.activeBackground": "#b97e01",
17+
"titleBar.activeForeground": "#15202b",
18+
"titleBar.inactiveBackground": "#b97e0199",
19+
"titleBar.inactiveForeground": "#15202b99"
2020
},
21-
"peacock.remoteColor": "#924911"
21+
"peacock.remoteColor": "#b97e01"
2222
}

Diff for: apps/api/drizzle.config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { Config } from 'drizzle-kit';
2+
3+
export default {
4+
schema: './src/db/schema.ts',
5+
out: './migrations',
6+
driver: 'd1',
7+
} satisfies Config;

Diff for: apps/api/migrations/0000_sleepy_the_hunter.sql

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE `simulations` (
2+
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
3+
`name` text NOT NULL,
4+
`role` text NOT NULL,
5+
`created_at` integer DEFAULT (unixepoch()) NOT NULL,
6+
`updated_at` integer DEFAULT (unixepoch()) NOT NULL
7+
);

Diff for: apps/api/migrations/meta/0000_snapshot.json

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"version": "5",
3+
"dialect": "sqlite",
4+
"id": "7e1e55fe-4eef-499c-a678-d44a186e47ca",
5+
"prevId": "00000000-0000-0000-0000-000000000000",
6+
"tables": {
7+
"simulations": {
8+
"name": "simulations",
9+
"columns": {
10+
"id": {
11+
"name": "id",
12+
"type": "integer",
13+
"primaryKey": true,
14+
"notNull": true,
15+
"autoincrement": true
16+
},
17+
"name": {
18+
"name": "name",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": true,
22+
"autoincrement": false
23+
},
24+
"role": {
25+
"name": "role",
26+
"type": "text",
27+
"primaryKey": false,
28+
"notNull": true,
29+
"autoincrement": false
30+
},
31+
"created_at": {
32+
"name": "created_at",
33+
"type": "integer",
34+
"primaryKey": false,
35+
"notNull": true,
36+
"autoincrement": false,
37+
"default": "(unixepoch())"
38+
},
39+
"updated_at": {
40+
"name": "updated_at",
41+
"type": "integer",
42+
"primaryKey": false,
43+
"notNull": true,
44+
"autoincrement": false,
45+
"default": "(unixepoch())"
46+
}
47+
},
48+
"indexes": {},
49+
"foreignKeys": {},
50+
"compositePrimaryKeys": {},
51+
"uniqueConstraints": {}
52+
}
53+
},
54+
"enums": {},
55+
"_meta": {
56+
"schemas": {},
57+
"tables": {},
58+
"columns": {}
59+
}
60+
}

Diff for: apps/api/migrations/meta/_journal.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "5",
3+
"dialect": "sqlite",
4+
"entries": [
5+
{
6+
"idx": 0,
7+
"version": "5",
8+
"when": 1713095250887,
9+
"tag": "0000_sleepy_the_hunter",
10+
"breakpoints": true
11+
}
12+
]
13+
}

Diff for: apps/api/package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
{
22
"scripts": {
33
"dev": "wrangler dev src/index.ts",
4-
"deploy": "wrangler deploy --minify src/index.ts"
4+
"dev:remote": "wrangler dev src/index.ts --remote",
5+
"migrations:generate": "drizzle-kit generate:sqlite",
6+
"migrations:list": "wrangler d1 migrations list interviews_db --local",
7+
"migrations:apply": "wrangler d1 migrations apply interviews_db --local",
8+
"migrations:apply:prod": "wrangler d1 migrations apply interviews_db --remote"
59
},
610
"dependencies": {
7-
"hono": "4.2.4"
11+
"@hono/swagger-ui": "^0.2.1",
12+
"@hono/zod-openapi": "^0.11.0",
13+
"@langchain/cloudflare": "^0.0.4",
14+
"drizzle-orm": "^0.30.8",
15+
"hono": "4.2.4",
16+
"langchain": "^0.1.33"
817
},
918
"devDependencies": {
1019
"@cloudflare/workers-types": "4.20240405.0",
20+
"drizzle-kit": "^0.20.14",
1121
"wrangler": "3.50.0"
1222
}
1323
}

Diff for: apps/api/src/bindings.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type Bindings = {
2+
DB: D1Database;
3+
CLOUDFLARE_ACCOUNT_ID: string;
4+
CLOUDFLARE_API_TOKEN: string;
5+
AI: any;
6+
}

Diff for: apps/api/src/db/schema.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { sql } from "drizzle-orm";
2+
import { text, integer, sqliteTable } from "drizzle-orm/sqlite-core";
3+
4+
export const simulations = sqliteTable('simulations', {
5+
id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),
6+
name: text('name').notNull(),
7+
role: text('role').notNull(),
8+
createdAt: integer('created_at', { mode: 'timestamp' })
9+
.notNull()
10+
.default(sql`(unixepoch())`),
11+
updatedAt: integer('updated_at', { mode: 'timestamp' })
12+
.notNull()
13+
.default(sql`(unixepoch())`)
14+
});

Diff for: apps/api/src/dtos/feedback.dto.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { z } from '@hono/zod-openapi';
2+
3+
export const FeedbackSchema = z
4+
.object({
5+
id: z.string().openapi({
6+
example: '1',
7+
}),
8+
from: z.string().openapi({
9+
example: 'user',
10+
}),
11+
text: z.string().openapi({
12+
example: 'message',
13+
}),
14+
})
15+
.openapi('Feedback');

Diff for: apps/api/src/dtos/message.dto.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { z } from '@hono/zod-openapi';
2+
3+
export const NewMessageSchema = z.object({
4+
message: z
5+
.string()
6+
.min(3)
7+
.openapi({
8+
example: 'Message',
9+
}),
10+
simulationId: z.string().openapi({
11+
example: '1',
12+
}),
13+
});
14+
15+
export const MessageSchema = z
16+
.object({
17+
id: z.string().openapi({
18+
example: '1',
19+
}),
20+
from: z.string().openapi({
21+
example: 'user',
22+
}),
23+
text: z.string().openapi({
24+
example: 'message',
25+
}),
26+
type: z.string().openapi({
27+
example: 'feedback',
28+
}),
29+
})
30+
.openapi('Message');
31+
32+
export const MessageListSchema = z.array(MessageSchema);

Diff for: apps/api/src/dtos/simulation.dto.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { z } from '@hono/zod-openapi';
2+
3+
export const SimulationIdSchema = z.object({
4+
id: z
5+
.string()
6+
.min(1)
7+
.openapi({
8+
param: {
9+
name: 'id',
10+
in: 'path',
11+
},
12+
example: '1',
13+
}),
14+
});
15+
16+
export const CreateSimulationSchema = z.object({
17+
role: z
18+
.string()
19+
.min(3)
20+
.openapi({
21+
example: 'Male',
22+
}),
23+
name: z
24+
.string()
25+
.min(3)
26+
.openapi({
27+
example: 'Nicolas',
28+
}),
29+
});
30+
export type CreateSimulationDto = z.infer<typeof CreateSimulationSchema>;
31+
32+
export const SimulationSchema = z
33+
.object({
34+
id: z.number().openapi({
35+
example: 1,
36+
}),
37+
role: z.string().openapi({
38+
example: 'John Doe',
39+
}),
40+
})
41+
.openapi('Simulation');
42+
43+
export const SimulationListSchema = z.array(SimulationSchema);
44+
45+

Diff for: apps/api/src/index.ts

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1-
import { Hono } from 'hono';
1+
import { OpenAPIHono } from '@hono/zod-openapi';
2+
import { swaggerUI } from "@hono/swagger-ui";
3+
import { cors } from "hono/cors";
4+
import { prettyJSON } from 'hono/pretty-json';
25

3-
const app = new Hono();
6+
import { dbMiddleware } from '@src/middlewares/db.middleware';
47

5-
app.get('/', (c) => {
6-
return c.text('Hello Hono!');
8+
import createSimulation from '@src/routes/createSimulation';
9+
import createQuestion from '@src/routes/createQuestion';
10+
import createFeedback from '@src/routes/createFeedback';
11+
12+
const app = new OpenAPIHono();
13+
app.use("*", cors());
14+
app.use('*', prettyJSON());
15+
app.notFound((c) => c.json({ message: 'Not Found', ok: false }, 404));
16+
17+
app.use('/api/v1/*', dbMiddleware);
18+
19+
app.route('/api/v1/simulations', createSimulation);
20+
app.route('/api/v1/questions', createQuestion);
21+
app.route('/api/v1/feedback', createFeedback);
22+
23+
app.get("/", swaggerUI({ url: "/docs" }));
24+
app.doc("/docs", {
25+
info: {
26+
title: "Interviews API",
27+
version: "v1",
28+
},
29+
openapi: "3.1.0",
730
});
831

932
export default app;

Diff for: apps/api/src/middlewares/db.middleware.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createFactory } from 'hono/factory';
2+
import { drizzle } from 'drizzle-orm/d1';
3+
import * as schema from '@src/db/schema';
4+
import { App } from '@src/types';
5+
6+
const factory = createFactory<App>();
7+
8+
export const dbMiddleware = factory.createMiddleware(async (c, next) => {
9+
const db = drizzle(c.env.DB, { schema });
10+
c.set('db', db);
11+
await next();
12+
});

0 commit comments

Comments
 (0)