Prerequisites
Before you begin, ensure you have the following installed:- Node.js: Version 6.x or higher (the project uses legacy dependencies)
- PostgreSQL: Version 9.x or higher for database operations
- npm: Comes with Node.js, used for dependency management
- Git: For cloning the repository
Installation
Install dependencies
Install all required npm packages:This will install all dependencies and devDependencies listed in
package.json, including:- React and Redux ecosystem
- Express server framework
- Sequelize ORM and PostgreSQL driver
- Webpack and Babel for bundling
- Material-UI for components
Set up the database
Create a PostgreSQL database for the application:The application expects a database named
mtg at postgres://localhost:5432/mtg. If you need to use a different database URL, you’ll need to modify server/db/models/index.js.The database will be automatically synced when you start the server. Sequelize will create the necessary tables:cards- Stores MTG card datadeck- Stores deck informationcards_decks- Junction table for deck-card relationships
Development workflow
Hot reloading
The development setup includes automatic reloading:- Frontend changes: Webpack watches for changes in the
app/directory and rebuildspublic/bundle.jsautomatically - Backend changes: Nodemon watches for changes in the
server/directory and restarts the Express server
Webpack configuration
The project uses Webpack 3 with the following setup:- Babel transpilation for React and ES2015+
- Support for
.jsand.jsxextensions - Stage-2 JavaScript features enabled
Port configuration
The Express server runs on port 4000 by default. You can change this inserver/index.js:30.
Database seeding
Loading card data (optional)
Loading card data (optional)
If you need to populate the database with MTG card data, you can use the fixtures system:
- Place your card data in
server/db/fixtures/ - Use
sequelize-fixturesto load the data (implementation depends on your data source)
Card model includes fields for card properties like name, mana cost, colors, type, power/toughness, and text.Development tools
Redux DevTools
The application is configured to work with the Redux DevTools browser extension. Install the extension for Chrome or Firefox to inspect Redux state and actions. The store configuration inapp/store.js automatically enables the extension when available:
Redux Logger
Redux Logger middleware is enabled in development, logging all actions and state changes to the browser console.Troubleshooting
Database connection errors
Error:ECONNREFUSED or database "mtg" does not exist
Solution:
- Ensure PostgreSQL is running:
pg_ctl statusorbrew services list(macOS) - Create the database:
createdb mtg - Check the connection string in
server/db/models/index.js:2
Port already in use
Error:EADDRINUSE: address already in use :::4000
Solution:
- Find the process using port 4000:
lsof -i :4000 - Kill the process:
kill -9 <PID> - Or change the port in
server/index.js
Webpack build errors
Error: Babel or Webpack compilation errors Solution:- Delete
node_modulesand reinstall:rm -rf node_modules && npm install - Clear the bundle:
rm public/bundle.js public/bundle.js.map - Restart the development server
Module not found errors
Error:Cannot find module 'xyz'
Solution:
- Ensure all dependencies are installed:
npm install - Check for missing peer dependencies in the console output
- Verify the import path is correct (case-sensitive on Linux)
Production build
For production deployment:node main which should point to your production entry point.
Next steps
Architecture
Learn about the application architecture and design patterns
Contributing
Guidelines for contributing to the project
