
- Set up project structure with FastAPI application - Implement SQLAlchemy models for users, services, projects, team members, contacts - Create API endpoints for website functionality - Implement JWT authentication system with user roles - Add file upload functionality for media - Configure CORS and health check endpoints - Add database migrations with Alembic - Create comprehensive README with setup instructions
195 lines
5.7 KiB
Markdown
195 lines
5.7 KiB
Markdown
# Communications Agency API
|
|
|
|
A modern FastAPI backend for a communications and creative agency website.
|
|
|
|
## Features
|
|
|
|
- **User Authentication**: Secure JWT-based authentication with role-based access control
|
|
- **Services Management**: Create, update, and retrieve agency services
|
|
- **Portfolio Projects**: Manage case studies and client projects
|
|
- **Team Members**: Manage team profiles and details
|
|
- **Contact Form**: Handle client inquiries and messages
|
|
- **Site Settings**: Configure global site information
|
|
- **Media Upload**: Upload and manage images and documents
|
|
- **Admin Panel API**: Secure endpoints for site administration
|
|
|
|
## Technology Stack
|
|
|
|
- **Framework**: FastAPI
|
|
- **Database**: SQLite
|
|
- **ORM**: SQLAlchemy
|
|
- **Migration**: Alembic
|
|
- **Authentication**: JWT (JSON Web Tokens)
|
|
- **Validation**: Pydantic
|
|
- **Linting**: Ruff
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── alembic.ini
|
|
├── app
|
|
│ ├── api
|
|
│ │ ├── deps.py
|
|
│ │ └── v1
|
|
│ │ ├── api.py
|
|
│ │ └── endpoints
|
|
│ │ ├── auth.py
|
|
│ │ ├── contact.py
|
|
│ │ ├── health.py
|
|
│ │ ├── projects.py
|
|
│ │ ├── services.py
|
|
│ │ ├── settings.py
|
|
│ │ ├── team.py
|
|
│ │ ├── uploads.py
|
|
│ │ └── users.py
|
|
│ ├── core
|
|
│ │ ├── config.py
|
|
│ │ └── security.py
|
|
│ ├── crud
|
|
│ │ ├── base.py
|
|
│ │ ├── crud_contact.py
|
|
│ │ ├── crud_project.py
|
|
│ │ ├── crud_service.py
|
|
│ │ ├── crud_settings.py
|
|
│ │ ├── crud_team_member.py
|
|
│ │ └── crud_user.py
|
|
│ ├── db
|
|
│ │ ├── base.py
|
|
│ │ ├── base_class.py
|
|
│ │ └── session.py
|
|
│ ├── models
|
|
│ │ ├── contact.py
|
|
│ │ ├── project.py
|
|
│ │ ├── service.py
|
|
│ │ ├── settings.py
|
|
│ │ ├── team_member.py
|
|
│ │ └── user.py
|
|
│ ├── schemas
|
|
│ │ ├── contact.py
|
|
│ │ ├── project.py
|
|
│ │ ├── service.py
|
|
│ │ ├── settings.py
|
|
│ │ ├── team_member.py
|
|
│ │ ├── token.py
|
|
│ │ └── user.py
|
|
│ └── utils
|
|
│ ├── files.py
|
|
│ └── init_db.py
|
|
├── main.py
|
|
├── migrations
|
|
│ ├── README
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ └── versions
|
|
│ └── initial_migration.py
|
|
└── requirements.txt
|
|
```
|
|
|
|
## Setup and Installation
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8+
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone <repository-url>
|
|
cd communicationsagencywebsite
|
|
```
|
|
|
|
2. Create a virtual environment:
|
|
```bash
|
|
python -m venv venv
|
|
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
```
|
|
|
|
3. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
4. Set up environment variables:
|
|
```bash
|
|
# Create a .env file in the project root with the following variables
|
|
SECRET_KEY=your_secret_key_here
|
|
ADMIN_EMAIL=admin@example.com
|
|
ADMIN_PASSWORD=securepassword
|
|
```
|
|
|
|
5. Apply database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
### Running the API
|
|
|
|
Run the development server:
|
|
```bash
|
|
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000
|
|
|
|
API documentation:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## Environment Variables
|
|
|
|
| Variable | Description | Default |
|
|
|----------|-------------|---------|
|
|
| SECRET_KEY | JWT secret key for token generation | supersecretkey123 |
|
|
| ADMIN_EMAIL | Initial admin user email | None |
|
|
| ADMIN_PASSWORD | Initial admin user password | None |
|
|
| ACCESS_TOKEN_EXPIRE_MINUTES | Token expiration time in minutes | 11520 (8 days) |
|
|
|
|
## API Endpoints
|
|
|
|
### Authentication
|
|
- `POST /api/v1/auth/login` - Obtain JWT token
|
|
- `POST /api/v1/auth/register` - Register a new user
|
|
- `GET /api/v1/auth/me` - Get current user info
|
|
|
|
### Services
|
|
- `GET /api/v1/services` - List all services
|
|
- `POST /api/v1/services` - Create a new service (admin only)
|
|
- `GET /api/v1/services/{slug}` - Get service details
|
|
- `PUT /api/v1/services/{id}` - Update a service (admin only)
|
|
- `DELETE /api/v1/services/{id}` - Delete a service (admin only)
|
|
|
|
### Projects
|
|
- `GET /api/v1/projects` - List all projects
|
|
- `GET /api/v1/projects/featured` - List featured projects
|
|
- `POST /api/v1/projects` - Create a new project (admin only)
|
|
- `GET /api/v1/projects/{slug}` - Get project details
|
|
- `PUT /api/v1/projects/{id}` - Update a project (admin only)
|
|
- `DELETE /api/v1/projects/{id}` - Delete a project (admin only)
|
|
|
|
### Team
|
|
- `GET /api/v1/team` - List all team members
|
|
- `POST /api/v1/team` - Create a new team member (admin only)
|
|
- `GET /api/v1/team/{id}` - Get team member details
|
|
- `PUT /api/v1/team/{id}` - Update a team member (admin only)
|
|
- `DELETE /api/v1/team/{id}` - Delete a team member (admin only)
|
|
|
|
### Contact
|
|
- `POST /api/v1/contact` - Send a contact message
|
|
- `GET /api/v1/contact` - List all contact messages (admin only)
|
|
- `PUT /api/v1/contact/{id}/read` - Mark a contact message as read (admin only)
|
|
- `DELETE /api/v1/contact/{id}` - Delete a contact message (admin only)
|
|
|
|
### Settings
|
|
- `GET /api/v1/settings` - Get site settings
|
|
- `PUT /api/v1/settings` - Update site settings (admin only)
|
|
|
|
### Uploads
|
|
- `POST /api/v1/uploads/images` - Upload an image (admin only)
|
|
- `POST /api/v1/uploads/documents` - Upload a document (admin only)
|
|
- `DELETE /api/v1/uploads/{file_path}` - Delete an uploaded file (admin only)
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details. |