Skip to content

Commit cb33b6c

Browse files
Frontend: Build, wireframe, config (#26)
## Summary This PR includes significant updates to the project: ### 1. Frontend Built and Served with Node.js - The frontend is now built and served using Node.js, allowing for **Server-Side Rendering (SSR)**. This can lead to faster load times if we choose to enable it (which I have). Additionally, Node.js provides more flexibility for future configuration, as it's JavaScript-based. ### 2. Initial Wireframe of the App - A basic wireframe has been created for the app, featuring a left navigation bar, API calls, and configurations. As Eugene progresses, we'll expand on this wireframe to better reflect the final design. ### 3. App Configuration - Set up various app-specific configurations to integrate **shadcn-svelte**, **Tailwind**, **ECharts**, and other necessary libraries. This foundational work will make future development smoother. In the future, I'll aim to break down updates into smaller, more manageable pull requests. ### Relevant Commands: - **From `/chronon/frontend`:** `npm run dev` This command starts the development server locally. Ensure the backend is running at `localhost:9000` before starting. - **From `/chronon`:** `docker-compose -f docker-init/compose.yaml up --build` This builds both the backend and frontend using Docker. The frontend will use the `.env.docker` environment variables. The backend will start at `http://localhost:9000/` and the frontend at `http://localhost:3000/` ## Checklist - [ ] Added Unit Tests - [ ] Covered by existing CI - [ ] Integration tested - [ ] Documentation update <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new frontend service in Docker configuration. - Added a module for handling API requests, simplifying GET requests. - Enhanced README for the frontend with updated installation and testing instructions. - Implemented Tailwind CSS for custom theming in the frontend. - Added support for a dark theme in the application. - Introduced a new configuration file for frontend components. - Added environment variables for API base URLs in development and Docker. - **Bug Fixes** - Updated instructions for accessing backend and frontend services in Docker documentation. - **Documentation** - Restructured README files for clearer guidance on setup and usage. - Added new configuration files for PostCSS and component settings. - **Chores** - Expanded `.gitignore` to exclude additional build artifacts and temporary files. - Updated dependency versions and build commands in configuration files. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Piyush Narang <[email protected]>
1 parent 52a2ed4 commit cb33b6c

Some content is hidden

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

61 files changed

+2916
-127
lines changed

.gitignore

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@ releases
6060
/frontend/.DS_Store
6161
/frontend/Thumbs.db
6262

63-
# Frontend Env
64-
/frontend/.env
65-
/frontend/.env.*
66-
!/frontend/.env.example
67-
!/frontend/.env.test
68-
6963
# Frontend Vite
7064
/frontend/vite.config.js.timestamp-*
7165
/frontend/vite.config.ts.timestamp-*
66+
67+
# Frontend Test Results
68+
/frontend/test-results

build.sbt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ lazy val frontend = (project in file("frontend"))
193193
}
194194

195195
println("Building frontend...")
196-
val buildResult = Process("npm run build", file("frontend")).!
196+
val buildResult = Process("npm run build:docker", file("frontend")).!
197197

198198
if (buildResult == 0) {
199199
println("Copying frontend assets to /hub/public...")
@@ -224,9 +224,6 @@ lazy val hub = (project in file("hub"))
224224
"io.circe" %% "circe-generic" % circeVersion,
225225
"io.circe" %% "circe-parser" % circeVersion
226226
),
227-
// Ensure hub depends on frontend build
228-
Compile / run := ((Compile / run) dependsOn (frontend / buildFrontend)).evaluated,
229-
Compile / stage := ((Compile / stage) dependsOn (frontend / buildFrontend)).value
230227
)
231228

232229
ThisBuild / assemblyMergeStrategy := {

docker-init/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ app-1 | [info] 2024-09-30 20:47:56,448 [main] INFO play.api.Play - Ap
1010
app-1 | [info] 2024-09-30 20:47:56,665 [main] INFO play.core.server.PekkoHttpServer - Listening for HTTP on /[0:0:0:0:0:0:0:0]:9000
1111
```
1212

13-
You can now pull up the web-server on http://localhost:9000
13+
The **backend** is served at: http://localhost:9000
14+
15+
The **frontend** is served at: http://localhost:3000
1416

1517
You can also access the parquet anomaly data table. To do so, from another terminal run:
1618

17-
```docker-compose exec app bash```
19+
`docker-compose exec app bash`
1820

1921
The parquet is available in the /app/data directory.

docker-init/compose.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'hub-monitoring-demo'
1+
name: "hub-monitoring-demo"
22
services:
33
dynamo:
44
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data"
@@ -21,8 +21,8 @@ services:
2121
- SPARK_SSL_ENABLED=no
2222
- SPARK_USER=spark
2323
ports:
24-
- '8080:8080'
25-
- '7077:7077'
24+
- "8080:8080"
25+
- "7077:7077"
2626

2727
spark-worker:
2828
image: bitnami/spark:3.5.2
@@ -57,10 +57,26 @@ services:
5757
- PLAY_HTTP_SECRET_KEY=my_fake_chronon_monitoring_hub_http_secret_key # needs to be long to make Play happy
5858
- JAVA_OPTS=-Xms1g -Xmx1g
5959
ports:
60-
- '9000:9000'
60+
- "9000:9000"
6161
healthcheck:
6262
interval: 1s
6363
retries: 5
6464
start_period: 60s
6565
test: curl -sS --fail http://app:${APP_PORT:-9000}/api/v1/ping
6666
timeout: 5s
67+
68+
frontend:
69+
build:
70+
context: ..
71+
dockerfile: docker-init/frontend/Dockerfile
72+
depends_on:
73+
- base
74+
- app
75+
ports:
76+
- "3000:3000"
77+
healthcheck:
78+
test: ["CMD", "curl", "-f", "http://localhost:3000"]
79+
interval: 30s
80+
timeout: 10s
81+
retries: 3
82+
start_period: 40s

docker-init/frontend/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM base_image:latest AS build_env
2+
3+
# Copy the entire project directory into the container
4+
COPY . /app
5+
6+
# Install Node.js and npm
7+
RUN apk add --update nodejs npm
8+
9+
# Build the frontend using SBT
10+
RUN sbt "project frontend" buildFrontend
11+
12+
FROM node:18-alpine
13+
14+
# Copy the built frontend from the previous stage to the new container
15+
COPY --from=build_env app/frontend /app/frontend
16+
17+
# Set the working directory for subsequent commands
18+
WORKDIR /app/frontend
19+
20+
# Expose port 3000 for the SvelteKit app
21+
EXPOSE 3000
22+
23+
# Specify the command to run when the container starts
24+
CMD ["node", "build/index.js"]

frontend/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=http://localhost:9000

frontend/.env.docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_API_BASE_URL=http://app:9000

frontend/README.md

Lines changed: 124 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,144 @@
1-
# create-svelte
1+
# Chronon Frontend
22

3-
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
3+
The frontend for Chronon.
44

5-
## Creating a project
5+
## Getting Started
66

7-
If you're seeing this, you've probably already done this step. Congrats!
7+
### Prerequisites
8+
9+
- [Node.js](https://nodejs.org/en/) (LTS version recommended)
10+
- npm (comes with Node.js)
11+
12+
### Installation
13+
14+
1. Clone the repository:
15+
16+
```bash
17+
git clone https://github.com/zipline-ai/chronon.git
18+
cd chronon
19+
```
20+
21+
2. Navigate to the frontend directory:
22+
23+
```bash
24+
cd frontend
25+
```
26+
27+
3. Install dependencies:
28+
```bash
29+
npm install
30+
```
31+
32+
### Development
33+
34+
To start the development server:
35+
36+
1. First, start the backend project:
837

938
```bash
10-
# create a new project in the current directory
11-
npm create svelte@latest
39+
# Run this command in the root directory
40+
sbt "project hub" run
41+
```
42+
43+
2. Then, start the development server:
1244

13-
# create a new project in my-app
14-
npm create svelte@latest my-app
45+
```bash
46+
npm run dev
1547
```
1648

17-
## Developing
49+
This will start a local server. The app will automatically reload if you make changes to the code.
1850

19-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
51+
### Build
52+
53+
To create an optimized production build:
2054

2155
```bash
22-
npm run dev
56+
npm run build
57+
```
58+
59+
This will create an optimized version of your project in the `build` directory.
60+
61+
### Preview
2362

24-
# or start the server and open the app in a new browser tab
25-
npm run dev -- --open
63+
To preview the production build locally:
64+
65+
```bash
66+
npm run preview
2667
```
2768

28-
## Building
69+
### Running Tests
2970

30-
To create a production version of your app:
71+
#### All Tests
72+
73+
To run both unit and integration tests together:
3174

3275
```bash
33-
npm run build
76+
npm run test
77+
```
78+
79+
#### Unit Tests
80+
81+
To run unit tests using Vitest:
82+
83+
```bash
84+
npm run test:unit
85+
```
86+
87+
To run unit tests once:
88+
89+
```bash
90+
npm run test:unit:once
91+
```
92+
93+
#### Integration Tests
94+
95+
To run integration tests using Playwright:
96+
97+
```bash
98+
npm run test:integration
99+
```
100+
101+
To run integration tests once:
102+
103+
```bash
104+
npm run test:integration:once
105+
```
106+
107+
For the Playwright UI to explore test results:
108+
109+
```bash
110+
npm run test:integration:ui
111+
```
112+
113+
### Linting and Formatting
114+
115+
To check code formatting and linting issues:
116+
117+
```bash
118+
npm run lint
119+
```
120+
121+
To format the codebase:
122+
123+
```bash
124+
npm run format
125+
```
126+
127+
### Type Checking
128+
129+
To check the TypeScript types:
130+
131+
```bash
132+
npm run check
133+
```
134+
135+
To continuously check types while developing:
136+
137+
```bash
138+
npm run check:watch
34139
```
35140

36-
You can preview the production build with `npm run preview`.
141+
## Best Practices
37142

38-
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
143+
1. **Code Style**: This project uses Prettier and ESLint for code formatting and linting. Please run `npm run lint` and `npm run format` before committing changes.
144+
2. **Testing**: Ensure all changes are covered with unit and integration tests. Use Vitest for unit tests and Playwright for integration tests.

frontend/components.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://shadcn-svelte.com/schema.json",
3+
"style": "new-york",
4+
"tailwind": {
5+
"config": "tailwind.config.js",
6+
"css": "src/app.css",
7+
"baseColor": "neutral"
8+
},
9+
"aliases": {
10+
"components": "$lib/components",
11+
"utils": "$lib/utils"
12+
},
13+
"typescript": true
14+
}

frontend/eslint.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ export default [
2525
parserOptions: {
2626
parser: ts.parser
2727
}
28+
},
29+
rules: {
30+
'@typescript-eslint/no-unused-vars': [
31+
'error',
32+
{
33+
argsIgnorePattern: '^_',
34+
varsIgnorePattern: '^\\$\\$(Props|Events|Slots|Generic)$'
35+
}
36+
]
2837
}
2938
},
3039
{

0 commit comments

Comments
 (0)