BLOG-145 Add pre-commit hooks (#147)
All checks were successful
Frontend CI / build (push) Successful in 1m37s
All checks were successful
Frontend CI / build (push) Successful in 1m37s
### Description - READMEs are also updated! ### Package Changes _No response_ ### Screenshots _No response_ ### Reference Resolves #145. ### Checklist - [x] A milestone is set - [x] The related issuse has been linked to this branch Reviewed-on: #147 Co-authored-by: SquidSpirit <squid@squidspirit.com> Co-committed-by: SquidSpirit <squid@squidspirit.com>
This commit is contained in:
parent
d22f8cc292
commit
d1f085b255
18
.pre-commit-config.yaml
Normal file
18
.pre-commit-config.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
repos:
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: sqlx-prepare
|
||||||
|
name: sqlx prepare
|
||||||
|
language: script
|
||||||
|
entry: ./script/sqlx-prepare.sh
|
||||||
|
pass_filenames: false
|
||||||
|
- id: backend-check
|
||||||
|
name: backend check
|
||||||
|
language: script
|
||||||
|
entry: ./script/backend-check.sh
|
||||||
|
pass_filenames: false
|
||||||
|
- id: frontend-lint
|
||||||
|
name: frontend lint
|
||||||
|
language: script
|
||||||
|
entry: ./script/frontend-lint.sh
|
||||||
|
pass_filenames: false
|
64
README.md
64
README.md
@ -1,6 +1,6 @@
|
|||||||
# Blog
|
# Blog
|
||||||
|
|
||||||
## Development
|
## Description
|
||||||
|
|
||||||
- Frontend: SvelteKit with Tailwind CSS
|
- Frontend: SvelteKit with Tailwind CSS
|
||||||
- Backend: Rust actix-web
|
- Backend: Rust actix-web
|
||||||
@ -13,6 +13,68 @@ These will allow me to become more proficient in these modern development practi
|
|||||||
|
|
||||||
For more information about the development process, you can check out the [project board](https://git.squidspirit.com/squid/blog/projects). As for the details of the architecture and convention, you can find them in the [wiki](https://git.squidspirit.com/squid/blog/wiki).
|
For more information about the development process, you can check out the [project board](https://git.squidspirit.com/squid/blog/projects). As for the details of the architecture and convention, you can find them in the [wiki](https://git.squidspirit.com/squid/blog/wiki).
|
||||||
|
|
||||||
|
## Build & Development Setup
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- [Node.js](https://nodejs.org/) (LTS version recommended)
|
||||||
|
- [pnpm](https://pnpm.io/) - Package manager for frontend
|
||||||
|
- [Rust](https://rustup.rs/) - For backend development
|
||||||
|
- [Podman](https://podman.io/) (Optional) - For containerized deployment
|
||||||
|
|
||||||
|
### Pre-commit Setup
|
||||||
|
|
||||||
|
This project uses pre-commit hooks to ensure code quality. To set up pre-commit:
|
||||||
|
|
||||||
|
1. Install pre-commit:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install pre-commit
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Install the git hook scripts:
|
||||||
|
```bash
|
||||||
|
pre-commit install
|
||||||
|
```
|
||||||
|
|
||||||
|
The pre-commit configuration will automatically run:
|
||||||
|
|
||||||
|
- Backend Rust code checking and formatting
|
||||||
|
- Frontend linting and formatting
|
||||||
|
- SQL schema preparation
|
||||||
|
|
||||||
|
### Backend Setup
|
||||||
|
|
||||||
|
For detailed backend development setup, see [backend/README.md](./backend/README.md).
|
||||||
|
|
||||||
|
Quick start:
|
||||||
|
|
||||||
|
1. Install sqlx CLI: `cargo install sqlx-cli`
|
||||||
|
2. Run database migrations: `sqlx migrate run`
|
||||||
|
3. Prepare SQL schema: `cargo sqlx prepare --workspace`
|
||||||
|
4. Run the server: `RUST_LOG=debug cargo run`
|
||||||
|
|
||||||
|
### Frontend Setup
|
||||||
|
|
||||||
|
For detailed frontend development setup, see [frontend/README.md](./frontend/README.md).
|
||||||
|
|
||||||
|
Quick start:
|
||||||
|
|
||||||
|
1. Navigate to frontend directory: `cd frontend`
|
||||||
|
2. Install dependencies: `pnpm install`
|
||||||
|
3. Start development server: `pnpm dev`
|
||||||
|
4. Build for production: `pnpm build`
|
||||||
|
|
||||||
|
### Full Project Setup
|
||||||
|
|
||||||
|
To set up the entire project:
|
||||||
|
|
||||||
|
1. Clone the repository
|
||||||
|
2. Set up pre-commit hooks (see above)
|
||||||
|
3. Set up backend (see [backend/README.md](./backend/README.md))
|
||||||
|
4. Set up frontend (see [frontend/README.md](./frontend/README.md))
|
||||||
|
5. Start both servers for full-stack development
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project uses a combination of the [MIT License and a custom license](./LICENSE.md). Based on the MIT License, anyone is permitted to use the code. However, before deploying the code, they must first replace any information belonging to "me" or any content that could identify "me," such as logos, names, and "about me" sections.
|
This project uses a combination of the [MIT License and a custom license](./LICENSE.md). Based on the MIT License, anyone is permitted to use the code. However, before deploying the code, they must first replace any information belonging to "me" or any content that could identify "me," such as logos, names, and "about me" sections.
|
||||||
|
@ -2,40 +2,71 @@
|
|||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
### SQL Migration
|
### Prerequisites
|
||||||
|
|
||||||
1. Install sqlx
|
- [Rust](https://rustup.rs/) - Latest stable version
|
||||||
|
- [sqlx-cli](https://github.com/launchbadge/sqlx/tree/main/sqlx-cli) - Database migration tool
|
||||||
|
- [watchexec](https://github.com/watchexec/watchexec) (Optional) - For hot reloading
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
1. Install sqlx CLI:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo install sqlx-cli
|
cargo install sqlx-cli
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run migration
|
2. Run database migrations:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sqlx migrate run
|
sqlx migrate run
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run Project
|
3. Prepare SQL schema:
|
||||||
|
|
||||||
1. Prepare for sql schema setup
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cargo sqlx prepare --workspace
|
cargo sqlx prepare --workspace
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run the server
|
4. Run the server:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
RUST_LOG=debug cargo run
|
RUST_LOG=debug cargo run
|
||||||
```
|
```
|
||||||
|
|
||||||
3. (Optional) Hot restart
|
### Development Commands
|
||||||
|
|
||||||
1. Install `watchexec`
|
- **Run server**: `RUST_LOG=debug cargo run`
|
||||||
|
- **Hot reload** (optional): `RUST_LOG=debug watchexec -e rs -r 'cargo run'`
|
||||||
|
- **Database migration**: `sqlx migrate run`
|
||||||
|
- **Schema preparation**: `cargo sqlx prepare --workspace`
|
||||||
|
- **Build**: `cargo build`
|
||||||
|
- **Test**: `cargo test`
|
||||||
|
|
||||||
2. Run the server with `watchexec`
|
### Project Structure
|
||||||
|
|
||||||
```bash
|
The backend follows Clean Architecture principles with a modular structure:
|
||||||
RUST_LOG=debug watchexec -e rs -r 'cargo run'
|
|
||||||
```
|
- `server/` - Main server application and configuration
|
||||||
|
- `feature/` - Feature modules organized by domain
|
||||||
|
- `auth/` - Authentication and authorization
|
||||||
|
- `post/` - Blog post management
|
||||||
|
- `label/` - Label/tag system
|
||||||
|
- `image/` - Image handling
|
||||||
|
- `common/` - Shared utilities and types
|
||||||
|
- `migrations/` - Database migration scripts
|
||||||
|
|
||||||
|
Each feature module follows the Clean Architecture pattern:
|
||||||
|
|
||||||
|
- `domain/` - Business logic and entities
|
||||||
|
- `application/` - Use cases and application services
|
||||||
|
- `adapter/` - Interface adapters (controllers, presenters)
|
||||||
|
- `framework/` - External frameworks (database, HTTP)
|
||||||
|
|
||||||
|
### Technology Stack
|
||||||
|
|
||||||
|
- **Framework**: Actix-web
|
||||||
|
- **Database**: PostgreSQL with SQLx
|
||||||
|
- **Authentication**: JWT-based
|
||||||
|
- **Serialization**: Serde
|
||||||
|
- **Migration**: SQLx migrations
|
||||||
|
- **Logging**: env_logger with RUST_LOG
|
||||||
|
65
frontend/README.md
Normal file
65
frontend/README.md
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
# Frontend
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
- [Node.js](https://nodejs.org/) (LTS version recommended)
|
||||||
|
- [pnpm](https://pnpm.io/) - Package manager
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
1. Install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Start development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Build for production:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Preview production build:
|
||||||
|
```bash
|
||||||
|
pnpm preview
|
||||||
|
```
|
||||||
|
|
||||||
|
### Development Commands
|
||||||
|
|
||||||
|
- **Type checking**: `pnpm check`
|
||||||
|
- **Type checking (watch mode)**: `pnpm check:watch`
|
||||||
|
- **Linting**: `pnpm lint`
|
||||||
|
- **Formatting**: `pnpm format`
|
||||||
|
|
||||||
|
### Project Structure
|
||||||
|
|
||||||
|
The frontend is built with SvelteKit and Tailwind CSS following Clean Architecture principles:
|
||||||
|
|
||||||
|
- `src/lib/` - Core application modules organized by feature
|
||||||
|
- `src/routes/` - SvelteKit route pages
|
||||||
|
- `src/app.html` - Main HTML template
|
||||||
|
- `src/app.css` - Global styles
|
||||||
|
|
||||||
|
Each feature module in `src/lib/` follows the Clean Architecture pattern:
|
||||||
|
|
||||||
|
- `domain/` - Business logic and entities
|
||||||
|
- `application/` - Use cases and application services
|
||||||
|
- `adapter/` - Interface adapters (presenters, view models)
|
||||||
|
- `framework/` - External frameworks (UI components, API services)
|
||||||
|
|
||||||
|
### Technology Stack
|
||||||
|
|
||||||
|
- **Framework**: SvelteKit 5
|
||||||
|
- **Styling**: Tailwind CSS 4
|
||||||
|
- **UI Components**: bits-ui, Lucide icons
|
||||||
|
- **Type Safety**: TypeScript
|
||||||
|
- **Linting**: ESLint with Prettier
|
||||||
|
- **Package Manager**: pnpm
|
6
script/backend-check.sh
Executable file
6
script/backend-check.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
|
|
||||||
|
cd "$SCRIPT_DIR/../backend"
|
||||||
|
cargo check
|
6
script/frontend-lint.sh
Executable file
6
script/frontend-lint.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
|
|
||||||
|
cd "$SCRIPT_DIR/../frontend"
|
||||||
|
pnpm lint
|
15
script/sqlx-prepare.sh
Executable file
15
script/sqlx-prepare.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||||
|
|
||||||
|
cd "$SCRIPT_DIR/../backend"
|
||||||
|
|
||||||
|
# Generate sqlx-data.json
|
||||||
|
cargo sqlx prepare --workspace
|
||||||
|
|
||||||
|
# Check if sqlx-data.json was modified and is not staged
|
||||||
|
if ! git diff --quiet .sqlx; then
|
||||||
|
echo "Error: json files in .sqlx were modified by 'cargo sqlx prepare' but are not staged."
|
||||||
|
echo "Please run 'git add backend/.sqlx' and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user