Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Mykyta Chernenko

Rating No ratings yet

Unleash the power of modern web development and master both frontend and backend development by building a real-world application Key Features Integrate AI capabilities in an application using the OpenAI API and learn AI-based features Build robust web applications with advanced TypeScript features like typing, generics, classes, and interfaces Implement user authentication and authorization mechanisms to protect your apps and user data Book Description This book takes you on a journey with TypeScript 5, introducing its nuances and advantages over traditional JavaScript, explaining TypeScript basics, and highlighting the syntax, typing, generics, classes, and interfaces. Expert advice will help you build your understanding of TypeScript's role in modern web applications. You'll gain hands-on experience with the tools required to write full-stack web applications end to end, beginning with setting up the Bun environment for backend development. This book also explores server-side functionality such as authentication, routing, and database integration with PostgreSQL. The second part of the book focuses on the integration of the OpenAI API, demonstrating the use of the GPT API for different use cases. The final part covers frontend development using Svelte, guiding you through UI design, state management, and performance optimization. Each chapter has real-world examples and comparisons to other technologies, providing you with a comprehensive understanding of full-stack development. By the end of this book, you'll have learned how to build modern web applications using TypeScript 5 and confidently tackle full-stack development challenges. Who this book is for This book is for junior to mid-level software engineers with foundational knowledge of JavaScript and web development, who are enthusiastic about the most cutting-edge technologies and want to expand their understanding of building full-stack applications end to end.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide for junior-to-mid-level developers who want to build one real full-stack chat application end to end, using TypeScript 5 across a Bun/Hono backend, PostgreSQL persistence, an OpenAI-powered feature, and a Svelte frontend. 【Book Arc】 - **Opening (~0%–10%)**: Orients you to the project and the stack. The preface maps the whole journey — TypeScript fundamentals, backend with Bun/Hono, PostgreSQL, OpenAI integration, then Svelte — so you know the destination before writing code. - **Early (~10%–30%)**: A TypeScript deep dive. Covers why static typing beats JavaScript's coercion quirks, then typing, narrowing, null handling, interfaces vs. classes, generics, and promises — the vocabulary the rest of the book assumes. - **Early–Middle (~30%–45%)**: Backend foundations. Sets up Bun with Hono, configures `tsconfig` and `package.json`, introduces middleware, defines database/API types, and implements JWT authentication with hashed passwords and per-request user context. - **Middle (~45%–55%)**: Reliability and hardening. Adds Zod validation for incoming data, Bun's test module, plus security, throttling, caching, and logging concerns — the "make it trustworthy" layer. - **Middle–Late (~55%–75%)**: Data and external services. Moves from in-memory storage to PostgreSQL in Docker, then to the `pg` library and Prisma ORM, and finally to resilient external API calls (fetch, retries, validation) and OpenAI API configuration. - **Late–Ending (~75%–100%)**: Frontend with Svelte. Introduces Svelte and SvelteKit/Vite setup, builds the chat UI with routing and state management, and closes with advanced techniques — testing, linting, accessibility, and internationalization. 【Key Takeaways】 - **TypeScript earns its place through static typing and narrowing** (Early): The book frames TS as a superset that only exists at development time, then shows practical narrowing (`unknown` → `number`, null guards, optional chaining, `??`) as the daily payoff over JavaScript's coercion traps. - **Interfaces define contracts; classes encapsulate behavior** (Early): A clear rule of thumb — use interfaces for data shapes and function parameters, classes for inheritance/polymorphism — reinforced with a worked abstract-resource example. - **Generics make components reusable without losing type safety** (Early): Introduced with a minimal `printValue<T>` example, then applied to the app's storage abstractions. - **Abstraction lets you swap storage implementations** (Middle): The app codes against an `IDatabaseResource` interface, so in-memory, SQL, and ORM backends can replace each other without touching types or callers — the book's central architectural move. - **Authentication is built in layers** (Middle): JWT middleware, a `JWT_SECRET` in `.env`, password hashing via `Bun.password`, and attaching the user ID to request context so controllers stay simple. - **Validation and testing are treated as first-class** (Middle): Zod schemas guard endpoint inputs (IDs, chat names, message content) and Bun's test module covers the code — reliability is a chapter, not an afterthought. - **Persistence progresses deliberately** (Middle–Late): PostgreSQL in Docker → raw SQL via `pg` → Prisma ORM, each step motivated by productivity, error reduction, and migration management. - **The frontend is the final integration point** (Late): Svelte/SvelteKit handles routing, state, and UI for the chat app, with a closing chapter on testing, linting, accessibility, and i18n for maintainability. 【Reading Tips】 - **Deep-read the TypeScript chapters (~10%–30%)** even if you know JS; the narrowing, generics, and interface/class guidance is reused constantly later. - **Skim setup/config passages** (Docker, `tsconfig`, `package.json`) if you're already comfortable — they're reference material you can return to. - **Follow the storage refactor closely** (in-memory → `pg` → Prisma): it's the clearest demonstration of the book's abstraction philosophy and the easiest place to get lost. - **Treat the OpenAI and Svelte sections as integration exercises** — read them with the GitHub repo open, since the excerpts show code-heavy, step-by-step instruction. - **Don't skip the validation/testing chapter**; it's where the app becomes something you'd actually ship. 【Coverage Limits】 The excerpts are mostly front matter, table of contents, and early/middle chapters; the OpenAI integration details and the Svelte chapters are only summarized at the chapter level, so this guide cannot vouch for their depth or specific code.
Excerpt 1
e full-stack development challenges. Who this book is for This book is for junior to mid-level software engineers with foundational knowledge of JavaScript a...
View in text
Excerpt 2
broad unknown type to a more specific type of number type. Further down in the code, we encounter the following instance of narrowing: if (messages !== null)...
View in text
Excerpt 3
un types, leading to the following content: tsconfig.json { "compilerOptions": { "strict": true, "esModuleInterop": true, "types": ["bun-types"] } } Adding m...
View in text
Excerpt 4
MemoryResource<DBUser, DBCreateUser>()), createChatApp( 5 Improving Reliability – Testing and Validation In Chapter 4, we put together the endpoints we need...
View in text
Excerpt 5
pe of common and dangerous attacks can be executed against our REST server and how we can protect against them: • SQL injection: SQL injection is a type of a...
View in text
Excerpt 6
C [1] LOG: database system is ready to accept connections Now, our database is accessible at localhost:5434 and is ready to be interacted with. Next, it is t...
View in text
Excerpt 7
se interactions. This integration allows us to efficiently store, retrieve, and manipulate data within our server, laying the groundwork for a robust and dyn...
View in text
Excerpt 8
ent string. Introduction to LLMs and their applications 157 • Context windows: The context window refers to the maximum number of tokens the model can consid...
View in text
Tags
AI categories
TypeScriptWeb TechnologyFull-Stack Development
ISBN: 1835885586
Publisher: Packt Publishing
Publish Year: 2024
Language: English
Pages: 272
File Format: PDF
File Size: 2.5 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…