Przejdź do głównej zawartości

Project Setup & Initialization

Ta treść nie jest jeszcze dostępna w Twoim języku.

Starting a new project can be overwhelming. There’s boilerplate to write, dependencies to configure, architecture decisions to make. Claude Code transforms this process from hours of manual setup into minutes of intelligent automation, while ensuring best practices from day one.

Scenario: It’s Monday morning. Your product manager just described a new microservice: “We need a REST API that handles user preferences, stores them in PostgreSQL, includes authentication, rate limiting, and comprehensive logging.” Traditional approach? Hours of setup. With Claude Code? Let’s see.

  1. Navigate to your workspace

    Terminal window
    cd ~/projects
    mkdir user-preferences-api && cd user-preferences-api
  2. Launch Claude Code

    Terminal window
    claude
  3. Describe your project

    > Create a Node.js REST API for user preferences with PostgreSQL,
    > JWT auth, rate limiting, structured logging, and Docker support.
    > Include tests and CI/CD pipeline.
  4. Watch the magic happen Claude analyzes your requirements, creates a complete project structure, installs dependencies, and provides a running application.

Within minutes, you have a production-ready codebase with:

  • Organized folder structure following best practices
  • Configured dependencies in package.json
  • Database schema and migrations
  • Authentication middleware
  • Rate limiting setup
  • Structured logging with Winston
  • Docker configuration
  • Jest test suite
  • GitHub Actions CI/CD pipeline

The secret to Claude Code’s effectiveness lies in context. The CLAUDE.md file serves as your project’s AI memory - a persistent context that survives across sessions.

> /init

Claude analyzes your project and generates a comprehensive CLAUDE.md:

# User Preferences API
## Overview
REST API for managing user preferences with PostgreSQL storage.
## Tech Stack
- Node.js 20.x
- Express.js
- PostgreSQL 15
- Redis (caching/sessions)
- Docker
## Commands
- `npm run dev` - Start development server
- `npm test` - Run test suite
- `npm run migrate` - Run database migrations
- `docker-compose up` - Start all services
## Architecture
- `src/routes/` - API endpoints
- `src/models/` - Database models
- `src/middleware/` - Auth, rate limiting
- `src/services/` - Business logic
## Environment Variables
Copy `.env.example` to `.env` and configure:
- DATABASE_URL
- JWT_SECRET
- REDIS_URL

Claude Code excels at creating project structures that grow with your needs. Let’s explore different initialization patterns.

> Create a microservices setup with API gateway, user service,
> notification service, and shared libraries. Use Docker Compose
> for local development.

Claude generates:

project/
├── docker-compose.yml
├── api-gateway/
│ ├── Dockerfile
│ ├── package.json
│ └── src/
├── services/
│ ├── user-service/
│ └── notification-service/
├── shared/
│ ├── auth-middleware/
│ └── error-handlers/
└── scripts/
├── setup-dev.sh
└── run-migrations.sh
> Set up a monorepo with Next.js web app, React Native mobile app,
> and shared component library. Use pnpm workspaces.

Result:

monorepo/
├── pnpm-workspace.yaml
├── apps/
│ ├── web/ # Next.js
│ └── mobile/ # React Native
├── packages/
│ ├── ui/ # Shared components
│ ├── api-client/ # API wrapper
│ └── utils/ # Common utilities
└── tooling/
├── eslint-config/
└── typescript-config/

Scenario: You’re tasked with modernizing a legacy Express.js application. Instead of a risky rewrite, you need to progressively enhance it with TypeScript, better structure, and modern patterns.

  1. Analyze existing codebase

    > Analyze this Express app and suggest a migration strategy to TypeScript
    > with minimal disruption to the running service
  2. Create migration plan

    > Create a phased migration plan that allows gradual TypeScript adoption
    > while keeping the app deployable at each step
  3. Execute phase 1

    > Implement phase 1: Add TypeScript configuration and convert the
    > simplest modules first
  4. Validate and iterate

    > Run the tests and ensure everything still works. What's next?

Claude handles the complexity of gradual migration:

  • Adds TypeScript configuration that works with existing JavaScript
  • Converts files incrementally, starting with leaf modules
  • Updates import statements as needed
  • Maintains backward compatibility
  • Suggests type definitions for external dependencies

Claude Code shines when setting up polyglot projects. Here’s how to bootstrap a full-stack application with multiple languages:

> Create a full-stack app: React frontend, Python FastAPI backend,
> Go microservice for image processing, PostgreSQL database,
> Redis cache, all containerized with Docker Compose

Claude orchestrates the entire setup:

Frontend (React + TypeScript)

  • Vite for fast builds
  • React Router for navigation
  • Tailwind CSS for styling
  • Axios for API calls
  • Environment-based configs

Backend (Python FastAPI)

  • Async request handling
  • SQLAlchemy ORM
  • Alembic migrations
  • Pydantic validation
  • JWT authentication

Microservice (Go)

  • Gin web framework
  • Image processing pipeline
  • gRPC for internal communication
  • Structured logging
  • Health checks

Infrastructure

  • Docker Compose orchestration
  • Nginx reverse proxy
  • PostgreSQL with init scripts
  • Redis configuration
  • Volume management

Claude Code can create sophisticated configuration management:

> Set up environment-specific configurations for development, staging,
> and production. Include secrets management and validation.

Generated structure:

config/
├── base.js # Shared settings
├── development.js # Local overrides
├── staging.js # Staging environment
├── production.js # Production settings
├── index.js # Smart loader
└── validate.js # Config validation
config/index.js
const env = process.env.NODE_ENV || 'development';
const baseConfig = require('./base');
const envConfig = require(`./${env}`);
// Deep merge configurations
const config = deepMerge(baseConfig, envConfig);
// Validate on startup
require('./validate')(config);
module.exports = config;

Scenario: You’re in a hackathon. Time is critical. You need to go from idea to demo in hours, not days.

> YOLO mode on. Create a real-time collaborative whiteboard app.
> Tech: Next.js, Socket.io, Canvas API, Vercel-ready.
> Skip the nice-to-haves, focus on core functionality.

Claude in YOLO mode prioritizes speed:

  • Minimal but functional setup
  • Core features only
  • Inline styles instead of complex CSS
  • Mock data instead of real database
  • Deploy-ready from the start

Claude Code can set up sophisticated Git workflows:

  1. Initialize with .gitignore

    > Initialize git repo with comprehensive .gitignore for Node.js,
    > environment files, IDE configs, and OS-specific files
  2. Create branch protection rules

    > Set up git flow with main, develop, and feature branches.
    > Include pre-commit hooks for linting and testing.
  3. Configure commit conventions

    > Set up conventional commits with commitizen and automatic
    > changelog generation

Result: A professionally configured repository with:

  • Comprehensive .gitignore
  • Pre-commit hooks via Husky
  • Commit message validation
  • Automatic versioning
  • Changelog generation
  • Branch protection scripts

Build reusable project templates:

> Create a reusable template for our company's microservices.
> Include our standard logging, monitoring, error handling,
> and deployment configurations.

Claude generates a template structure:

company-microservice-template/
├── .claude/
│ └── template.json # Template metadata
├── {{cookiecutter.project_name}}/
│ ├── src/
│ ├── tests/
│ ├── Dockerfile
│ └── package.json
├── hooks/
│ ├── pre_gen_project.py
│ └── post_gen_project.py
└── cookiecutter.json # Template variables
> Use our microservice template to create a new order-processing service

Claude:

  1. Loads the template
  2. Prompts for variables
  3. Generates the project
  4. Runs post-generation setup
  5. Initializes git repository
  6. Installs dependencies
> Configure VS Code for this project with recommended extensions,
> settings, and debug configurations

Generated .vscode/ folder:

.vscode/
├── extensions.json # Recommended extensions
├── settings.json # Project settings
├── launch.json # Debug configurations
└── tasks.json # Build tasks
> Set up GitHub Actions for CI/CD with testing, linting,
> security scanning, and deployment to AWS

Claude creates:

  • .github/workflows/ci.yml - Continuous Integration
  • .github/workflows/deploy.yml - Deployment pipeline
  • .github/dependabot.yml - Dependency updates
  • AWS deployment scripts
  • Environment secrets documentation

The more specific your initial prompt, the better the result:

❌ “Create a web app” ✅ “Create a Next.js e-commerce site with Stripe payments, user auth, and PostgreSQL”

Don’t expect perfection on the first try:

> The structure looks good, but add a separate services layer
> between controllers and models for business logic

If you have a similar project:

> Create a new project similar to ../existing-project but
> use PostgreSQL instead of MongoDB and add GraphQL API
> Update CLAUDE.md with the architectural decisions we just made

Create a setup-log.md:

> Document all the steps we took to set up this project
> so a new developer can understand our choices

You’ve learned how to go from zero to a running project in minutes. But setup is just the beginning. In the next lesson, we’ll explore how to analyze and understand existing codebases - a crucial skill when joining ongoing projects or maintaining legacy systems.

Remember: Claude Code isn’t just about writing code faster. It’s about starting projects the right way, with proper structure, best practices, and room to grow. Use these patterns to bootstrap your next project and watch your productivity soar.