Monorepo structure
The codebase is organized as a monorepo with two main packages:The
dev.sh script installs dependencies and starts both the API and client in development mode simultaneously.Backend architecture (NestJS)
The API is built with NestJS, a progressive Node.js framework that uses TypeScript and follows architectural patterns similar to Angular.Core technologies
- Framework: NestJS 10.4
- Database: PostgreSQL with TypeORM
- Authentication: JWT with bcrypt password hashing
- Validation: class-validator and class-transformer
- Logging: Pino logger
Directory structure
Module architecture
Each feature module follows the NestJS pattern:Example: Releases module structure
Example: Releases module structure
Database layer
The application uses TypeORM with PostgreSQL. All entities extend from a baseAbstractEntity:
Entity relationships
The database schema includes the following main entities and relationships:User entity
Central entity managing authentication and ownership:
- Has many Labels
- Has many Artists
- Has many Releases
- Has many Roles (as creator)
Label entity
Represents music labels:
- Belongs to User
- Has many Releases
- Contains: name, email, description, country
Artist entity
Artist profiles:
- Belongs to User
- Has many ReleaseArtist (many-to-many with Releases)
- Has status: ACTIVE/INACTIVE
Release entity
Music releases (albums, singles, EPs):
- Belongs to User and Label
- Has many Tracks
- Has many ReleaseArtist (artists on the release)
- Contains: title, UPC, release date, catalog number, production year
- Unique constraint: [title, releaseDate, productionYear, userId, labelId, version]
Application bootstrap
The API starts on port 8080 (configurable viaPORT environment variable):
Frontend architecture (React)
The client is a modern React application built with Vite and TypeScript.Core technologies
- Framework: React 18.2
- Build tool: Vite 5.2
- State management: Redux Toolkit with RTK Query
- Routing: React Router v6
- UI components: Radix UI primitives
- Styling: Tailwind CSS 4.1 with custom animations
- Forms: React Hook Form
- Icons: Font Awesome, Lucide React
- 3D graphics: Three.js with React Three Fiber
Directory structure
State management
The application uses Redux Toolkit with separate slices for different features:RTK Query is used for API communication, providing automatic caching, request deduplication, and optimistic updates.
Routing structure
The application uses React Router with protected routes:AuthenticatedRoutes outlet that handles authentication checks.
Component organization
Component categories
Component categories
UI Components (
components/ui/)- Radix UI primitives (dialogs, popovers, selects)
- Styled with Tailwind CSS and class-variance-authority
components/inputs/)- Form fields integrated with React Hook Form
- Validation with real-time feedback
components/layout/)- Headers, sidebars, navigation
- Responsive design patterns
pages/)- Full page views
- Data fetching with custom hooks
- Integration with Redux state
API communication
The frontend communicates with the backend through:- Base URL: Configured API endpoint (default:
http://localhost:8080/api) - Authentication: JWT tokens stored in Redux and sent via Authorization headers
- Request handling: RTK Query for automatic caching and state synchronization
Request flow
Development workflow
Starting the application
Environment configuration
The API requires environment variables:Security features
Authentication
Authentication
- JWT tokens with 1-week expiration
- Bcrypt password hashing
- Custom
@CurrentUser()decorator for accessing authenticated user
Authorization
Authorization
Validation
Validation
- Global ValidationPipe with whitelist
- DTO validation with class-validator
- Email validation helper
Error handling
Error handling
- Global HttpExceptionFilter
- Structured error responses
- Logging with Pino
Deployment considerations
Next steps
Quickstart Guide
Start building with Lens Music
API Reference
Explore all API endpoints
Database Schema
Deep dive into the data model
Development Setup
Set up your development environment