Files
motovaultpro/backend/README.md
Eric Gullickson e22d643ae3 Security Fixes
2025-08-24 14:39:50 -05:00

105 lines
2.5 KiB
Markdown

# MotoVaultPro Backend
## Modified Feature Capsule Architecture
Each feature is 100% self-contained in `src/features/[name]/`:
- **api/** - HTTP endpoints and routing
- **domain/** - Business logic and types
- **data/** - Database operations
- **migrations/** - Feature-specific schema
- **external/** - External API integrations
- **tests/** - All feature tests
- **docs/** - Feature documentation
## Quick Start (Containerized)
```bash
# From project root directory
# Copy environment variables
cp .env.example .env
# Update .env with your credentials
# Build and start all services (including backend)
make setup
# View logs
make logs-backend
# Run migrations
make migrate
# Run tests
make test
```
## Available Commands (Containerized)
**From project root:**
- `make dev` - Start all services in development mode
- `make test` - Run tests in containers
- `make migrate` - Run database migrations
- `make logs-backend` - View backend logs
- `make shell-backend` - Open shell in backend container
**Inside container (via make shell-backend):**
- `npm run dev` - Start development server with hot reload
- `npm run build` - Build for production
- `npm start` - Run production build
- `npm test` - Run all tests
- `npm run test:feature -- --feature=vehicles` - Test specific feature
- `npm run schema:generate` - Generate combined schema
## Core Modules
### Configuration (`src/core/config/`)
- `environment.ts` - Environment variable validation
- `database.ts` - PostgreSQL connection pool
- `redis.ts` - Redis client and cache service
### Security (Fastify Plugin)
- `src/core/plugins/auth.plugin.ts` - Auth plugin (mock user in dev; plan for Auth0 JWT)
### Logging (`src/core/logging/`)
- `logger.ts` - Structured logging with Winston
## Feature Development
To create a new feature capsule:
```bash
../scripts/generate-feature-capsule.sh feature-name
```
This creates the complete capsule structure with all necessary files.
## Testing
Tests mirror the source structure:
```
features/vehicles/
├── domain/
│ └── vehicles.service.ts
└── tests/
└── unit/
└── vehicles.service.test.ts
```
Run tests:
```bash
# All tests
npm test
# Specific feature
npm test -- features/vehicles
# Watch mode
npm run test:watch
```
## Environment Variables
See `.env.example` for required variables. Key variables:
- Database connection (DB_*)
- Redis connection (REDIS_*)
- Auth0 configuration (AUTH0_*) — backend currently uses mock auth; JWT enforcement planned
- External API keys