diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9c7292d --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 2529ed8..4413aae 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Blog -## Development +## Description - Frontend: SvelteKit with Tailwind CSS - 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). +## 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 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. diff --git a/backend/README.md b/backend/README.md index dbc4b51..4b18f6e 100644 --- a/backend/README.md +++ b/backend/README.md @@ -2,40 +2,71 @@ ## 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 cargo install sqlx-cli ``` -2. Run migration +2. Run database migrations: ```bash sqlx migrate run ``` -### Run Project - -1. Prepare for sql schema setup +3. Prepare SQL schema: ```bash cargo sqlx prepare --workspace ``` -2. Run the server - +4. Run the server: ```bash 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 - RUST_LOG=debug watchexec -e rs -r 'cargo run' - ``` +The backend follows Clean Architecture principles with a modular structure: + +- `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 diff --git a/frontend/README.md b/frontend/README.md new file mode 100644 index 0000000..8571b46 --- /dev/null +++ b/frontend/README.md @@ -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 diff --git a/script/backend-check.sh b/script/backend-check.sh new file mode 100755 index 0000000..aa938b2 --- /dev/null +++ b/script/backend-check.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +cd "$SCRIPT_DIR/../backend" +cargo check diff --git a/script/frontend-lint.sh b/script/frontend-lint.sh new file mode 100755 index 0000000..c6d3377 --- /dev/null +++ b/script/frontend-lint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +cd "$SCRIPT_DIR/../frontend" +pnpm lint diff --git a/script/sqlx-prepare.sh b/script/sqlx-prepare.sh new file mode 100755 index 0000000..65f4d3f --- /dev/null +++ b/script/sqlx-prepare.sh @@ -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