Project Setup and Architecture
You have learned all the Angular concepts you need. Now you put them together. This module builds CinemaVault from scratch, one feature at a time.
Getting a TMDb API key
Section titled “Getting a TMDb API key”CinemaVault uses the TMDb API for movie data. Get a free API key:
- Create an account at themoviedb.org
- Go to Settings → API
- Request an API key (select “Developer” type, describe your use as a learning project)
- Copy the API key — you will use it in the next step
Scaffold the project
Section titled “Scaffold the project”ng new cinema-vaultSelect CSS stylesheets and No for SSR.
cd cinema-vaultEnvironment files
Section titled “Environment files”Angular’s environment file system lets you use different values for development and production. Create three files:
# Already exists — edit itsrc/environments/environment.ts
# Create these:src/environments/environment.prod.tssrc/environments/environment.local.ts// environment.ts — default dev build (no real key)export const environment = { tmdbApiKey: ''};
// environment.prod.ts — production build (key injected by CI)export const environment = { tmdbApiKey: ''};
// environment.local.ts — local dev with your real key (GITIGNORED)export const environment = { tmdbApiKey: 'YOUR_ACTUAL_API_KEY_HERE'};Add environment.local.ts to .gitignore — your API key should never be committed:
src/environments/environment.local.tsConfigure angular.json to use environment.local.ts when running ng serve --configuration=local:
In angular.json, under projects.cinema-vault.architect.build.configurations, add:
"local": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.local.ts" } ]}And under architect.serve.configurations:
"local": { "buildTarget": "cinema-vault:build:local"}Add an npm script in package.json:
"scripts": { "start:local": "ng serve --configuration=local"}Run with npm run start:local to use your local API key.
The planned architecture
Section titled “The planned architecture”src/app/├── app.ts ← root component├── app.html├── app.css├── app.config.ts ← provideRouter + provideHttpClient├── app.routes.ts ← all 5 routes├── core/│ └── tmdb.config.ts ← API key + URL helpers├── models/│ └── movie.model.ts ← TypeScript interfaces├── services/│ ├── movie.ts ← MovieService│ ├── watchlist.ts ← WatchlistService│ └── toast.ts ← ToastService├── guards/│ └── watchlist-guard.ts├── components/│ ├── nav-bar/│ ├── movie-card/│ └── toast/└── pages/ ├── home/ ├── browse/ ├── search-results/ ├── movie-detail/ └── watchlist/Create the directory structure
Section titled “Create the directory structure”mkdir -p src/app/{core,models,services,guards,components/{nav-bar,movie-card,toast},pages/{home,browse,search-results,movie-detail,watchlist}}Exercise
Section titled “Exercise”- Scaffold
cinema-vaultwithng new, choosing CSS and no SSR. - Create the three environment files with the content shown above.
- Add your actual API key to
environment.local.ts. - Configure
angular.jsonwith thelocalconfiguration. - Add the
start:localscript topackage.json. - Create the directory structure with
mkdir -p. - Run
npm run start:localand confirm the app starts atlocalhost:4200.
- Scaffold with
ng new cinema-vault, selecting CSS and no SSR. - Three environment files:
environment.ts(default),environment.prod.ts(CI),environment.local.ts(gitignored, has real key). - Configure
angular.jsonto swap the environment file when building with--configuration=local. - The app uses
core/,models/,services/,guards/,components/, andpages/directories.