A full-stack Star Wars API application built with Node.js, NestJS, React, and TypeScript. This project provides a comprehensive API for managing Star Wars universe data including films, people, planets, species, starships, and vehicles.
- RESTful API with full CRUD operations for Star Wars entities
- JWT Authentication with role-based access control
- React Frontend with modern UI components
- PostgreSQL Database with TypeORM
- Swagger Documentation for API exploration
- Docker Support for easy deployment
- Comprehensive Testing with Jest
- Multi-language Support (English, Portuguese)
This is a monorepo containing:
- Server: NestJS backend API (
/server) - Client: React frontend application (
/client) - Docker: Containerization configuration (
/docker)
- Node.js >= 22.14.0
- npm >= 9.0.0
- Docker and Docker Compose (for containerized deployment)
- PostgreSQL (for local development)
-
Clone the repository
git clone <repository-url> cd swapi_njs
-
Install dependencies
npm install
-
Set up the database
# Start PostgreSQL with Docker npm run docker:db:up -
Start the application
# Start both server and client concurrently npm start # Or start them separately npm run start:server # Backend on http://localhost:8080 npm run start:client # Frontend on http://localhost:9000
-
Build and run with Docker Compose
# Start the full application stack npm run app:up # Or manually with docker-compose docker-compose -f docker/app.yml up --build
-
Access the application
- API: http://localhost:8080
- Frontend: http://localhost:8080 (served by backend)
- Swagger Documentation: http://localhost:8080/api/v2/api-docs
npm start # Start both server and client
npm run build # Build both server and client
npm test # Run all tests
npm run test:server # Run server tests only
npm run test:client # Run client tests only
npm run test:server:e2e # Run end-to-end testscd server
npm start # Start in development mode
npm run start:prod # Start in production mode
npm run build # Build the application
npm test # Run unit tests
npm run test:e2e # Run end-to-end tests
npm run lint # Run ESLint
npm run lint:fix # Fix ESLint issuescd client
npm start # Start development server
npm run build # Build for production
npm test # Run tests
npm run lint # Run ESLintThe API provides comprehensive CRUD operations for Star Wars entities. All endpoints require JWT authentication.
POST /api/authenticate- Login and get JWT token
GET /api/films- List all films (paginated)GET /api/films/:id- Get film by IDPOST /api/films- Create new filmPUT /api/films- Update filmPUT /api/films/:id- Update film by IDDELETE /api/films/:id- Delete film
GET /api/people- List all people (paginated)GET /api/people/:id- Get person by IDPOST /api/people- Create new personPUT /api/people- Update personPUT /api/people/:id- Update person by IDDELETE /api/people/:id- Delete person
GET /api/planets- List all planets (paginated)GET /api/planets/:id- Get planet by IDPOST /api/planets- Create new planetPUT /api/planets- Update planetPUT /api/planets/:id- Update planet by IDDELETE /api/planets/:id- Delete planet
GET /api/species- List all species (paginated)GET /api/species/:id- Get species by IDPOST /api/species- Create new speciesPUT /api/species- Update speciesPUT /api/species/:id- Update species by IDDELETE /api/species/:id- Delete species
GET /api/starships- List all starships (paginated)GET /api/starships/:id- Get starship by IDPOST /api/starships- Create new starshipPUT /api/starships- Update starshipPUT /api/starships/:id- Update starship by IDDELETE /api/starships/:id- Delete starship
GET /api/vehicles- List all vehicles (paginated)GET /api/vehicles/:id- Get vehicle by IDPOST /api/vehicles- Create new vehiclePUT /api/vehicles- Update vehiclePUT /api/vehicles/:id- Update vehicle by IDDELETE /api/vehicles/:id- Delete vehicle
All list endpoints support pagination and sorting:
page- Page number (default: 0)size- Page size (default: 20)sort- Sort field and direction (e.g.,name,ASCorid,DESC)
The API uses JWT (JSON Web Token) authentication:
- Login: Send POST request to
/api/authenticatewith username/password - Token: Include the returned JWT token in the
Authorizationheader asBearer <token> - Expiration: Tokens are valid for 24 hours by default
# Login
curl -X POST http://localhost:8080/api/authenticate \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin"}'
# Use token in subsequent requests
curl -X GET http://localhost:8080/api/films \
-H "Authorization: Bearer <your-jwt-token>"- Host: localhost
- Port: 5432
- Database: swapi_api
- Username: swapi_api
- Password: (trust authentication for development)
cd server
npm run typeorm:migration:run # Run pending migrations
npm run typeorm:schema:sync # Sync schema# All tests
npm test
# Server tests only
npm run test:server
# Client tests only
npm run test:client
# End-to-end tests
npm run test:server:e2e
# Test coverage
npm run test:server -- --coverage- Unit Tests: Located in
*.spec.tsfiles - E2E Tests: Located in
/server/e2e/directory - Frontend Tests: Located in
/client/src/with Jest and React Testing Library
Interactive API documentation is available via Swagger UI:
- Swagger UI: http://localhost:8080/api/v2/api-docs
- OpenAPI Spec: Available at the same endpoint
- Application: Node.js app with React frontend
- PostgreSQL: Database service
- Health Checks: Built-in health monitoring
# Start all services
npm run app:up
# Start only database
npm run docker:db:up
# Stop database
npm run docker:db:down
# View logs
docker-compose -f docker/app.yml logs -fThe application supports multiple environments:
- Development (
BACKEND_ENV=dev) - Test (
BACKEND_ENV=test) - Production (
BACKEND_ENV=prod)
Configuration files:
server/src/config/application.yml- Base configurationserver/src/config/application-{env}.yml- Environment-specific overrides
- Server Port: 8080
- JWT Secret: Base64 encoded secret (configured in application.yml)
- Token Validity: 24 hours (86400 seconds)
- Database: PostgreSQL with TypeORM
- CORS: Enabled for development
BACKEND_ENV- Environment (dev/test/prod)NODE_SERVER_PORT- Server port (default: 8080)
-
Build the application
npm run build
-
Set production environment
export BACKEND_ENV=prod -
Start with Docker
docker-compose -f docker/app.yml up -d
- Install Node.js dependencies
- Build both server and client
- Configure PostgreSQL database
- Set environment variables
- Start the server:
npm run start:prod
swapi_njs/
βββ client/ # React frontend
β βββ src/
β β βββ app/ # Main application code
β β βββ entities/ # Entity-specific components
β β βββ modules/ # Feature modules
β β βββ shared/ # Shared components
β βββ webpack/ # Webpack configuration
βββ server/ # NestJS backend
β βββ src/
β β βββ domain/ # Database entities
β β βββ module/ # Feature modules
β β βββ service/ # Business logic
β β βββ web/rest/ # REST controllers
β β βββ security/ # Authentication & authorization
β βββ e2e/ # End-to-end tests
βββ docker/ # Docker configurations
βββ package.json # Root package configuration
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the UNLICENSED License.
For support and questions:
- Check the Swagger documentation at
/api/v2/api-docs - Review the test files for usage examples
- Check the Docker logs for troubleshooting
- v0.0.1 - Initial release with basic CRUD operations for all Star Wars entities
- v0.0.0 - Development version
Built with β€οΈ using NestJS, React, TypeScript, and PostgreSQL