5.2 KiB
Seanime Development and Build Guide
Prerequisites
- Go 1.23+
- Node.js 18+ and npm
Build Process
1. Building the Web Interface
-
Build the web interface:
npm run build -
After the build completes, a new
outdirectory will be created insideseanime-web. -
Move the contents of the
outdirectory to a newwebdirectory at the root of the project.
2. Building the Server
Choose the appropriate command based on your target platform:
-
Windows (System Tray):
set CGO_ENABLED=1 go build -o seanime.exe -trimpath -ldflags="-s -w -H=windowsgui -extldflags '-static'" -
Windows (No System Tray) - Used by the desktop app:
go build -o seanime.exe -trimpath -ldflags="-s -w" -tags=nosystray -
Linux/macOS:
go build -o seanime -trimpath -ldflags="-s -w"
Important: The web interface must be built first before building the server.
Development Guide
Getting Started
The project is built with:
- Backend: Go server with REST API endpoints
- Frontend: React/Next.js web interface
For development, you should be familiar with both Go and React.
Setting Up the Development Environment
Server Development
-
Development environment:
- Create a dummy directory that will be used as the data directory during development.
- Create a dummy
webfolder at the root containing at least one file, or simply do the Building the Web Interface step of the build process. (This is required for the server to start.)
-
Run the server:
go run main.go --datadir="path/to/datadir"- This will generate all the files needed in the
path/to/datadirdirectory.
- This will generate all the files needed in the
-
Configure the development server:
- Change the port in the
config.tomllocated in the development data directory to43000. The web interface will connect to this port during development. Change the host to0.0.0.0to allow connections from other devices. - Re-run the server with the updated configuration.
The server will be available at
http://127.0.0.1:43000. - Change the port in the
Web Interface Development
-
Navigate to the web directory:
cd seanime-web -
Install dependencies:
npm install -
Start the development server:
npm run devThe development web interface will be accessible at
http://127.0.0.1:43210.
Note: During development, the web interface is served by the Next.js development server on port 43210.
The Next.js development environment is configured such that all requests are made to the Go server running on port 43000.
Understanding the Codebase Architecture
API and Route Handlers
The backend follows a well-defined structure:
-
Routes Declaration:
- All routes are registered in
internal/handlers/routes.go - Each route is associated with a specific handler method
- All routes are registered in
-
Handler Implementation:
- Handler methods are defined in
internal/handlers/directory - Handlers are documented with comments above each declaration (similar to OpenAPI)
- Handler methods are defined in
-
Automated Type Generation:
- The comments above route handlers serve as documentation for automatic type generation
- Types for the frontend are generated in:
seanime-web/api/generated/types.tsseanime-web/api/generated/endpoint.types.tsseanime-web/api/generated/hooks_template.ts
Updating API Types
After modifying route handlers or structs used by the frontend, you must regenerate the TypeScript types:
# Run the code generator
go generate ./codegen/main.go
AniList GraphQL API Integration
The project integrates with the AniList GraphQL API:
-
GraphQL Queries:
- Queries are defined in
internal/anilist/queries/*.graphql - Generated using
gqlgenc
- Queries are defined in
-
Updating GraphQL Schema: If you modify the GraphQL schema, run these commands:
go get github.com/Yamashou/gqlgenc@v0.25.4
cd internal/api/anilist
go run github.com/Yamashou/gqlgenc
cd ../../..
go mod tidy
- Client Implementation:
- Generated queries and types are in
internal/api/anilist/client_gen.go - A wrapper implementation in
internal/api/anilist/client.goprovides a cleaner interface - The wrapper also includes a mock client for testing
- Generated queries and types are in
Running Tests
Important: Run tests individually rather than all at once.
Test Configuration
- Create a dummy AniList account for testing
- Obtain an access token (from browser)
- Create/edit
test/config.tomlusingconfig.example.tomlas a template
Writing Tests
Tests use the test_utils package which provides:
InitTestProvidermethod to initialize the test configuration- Flags to enable/disable specific test categories
Example:
func TestSomething(t *testing.T) {
test_utils.InitTestProvider(t, test_utils.Anilist())
// Test code here
}
Testing with Third-Party Apps
Some tests interact with applications like Transmission and qBittorrent:
- Ensure these applications are installed and running
- Configure
test/config.tomlwith appropriate connection details
Notes and Warnings
- hls.js versions 1.6.0 and above may cause appendBuffer fatal errors