initial
This commit is contained in:
@@ -1,93 +1,513 @@
|
||||
# MTG Search
|
||||
# MTG Search - Magic The Gathering Card Search Platform
|
||||
|
||||
A full-stack web application for searching and exploring Magic The Gathering cards with user authentication, built with Spring Boot, Vue.js, PostgreSQL, and deployed with Docker.
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
|
||||
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
||||
## Architecture Overview
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.moustos.net/dionmoustos/mtg-search.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
├── Backend (Java 21, Spring Boot 3.2.5)
|
||||
│ ├── REST API with OpenAPI/Swagger documentation
|
||||
│ ├── JWT-based authentication
|
||||
│ ├── PostgreSQL database with jOOQ ORM
|
||||
│ ├── Flyway database migrations
|
||||
│ ├── Comprehensive logging with Logback
|
||||
│ └── JUnit 5 and integration tests
|
||||
│
|
||||
├── Frontend (Vue 3, TypeScript, Vite)
|
||||
│ ├── Single Page Application (SPA)
|
||||
│ ├── Responsive UI with CSS Grid/Flexbox
|
||||
│ ├── Pinia state management
|
||||
│ ├── Vue Router with auth guards
|
||||
│ └── Axios HTTP client with JWT interceptors
|
||||
│
|
||||
├── Database (PostgreSQL 16)
|
||||
│ ├── Schema managed by Flyway migrations
|
||||
│ ├── jOOQ-generated DTOs and repositories
|
||||
│ └── Indexed queries for performance
|
||||
│
|
||||
└── Deployment
|
||||
├── Docker multi-stage build
|
||||
├── Docker Compose for local dev
|
||||
└── GitLab CI/CD pipeline
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
## Prerequisites
|
||||
|
||||
* [Set up project integrations](https://gitlab.moustos.net/dionmoustos/mtg-search/-/settings/integrations)
|
||||
- **Java 21** or later
|
||||
- **Node.js 20+** and npm 10+
|
||||
- **PostgreSQL 16+**
|
||||
- **Docker & Docker Compose** (for containerized setup)
|
||||
- **Git**
|
||||
|
||||
## Collaborate with your team
|
||||
## Quick Start
|
||||
|
||||
* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
|
||||
* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
|
||||
* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
|
||||
* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
|
||||
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
||||
### Using Docker Compose (Recommended)
|
||||
|
||||
## Test and Deploy
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone <repository-url>
|
||||
cd mtg-search
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
# Start all services (PostgreSQL, Backend, built Frontend)
|
||||
docker-compose up --build
|
||||
|
||||
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
|
||||
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
|
||||
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
|
||||
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
|
||||
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
|
||||
# Backend will be available at: http://localhost:8080
|
||||
# Frontend will be served by the backend
|
||||
```
|
||||
|
||||
***
|
||||
### Local Development Setup
|
||||
|
||||
# Editing this README
|
||||
#### 1. Database Setup
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
```bash
|
||||
# Start PostgreSQL (using Docker)
|
||||
docker run --name mtgsearch-postgres \
|
||||
-e POSTGRES_DB=mtgsearch \
|
||||
-e POSTGRES_USER=postgres \
|
||||
-e POSTGRES_PASSWORD=postgres \
|
||||
-p 5432:5432 \
|
||||
-d postgres:16-alpine
|
||||
|
||||
## Suggestions for a good README
|
||||
# Or use your local PostgreSQL installation
|
||||
```
|
||||
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
#### 2. Backend Setup
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
```bash
|
||||
cd backend
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
# Build the project
|
||||
../gradlew build
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
# Run the application
|
||||
../gradlew bootRun
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
# Backend starts on http://localhost:8080
|
||||
# Swagger UI available at: http://localhost:8080/swagger-ui.html
|
||||
# API Docs available at: http://localhost:8080/v3/api-docs
|
||||
```
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
#### 3. Frontend Setup
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
```bash
|
||||
cd frontend
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
# Start development server
|
||||
npm run dev
|
||||
|
||||
# Frontend starts on http://localhost:5173
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Authentication
|
||||
|
||||
- **POST** `/api/v1/auth/register` - Register a new user
|
||||
```json
|
||||
{
|
||||
"username": "john_doe",
|
||||
"email": "john@example.com",
|
||||
"password": "SecurePassword123!"
|
||||
}
|
||||
```
|
||||
|
||||
- **POST** `/api/v1/auth/login` - Login and get JWT token
|
||||
```json
|
||||
{
|
||||
"username": "john_doe",
|
||||
"password": "SecurePassword123!"
|
||||
}
|
||||
```
|
||||
Returns:
|
||||
```json
|
||||
{
|
||||
"token": "eyJhbGc...",
|
||||
"id": 1,
|
||||
"username": "john_doe",
|
||||
"email": "john@example.com"
|
||||
}
|
||||
```
|
||||
|
||||
- **GET** `/api/v1/auth/health` - Health check (no auth required)
|
||||
|
||||
### Protected Endpoints
|
||||
|
||||
All protected endpoints require JWT token in Authorization header:
|
||||
```
|
||||
Authorization: Bearer <token>
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
### Build Backend
|
||||
|
||||
```bash
|
||||
./gradlew clean build
|
||||
|
||||
# Build outputs to: backend/build/libs/
|
||||
```
|
||||
|
||||
### Build Frontend
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm run build
|
||||
|
||||
# Build outputs to: backend/src/main/resources/static/
|
||||
```
|
||||
|
||||
### Build Full Docker Image
|
||||
|
||||
```bash
|
||||
docker build -t mtgsearch:latest .
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
### Backend Unit Tests
|
||||
|
||||
```bash
|
||||
./gradlew test
|
||||
```
|
||||
|
||||
### Backend Integration Tests
|
||||
|
||||
```bash
|
||||
./gradlew integrationTest
|
||||
```
|
||||
|
||||
### Frontend Tests
|
||||
|
||||
```bash
|
||||
cd frontend
|
||||
npm run test
|
||||
npm run test:ui # Opens UI dashboard
|
||||
```
|
||||
|
||||
### All Tests with Coverage
|
||||
|
||||
```bash
|
||||
./gradlew test jacocoTestReport
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
|
||||
Create a `.env` file in the project root:
|
||||
|
||||
```env
|
||||
# Database
|
||||
DB_URL=jdbc:postgresql://localhost:5432/mtgsearch
|
||||
DB_USER=postgres
|
||||
DB_PASSWORD=postgres
|
||||
|
||||
# JWT
|
||||
JWT_SECRET=your-secret-key-change-in-production
|
||||
JWT_EXPIRATION=86400
|
||||
|
||||
# Frontend
|
||||
VITE_API_URL=http://localhost:8080
|
||||
```
|
||||
|
||||
### Application Properties
|
||||
|
||||
Backend configuration in `backend/src/main/resources/application.yml`:
|
||||
|
||||
```yaml
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/mtgsearch
|
||||
username: postgres
|
||||
password: postgres
|
||||
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
|
||||
app:
|
||||
jwt:
|
||||
secret: ${JWT_SECRET:your-secret-key}
|
||||
expiration: ${JWT_EXPIRATION:86400}
|
||||
```
|
||||
|
||||
## Database Migrations
|
||||
|
||||
Migrations are managed by Flyway and located in `backend/src/main/resources/db/migration/`
|
||||
|
||||
### Adding a New Migration
|
||||
|
||||
1. Create a new file: `V2__Add_new_table.sql`
|
||||
2. Write SQL migration
|
||||
3. Run application - Flyway will auto-apply migrations
|
||||
|
||||
Example migration:
|
||||
```sql
|
||||
-- V2__Add_cards_table.sql
|
||||
CREATE TABLE IF NOT EXISTS cards (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
```
|
||||
|
||||
## Logging
|
||||
|
||||
Logs are configured in `backend/src/main/resources/logback-spring.xml`
|
||||
|
||||
- **Log Location**: `logs/mtg-search.log`
|
||||
- **Error Logs**: `logs/mtg-search-error.log`
|
||||
- **Max File Size**: 100MB
|
||||
- **Retention**: 30 days
|
||||
- **Compression**: Automatic gzip compression
|
||||
|
||||
View logs:
|
||||
```bash
|
||||
tail -f logs/mtg-search.log
|
||||
tail -f logs/mtg-search-error.log
|
||||
```
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Code Generation
|
||||
|
||||
The project uses OpenAPI Generator and jOOQ for code generation:
|
||||
|
||||
```bash
|
||||
# Generate server stubs from OpenAPI spec
|
||||
./gradlew openApiGenerate
|
||||
|
||||
# Generate jOOQ entities from database schema
|
||||
./gradlew generateJooqCode
|
||||
```
|
||||
|
||||
### Code Quality
|
||||
|
||||
```bash
|
||||
# Format code
|
||||
./gradlew spotlessApply
|
||||
|
||||
# Run static analysis
|
||||
./gradlew check
|
||||
|
||||
# Frontend linting
|
||||
cd frontend
|
||||
npm run lint
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
### Staging Deployment
|
||||
|
||||
```bash
|
||||
git checkout develop
|
||||
git merge feature-branch
|
||||
git push origin develop
|
||||
|
||||
# GitLab CI will automatically build and deploy to staging
|
||||
```
|
||||
|
||||
### Production Deployment
|
||||
|
||||
```bash
|
||||
git tag v0.2.0
|
||||
git push origin v0.2.0
|
||||
|
||||
# GitLab CI will build, test, and deploy to production
|
||||
```
|
||||
|
||||
### Manual Deployment
|
||||
|
||||
```bash
|
||||
# Build Docker image
|
||||
docker build -t mtgsearch:v0.1.0 .
|
||||
docker tag mtgsearch:v0.1.0 your-registry/mtgsearch:v0.1.0
|
||||
|
||||
# Push to registry
|
||||
docker push your-registry/mtgsearch:v0.1.0
|
||||
|
||||
# Pull and run on server
|
||||
docker pull your-registry/mtgsearch:v0.1.0
|
||||
docker run -d \
|
||||
-e SPRING_DATASOURCE_URL=jdbc:postgresql://db-host:5432/mtgsearch \
|
||||
-e SPRING_DATASOURCE_USERNAME=postgres \
|
||||
-e SPRING_DATASOURCE_PASSWORD=secure-password \
|
||||
-e JWT_SECRET=your-production-secret \
|
||||
-p 8080:8080 \
|
||||
--name mtgsearch \
|
||||
your-registry/mtgsearch:v0.1.0
|
||||
```
|
||||
|
||||
## CI/CD Pipeline
|
||||
|
||||
The project includes a comprehensive GitLab CI/CD pipeline (`.gitlab-ci.yml`):
|
||||
|
||||
1. **Build Stage**
|
||||
- Compiles Java backend
|
||||
- Builds Vue.js frontend
|
||||
- Caches dependencies
|
||||
|
||||
2. **Test Stage**
|
||||
- Unit tests
|
||||
- Integration tests with PostgreSQL
|
||||
- Code quality checks
|
||||
|
||||
3. **Docker Stage**
|
||||
- Builds multi-stage Docker image
|
||||
- Pushes to registry
|
||||
|
||||
4. **Deploy Stage**
|
||||
- Deploys to staging with manual trigger
|
||||
- Deploys to production on version tags
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
mtg-search/
|
||||
├── backend/
|
||||
│ ├── src/
|
||||
│ │ ├── main/
|
||||
│ │ │ ├── java/net/moustos/mtgsearch/
|
||||
│ │ │ │ ├── MtgSearchApplication.java
|
||||
│ │ │ │ ├── config/
|
||||
│ │ │ │ ├── controller/
|
||||
│ │ │ │ ├── service/
|
||||
│ │ │ │ ├── repository/
|
||||
│ │ │ │ ├── model/
|
||||
│ │ │ │ └── security/
|
||||
│ │ │ └── resources/
|
||||
│ │ │ ├── application.yml
|
||||
│ │ │ ├── logback-spring.xml
|
||||
│ │ │ └── db/migration/
|
||||
│ │ └── test/
|
||||
│ │ └── java/
|
||||
│ └── build.gradle.kts
|
||||
│
|
||||
├── frontend/
|
||||
│ ├── src/
|
||||
│ │ ├── pages/
|
||||
│ │ ├── components/
|
||||
│ │ ├── services/
|
||||
│ │ ├── stores/
|
||||
│ │ ├── router/
|
||||
│ │ ├── types/
|
||||
│ │ ├── main.ts
|
||||
│ │ └── App.vue
|
||||
│ ├── public/
|
||||
│ ├── index.html
|
||||
│ ├── package.json
|
||||
│ ├── vite.config.ts
|
||||
│ └── tsconfig.json
|
||||
│
|
||||
├── gradle/
|
||||
├── build.gradle.kts
|
||||
├── settings.gradle.kts
|
||||
├── gradle.properties
|
||||
├── gradlew
|
||||
├── gradlew.bat
|
||||
│
|
||||
├── Dockerfile
|
||||
├── docker-compose.yml
|
||||
├── .gitlab-ci.yml
|
||||
├── .gitignore
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Backend won't start
|
||||
```bash
|
||||
# Check if port 8080 is already in use
|
||||
lsof -i :8080
|
||||
|
||||
# Check PostgreSQL is running
|
||||
psql -U postgres -h localhost -d mtgsearch -c "SELECT 1;"
|
||||
|
||||
# View logs
|
||||
tail -f logs/mtg-search.log
|
||||
```
|
||||
|
||||
### Frontend connection issues
|
||||
- Check backend is running on 8080
|
||||
- Check browser console for errors
|
||||
- Verify CORS settings in SecurityConfig.java
|
||||
|
||||
### Database migration failures
|
||||
```bash
|
||||
# Check migration status
|
||||
./gradlew flywayInfo
|
||||
|
||||
# Repair migrations (use with caution)
|
||||
./gradlew flywayRepair
|
||||
|
||||
# Clean database (WARNING: deletes all data)
|
||||
./gradlew flywayClean
|
||||
```
|
||||
|
||||
### Docker build fails
|
||||
```bash
|
||||
# Clear Docker cache
|
||||
docker system prune -a
|
||||
|
||||
# Rebuild with no cache
|
||||
docker build --no-cache -t mtgsearch:latest .
|
||||
```
|
||||
|
||||
## Performance Optimization
|
||||
|
||||
### Backend
|
||||
- Connection pooling: HikariCP configured with 10 max connections
|
||||
- Database indexing on frequently queried columns
|
||||
- Flyway async migration setup
|
||||
- Request caching headers
|
||||
|
||||
### Frontend
|
||||
- Code splitting with Vite
|
||||
- Lazy route loading
|
||||
- Production build minification
|
||||
- Gzip compression
|
||||
|
||||
### Database
|
||||
- Query result caching
|
||||
- Indexed columns for search operations
|
||||
- Batch operations optimization
|
||||
|
||||
## Security
|
||||
|
||||
- **Password Hashing**: BCrypt with strength 12
|
||||
- **JWT Tokens**: Auth0 library with HMAC256
|
||||
- **CORS**: Configured for development (update for production)
|
||||
- **HTTPS**: Required for production deployment
|
||||
- **SQL Injection**: Protected via parameterized queries with jOOQ
|
||||
- **CSRF**: Disabled for API (JWT-based auth)
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
1. Create a feature branch: `git checkout -b feature/amazing-feature`
|
||||
2. Commit changes: `git commit -m 'Add amazing feature'`
|
||||
3. Push to branch: `git push origin feature/amazing-feature`
|
||||
4. Open a Pull Request
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
MIT License - see LICENSE file for details
|
||||
|
||||
## Support
|
||||
|
||||
For issues and questions:
|
||||
- Open an issue on GitLab
|
||||
- Check existing documentation
|
||||
- Review API Swagger docs at `/swagger-ui.html`
|
||||
|
||||
## Roadmap
|
||||
|
||||
- [ ] Card search functionality with filters
|
||||
- [ ] Deck building feature
|
||||
- [ ] Social features (friends, sharing)
|
||||
- [ ] Mobile app
|
||||
- [ ] Advanced analytics
|
||||
- [ ] Magic Online API integration
|
||||
- [ ] Performance tuning for large datasets
|
||||
|
||||
Reference in New Issue
Block a user